Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [TimeLock Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/timelock)
- [Crowdfunding Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/crowdfunding)
- [Token Vault](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/token-vault)
- [Inventory Tracker](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/inventory-tracker)

### :three: Complex Applications
- [Constant Product AMM](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/constant-product-amm)
Expand Down
43 changes: 43 additions & 0 deletions inventory-tracker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "inventory-tracker"
version = "0.1.0"
edition = "2021"

exclude = [
"contract.wasm",
"hash.txt",
]

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
backtraces = ["cosmwasm-std/backtraces"]
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.10
"""

[dependencies]
cosmwasm-schema = "1.1.3"
cosmwasm-std = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
119 changes: 119 additions & 0 deletions inventory-tracker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Inventory Tracker Contract

This example shows a simple per-wallet inventory tracker.

Each wallet can add inventory items, increase or decrease quantities, update item metadata, delete records, and page through its own inventory. The contract owner controls the maximum number of records each wallet can keep.

## Features

- Independent inventory for each address.
- Sequential item IDs per user.
- SKU, item name, optional note, and quantity fields.
- Increase, decrease, and set quantity flows.
- Safe underflow checks when decreasing quantity.
- Owner-managed maximum item limit per user.
- Paginated item listing and item count queries.

## Instantiate

```json
{
"max_items_per_user": 100
}
```

## Execute

Add an item:

```json
{
"add_item": {
"sku": "HW-WALLET-01",
"name": "Hardware Wallet",
"quantity": "2",
"note": "Cold storage devices"
}
}
```

Increase quantity:

```json
{
"increase_quantity": {
"item_id": 1,
"amount": "3"
}
}
```

Decrease quantity:

```json
{
"decrease_quantity": {
"item_id": 1,
"amount": "1"
}
}
```

Update item metadata:

```json
{
"update_item": {
"item_id": 1,
"sku": "HW-WALLET-02",
"name": "Hardware Wallet Pro",
"note": null
}
}
```

Set quantity directly:

```json
{
"set_quantity": {
"item_id": 1,
"quantity": "10"
}
}
```

Delete an item:

```json
{
"delete_item": {
"item_id": 1
}
}
```

## Query

List a user's inventory:

```json
{
"user_items": {
"owner": "cosmos1owner...",
"start_after": null,
"limit": 10
}
}
```

Query one item:

```json
{
"item": {
"owner": "cosmos1owner...",
"item_id": 1
}
}
```
10 changes: 10 additions & 0 deletions inventory-tracker/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use inventory_tracker::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
Loading