The Fee Collection Lifecycle

Fee Collection

Based on the Jupiter system of fee accrual, fees are accrued in pnl variables in the Position Lifecycle and Liquidation Lifecycle. While the tokens never actually leave the Custody token account, they actually do leave the base, owned, and locked variables and so are unavailable for use.

Specifically, realized_fee_usd on Pool and fee_reserves on the child Custody's assets object are used to track how many fees are owed to the two objects.

Fee Cranks

A permissioned crank at a daily interval will hit the clear_fee_reserves on each Custody, with the following account data:

#[derive(Accounts)]
pub struct ClearFeeReserves<'info> {
    #[account(mut, has_one = state)]
    pub pool: Box<Account<'info, Pool>>,
    pub admin: Signer<'info>,
    #[account(
        has_one = admin,
        seeds = [b"state"],
        bump)]
    pub state: Box<Account<'info, State>>,
    #[account(
        mut,
        has_one = pool,
        seeds = [b"custody", pool.key().as_ref(), custody.mint.as_ref()],
        bump
    )]
    pub custody: Box<Account<'info, Custody>>,
}

Each time this is hit, base and owned on the Custody is increased, fee_reserves is set to 0, and realized_fee_usd on Pool is decreased by the amount that fee_reserves was decreased by. In this way, the tokens already present in the token account become available for use for lending and for swapping out by LPs.

Future Considerations

We plan to open up this endpoint in a permissionless way in the future once proper audits have been completed, and attach to it a rewards system for those who run it. We do not have a timeline on this.

Last updated