swap amounts
This commit is contained in:
@@ -316,7 +316,7 @@ contract PartyPoolTest is Test {
|
||||
token2.approve(address(pool), type(uint256).max);
|
||||
|
||||
// Inspect the deposit amounts that the pool will require (these are rounded up)
|
||||
uint256[] memory deposits = pool.computeMintAmounts(1);
|
||||
uint256[] memory deposits = pool.mintDepositAmounts(1);
|
||||
|
||||
// Basic sanity: deposits array length must match token count and not all zero necessarily
|
||||
assertEq(deposits.length, 3);
|
||||
@@ -358,7 +358,7 @@ contract PartyPoolTest is Test {
|
||||
uint256 totalLpBefore = pool.totalSupply();
|
||||
|
||||
// Compute required deposits and perform mint for 1 wei
|
||||
uint256[] memory deposits = pool.computeMintAmounts(1);
|
||||
uint256[] memory deposits = pool.mintDepositAmounts(1);
|
||||
|
||||
// Sum deposits as deposited_value
|
||||
uint256 depositedValue = 0;
|
||||
@@ -392,14 +392,14 @@ contract PartyPoolTest is Test {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
/// @notice computeMintAmounts should round up deposit amounts to protect the pool.
|
||||
function testComputeMintAmountsRoundingUp() public view {
|
||||
/// @notice mintDepositAmounts should round up deposit amounts to protect the pool.
|
||||
function testMintDepositAmountsRoundingUp() public view {
|
||||
uint256 totalLp = pool.totalSupply();
|
||||
assertTrue(totalLp > 0, "precondition: total supply > 0");
|
||||
|
||||
// Request half of LP supply
|
||||
uint256 want = totalLp / 2;
|
||||
uint256[] memory deposits = pool.computeMintAmounts(want);
|
||||
uint256[] memory deposits = pool.mintDepositAmounts(want);
|
||||
|
||||
// We expect each deposit to be roughly half the pool balance, but due to rounding up it should satisfy:
|
||||
// deposits[i] * 2 >= cached balance (i.e., rounding up)
|
||||
@@ -416,7 +416,7 @@ contract PartyPoolTest is Test {
|
||||
assertTrue(totalLp > 0, "precondition: LP > 0");
|
||||
|
||||
// Compute amounts required to redeem entire supply (should be current balances)
|
||||
uint256[] memory withdrawAmounts = pool.computeBurnAmounts(totalLp);
|
||||
uint256[] memory withdrawAmounts = pool.burnReceiveAmounts(totalLp);
|
||||
|
||||
// Sanity: withdrawAmounts should equal pool balances (or very close due to rounding)
|
||||
for (uint i = 0; i < withdrawAmounts.length; i++) {
|
||||
@@ -632,8 +632,8 @@ contract PartyPoolTest is Test {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
/// @notice Verify computeMintAmounts matches the actual token transfers performed by mint()
|
||||
function testComputeMintAmountsMatchesMint_3TokenPool() public {
|
||||
/// @notice Verify mintDepositAmounts matches the actual token transfers performed by mint()
|
||||
function testMintDepositAmountsMatchesMint_3TokenPool() public {
|
||||
// Use a range of LP requests (tiny to large fraction)
|
||||
uint256 totalLp = pool.totalSupply();
|
||||
uint256[] memory requests = new uint256[](4);
|
||||
@@ -646,7 +646,7 @@ contract PartyPoolTest is Test {
|
||||
if (req == 0) req = 1;
|
||||
|
||||
// Compute expected deposit amounts via view
|
||||
uint256[] memory expected = pool.computeMintAmounts(req);
|
||||
uint256[] memory expected = pool.mintDepositAmounts(req);
|
||||
|
||||
// Ensure alice has tokens and approve pool
|
||||
vm.startPrank(alice);
|
||||
@@ -660,7 +660,7 @@ contract PartyPoolTest is Test {
|
||||
uint256 a2Before = token2.balanceOf(alice);
|
||||
|
||||
// Perform mint (may revert for zero-request; ensure req>0 above)
|
||||
// Guard: if computeMintAmounts returned all zeros, skip (nothing to transfer)
|
||||
// Guard: if mintDepositAmounts returned all zeros, skip (nothing to transfer)
|
||||
bool allZero = (expected[0] == 0 && expected[1] == 0 && expected[2] == 0);
|
||||
if (!allZero) {
|
||||
uint256 lpBefore = pool.balanceOf(alice);
|
||||
@@ -679,8 +679,8 @@ contract PartyPoolTest is Test {
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Verify computeMintAmounts matches the actual token transfers performed by mint() for 10-token pool
|
||||
function testComputeMintAmountsMatchesMint_10TokenPool() public {
|
||||
/// @notice Verify mintDepositAmounts matches the actual token transfers performed by mint() for 10-token pool
|
||||
function testMintDepositAmountsMatchesMint_10TokenPool() public {
|
||||
uint256 totalLp = pool10.totalSupply();
|
||||
uint256[] memory requests = new uint256[](4);
|
||||
requests[0] = 1;
|
||||
@@ -691,7 +691,7 @@ contract PartyPoolTest is Test {
|
||||
uint256 req = requests[k];
|
||||
if (req == 0) req = 1;
|
||||
|
||||
uint256[] memory expected = pool10.computeMintAmounts(req);
|
||||
uint256[] memory expected = pool10.mintDepositAmounts(req);
|
||||
|
||||
// Approve all tokens from alice
|
||||
vm.startPrank(alice);
|
||||
@@ -742,8 +742,8 @@ contract PartyPoolTest is Test {
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Verify computeBurnAmounts matches actual transfers performed by burn() for 3-token pool
|
||||
function testComputeBurnAmountsMatchesBurn_3TokenPool() public {
|
||||
/// @notice Verify burnReceiveAmounts matches actual transfers performed by burn() for 3-token pool
|
||||
function testBurnReceiveAmountsMatchesBurn_3TokenPool() public {
|
||||
// Use address(this) as payer (holds initial LP from setUp)
|
||||
uint256 totalLp = pool.totalSupply();
|
||||
uint256[] memory burns = new uint256[](4);
|
||||
@@ -769,7 +769,7 @@ contract PartyPoolTest is Test {
|
||||
}
|
||||
|
||||
// Recompute withdraw amounts via view after any top-up
|
||||
uint256[] memory expected = pool.computeBurnAmounts(req);
|
||||
uint256[] memory expected = pool.burnReceiveAmounts(req);
|
||||
|
||||
// If expected withdraws are all zero (rounding edge), skip this iteration
|
||||
if (expected[0] == 0 && expected[1] == 0 && expected[2] == 0) {
|
||||
@@ -795,8 +795,8 @@ contract PartyPoolTest is Test {
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Verify computeBurnAmounts matches actual transfers performed by burn() for 10-token pool
|
||||
function testComputeBurnAmountsMatchesBurn_10TokenPool() public {
|
||||
/// @notice Verify burnReceiveAmounts matches actual transfers performed by burn() for 10-token pool
|
||||
function testBurnReceiveAmountsMatchesBurn_10TokenPool() public {
|
||||
uint256 totalLp = pool10.totalSupply();
|
||||
uint256[] memory burns = new uint256[](4);
|
||||
burns[0] = 1;
|
||||
@@ -826,7 +826,7 @@ contract PartyPoolTest is Test {
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
uint256[] memory expected = pool10.computeBurnAmounts(req);
|
||||
uint256[] memory expected = pool10.burnReceiveAmounts(req);
|
||||
|
||||
// If expected withdraws are all zero (rounding edge), skip this iteration
|
||||
bool allZero = true;
|
||||
@@ -1311,8 +1311,8 @@ contract PartyPoolTest is Test {
|
||||
);
|
||||
}
|
||||
|
||||
/// @notice Test computeFlashRepaymentAmounts matches flash implementation
|
||||
function testComputeFlashRepaymentAmounts() public view {
|
||||
/// @notice Test flashRepaymentAmounts matches flash implementation
|
||||
function testFlashRepaymentAmounts() public view {
|
||||
// Create different loan amount scenarios
|
||||
uint256[][] memory testCases = new uint256[][](3);
|
||||
|
||||
@@ -1336,7 +1336,7 @@ contract PartyPoolTest is Test {
|
||||
|
||||
for (uint256 i = 0; i < testCases.length; i++) {
|
||||
uint256[] memory loanAmounts = testCases[i];
|
||||
uint256[] memory repaymentAmounts = pool.computeFlashRepaymentAmounts(loanAmounts);
|
||||
uint256[] memory repaymentAmounts = pool.flashRepaymentAmounts(loanAmounts);
|
||||
|
||||
// Verify each repayment amount is correctly calculated
|
||||
for (uint256 j = 0; j < loanAmounts.length; j++) {
|
||||
|
||||
Reference in New Issue
Block a user