In the function CreditDelegationBranch::settleVaultsDebt
, when the vault is in credit, the protocol only needs to swap the excess USDC to asset. However, the current approach involves estimating the amount of USDC needed to obtain the required amount of the vault's asset, which leads to unnecessary swaps and potential deficits in the vault's USDC balance.
The problematic code snippet is as follows:
Example Scenario:
Debt: 100.000 USDC
USDC Balance: 120.000 USDC
Excess USDC (in credit): 120.000 - 100.000 = 20.000 USDC
In this case, the protocol only needs to swap the excess 20.000 USDC into the vault asset. However, the protocol is currently performing the following:
Convert 20.000 USDC to vault asset (x
).
Estimate the amount of USDC (y
) required by the DEX to get x
vault asset.
Swap y
USDC to get the vault asset.
The amount of USDC needed (y
) can be more than the 20.000 USDC originally available. For example, due to the DEX’s behavior, the calculated amount y
might be 20.020 USDC, which is more than the 20.000 USDC the protocol originally wanted to swap. As a result, the protocol will end up with a deficit of 20 USDC.
The current approach of estimating the amount of USDC needed for swaps in the settleVaultsDebt
function introduces several issues, including potential deficits in the vault's USDC balance, inefficient use of resources from unnecessary swaps. Additionally, the added complexity of estimation increases the risk of errors and unpredictability in the debt settlement process, making the protocol harder to maintain and less reliable.
Instead of estimating the USDC required and potentially swapping more than the excess 20.000 USDC, the protocol should directly swap the exact 20.000 USDC to obtain the necessary vault asset. This approach eliminates any risk of excess swap amounts.
The Correct Process:
Directly swap 20.000 USDC to the vault asset (which is exactly what is needed to cover the debt).
Avoid unnecessary estimation or excess swaps.
By directly swapping the exact amount of excess USDC to the vault asset, the protocol ensures it doesn't end up in a deficit.
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.