From 0f180c1f2ce518a52fca79fd9d042d056a2abf53 Mon Sep 17 00:00:00 2001 From: 0xsmrpn Date: Fri, 24 Jan 2025 16:02:19 +0530 Subject: [PATCH] fix: mad merge --- .gas-snapshot | 20 ++++++++-------- src/Aggregator.sol | 57 +++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index aedbd1e..294f418 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,8 +1,10 @@ -AggregatorTest:test__addLiquidity() (gas: 4183082) -AggregatorTest:test__deposit() (gas: 486180) -AggregatorTest:test__depositFor() (gas: 494865) -AggregatorTest:test__redeemBalanced() (gas: 4005846) -AggregatorTest:test__redeemSingle() (gas: 4085511) +AggregatorTest:test__addLiquidity() (gas: 4182378) +AggregatorTest:test__deposit() (gas: 485840) +AggregatorTest:test__depositFor() (gas: 424495) +AggregatorTest:test__depositForSingle() (gas: 502364) +AggregatorTest:test__depositSingle() (gas: 464219) +AggregatorTest:test__redeemBalanced() (gas: 4005877) +AggregatorTest:test__redeemSingle() (gas: 4085581) ManualRegistryTest:test__addPoolAddress() (gas: 1092647) PoolAdd:testAddLiquidityInitial() (gas: 778015) PoolAdd:testAddLiquidityMultiple() (gas: 4742677) @@ -16,11 +18,11 @@ PoolAdd:testRampWeight() (gas: 5955005) PoolAdd:testRateUpdate() (gas: 5570065) PoolOwnerTest:test__addLiquidity() (gas: 4183182) PoolOwnerTest:test__addTokenThroughPoolOwnerContract() (gas: 501843) -PoolOwnerTest:test__deposit() (gas: 486190) -PoolOwnerTest:test__depositFor() (gas: 494899) +PoolOwnerTest:test__deposit() (gas: 486430) +PoolOwnerTest:test__depositFor() (gas: 419909) PoolOwnerTest:test__pausePoolThroughPoolOwnerContract() (gas: 103988) -PoolOwnerTest:test__redeemBalanced() (gas: 4005921) -PoolOwnerTest:test__redeemSingle() (gas: 4085676) +PoolOwnerTest:test__redeemBalanced() (gas: 4005933) +PoolOwnerTest:test__redeemSingle() (gas: 4085702) PoolOwnerTest:test__setRampStepThroughPoolOwnerContract() (gas: 87284) PoolOwnerTest:test__setRampThroughPoolOwnerContract() (gas: 173968) PoolOwnerTest:test__setRateProviderThroughPoolOwnerContract() (gas: 257719) diff --git a/src/Aggregator.sol b/src/Aggregator.sol index 848c65d..e1ba2f0 100644 --- a/src/Aggregator.sol +++ b/src/Aggregator.sol @@ -6,12 +6,11 @@ import {LibSort} from "solady/utils/LibSort.sol"; import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; -import {Pool} from "../src/Poolv2.sol"; +import {PoolV2} from "../src/Poolv2.sol"; import {PoolToken} from "../src/PoolToken.sol"; import {Vault} from "../src/Vault.sol"; import {MockToken} from "../src/Mocks/MockToken.sol"; import {MockRateProvider} from "../src/Mocks/MockRateProvider.sol"; -import {PoolEstimator} from "../tests/PoolEstimator.sol"; import {LogExpMath} from "../src/BalancerLibCode/LogExpMath.sol"; import {IRateProvider} from "../src/RateProvider/IRateProvider.sol"; @@ -30,9 +29,9 @@ contract Aggregator { ERC20(tokens[i]).approve(poolAddress, tokenAmounts[i]); } - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 lpReceived = Pool(poolAddress).addLiquidity(tokenAmounts, minLpAmount, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 lpReceived = PoolV2(poolAddress).addLiquidity(tokenAmounts, minLpAmount, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -49,9 +48,9 @@ contract Aggregator { ERC20(tokens[i]).approve(poolAddress, tokenAmounts[i]); } - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 lpReceived = Pool(poolAddress).addLiquidity(tokenAmounts, minLpAmount, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 lpReceived = PoolV2(poolAddress).addLiquidity(tokenAmounts, minLpAmount, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -62,16 +61,16 @@ contract Aggregator { uint256 minLpAmount, address poolAddress ) external returns (uint256 shares) { - address token = Pool(poolAddress).tokens(tokenIndex); + address token = PoolV2(poolAddress).tokens(tokenIndex); SafeTransferLib.safeTransferFrom(token, msg.sender, address(this), tokenAmount); ERC20(token).approve(poolAddress, tokenAmount); - uint256 numTokens = Pool(poolAddress).numTokens(); + uint256 numTokens = PoolV2(poolAddress).numTokens(); uint256[] memory addLiquidityAmounts = new uint256[](numTokens); addLiquidityAmounts[tokenIndex] = tokenAmount; - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 lpReceived = Pool(poolAddress).addLiquidity(addLiquidityAmounts, minLpAmount, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 lpReceived = PoolV2(poolAddress).addLiquidity(addLiquidityAmounts, minLpAmount, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -82,15 +81,15 @@ contract Aggregator { uint256 minLpAmount, address poolAddress ) external returns (uint256 shares) { - address token = Pool(poolAddress).tokens(tokenIndex); + address token = PoolV2(poolAddress).tokens(tokenIndex); ERC20(token).approve(poolAddress, tokenAmount); - uint256 numTokens = Pool(poolAddress).numTokens(); + uint256 numTokens = PoolV2(poolAddress).numTokens(); uint256[] memory addLiquidityAmounts = new uint256[](numTokens); addLiquidityAmounts[tokenIndex] = tokenAmount; - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 lpReceived = Pool(poolAddress).addLiquidity(addLiquidityAmounts, minLpAmount, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 lpReceived = PoolV2(poolAddress).addLiquidity(addLiquidityAmounts, minLpAmount, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -102,9 +101,9 @@ contract Aggregator { address poolAddress ) external returns (uint256 shares) { require(tokens.length == tokenAmounts.length, "tokens and tokenAmounts should be of same length"); - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 lpReceived = Pool(poolAddress).addLiquidityFor(tokenAmounts, minLpAmount, msg.sender, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 lpReceived = PoolV2(poolAddress).addLiquidityFor(tokenAmounts, minLpAmount, msg.sender, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -115,13 +114,13 @@ contract Aggregator { uint256 minLpAmount, address poolAddress ) external returns (uint256 shares) { - address vaultAddress = Pool(poolAddress).vaultAddress(); - uint256 numTokens = Pool(poolAddress).numTokens(); + address vaultAddress = PoolV2(poolAddress).vaultAddress(); + uint256 numTokens = PoolV2(poolAddress).numTokens(); uint256[] memory addLiquidityAmounts = new uint256[](numTokens); addLiquidityAmounts[tokenIndex] = tokenAmount; uint256 lpReceived = - Pool(poolAddress).addLiquidityFor(addLiquidityAmounts, minLpAmount, msg.sender, address(this)); - PoolToken(Pool(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); + PoolV2(poolAddress).addLiquidityFor(addLiquidityAmounts, minLpAmount, msg.sender, address(this)); + PoolToken(PoolV2(poolAddress).tokenAddress()).approve(vaultAddress, lpReceived); shares = Vault(vaultAddress).deposit(lpReceived, receiver); } @@ -131,9 +130,9 @@ contract Aggregator { uint256[] calldata minAmountsOut, address receiver ) external { - Vault vault = Vault(Pool(poolAddress).vaultAddress()); + Vault vault = Vault(PoolV2(poolAddress).vaultAddress()); uint256 lpRedeemed = vault.redeem(sharesToBurn, address(this), msg.sender); - Pool(poolAddress).removeLiquidity(lpRedeemed, minAmountsOut, receiver); + PoolV2(poolAddress).removeLiquidity(lpRedeemed, minAmountsOut, receiver); } function redeemSingle( @@ -143,8 +142,8 @@ contract Aggregator { uint256 minAmountOut, address receiver ) external returns (uint256 tokenOutAmount) { - Vault vault = Vault(Pool(poolAddress).vaultAddress()); + Vault vault = Vault(PoolV2(poolAddress).vaultAddress()); uint256 lpRedeemed = vault.redeem(sharesToBurn, address(this), msg.sender); - tokenOutAmount = Pool(poolAddress).removeLiquiditySingle(tokenOut, lpRedeemed, minAmountOut, receiver); + tokenOutAmount = PoolV2(poolAddress).removeLiquiditySingle(tokenOut, lpRedeemed, minAmountOut, receiver); } }