PartyPlanner; chain.json
This commit is contained in:
@@ -25,9 +25,12 @@ contract FlashBorrower is IPartyFlashCallback {
|
||||
address public recipient;
|
||||
address[] public tokens;
|
||||
|
||||
constructor(address _pool, address[] memory _tokens) {
|
||||
constructor(address _pool, IERC20[] memory _tokens) {
|
||||
pool = _pool;
|
||||
tokens = _tokens;
|
||||
tokens = new address[](_tokens.length);
|
||||
for (uint i = 0; i < _tokens.length; i++) {
|
||||
tokens[i] = address(_tokens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function setAction(Action _action, address _recipient) external {
|
||||
@@ -162,7 +165,11 @@ contract GasTest is Test {
|
||||
// Deploy pool with a small fee to test fee-handling paths (use 1000 ppm = 0.1%)
|
||||
uint256 feePpm = 1000;
|
||||
string memory poolName = string(abi.encodePacked("LP", vm.toString(numTokens)));
|
||||
PartyPool newPool = new PartyPool(poolName, poolName, tokens, bases, tradeFrac, targetSlippage, feePpm, feePpm, false);
|
||||
IERC20[] memory ierc20Tokens = new IERC20[](tokens.length);
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
ierc20Tokens[i] = IERC20(tokens[i]);
|
||||
}
|
||||
PartyPool newPool = new PartyPool(poolName, poolName, ierc20Tokens, bases, tradeFrac, targetSlippage, feePpm, feePpm, false);
|
||||
|
||||
// Transfer initial deposit amounts into pool before initial mint
|
||||
for (uint256 i = 0; i < numTokens; i++) {
|
||||
@@ -170,7 +177,7 @@ contract GasTest is Test {
|
||||
}
|
||||
|
||||
// Perform initial mint (initial deposit); receiver is this contract
|
||||
newPool.mint(address(0), address(this), 0, 0);
|
||||
newPool.initialMint(address(this), 0);
|
||||
|
||||
return newPool;
|
||||
}
|
||||
@@ -197,7 +204,11 @@ contract GasTest is Test {
|
||||
uint256 feePpm = 1000;
|
||||
string memory poolName = string(abi.encodePacked("LPs", vm.toString(numTokens)));
|
||||
// Note the final 'true' arg to activate stable-pair optimization path
|
||||
PartyPool newPool = new PartyPool(poolName, poolName, tokens, bases, tradeFrac, targetSlippage, feePpm, feePpm, true);
|
||||
IERC20[] memory ierc20Tokens = new IERC20[](tokens.length);
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
ierc20Tokens[i] = IERC20(tokens[i]);
|
||||
}
|
||||
PartyPool newPool = new PartyPool(poolName, poolName, ierc20Tokens, bases, tradeFrac, targetSlippage, feePpm, feePpm, true);
|
||||
|
||||
// Transfer initial deposit amounts into pool before initial mint
|
||||
for (uint256 i = 0; i < numTokens; i++) {
|
||||
@@ -205,7 +216,7 @@ contract GasTest is Test {
|
||||
}
|
||||
|
||||
// Perform initial mint (initial deposit); receiver is this contract
|
||||
newPool.mint(address(0), address(this), 0, 0);
|
||||
newPool.initialMint(address(this), 0);
|
||||
|
||||
return newPool;
|
||||
}
|
||||
@@ -228,7 +239,7 @@ contract GasTest is Test {
|
||||
/// @notice Setup a flash borrower for testing
|
||||
function setupFlashBorrower() internal returns (FlashBorrower borrower) {
|
||||
// Get token addresses from the 2-token pool
|
||||
address[] memory tokenAddresses = pool2.allTokens();
|
||||
IERC20[] memory tokenAddresses = pool2.allTokens();
|
||||
|
||||
// Deploy the borrower contract
|
||||
borrower = new FlashBorrower(address(pool2), tokenAddresses);
|
||||
@@ -236,22 +247,22 @@ contract GasTest is Test {
|
||||
// Mint tokens to alice to be used for repayments and approve borrower
|
||||
vm.startPrank(alice);
|
||||
for (uint256 i = 0; i < tokenAddresses.length; i++) {
|
||||
TestERC20(tokenAddresses[i]).mint(alice, INIT_BAL * 2);
|
||||
TestERC20(tokenAddresses[i]).approve(address(borrower), type(uint256).max);
|
||||
TestERC20(address(tokenAddresses[i])).mint(alice, INIT_BAL * 2);
|
||||
TestERC20(address(tokenAddresses[i])).approve(address(borrower), type(uint256).max);
|
||||
}
|
||||
vm.stopPrank();
|
||||
}
|
||||
|
||||
/// @notice Helper function: perform 10 swaps back-and-forth between the first two tokens.
|
||||
function _performSwapGasTest(PartyPool testPool) internal {
|
||||
address[] memory tokens = testPool.allTokens();
|
||||
IERC20[] memory tokens = testPool.allTokens();
|
||||
require(tokens.length >= 2, "Pool must have at least 2 tokens");
|
||||
|
||||
// Ensure alice approves pool for both tokens
|
||||
vm.prank(alice);
|
||||
TestERC20(tokens[0]).approve(address(testPool), type(uint256).max);
|
||||
TestERC20(address(tokens[0])).approve(address(testPool), type(uint256).max);
|
||||
vm.prank(alice);
|
||||
TestERC20(tokens[1]).approve(address(testPool), type(uint256).max);
|
||||
TestERC20(address(tokens[1])).approve(address(testPool), type(uint256).max);
|
||||
|
||||
uint256 maxIn = 1_000;
|
||||
|
||||
@@ -310,13 +321,13 @@ contract GasTest is Test {
|
||||
function _performSwapMintBurnSwapGasTest(PartyPool testPool) internal {
|
||||
uint256 iterations = 10;
|
||||
uint256 input = 1_000;
|
||||
address[] memory tokens = testPool.allTokens();
|
||||
IERC20[] memory tokens = testPool.allTokens();
|
||||
|
||||
// Top up alice so repeated operations won't fail
|
||||
TestERC20(tokens[0]).mint(alice, iterations * input * 2);
|
||||
TestERC20(address(tokens[0])).mint(alice, iterations * input * 2);
|
||||
|
||||
vm.startPrank(alice);
|
||||
TestERC20(tokens[0]).approve(address(testPool), type(uint256).max);
|
||||
TestERC20(address(tokens[0])).approve(address(testPool), type(uint256).max);
|
||||
|
||||
for (uint256 k = 0; k < iterations; k++) {
|
||||
// Mint LP by providing single-token input; receive LP minted
|
||||
@@ -355,14 +366,14 @@ contract GasTest is Test {
|
||||
function _performMintBurnGasTest(PartyPool testPool) internal {
|
||||
uint256 iterations = 50;
|
||||
uint256 input = 1_000;
|
||||
address[] memory poolTokens = testPool.allTokens();
|
||||
IERC20[] memory poolTokens = testPool.allTokens();
|
||||
|
||||
vm.startPrank(alice);
|
||||
|
||||
// Mint additional tokens to alice and approve pool to transfer tokens for proportional mint
|
||||
for (uint256 i = 0; i < poolTokens.length; i++) {
|
||||
TestERC20(poolTokens[i]).mint(alice, iterations * input * 2);
|
||||
TestERC20(poolTokens[i]).approve(address(testPool), type(uint256).max);
|
||||
TestERC20(address(poolTokens[i])).mint(alice, iterations * input * 2);
|
||||
TestERC20(address(poolTokens[i])).approve(address(testPool), type(uint256).max);
|
||||
}
|
||||
|
||||
for (uint256 k = 0; k < iterations; k++) {
|
||||
@@ -422,7 +433,7 @@ contract GasTest is Test {
|
||||
borrower.setAction(FlashBorrower.Action.NORMAL, alice);
|
||||
|
||||
// Create loan request for single token (get array size from pool)
|
||||
address[] memory poolTokens = pool2.allTokens();
|
||||
IERC20[] memory poolTokens = pool2.allTokens();
|
||||
uint256[] memory amounts = new uint256[](poolTokens.length);
|
||||
amounts[0] = 1000;
|
||||
|
||||
@@ -440,7 +451,7 @@ contract GasTest is Test {
|
||||
borrower.setAction(FlashBorrower.Action.NORMAL, alice);
|
||||
|
||||
// Create loan request for multiple tokens (get array size from pool)
|
||||
address[] memory poolTokens = pool2.allTokens();
|
||||
IERC20[] memory poolTokens = pool2.allTokens();
|
||||
uint256[] memory amounts = new uint256[](poolTokens.length);
|
||||
amounts[0] = 1000;
|
||||
amounts[1] = 2000;
|
||||
|
||||
Reference in New Issue
Block a user