Palmswap
Ask or search…
K

Architecture and Infrastructure

Architecture overview

In general, there are 4 main components
  • Order managers: periphery contracts, e.g. Router, PositionRouter, OrderBook, etc. are the API for Palmswap. They receive user's orders, transfer fund, and store on-chain order info.
  • Vault is 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.

Use case flow

  • User call createIncreasePosition for opening and createDecreasePosition for closing a position to PositionRouter contract. This function call includes collateral and long/short info, e.g. index token, accepted price, size, etc. The PositionRouter will 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.