Skip to content

Commit

Permalink
test: no-fee case
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 26, 2024
1 parent 343d0f8 commit 7e9c592
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions test/invariants/fuzz/BMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ contract FuzzBMath is EchidnaTest {
// assert(tokenAmountIn <= calc_tokenAmountIn);
// }

uint256 constant SWAP_FEE_DELTA = 1e18;
uint256 constant TOLERANCE = 100e18;

// calcPoolOutGivenSingleIn * calcSingleOutGivenPoolIn should be equal to calcOutGivenIn
function fuzz_testIndirectSwaps_CalcOutGivenIn(
uint256 tokenBalanceIn,
Expand Down Expand Up @@ -174,14 +171,10 @@ contract FuzzBMath is EchidnaTest {
emit Log('poolSupply', poolSupply);
emit Log('swapFee', swapFee);

swapFee = swapFee * SWAP_FEE_DELTA / BONE;

uint256 calc_tokenAmountOut =
bmath.calcOutGivenIn(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountIn, swapFee);
bmath.calcOutGivenIn(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountIn, 0);
emit Log('calc_tokenAmountOut', calc_tokenAmountOut);

swapFee = swapFee * BONE / SWAP_FEE_DELTA;

uint256 calc_inv_poolAmountOut =
bmath.calcPoolOutGivenSingleIn(tokenBalanceIn, tokenWeightIn, poolSupply, totalWeight, tokenAmountIn, swapFee);
emit Log('calc_inv_poolAmountOut', calc_inv_poolAmountOut);
Expand All @@ -192,7 +185,7 @@ contract FuzzBMath is EchidnaTest {
emit Log('calc_inv_tokenAmountOut', calc_inv_tokenAmountOut);

assert(
calc_tokenAmountOut * TOLERANCE / BONE >= calc_inv_tokenAmountOut // direct path should be greater or equal to indirect path
calc_tokenAmountOut >= calc_inv_tokenAmountOut // direct path should be greater or equal to indirect path
);
}

Expand Down Expand Up @@ -225,14 +218,10 @@ contract FuzzBMath is EchidnaTest {
emit Log('poolSupply', poolSupply);
emit Log('swapFee', swapFee);

swapFee = swapFee * SWAP_FEE_DELTA / BONE;

uint256 calc_tokenAmountIn =
bmath.calcInGivenOut(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountOut, swapFee);
bmath.calcInGivenOut(tokenBalanceIn, tokenWeightIn, tokenBalanceOut, tokenWeightOut, tokenAmountOut, 0);
emit Log('calc_tokenAmountIn', calc_tokenAmountIn);

swapFee = swapFee * BONE / SWAP_FEE_DELTA;

uint256 calc_inv_tokenAmountIn =
bmath.calcPoolInGivenSingleOut(tokenBalanceOut, tokenWeightOut, poolSupply, totalWeight, tokenAmountOut, swapFee);
emit Log('calc_inv_tokenAmountIn', calc_inv_tokenAmountIn);
Expand All @@ -243,7 +232,7 @@ contract FuzzBMath is EchidnaTest {
emit Log('calc_inv_poolAmountIn', calc_inv_poolAmountIn);

assert(
calc_tokenAmountIn <= calc_inv_poolAmountIn * TOLERANCE / BONE // direct path should be lesser or equal to indirect path
calc_tokenAmountIn <= calc_inv_poolAmountIn // direct path should be lesser or equal to indirect path
);
}
}

0 comments on commit 7e9c592

Please sign in to comment.