Skip to content

Commit

Permalink
fix: mad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
0xethsign committed Jan 24, 2025
1 parent c7792c4 commit 0f180c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
20 changes: 11 additions & 9 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
57 changes: 28 additions & 29 deletions src/Aggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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(
Expand All @@ -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);
}
}

0 comments on commit 0f180c1

Please sign in to comment.