Agentic MarketAgentic Market Docs
Protocol Architecture

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)

ContractSourceRuntime SizeEIP-170 MarginStatus
BinaryEnginecontract/src/BinaryEngine.sol24,076 B500 B (below 24,576 B)Implemented & Audited (V1)
AdapterRegistrycontract/src/AdapterRegistry.sol2,380 B22,196 BImplemented & Audited (V1)
AgentIdAdaptercontract/src/AgentIdAdapter.sol354 B24,222 BImplemented & Unit-Tested (V1)
MultiEngineScheduled for V1.1——Multi-outcome (N∈[3,5]N \in [3, 5])

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:

marketId=keccak256(abi.encode(key))\text{marketId} = \text{keccak256}(\text{abi.encode}(\text{key}))

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 (1 USDT=1061\ \text{USDT} = 10^6 units) with exact 101210^{12} boundary conversion:

amountWei=units×1012\text{amountWei} = \text{units} \times 10^{12}

This guarantees zero 1-wei drift (INV-5) while enabling aggressive single-slot storage packing:

  • uint48 (up to 281.47M USDT): Pool reserves (r0, r1), market collateral, feeAcc, vaultBalance, and vaultShares.
  • uint40 (up to 1.09M USDT): Individual user outcome shares (shares0, shares1) and saturating netCostBasis.
  • 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,000 gas, reading at most 32 bytes) 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).
  • AgentIdAdapter (Production BSC Mainnet Adapter):
    • Immutable, ownerless adapter targeting the SPACE ID .ai ERC-721 registry on BSC Mainnet (0x60B9262456dE011F7d15a54CdD8c48bAaa8B022F, checking balanceOf(account) > 0), with no internal try/catch or fallback logic (relying on AdapterRegistry's fail-closed staticcall guarantees).
    • Installed directly in AdapterRegistry's constructor initialAdapters list by contract/script/DeployMainnet.s.sol so it is active immediately at deployment without waiting out the 48-hour timelock. BSC Testnet (97) has no official registry and continues using MockAgentIdAdapter.