When non-usdc and non-usdz asset is deposited to market, it is calculated as market and its connected vaults' realized debt. This will lead to serious miscalculation and malfunction of the protocol.
When user's order results in negative PnL or when user's position is getting liquidated, perps engine deposits part of user's collateral asset to market making engine via CreditDelegationBranch.depositCreditForMarket
. Essential part of the logic is as follows:
Before we dive into each if-else branches, let's recall how market's total debt is calculated in the current implementation:
, where
(*)
If collateral asset is usd token:
In this case, market.netUsdTokenIssuance
is decreased by deposited amount. Thus, market's total debt will be decreased by usd token deposit amount
If collateral asset is usdc
Below is market.settleCreditDeposit
source code
Since settledAsset == address(0)
, it does not affect market's totalDebt directly. But it increases usdcCreditPerVaultShare
and decreases realizedDebtUsdPerVaultShare
which all effectively decrease connected vault's debts
If collateral is non-usdz, non-usdc asset
According to Market.depositCredit
:
market's credit deposit value is increased by deposit amount. And from the formula (*), market's realizedDebtUsd
is increased!
This does not make sense in every perspect, including:
trader's negative PnL and liquidation are considered as house (market) win in all the other codebase. So, normal asset deposits should be considered as credit as well
usdc deposit and usdz deposit are considered as market credit, while equivalent worth of collateral asset being considered as market debt doesn't really make sense
Market's debt is distributed to connected vaults. When connected vault's debt is increased, indexTokenSwapRate
is decreased. So the conclusion is:
Liquidation providers will receive less assets on redeem in spite of perps market's gain.
Manual Review
Consider the following change when calculating market's realized debt usd
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.