caelum0x f9ee823b39 feat(contracts): ModelVault — CosmWasm bonding-curve market for AI model tokens (P2)
P2 of the AI-model-tokens plan: a standalone CosmWasm contract giving a model token a
constant-product market vs a CLAW reserve — buy/sell it like a stock.

contracts/model-vault/ (standalone crate, NOT in the dex workspace; cosmwasm-std 2.x,
cw-storage-plus, cw-multi-test):
- Fund (owner) / Buy / Sell over a native tokenfactory model-token coin vs uclaw,
  constant-product k = reserve*inventory (Uint256 intermediates), exactly-one-coin
  validation, BankMsg::Send payouts, InsufficientInventory/Reserve guards.
- reserve + inventory tracked explicitly in STATE (cw-storage-plus Items), NOT inferred
  from live contract balance — avoids the CosmWasm funds-double-count gotcha (info.funds
  are credited before execute runs). Documented in state.rs.
- Queries: Config / Pool / Quote (pure curve math).
- 7 curve unit tests + 11 cw-multi-test integration tests (buy/sell math, price rises
  after Buy / falls after Sell, insufficient-inventory, wrong-coin, round-trip
  conservation). clippy + fmt clean.
- wasm32 release build: model_vault.wasm 228KB, standard cosmwasm-std only (deployable
  under the chain's BuiltInCapabilities + token_factory caps).
- scripts/testnet/model-vault-demo.sh: live store->instantiate->Fund->Buy->Sell demo.

Verified independently: cargo build + cargo test (18 pass) + wasm build all green.
v0 is fee-less (dust drift bounded by a round-trip test); revenue/dividend pool is the
next P2 slice.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 17:47:16 +03:00

2 lines
8 B
Plaintext