The TSwapPool::getInputAmountBasedOnOutput
function is intended to calculate the amount of tokens a user should send in exchange of a specific amount of output tokens. However, the function currently miscalculates the resulting amount. When calculating the fee, it scales the amount by 10000 instead of 1000 required to calculate the 0.3% fee specified in the project's README.md
.
It reads: "The TSwap protocol accrues fees from users who make swaps. Every swap has a 0.3 fee, represented in getInputAmountBasedOnOutput and getOutputAmountBasedOnInput. Each applies a 997 out of 1000 multiplier. That fee stays in the protocol."
Protocol takes more fees than expected from users.
Correct calculation of the fee should be:
997 out of 1000
997 / 1000 = 0.997 | Multiplier
0.997 * 100 = 99.7% | Total after fee
100% - 99.7% = 0.3% | Fee
However, getInputAmountBasedOnOutput
currently calculates the fee as:
997 out of 10000
997 / 10000 = 0.0997 | Multiplier
0.0997 * 100 = 9.97% | Total after fee
100% - 9.97% = 90.03% | Fee
Every time a user swaps with TSwapPool:swapExactOutput
, fee is miscalculated.
Include this test in TSwapPool.t.sol
:
Foundry and manual review
Don't use magic numbers, declare them as constants instead.
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.