rename to PartyInfo; README fees

This commit is contained in:
tim
2025-11-07 16:18:00 -04:00
parent ff9ed674f9
commit a08a928f7f
10 changed files with 84 additions and 73 deletions

View File

@@ -9,7 +9,7 @@ import {PartyPoolBalancedPair} from "../src/PartyPoolBalancedPair.sol";
import {PartyPoolDeployer, PartyPoolBalancedPairDeployer} from "../src/PartyPoolDeployer.sol";
import {PartyPoolMintImpl} from "../src/PartyPoolMintImpl.sol";
import {PartyPoolSwapImpl} from "../src/PartyPoolSwapImpl.sol";
import {PartyPoolViewer} from "../src/PartyPoolViewer.sol";
import {PartyInfo} from "../src/PartyInfo.sol";
import {WETH9} from "./WETH9.sol";
library Deploy {
@@ -99,8 +99,8 @@ library Deploy {
}
function newViewer() internal returns (PartyPoolViewer) {
function newInfo() internal returns (PartyInfo) {
NativeWrapper wrapper = new WETH9();
return new PartyPoolViewer(new PartyPoolSwapImpl(wrapper), new PartyPoolMintImpl(wrapper));
return new PartyInfo(new PartyPoolSwapImpl(wrapper), new PartyPoolMintImpl(wrapper));
}
}

View File

@@ -10,7 +10,7 @@ import "../src/PartyPool.sol";
import {NativeWrapper} from "../src/NativeWrapper.sol";
import {PartyPlanner} from "../src/PartyPlanner.sol";
import {Deploy} from "./Deploy.sol";
import {PartyPoolViewer} from "../src/PartyPoolViewer.sol";
import {PartyInfo} from "../src/PartyInfo.sol";
import {WETH9} from "./WETH9.sol";
/// @notice Minimal ERC20 token for tests with an external mint function.
@@ -41,7 +41,7 @@ contract NativeTest is Test {
TestERC20Native token1;
WETH9 weth; // WETH is our third token
PartyPool pool;
PartyPoolViewer viewer;
PartyInfo info;
address alice;
address bob;
@@ -111,7 +111,7 @@ contract NativeTest is Test {
token0.mint(bob, INIT_BAL);
token1.mint(bob, INIT_BAL);
viewer = Deploy.newViewer();
info = Deploy.newInfo();
}
/// @notice Helper to verify refunds work correctly
@@ -300,7 +300,7 @@ contract NativeTest is Test {
uint256 lpRequest = pool.totalSupply() / 10; // Request 10% of pool
// Get required deposit amounts
uint256[] memory deposits = viewer.mintAmounts(pool, lpRequest);
uint256[] memory deposits = info.mintAmounts(pool, lpRequest);
vm.startPrank(alice);
token0.approve(address(pool), type(uint256).max);
@@ -329,7 +329,7 @@ contract NativeTest is Test {
/// @notice Test mint with excess native currency - verify refund
function testMintWithExcessNativeRefunded() public {
uint256 lpRequest = pool.totalSupply() / 10;
uint256[] memory deposits = viewer.mintAmounts(pool, lpRequest);
uint256[] memory deposits = info.mintAmounts(pool, lpRequest);
vm.startPrank(alice);
token0.approve(address(pool), type(uint256).max);
@@ -365,7 +365,7 @@ contract NativeTest is Test {
uint256 lpToBurn = pool.totalSupply() / 10;
// Get expected withdraw amounts
uint256[] memory withdraws = viewer.burnAmounts(pool, lpToBurn);
uint256[] memory withdraws = info.burnAmounts(pool, lpToBurn);
uint256 thisEthBefore = address(this).balance;
uint256 expectedWethWithdraw = withdraws[2]; // WETH is index 2
@@ -391,7 +391,7 @@ contract NativeTest is Test {
/// @notice Test burn to a different receiver with native output
function testBurnToReceiverWithNativeOutput() public {
uint256 lpToBurn = pool.totalSupply() / 10;
uint256[] memory withdraws = viewer.burnAmounts(pool, lpToBurn);
uint256[] memory withdraws = info.burnAmounts(pool, lpToBurn);
uint256 bobEthBefore = bob.balance;
uint256 bobToken0Before = token0.balanceOf(bob);
@@ -531,7 +531,7 @@ contract NativeTest is Test {
// 1. Mint with native currency
uint256 lpRequest = pool.totalSupply() / 20; // 5% of pool
uint256[] memory deposits = viewer.mintAmounts(pool, lpRequest);
uint256[] memory deposits = info.mintAmounts(pool, lpRequest);
token0.approve(address(pool), type(uint256).max);
token1.approve(address(pool), type(uint256).max);

View File

@@ -12,7 +12,7 @@ import "../src/PartyPool.sol";
import "../lib/openzeppelin-contracts/contracts/interfaces/IERC3156FlashBorrower.sol";
import {PartyPlanner} from "../src/PartyPlanner.sol";
import {Deploy} from "./Deploy.sol";
import {PartyPoolViewer} from "../src/PartyPoolViewer.sol";
import {PartyInfo} from "../src/PartyInfo.sol";
/// @notice Test contract that implements the flash callback for testing flash loans
contract FlashBorrower is IERC3156FlashBorrower {
@@ -113,7 +113,7 @@ contract PartyPoolTest is Test {
PartyPlanner planner;
PartyPool pool;
PartyPool pool10;
PartyPoolViewer viewer;
PartyInfo info;
address alice;
address bob;
@@ -244,7 +244,7 @@ contract PartyPoolTest is Test {
token8.mint(bob, INIT_BAL);
token9.mint(bob, INIT_BAL);
viewer = Deploy.newViewer();
info = Deploy.newInfo();
}
/// @notice Basic sanity: initial mint should have produced LP _tokens for this contract and the pool holds _tokens.
@@ -286,7 +286,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 = viewer.mintAmounts(pool, 1);
uint256[] memory deposits = info.mintAmounts(pool, 1);
// Basic sanity: deposits array length must match token count and not all zero necessarily
assertEq(deposits.length, 3);
@@ -328,7 +328,7 @@ contract PartyPoolTest is Test {
uint256 totalLpBefore = pool.totalSupply();
// Compute required deposits and perform mint for 1 wei
uint256[] memory deposits = viewer.mintAmounts(pool, 1);
uint256[] memory deposits = info.mintAmounts(pool, 1);
// Sum deposits as deposited_value
uint256 depositedValue = 0;
@@ -369,7 +369,7 @@ contract PartyPoolTest is Test {
// Request half of LP supply
uint256 want = totalLp / 2;
uint256[] memory deposits = viewer.mintAmounts(pool, want);
uint256[] memory deposits = info.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)
@@ -386,7 +386,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 = viewer.burnAmounts(pool, totalLp);
uint256[] memory withdrawAmounts = info.burnAmounts(pool, totalLp);
// Sanity: withdrawAmounts should equal pool balances (or very close due to rounding)
for (uint i = 0; i < withdrawAmounts.length; i++) {
@@ -490,7 +490,7 @@ contract PartyPoolTest is Test {
if (req == 0) req = 1;
// Compute expected deposit amounts via view
uint256[] memory expected = viewer.mintAmounts(pool, req);
uint256[] memory expected = info.mintAmounts(pool, req);
// Ensure alice has _tokens and approve pool
vm.startPrank(alice);
@@ -535,7 +535,7 @@ contract PartyPoolTest is Test {
uint256 req = requests[k];
if (req == 0) req = 1;
uint256[] memory expected = viewer.mintAmounts(pool10, req);
uint256[] memory expected = info.mintAmounts(pool10, req);
// Approve all _tokens from alice
vm.startPrank(alice);
@@ -613,7 +613,7 @@ contract PartyPoolTest is Test {
}
// Recompute withdraw amounts via view after any top-up
uint256[] memory expected = viewer.burnAmounts(pool, req);
uint256[] memory expected = info.burnAmounts(pool, req);
// If expected withdraws are all zero (rounding edge), skip this iteration
if (expected[0] == 0 && expected[1] == 0 && expected[2] == 0) {
@@ -670,7 +670,7 @@ contract PartyPoolTest is Test {
vm.stopPrank();
}
uint256[] memory expected = viewer.burnAmounts(pool10, req);
uint256[] memory expected = info.burnAmounts(pool10, req);
// If expected withdraws are all zero (rounding edge), skip this iteration
bool allZero = true;
@@ -949,7 +949,7 @@ contract PartyPoolTest is Test {
for (uint256 i = 0; i < testAmounts.length; i++) {
uint256 amount = testAmounts[i];
uint256 fee = viewer.flashFee(pool, address(token0), amount);
uint256 fee = info.flashFee(pool, address(token0), amount);
// Calculate expected fee
uint256 expectedFee = (amount * pool.flashFeePpm() + 1_000_000 - 1) / 1_000_000; // ceiling
@@ -1096,8 +1096,8 @@ contract PartyPoolTest is Test {
token2.approve(address(poolCustom), type(uint256).max);
// Get required deposit amounts for both pools
uint256[] memory depositsDefault = viewer.mintAmounts(poolDefault, lpRequestDefault);
uint256[] memory depositsCustom = viewer.mintAmounts(poolCustom, lpRequestCustom);
uint256[] memory depositsDefault = info.mintAmounts(poolDefault, lpRequestDefault);
uint256[] memory depositsCustom = info.mintAmounts(poolCustom, lpRequestCustom);
// Deposits should be identical (same proportion of identical balances)
assertEq(depositsDefault[0], depositsCustom[0], "Token0 deposits should be identical");
@@ -1126,8 +1126,8 @@ contract PartyPoolTest is Test {
/// @notice Verify that the initial relative price between token0 and token1 is 1.0000000
function testInitialPriceIsOne() public view {
// Query the viewer for the relative price between token index 0 and 1
int128 price = viewer.price(pool, 0, 1);
// Query the info viewer for the relative price between token index 0 and 1
int128 price = info.price(pool, 0, 1);
// Expected price is 1.0 in ABDK 64.64 fixed point
int128 expected = ABDKMath64x64.fromInt(1);
@@ -1137,8 +1137,8 @@ contract PartyPoolTest is Test {
/// @notice Verify that the initial LP price in terms of token0 is 1.0000000
function testInitialPoolPriceIsOne() public {
// Query the viewer for the pool price for token0
int128 price = viewer.poolPrice(pool, 0);
// Query the info viewer for the pool price for token0
int128 price = info.poolPrice(pool, 0);
// Expected price is 1.0 in ABDK 64.64 fixed point
int128 expected = ABDKMath64x64.fromInt(1);
@@ -1157,7 +1157,7 @@ contract PartyPoolTest is Test {
if (lpRequest == 0) lpRequest = 1;
// Compute required deposits and perform mint if not trivial
uint256[] memory deposits = viewer.mintAmounts(pool, lpRequest);
uint256[] memory deposits = info.mintAmounts(pool, lpRequest);
bool allZero = true;
for (uint i = 0; i < deposits.length; i++) { if (deposits[i] != 0) { allZero = false; break; } }
@@ -1167,7 +1167,7 @@ contract PartyPoolTest is Test {
vm.stopPrank();
// Re-query the pool price and ensure it remains 1.0 (within exact fixed-point equality)
int128 priceAfter = viewer.poolPrice(pool, 0);
int128 priceAfter = info.poolPrice(pool, 0);
assertEq(uint256(uint128(priceAfter)), uint256(uint128(expected)), "Pool price should remain 1.0000000 after mint");
}