PartyPoolView

This commit is contained in:
tim
2025-10-07 12:36:24 -04:00
parent 20af14c872
commit 677ce4886c
8 changed files with 245 additions and 214 deletions

View File

@@ -12,6 +12,7 @@ import "../src/PartyPool.sol";
import "../src/IPartyFlashCallback.sol";
import {PartyPlanner} from "../src/PartyPlanner.sol";
import {Deploy} from "../src/Deploy.sol";
import {PartyPoolView} from "../src/PartyPoolView.sol";
/// @notice Test contract that implements the flash callback for testing flash loans
contract FlashBorrower is IPartyFlashCallback {
@@ -143,6 +144,7 @@ contract PartyPoolTest is Test {
PartyPlanner planner;
PartyPool pool;
PartyPool pool10;
PartyPoolView viewer;
address alice;
address bob;
@@ -283,6 +285,8 @@ contract PartyPoolTest is Test {
token7.mint(bob, INIT_BAL);
token8.mint(bob, INIT_BAL);
token9.mint(bob, INIT_BAL);
viewer = Deploy.newViewer();
}
/// @notice Basic sanity: initial mint should have produced LP tokens for this contract and the pool holds tokens.
@@ -324,7 +328,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.mintAmounts(1);
uint256[] memory deposits = viewer.mintAmounts(pool, 1);
// Basic sanity: deposits array length must match token count and not all zero necessarily
assertEq(deposits.length, 3);
@@ -366,7 +370,7 @@ contract PartyPoolTest is Test {
uint256 totalLpBefore = pool.totalSupply();
// Compute required deposits and perform mint for 1 wei
uint256[] memory deposits = pool.mintAmounts(1);
uint256[] memory deposits = viewer.mintAmounts(pool, 1);
// Sum deposits as deposited_value
uint256 depositedValue = 0;
@@ -407,7 +411,7 @@ contract PartyPoolTest is Test {
// Request half of LP supply
uint256 want = totalLp / 2;
uint256[] memory deposits = pool.mintAmounts(want);
uint256[] memory deposits = viewer.mintAmounts(pool, 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)
@@ -424,7 +428,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.burnAmounts(totalLp);
uint256[] memory withdrawAmounts = viewer.burnAmounts(pool, totalLp);
// Sanity: withdrawAmounts should equal pool balances (or very close due to rounding)
for (uint i = 0; i < withdrawAmounts.length; i++) {
@@ -528,7 +532,7 @@ contract PartyPoolTest is Test {
if (req == 0) req = 1;
// Compute expected deposit amounts via view
uint256[] memory expected = pool.mintAmounts(req);
uint256[] memory expected = viewer.mintAmounts(pool, req);
// Ensure alice has tokens and approve pool
vm.startPrank(alice);
@@ -573,7 +577,7 @@ contract PartyPoolTest is Test {
uint256 req = requests[k];
if (req == 0) req = 1;
uint256[] memory expected = pool10.mintAmounts(req);
uint256[] memory expected = viewer.mintAmounts(pool10, req);
// Approve all tokens from alice
vm.startPrank(alice);
@@ -651,7 +655,7 @@ contract PartyPoolTest is Test {
}
// Recompute withdraw amounts via view after any top-up
uint256[] memory expected = pool.burnAmounts(req);
uint256[] memory expected = viewer.burnAmounts(pool, req);
// If expected withdraws are all zero (rounding edge), skip this iteration
if (expected[0] == 0 && expected[1] == 0 && expected[2] == 0) {
@@ -708,7 +712,7 @@ contract PartyPoolTest is Test {
vm.stopPrank();
}
uint256[] memory expected = pool10.burnAmounts(req);
uint256[] memory expected = viewer.burnAmounts(pool10, req);
// If expected withdraws are all zero (rounding edge), skip this iteration
bool allZero = true;
@@ -1169,7 +1173,7 @@ contract PartyPoolTest is Test {
for (uint256 i = 0; i < testCases.length; i++) {
uint256[] memory loanAmounts = testCases[i];
uint256[] memory repaymentAmounts = pool.flashRepaymentAmounts(loanAmounts);
uint256[] memory repaymentAmounts = viewer.flashRepaymentAmounts(pool, loanAmounts);
// Verify each repayment amount is correctly calculated
for (uint256 j = 0; j < loanAmounts.length; j++) {
@@ -1361,8 +1365,8 @@ contract PartyPoolTest is Test {
token2.approve(address(poolCustom), type(uint256).max);
// Get required deposit amounts for both pools
uint256[] memory depositsDefault = poolDefault.mintAmounts(lpRequestDefault);
uint256[] memory depositsCustom = poolCustom.mintAmounts(lpRequestCustom);
uint256[] memory depositsDefault = viewer.mintAmounts(poolDefault, lpRequestDefault);
uint256[] memory depositsCustom = viewer.mintAmounts(poolCustom, lpRequestCustom);
// Deposits should be identical (same proportion of identical balances)
assertEq(depositsDefault[0], depositsCustom[0], "Token0 deposits should be identical");