Architecture and Infrastructure
In general, there are 4 main components
- Order managers: periphery contracts, e.g.
OrderBook, etc. are the API for Palmswap. They receive user's orders, transfer fund, and store on-chain order info.
Vaultis the contract that holds liquidity and handle trading function, e.g. open/close/liquidate positions.
- Price feeds: contracts that contain prices from multiple sources, e.g. CEX, on-chain pool, Chainlink, off-chain oracles.
- Executors: off-chain components that update price to price feed contracts. They also check if the conditions of user's orders are met to submit execution transactions to order manager contracts.
In short, users submit orders to order managers, then executors watch the conditions. If the conditions are met, executors send execution signals to order managers. The order managers check the condition again, then call trading functions of the vault. The vault will use price from price feeds for calculations.
- User call
createIncreasePositionfor opening and
createDecreasePositionfor closing a position to
PositionRoutercontract. This function call includes collateral and long/short info, e.g. index token, accepted price, size, etc. The
PositionRouterwill get fund (collateral) from the client, store the order and emit an event. Off-chain components called position keepers will read events, then they update prices and execute orders together.
*Note: Executors are called keepers.