Skip to content

Commit

Permalink
test: update bin pool test around protoocl fee
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefMist committed Oct 18, 2024
1 parent 2697472 commit 7d1ccfa
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions test/pool-bin/libraries/math/PackedUint128Math.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,37 @@ contract PackedUint128MathTest is Test {
amounts.getProtocolFeeAmt(protocolFee, swapFee);
}

function test_getProtocolFeeAmt() external pure {
function test_getProtocolFeeAmtX() external pure {
{
// 0% fee
bytes32 x = uint128(100).encode(uint128(100));
uint24 fee = (0 << 12) + 0; // amt / 0 = 0%
assertEq(x.getProtocolFeeAmt(fee, 0), 0);
bytes32 totalFee = uint128(100).encode(uint128(100));
uint24 protocolFee = (0 << 12) + 0; // 0% fee
assertEq(totalFee.getProtocolFeeAmt(protocolFee, 0), 0);
}

{
// 0.01% fee
bytes32 x = uint128(10000).encode(uint128(10000));
uint24 fee = (100 << 12) + 100;
bytes32 totalFee = uint128(10_000).encode(uint128(10_000));
uint24 protocolFee = (100 << 12) + 100; // 0.01% fee

// lpFee 0%
assertEq(x.getProtocolFeeAmt(fee, 100), uint128(10000).encode(uint128(10000)));
assertEq(totalFee.getProtocolFeeAmt(protocolFee, 100), uint128(10_000).encode(uint128(10_000)));
}

{
// 0.1% fee
bytes32 x = uint128(10000).encode(uint128(10000));
uint24 fee = (1000 << 12) + 1000;
bytes32 totalFee = uint128(10_000).encode(uint128(10_000));
uint24 protocolFee = (1000 << 12) + 1000; // 0.1% fee

// 0.3% lp fee => swap fee 0.3997%
uint24 swapFee = ProtocolFeeLibrary.calculateSwapFee(1000, 3000);
assertEq(x.getProtocolFeeAmt(fee, swapFee), uint128(2501).encode(uint128(2501)));
uint24 swapFee = ProtocolFeeLibrary.calculateSwapFee(1000, 3000); // 0.1% protocolFee, 0.3% lpFee
// protocolFee is roughly more than 1/4 as protocolFee is taken out first
assertEq(totalFee.getProtocolFeeAmt(protocolFee, swapFee), uint128(2501).encode(uint128(2501)));
}

{
bytes32 totalFee = uint128(10_000).encode(uint128(10_000));
uint24 protocolFee = (4000 << 12) + 4000; // 0.4% fee

uint24 swapFee = ProtocolFeeLibrary.calculateSwapFee(4000, 3000);
// protocolFee is roughly more than 4/7 as protocolFee is taken out first
assertEq(totalFee.getProtocolFeeAmt(protocolFee, swapFee), uint128(5724).encode(uint128(5724)));
}
}
}

0 comments on commit 7d1ccfa

Please sign in to comment.