Created
June 7, 2023 07:48
-
-
Save codewithgun/20b3165c9e051bb5b5ef0e8a62dd49bb to your computer and use it in GitHub Desktop.
TraderJoe v2 fee overcharge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test_getFeeAmount() public { | |
// Configuration was copied from BTC.b/USDC pair | |
bytes32 params; | |
uint16 binStep = 10; | |
params = params.setStaticFeeParameters(10000, 30, 600, 5000, 40000, 1000, 350000); | |
// Set volatility accumulator to the max | |
params = params.setVolatilityAccumulator(350000); | |
// 5900000000000000 => 0.59% | |
console2.log("Total fee %s", totalFee); | |
uint128 totalFee = params.getTotalFee(binStep); | |
uint128 inAmount = 1234567; | |
uint128 feeAmount = inAmount.getFeeAmount(totalFee); | |
// feeAmount = 7328. However, Math.ceil(1234567 * 0.0059) = 7284. Extra 44 wei has been charged | |
console.log("Fee amount %s", feeAmount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment