CreditDelegationBranch.calculateSwapAmount
returns an expected output amount, but in the case of swapping the
vault asset to usdc, settleVaultsDebt
uses the function to decide the input amount.
For example, suppose a uniswap v2 ETH/USDC pool and there are (10 ETH, 30000 USDC) in the pool, so the invariant is
xy = 300000.
When a user sells 1 ETH, the invariant becomes (10 + 1) * (30000 - outputUSDC) = 300000, the output USDC is
(30000 - 27272) = 2728.
When a user buys 1 ETH, the invariant beomces (10 - 1) * (30000 + inputUSDC) = 300000, the input USDC is
(33333 - 30000) = 3333.
So it is not the same to calculate the input amount and the output amount.
In CreditDelegationBranch.settleVaultsDebt
, calculateSwapAmount
is used to calculate the swap input amount of vault
asset.
However, calculateSwapAmount
returns the expected output amount of assetOut.
This is same for the else block in the same function settleVaultsDebt
.
If the input amount is calculated lower than the actual amount, the vault may not be able to settle all its debt.
If the input amount is calculated higher than the actual amount, settleVaultsDebt
will revert.
Manual review
Rename CreditDelegationBranch.calculateSwapAmount
to calculateExpectedSwapOutput
.
Implement a separate CreditDelegationBranch.calculateSwapInputAmount
function to calculate the input amount for the swap.
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.