Smart Contracts (V5.0)
Immutable Dual Singletons, Commit-to-ID MarketKey, 6-decimal internal scaling, bit-packed storage, EIP-1153 reentrancy protection, and AdapterRegistry.
Agentic Market V5.0 compiles with solc 0.8.28, evm_version = "cancun", via_ir = true, optimizer_runs = 1, and Solady (FixedPointMathLib, SafeTransferLib).
Deployed Contract Footprint (forge build --sizes)
| Contract | Source | Runtime Size | EIP-170 Margin | Status |
|---|---|---|---|---|
BinaryEngine | contract/src/BinaryEngine.sol | 24,076 B | 500 B (below 24,576 B) | Implemented & Audited (V1) |
AdapterRegistry | contract/src/AdapterRegistry.sol | 2,380 B | 22,196 B | Implemented & Audited (V1) |
AgentIdAdapter | contract/src/AgentIdAdapter.sol | 354 B | 24,222 B | Implemented & Unit-Tested (V1) |
MultiEngine | Scheduled for V1.1 | — | — | Multi-outcome () |
100% Immutable & Zero Router
BinaryEngine has no upgrade proxy, no delegatecall, no unpause(), and no admin collateral withdrawal. Traders grant USDT.approve(BinaryEngine, amount) directly and interact with BinaryEngine with msg.sender unconditionally treated as the trader.
Commit-to-ID (MarketKey)
Static market configuration is never written to contract storage. Instead, every market is identified by:
Every function accepts MarketKey calldata key and hashes it using assembly ("memory-safe") (calldatacopy + keccak256 across 17 ABI words / 544 B). Mutating any single bit in cutoffTime, seed, maxPosition, initialProbBps, startPrice, or rulesHash hashes to an uninitialized marketId and reverts with MarketNotInitialized (INV-7).
6-Decimal Internal Scaling & Single-Slot Bit-Packing
BSC USDT uses 18 decimals on-chain. Internally, EngineBase and BinaryEngine run on 6-decimal integer units ( units) with exact boundary conversion:
This guarantees zero 1-wei drift (INV-5) while enabling aggressive single-slot storage packing:
uint48(up to281.47M USDT): Pool reserves (r0,r1), marketcollateral,feeAcc,vaultBalance, andvaultShares.uint40(up to1.09M USDT): Individual user outcome shares (shares0,shares1) and saturatingnetCostBasis.- Single-Slot Packing:
BinaryPool= 1 storage slot;BinaryPosition= 1 storage slot;VaultState(Leaky Bucket) = 1 storage slot.
EIP-1153 Transient Storage & AdapterRegistry
- Transient Reentrancy Guard: Uses EVM Cancun
TSTORE/TLOAD(ReentrancyGuardTransient, active on BSC since the June 2024 Haber hardfork) to block cross-market reentrancy at ~200 gas. AdapterRegistry(Buy-Only Gate):- Enforces a mandatory 48-hour timelock (
scheduleAdapterChange→executeAdapterChange) for adding or removing adapters. - Queries external adapters via bounded
staticcall(50,000gas, reading at most32bytes) to neutralize return-data bombs and fail closed on revert, out-of-gas, or malformed booleans. - Queried exclusively inside
buy(). All exit paths (sell(),redeem(),redeemVoid(),redeemBatch(),withdrawBond()) are permanently adapter-free (INV-8).
- Enforces a mandatory 48-hour timelock (
AgentIdAdapter(Production BSC Mainnet Adapter):- Immutable, ownerless adapter targeting the SPACE ID
.aiERC-721 registry on BSC Mainnet (0x60B9262456dE011F7d15a54CdD8c48bAaa8B022F, checkingbalanceOf(account) > 0), with no internaltry/catchor fallback logic (relying onAdapterRegistry's fail-closed staticcall guarantees). - Installed directly in
AdapterRegistry's constructorinitialAdapterslist bycontract/script/DeployMainnet.s.solso it is active immediately at deployment without waiting out the 48-hour timelock. BSC Testnet (97) has no official registry and continues usingMockAgentIdAdapter.
- Immutable, ownerless adapter targeting the SPACE ID