perpetuals icon indicating copy to clipboard operation
perpetuals copied to clipboard

Issue with Interest fee calculations

Open mzs-dev opened this issue 2 years ago • 4 comments
trafficstars

@askibin The interest amount being calcualted in usd value using position.size_usd is not appropriate. https://github.com/solana-labs/perpetuals/blob/30b9f8c344df14568475fa621dea1db7af15a6b3/programs/perpetuals/src/state/custody.rs#L312

Ideally Interest should be charged on the locked_amount assets that are collateralising the postions for pnl payoff and accounted accordingly.

mzs-dev avatar Jun 22 '23 22:06 mzs-dev

Also, the collective position handling invokes the get_interest_amount_usd() function under the context of the worng custody. For isntance: https://github.com/solana-labs/perpetuals/blob/85dc9ed43718590d1008c6bdd209d3c0091298ae/programs/perpetuals/src/instructions/open_position.rs#L346 Invokes: https://github.com/solana-labs/perpetuals/blob/85dc9ed43718590d1008c6bdd209d3c0091298ae/programs/perpetuals/src/state/custody.rs#L444

To solve this issue we propose a seperate "market" state once https://github.com/solana-labs/perpetuals/issues/16#issue-1770458393 is solved

mzs-dev avatar Jul 03 '23 11:07 mzs-dev

why do you think it is the wrong custody? a trader borrows the trade token not stablecoin so interest should be calculated on "custody" and not "collateral_custody"

askibin avatar Jul 03 '23 13:07 askibin

Only true for longs... Trader does not borrow the trade token, he borrows/locks the same token as the collateral token. For example, when a trader opens a short position, he brings stable-coin collateral and we should lock the same... Hence to solve for the possibiltiy of a many-many relationship between (position) custody and collateral custody we want to introduce a link-account state known as Market and handle this accordingly

mzs-dev avatar Jul 06 '23 10:07 mzs-dev

Any update here? Is this actually a current issue?

jakerumbles avatar Mar 21 '24 20:03 jakerumbles

this was changed to use collateral custody

askibin avatar Jan 01 '25 19:01 askibin