COPESolanaStakePlayCommunityUnderlineUnderlineUnderlineCope rectangleCope circleCope triangleCope batsuCope heartDots

Trading Pools

COPE trading pools are on-chain pools in which users can deposit COPE. User deposits is represented by a pool token, which automatically increase or decrease in value proportionally to the trading pool.

Trading

The trading pools are run on calls from COPE Leaderboard participants. These pools can open spot orders on Mango Markets with the deposited COPE as collateral.

Depositing

Users can deposit COPE into the trading pool and will receive a number of pool tokens that is proportional to the net value of their deposit and net value of the trading pool.

For example, if a uses deposits 10 COPE value at $50 and the trading pool value is $50,000, their proportional deposit represents 0.1% of the total pool value. If the pool token supply is 5,000 the user will receive 0.1% * 5,000 = 5 pool tokens.

npt=vdepositvaccountsupplyptn_{pt} = \frac{v_{deposit}}{v_{account}} \cdot supply_{pt}

Withdraws

Users can at any time withdraw exchange pool tokens for deposited funds + ROI from the trading pool.

nCOPE=nptvaccountsupplyptpCOPEn_{COPE} = \frac{n_{pt} \cdot v_{account}}{supply_{pt} \cdot p_{COPE}}

Withdraw of funds is instant, however because Mango markets enables margin trading, the trading pool will disable withdraws in case the account health falls below a certain level to protect itself from liquidations. If this happens, currently a manual re-adjust of open positions is necessary to improve account health, and users can continue to withdraw.

Security

The trading pool program uses a number of PDAs to secure its operations.

  • Trading authority PDA is used to interact with Mango markets.
  • Minting authority PDA is used to mint new pool tokens.

The only available operations to the pool are opening / cancelling stop orders (prep coming in v2). Additionally there is no admin/privileged access to the trading pool that would enable anyone to withdraw the mango account funds or mint new pool tokens.

Challenges

Some operations like withdrawing are computationally expensive, which requires us to find novels ways to deal with constraints of the Solana runtime. For this reason we are finding ways to chain instructions and contribute this back to Anchor.