Skip to content

Developers

Contracts

The seven contracts behind Stonkboxx (baskets + options) and how they fit together.

All contracts live in the contracts/ folder of the repository and are built and tested with Foundry.

ContractRole
MockUSDC6 decimal test USDC with a one hour faucet
Asset8 decimal token for each stock or prediction outcome, with a UI multiplier like B20
PriceOracleKeeper pushed prices with 8 decimals and a staleness limit (updated every 2h by Convex)
BasketRegistryBaskets, weights, versions, curation and votes
BasketRouterBuy, sell and rebalance in one transaction, fee split to creator, referrer and treasury
OptionVaultSingle-writer weekly epoch vault for USDC (Floor puts) and 14 stock pools (Gap calls)
OptionMarketERC-1155 option positions, realized-vol × session pricing, oracle-free exercise & settle, and sellBack

Flow

  1. The user approves USDC to the router.
  2. buy(basketId, usdcIn, minValueOut, referrer) takes the USDC, pays the fee split and mints every asset by weight at oracle prices.
  3. sell(assets, amounts, minUsdcOut) burns assets and pays USDC at oracle prices minus the fee.
  4. rebalance(basketId, minValueOut) values the caller's holdings of that basket and moves them to the current weights.

One purchase, every holding

Buy a basketApprove USDC, then buy. The router takes the fee and mints each simulated asset to your wallet.01 / PAY IN USDCYour wallet$100.00 USDCBasket router$99.80 after fee02 / SPLIT BY WEIGHTNVDAc30% · $29.94AVGOc25% · $24.95MUc25% · $24.95AMDc20% · $19.96
Buy a basketApprove USDC, then buy. The router takes the fee and mints each simulated asset to your wallet.01 / PAY IN USDCYour wallet$100.00 USDCBasket router$99.80 after fee · one purchaseNVDAc30% · $29.94AVGOc25% · $24.95MUc25% · $24.95AMDc20% · $19.96
A $100 purchase at the default 0.20% fee leaves $99.80 to allocate: 30%, 25%, 25% and 20%. A separate USDC approval may be needed first.

Units

ValueDecimals
USDC6
Prices & option strikes8
Asset amounts8 (1 option lot = 1e6 = 0.01 shares)
Weightsbasis points, sum 10000
value in USDC = amount x price / 1e10

Mainnet mapping

A mainnet implementation would require real trade routing, liquidity and issuer integration. Those execution paths are not implemented by the demo's mint-and-burn router. Testnet assets have no redemption rights. Builder attribution is attached only when a builder code is configured.

Deployed addresses are in contracts/deployments/84532.json.

Trust and permissions

The registry owner controls the tradable asset allowlist and curated status. Basket creators can change their own weights and metadata. The oracle keeper updates prices; the asset owner or keeper can resolve prediction outcomes. Contract owners can update privileged configuration, and the router owner can pause trading and change the fee up to its 1% cap.

These powers make this an operator-run simulation. The contracts are not independently audited. Existing tests cover access control, invalid allocations, fee splits, stale prices, slippage and fuzzed value conservation; passing tests is not a security certification.

Local development

Use Node 22.18 or newer and Foundry. From the repository root:

npm ci
npm run dev
npm run lint
npm run typecheck
npm run build
node --test tests/*.test.mjs

Run contract tests separately with forge test from contracts/. This does not broadcast transactions. Deployment and keeper scripts need explicit environment configuration; never expose their private key through a NEXT_PUBLIC_ variable.

Live price updates

A Convex cron job (convex/crons.ts) runs every 2 hours (12 runs/day) to fetch live Base DEX prices from GeckoTerminal, push them to PriceOracle, and record the latest quotes in Convex. Server-rendered pages (/options and /baskets/[slug]) overlay these live quotes with 5-minute ISR caching (revalidate = 300) to stay well within the Convex free plan.

Deployment sources

contracts/deployments/84532.json and contracts/deployments/84532-options.json record the Base Sepolia deployment. scripts/sync-deployment.mjs merges both into lib/deployment.json for the web app. After a deliberate redeployment, sync addresses and ABIs (node contracts/scripts/export-abi.mjs) together before rebuilding the interface.

The AI API key stays on the server. See .env.example for optional AI, RPC and attribution settings. The app can render without an AI key; AI requests then return an unavailable response.