We represent the protocol smart contract functionality using the OpenAPI spec, where writes map to
POST
and reads to GET
. For simplicity, we sometimes refer to the user positions as “tokens”, even though they are not represented as tokens/ERC20s.Protocol Architecture
The protocol consists of four main components:- BasedProtocol: The main contract that manages protocol-wide settings, coordinates market creation, and handles market deployment using the clone pattern. Emits events.
- BasedMarket: Implementation of the market logic and position management. Buying, selling, claiming fees is done here. Emits events.
- BasedMarketRouter: Router contract that provides a simplified interface for interacting with markets. Does not emit events in itself.
- Interfaces: Standardised interfaces for contract interaction.

Events
The core events to track state changes are:- Protocol
CreatorFeeUpdated(uint8 newFee);
MarketCreated(uint64 indexed marketCounter, address indexed marketAddress, address indexed creator);
MarketImplementationUpdated(address indexed newImplementation);
InitialAmmLevelUpdated(uint64 newLevel);
ProtocolFeeUpdated(uint8 newRate);
- Market
Buy(address indexed user, uint256 usdAmount, bool boughtBased, uint256 tokensReceived);
Sell(address indexed user, uint256 tokensAmount, bool soldBased, uint256 usdReceived);
CreatorFeesClaimed(uint256 amount);
ProtocolFeesClaimed(uint256 amount);
CreatorFeeRecipientChanged(address indexed newRecipient);