diff --git a/pkg/pool-hooks/test/foundry/DirectionalFeeHookExample.t.sol b/pkg/pool-hooks/test/foundry/DirectionalFeeHookExample.t.sol index 254d6ad0d..053157c32 100644 --- a/pkg/pool-hooks/test/foundry/DirectionalFeeHookExample.t.sol +++ b/pkg/pool-hooks/test/foundry/DirectionalFeeHookExample.t.sol @@ -31,6 +31,7 @@ import { import { PoolMock } from "@balancer-labs/v3-vault/contracts/test/PoolMock.sol"; import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; +import { PoolFactoryMock } from "@balancer-labs/v3-vault/contracts/test/PoolFactoryMock.sol"; import { DirectionalFeeHookExample } from "../../contracts/DirectionalFeeHookExample.sol"; @@ -42,9 +43,8 @@ contract DirectionalHookExampleTest is StablePoolContractsDeployer, BaseVaultTes uint256 internal daiIdx; uint256 internal usdcIdx; - StablePoolFactory internal stablePoolFactory; - address internal directionalFeeHook; + PoolFactoryMock internal poolFactoryMock; uint256 internal constant DEFAULT_AMP_FACTOR = 200; @@ -54,14 +54,19 @@ contract DirectionalHookExampleTest is StablePoolContractsDeployer, BaseVaultTes super.setUp(); (daiIdx, usdcIdx) = getSortedIndexes(address(dai), address(usdc)); + + poolFactoryMock = PoolFactoryMock(address(vault.getPoolFactoryMock())); + } + + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1")); } function createHook() internal override returns (address) { // Create the factory here, because it needs to be deployed after the Vault, but before the hook contract. - stablePoolFactory = deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); // lp will be the owner of the hook. Only LP is able to set hook fee percentages. vm.prank(lp); - directionalFeeHook = address(new DirectionalFeeHookExample(IVault(address(vault)), address(stablePoolFactory))); + directionalFeeHook = address(new DirectionalFeeHookExample(IVault(address(vault)), poolFactory)); vm.label(directionalFeeHook, "Directional Fee Hook"); return directionalFeeHook; } @@ -76,14 +81,10 @@ contract DirectionalHookExampleTest is StablePoolContractsDeployer, BaseVaultTes PoolRoleAccounts memory roleAccounts; vm.expectEmit(true, true, false, false); - emit DirectionalFeeHookExample.DirectionalFeeHookExampleRegistered( - directionalFeeHook, - address(stablePoolFactory), - address(0) - ); + emit DirectionalFeeHookExample.DirectionalFeeHookExampleRegistered(directionalFeeHook, poolFactory, address(0)); newPool = address( - stablePoolFactory.create( + StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -126,7 +127,7 @@ contract DirectionalHookExampleTest is StablePoolContractsDeployer, BaseVaultTes IVaultErrors.HookRegistrationFailed.selector, poolHooksContract, directionalFeePool, - address(factoryMock) + address(poolFactoryMock) ) ); _registerPoolWithHook(directionalFeePool, tokenConfig); @@ -345,6 +346,12 @@ contract DirectionalHookExampleTest is StablePoolContractsDeployer, BaseVaultTes LiquidityManagement memory liquidityManagement; - factoryMock.registerPool(directionalFeePool, tokenConfig, roleAccounts, poolHooksContract, liquidityManagement); + poolFactoryMock.registerPool( + directionalFeePool, + tokenConfig, + roleAccounts, + poolHooksContract, + liquidityManagement + ); } } diff --git a/pkg/pool-hooks/test/foundry/ExitFeeHookExample.t.sol b/pkg/pool-hooks/test/foundry/ExitFeeHookExample.t.sol index 9b9762e3e..3e2a82522 100644 --- a/pkg/pool-hooks/test/foundry/ExitFeeHookExample.t.sol +++ b/pkg/pool-hooks/test/foundry/ExitFeeHookExample.t.sol @@ -20,6 +20,7 @@ import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/Ar import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol"; import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; +import { PoolFactoryMock } from "@balancer-labs/v3-vault/contracts/test/PoolFactoryMock.sol"; import { PoolMock } from "@balancer-labs/v3-vault/contracts/test/PoolMock.sol"; import { ExitFeeHookExample } from "../../contracts/ExitFeeHookExample.sol"; @@ -29,6 +30,8 @@ contract ExitFeeHookExampleTest is BaseVaultTest { using FixedPoint for uint256; using ArrayHelpers for *; + PoolFactoryMock poolFactoryMock; + uint256 internal daiIdx; uint256 internal usdcIdx; @@ -39,6 +42,8 @@ contract ExitFeeHookExampleTest is BaseVaultTest { super.setUp(); (daiIdx, usdcIdx) = getSortedIndexes(address(dai), address(usdc)); + + poolFactoryMock = PoolFactoryMock(address(vault.getPoolFactoryMock())); } function createHook() internal override returns (address) { @@ -70,7 +75,7 @@ contract ExitFeeHookExampleTest is BaseVaultTest { vm.expectEmit(); emit ExitFeeHookExample.ExitFeeHookExampleRegistered(poolHooksContract, newPool); - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, @@ -200,6 +205,6 @@ contract ExitFeeHookExampleTest is BaseVaultTest { liquidityManagement.disableUnbalancedLiquidity = true; liquidityManagement.enableDonation = enableDonation; - factoryMock.registerPool(exitFeePool, tokenConfig, roleAccounts, poolHooksContract, liquidityManagement); + poolFactoryMock.registerPool(exitFeePool, tokenConfig, roleAccounts, poolHooksContract, liquidityManagement); } } diff --git a/pkg/pool-hooks/test/foundry/ExitFeeHookExampleStablePool.t.sol b/pkg/pool-hooks/test/foundry/ExitFeeHookExampleStablePool.t.sol index cd161ea8d..523648195 100644 --- a/pkg/pool-hooks/test/foundry/ExitFeeHookExampleStablePool.t.sol +++ b/pkg/pool-hooks/test/foundry/ExitFeeHookExampleStablePool.t.sol @@ -29,12 +29,17 @@ contract ExitFeeHookExampleStablePoolTest is StablePoolContractsDeployer, ExitFe using ArrayHelpers for *; using FixedPoint for uint256; + string constant POOL_VERSION = "Pool v1"; + // The minimum swap fee for a Stable Pool is 0.0001%. uint256 internal constant MIN_STABLE_SWAP_FEE = 1e12; - StablePoolFactory internal stablePoolFactory; uint256 internal constant DEFAULT_AMP_FACTOR = 200; + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + // Overrides pool creation to set liquidityManagement (disables unbalanced liquidity and enables donation). function _createPool( address[] memory tokens, @@ -42,12 +47,10 @@ contract ExitFeeHookExampleStablePoolTest is StablePoolContractsDeployer, ExitFe ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool Test"; string memory symbol = "STABLE-TEST"; - string memory poolVersion = "Pool v1"; - stablePoolFactory = deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); PoolRoleAccounts memory roleAccounts; - newPool = stablePoolFactory.create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -67,7 +70,7 @@ contract ExitFeeHookExampleStablePoolTest is StablePoolContractsDeployer, ExitFe name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-hooks/test/foundry/ExitFeeHookExampleWeightedPool.t.sol b/pkg/pool-hooks/test/foundry/ExitFeeHookExampleWeightedPool.t.sol index 4bd333ce6..61fe77f21 100644 --- a/pkg/pool-hooks/test/foundry/ExitFeeHookExampleWeightedPool.t.sol +++ b/pkg/pool-hooks/test/foundry/ExitFeeHookExampleWeightedPool.t.sol @@ -29,12 +29,17 @@ contract ExitFeeHookExampleWeightedPoolTest is WeightedPoolContractsDeployer, Ex using ArrayHelpers for *; using FixedPoint for uint256; + string constant POOL_VERSION = "Pool v1"; + // The minimum swap fee for a Weighted Pool is 0.001%. uint256 internal constant MIN_WEIGHTED_SWAP_FEE = 0.001e16; - WeightedPoolFactory internal weightedPoolFactory; uint256[] internal weights; + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + // Overrides pool creation to set liquidityManagement (disables unbalanced liquidity and enables donation). function _createPool( address[] memory tokens, @@ -42,14 +47,12 @@ contract ExitFeeHookExampleWeightedPoolTest is WeightedPoolContractsDeployer, Ex ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Weighted Pool Test"; string memory symbol = "WEIGHTED-TEST"; - string memory poolVersion = "Pool v1"; - weightedPoolFactory = deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); PoolRoleAccounts memory roleAccounts; weights = [uint256(50e16), uint256(50e16)].toMemoryArray(); - newPool = weightedPoolFactory.create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -69,7 +72,7 @@ contract ExitFeeHookExampleWeightedPoolTest is WeightedPoolContractsDeployer, Ex symbol: symbol, numTokens: tokens.length, normalizedWeights: [uint256(50e16), uint256(50e16)].toMemoryArray(), - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-hooks/test/foundry/FeeTakingHookExample.t.sol b/pkg/pool-hooks/test/foundry/FeeTakingHookExample.t.sol index 44ef53292..d69de3d8d 100644 --- a/pkg/pool-hooks/test/foundry/FeeTakingHookExample.t.sol +++ b/pkg/pool-hooks/test/foundry/FeeTakingHookExample.t.sol @@ -23,6 +23,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { BasePoolMath } from "@balancer-labs/v3-vault/contracts/BasePoolMath.sol"; import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; +import { PoolFactoryMock } from "@balancer-labs/v3-vault/contracts/test/PoolFactoryMock.sol"; import { BalancerPoolToken } from "@balancer-labs/v3-vault/contracts/BalancerPoolToken.sol"; import { PoolMock } from "@balancer-labs/v3-vault/contracts/test/PoolMock.sol"; @@ -70,7 +71,7 @@ contract FeeTakingHookExampleTest is BaseVaultTest { vm.expectEmit(); emit FeeTakingHookExample.FeeTakingHookExampleRegistered(poolHooksContract, newPool); - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/pool-hooks/test/foundry/LotteryHookExample.t.sol b/pkg/pool-hooks/test/foundry/LotteryHookExample.t.sol index 50c8162a7..ebf8015cc 100644 --- a/pkg/pool-hooks/test/foundry/LotteryHookExample.t.sol +++ b/pkg/pool-hooks/test/foundry/LotteryHookExample.t.sol @@ -18,6 +18,7 @@ import { CastingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpe import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol"; import { BaseVaultTest } from "@balancer-labs/v3-vault/test/foundry/utils/BaseVaultTest.sol"; +import { PoolFactoryMock } from "@balancer-labs/v3-vault/contracts/test/PoolFactoryMock.sol"; import { PoolMock } from "@balancer-labs/v3-vault/contracts/test/PoolMock.sol"; import { LotteryHookExample } from "../../contracts/LotteryHookExample.sol"; @@ -69,7 +70,7 @@ contract LotteryHookExampleTest is BaseVaultTest { vm.expectEmit(); emit LotteryHookExample.LotteryHookExampleRegistered(poolHooksContract, address(newPool)); - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/pool-hooks/test/foundry/NftLiquidityPositionExample.t.sol b/pkg/pool-hooks/test/foundry/NftLiquidityPositionExample.t.sol index cdb568f34..0b729714c 100644 --- a/pkg/pool-hooks/test/foundry/NftLiquidityPositionExample.t.sol +++ b/pkg/pool-hooks/test/foundry/NftLiquidityPositionExample.t.sol @@ -54,8 +54,8 @@ contract NftLiquidityPositionExampleTest is BaseVaultTest { vm.label(address(vaultAdmin), "vaultAdmin"); authorizer = BasicAuthorizerMock(address(vault.getAuthorizer())); vm.label(address(authorizer), "authorizer"); - factoryMock = PoolFactoryMock(address(vault.getPoolFactoryMock())); - vm.label(address(factoryMock), "factory"); + poolFactory = address(PoolFactoryMock(address(vault.getPoolFactoryMock()))); + vm.label(address(poolFactory), "factory"); router = deployRouterMock(IVault(address(vault)), weth, permit2); vm.label(address(router), "router"); batchRouter = deployBatchRouterMock(IVault(address(vault)), weth, permit2); @@ -131,7 +131,7 @@ contract NftLiquidityPositionExampleTest is BaseVaultTest { liquidityManagement.disableUnbalancedLiquidity = true; liquidityManagement.enableDonation = true; - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/pool-hooks/test/foundry/StableSurgeHook.t.sol b/pkg/pool-hooks/test/foundry/StableSurgeHook.t.sol index 1dae972f6..ce83b8970 100644 --- a/pkg/pool-hooks/test/foundry/StableSurgeHook.t.sol +++ b/pkg/pool-hooks/test/foundry/StableSurgeHook.t.sol @@ -33,7 +33,6 @@ contract StableSurgeHookTest is BaseVaultTest { uint256 internal daiIdx; uint256 internal usdcIdx; - StablePoolFactory internal stablePoolFactory; StableSurgeHook internal stableSurgeHook; StableSurgeMedianMathMock stableSurgeMedianMathMock = new StableSurgeMedianMathMock(); @@ -44,10 +43,12 @@ contract StableSurgeHookTest is BaseVaultTest { (daiIdx, usdcIdx) = getSortedIndexes(address(dai), address(usdc)); } - function createHook() internal override returns (address) { - stablePoolFactory = new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); + function createPoolFactory() internal override returns (address) { + return address(new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1")); + } - vm.prank(address(stablePoolFactory)); + function createHook() internal override returns (address) { + vm.prank(poolFactory); stableSurgeHook = new StableSurgeHook( vault, DEFAULT_MAX_SURGE_FEE_PERCENTAGE, @@ -63,7 +64,7 @@ contract StableSurgeHookTest is BaseVaultTest { ) internal override returns (address newPool, bytes memory poolArgs) { PoolRoleAccounts memory roleAccounts; - newPool = stablePoolFactory.create( + newPool = StablePoolFactory(poolFactory).create( "Stable Pool", "STABLEPOOL", vault.buildTokenConfig(tokens.asIERC20()), diff --git a/pkg/pool-hooks/test/foundry/StableSurgeHookUnit.t.sol b/pkg/pool-hooks/test/foundry/StableSurgeHookUnit.t.sol index 8d2fabc80..9677ade4b 100644 --- a/pkg/pool-hooks/test/foundry/StableSurgeHookUnit.t.sol +++ b/pkg/pool-hooks/test/foundry/StableSurgeHookUnit.t.sol @@ -39,7 +39,7 @@ contract StableSurgeHookUnitTest is BaseVaultTest { function setUp() public override { super.setUp(); - vm.prank(address(factoryMock)); + vm.prank(address(poolFactory)); stableSurgeHook = new StableSurgeHook( vault, DEFAULT_MAX_SURGE_FEE_PERCENTAGE, @@ -51,7 +51,7 @@ contract StableSurgeHookUnitTest is BaseVaultTest { assertEq(stableSurgeHook.getSurgeThresholdPercentage(pool), 0, "Surge threshold percentage should be 0"); vm.expectEmit(); - emit StableSurgeHook.StableSurgeHookRegistered(pool, address(factoryMock)); + emit StableSurgeHook.StableSurgeHookRegistered(pool, poolFactory); _registerPool(); assertEq( @@ -78,7 +78,7 @@ contract StableSurgeHookUnitTest is BaseVaultTest { LiquidityManagement memory emptyLiquidityManagement; vm.prank(address(vault)); - stableSurgeHook.onRegister(address(factoryMock), pool, new TokenConfig[](0), emptyLiquidityManagement); + stableSurgeHook.onRegister(poolFactory, pool, new TokenConfig[](0), emptyLiquidityManagement); } function testGetHookFlags() public view { diff --git a/pkg/pool-hooks/test/foundry/VeBALFeeDiscountHookExample.t.sol b/pkg/pool-hooks/test/foundry/VeBALFeeDiscountHookExample.t.sol index 2a4b29373..c7c8a99b7 100644 --- a/pkg/pool-hooks/test/foundry/VeBALFeeDiscountHookExample.t.sol +++ b/pkg/pool-hooks/test/foundry/VeBALFeeDiscountHookExample.t.sol @@ -53,7 +53,7 @@ contract VeBALFeeDiscountHookExampleTest is BaseVaultTest { // lp will be the owner of the hook. Only LP is able to set hook fee percentages. vm.prank(lp); address veBalFeeHook = address( - new VeBALFeeDiscountHookExample(IVault(address(vault)), address(factoryMock), address(veBAL), trustedRouter) + new VeBALFeeDiscountHookExample(IVault(address(vault)), poolFactory, address(veBAL), trustedRouter) ); vm.label(veBalFeeHook, "VeBAL Fee Hook"); return veBalFeeHook; @@ -92,15 +92,15 @@ contract VeBALFeeDiscountHookExampleTest is BaseVaultTest { IVaultErrors.HookRegistrationFailed.selector, poolHooksContract, veBalFeePool, - address(factoryMock) + poolFactory ) ); - _registerPoolWithHook(veBalFeePool, tokenConfig, address(factoryMock)); + _registerPoolWithHook(veBalFeePool, tokenConfig, poolFactory); } function testSuccessfulRegistry() public { // Register with the allowed factory. - address veBalFeePool = factoryMock.createPool("Test Pool", "TEST"); + address veBalFeePool = PoolFactoryMock(poolFactory).createPool("Test Pool", "TEST"); TokenConfig[] memory tokenConfig = vault.buildTokenConfig( [address(dai), address(usdc)].toMemoryArray().asIERC20() ); @@ -108,11 +108,11 @@ contract VeBALFeeDiscountHookExampleTest is BaseVaultTest { vm.expectEmit(); emit VeBALFeeDiscountHookExample.VeBALFeeDiscountHookExampleRegistered( poolHooksContract, - address(factoryMock), + poolFactory, veBalFeePool ); - _registerPoolWithHook(veBalFeePool, tokenConfig, address(factoryMock)); + _registerPoolWithHook(veBalFeePool, tokenConfig, poolFactory); HooksConfig memory hooksConfig = vault.getHooksConfig(veBalFeePool); diff --git a/pkg/pool-stable/test/foundry/E2eBatchSwap.t.sol b/pkg/pool-stable/test/foundry/E2eBatchSwap.t.sol index a70567325..14d4fc523 100644 --- a/pkg/pool-stable/test/foundry/E2eBatchSwap.t.sol +++ b/pkg/pool-stable/test/foundry/E2eBatchSwap.t.sol @@ -20,6 +20,7 @@ import { StablePoolContractsDeployer } from "./utils/StablePoolContractsDeployer contract E2eBatchSwapStableTest is E2eBatchSwapTest, StablePoolContractsDeployer { using CastingHelpers for address[]; + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_SWAP_FEE_STABLE = 1e12; // 0.0001% uint256 internal constant DEFAULT_AMP_FACTOR = 200; @@ -41,6 +42,10 @@ contract E2eBatchSwapStableTest is E2eBatchSwapTest, StablePoolContractsDeployer maxSwapAmountTokenD = poolInitAmount / 4; } + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by E2eBatchSwapTest tests. function _createPool( address[] memory tokens, @@ -48,17 +53,11 @@ contract E2eBatchSwapStableTest is E2eBatchSwapTest, StablePoolContractsDeployer ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; - StablePoolFactory factory = deployStablePoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; - newPool = factory.create( + bytes32 salt = keccak256(abi.encode(label)); + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -68,7 +67,7 @@ contract E2eBatchSwapStableTest is E2eBatchSwapTest, StablePoolContractsDeployer address(0), false, // Do not enable donations false, // Do not disable unbalanced add/remove liquidity - ZERO_BYTES32 + salt ); vm.label(address(newPool), label); @@ -83,7 +82,7 @@ contract E2eBatchSwapStableTest is E2eBatchSwapTest, StablePoolContractsDeployer name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/E2eErc4626Swaps.t.sol b/pkg/pool-stable/test/foundry/E2eErc4626Swaps.t.sol index 8e29dc8ca..ca56ddc8a 100644 --- a/pkg/pool-stable/test/foundry/E2eErc4626Swaps.t.sol +++ b/pkg/pool-stable/test/foundry/E2eErc4626Swaps.t.sol @@ -16,29 +16,27 @@ import { StablePool } from "../../contracts/StablePool.sol"; import { StablePoolContractsDeployer } from "./utils/StablePoolContractsDeployer.sol"; contract E2eErc4626SwapsStableTest is E2eErc4626SwapsTest, StablePoolContractsDeployer { + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 internal constant DEFAULT_AMP_FACTOR = 200; + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function createPool() internal override returns (address newPool, bytes memory poolArgs) { string memory name = "ERC4626 Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; // Gets the tokenConfig from BaseERC4626BufferTest (it means, waDAI and waUSDC with rate providers). TokenConfig[] memory tokenConfig = getTokenConfig(); - StablePoolFactory factory = deployStablePoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, tokenConfig, @@ -63,7 +61,7 @@ contract E2eErc4626SwapsStableTest is E2eErc4626SwapsTest, StablePoolContractsDe name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/E2eSwap.t.sol b/pkg/pool-stable/test/foundry/E2eSwap.t.sol index df55c675f..a76e3050e 100644 --- a/pkg/pool-stable/test/foundry/E2eSwap.t.sol +++ b/pkg/pool-stable/test/foundry/E2eSwap.t.sol @@ -22,6 +22,7 @@ contract E2eSwapStableTest is E2eSwapTest, StablePoolContractsDeployer { using CastingHelpers for address[]; using FixedPoint for uint256; + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 internal constant DEFAULT_AMP_FACTOR = 200; @@ -81,6 +82,10 @@ contract E2eSwapStableTest is E2eSwapTest, StablePoolContractsDeployer { maxSwapAmountTokenB = poolInitAmountTokenB.mulDown(50e16); } + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by E2eSwapTest tests. function _createPool( address[] memory tokens, @@ -88,20 +93,13 @@ contract E2eSwapStableTest is E2eSwapTest, StablePoolContractsDeployer { ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; - StablePoolFactory factory = deployStablePoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -126,7 +124,7 @@ contract E2eSwapStableTest is E2eSwapTest, StablePoolContractsDeployer { name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/E2eSwapRateProvider.t.sol b/pkg/pool-stable/test/foundry/E2eSwapRateProvider.t.sol index 8fa3d24f1..575289883 100644 --- a/pkg/pool-stable/test/foundry/E2eSwapRateProvider.t.sol +++ b/pkg/pool-stable/test/foundry/E2eSwapRateProvider.t.sol @@ -28,6 +28,10 @@ contract E2eSwapRateProviderStableTest is VaultContractsDeployer, E2eSwapRatePro uint256 internal constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 internal constant DEFAULT_AMP_FACTOR = 200; + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1")); + } + function _createPool( address[] memory tokens, string memory label @@ -42,13 +46,12 @@ contract E2eSwapRateProviderStableTest is VaultContractsDeployer, E2eSwapRatePro rateProviders[tokenAIdx] = IRateProvider(address(rateProviderTokenA)); rateProviders[tokenBIdx] = IRateProvider(address(rateProviderTokenB)); - StablePoolFactory factory = deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = StablePoolFactory(poolFactory).create( "Stable Pool", "STABLE", vault.buildTokenConfig(tokens.asIERC20(), rateProviders), diff --git a/pkg/pool-stable/test/foundry/FungibilityStable.t.sol b/pkg/pool-stable/test/foundry/FungibilityStable.t.sol index 83c75a6c8..2c33d72f6 100644 --- a/pkg/pool-stable/test/foundry/FungibilityStable.t.sol +++ b/pkg/pool-stable/test/foundry/FungibilityStable.t.sol @@ -19,8 +19,13 @@ import { StablePoolContractsDeployer } from "./utils/StablePoolContractsDeployer contract FungibilityStableTest is StablePoolContractsDeployer, FungibilityTest { using CastingHelpers for address[]; + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_AMP_FACTOR = 2000; + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by FungibilityTest. function _createPool( address[] memory tokens, @@ -28,20 +33,13 @@ contract FungibilityStableTest is StablePoolContractsDeployer, FungibilityTest { ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; - StablePoolFactory factory = deployStablePoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -60,7 +58,7 @@ contract FungibilityStableTest is StablePoolContractsDeployer, FungibilityTest { name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/LiquidityApproximationStable.t.sol b/pkg/pool-stable/test/foundry/LiquidityApproximationStable.t.sol index 2a1bb6786..60e496cee 100644 --- a/pkg/pool-stable/test/foundry/LiquidityApproximationStable.t.sol +++ b/pkg/pool-stable/test/foundry/LiquidityApproximationStable.t.sol @@ -23,6 +23,8 @@ contract LiquidityApproximationStableTest is LiquidityApproximationTest, StableP using CastingHelpers for address[]; uint256 poolCreationNonce; + + string constant POOL_VERSION = "Pool v1"; uint256 constant DEFAULT_AMP_FACTOR = 200; function setUp() public virtual override { @@ -42,26 +44,24 @@ contract LiquidityApproximationStableTest is LiquidityApproximationTest, StableP maxSwapFeePercentage = IBasePool(swapPool).getMaximumSwapFeePercentage(); } + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function _createPool( address[] memory tokens, string memory label ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; - StablePoolFactory factory = deployStablePoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use PoolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + bytes32 salt = keccak256(abi.encodePacked(poolCreationNonce++)); + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -71,7 +71,7 @@ contract LiquidityApproximationStableTest is LiquidityApproximationTest, StableP poolHooksContract, false, // Do not enable donations false, // Do not disable unbalanced add/remove liquidity - ZERO_BYTES32 + salt ); vm.label(newPool, label); @@ -80,7 +80,7 @@ contract LiquidityApproximationStableTest is LiquidityApproximationTest, StableP name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/RoundingDirectionEdgeCases.t.sol b/pkg/pool-stable/test/foundry/RoundingDirectionEdgeCases.t.sol index 7d4c966b3..d35d5729f 100644 --- a/pkg/pool-stable/test/foundry/RoundingDirectionEdgeCases.t.sol +++ b/pkg/pool-stable/test/foundry/RoundingDirectionEdgeCases.t.sol @@ -29,6 +29,7 @@ contract RoundingDirectionStablePoolEdgeCasesTest is StablePoolContractsDeployer using ArrayHelpers for *; using FixedPoint for uint256; + string constant POOL_VERSION = "Pool v1"; uint256 constant TOKEN_AMOUNT = 1e3 ether; RateProviderMock rateProviderWstEth; @@ -41,12 +42,13 @@ contract RoundingDirectionStablePoolEdgeCasesTest is StablePoolContractsDeployer poolMaxSwapFeePercentage = 10e16; } + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function createPool() internal override returns (address newPool, bytes memory poolArgs) { string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - string memory poolVersion = "Pool v1"; - - factory = deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); TokenConfig[] memory tokenConfigs = new TokenConfig[](2); IERC20[] memory sortedTokens = InputHelpers.sortTokens( @@ -66,9 +68,9 @@ contract RoundingDirectionStablePoolEdgeCasesTest is StablePoolContractsDeployer PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = StablePoolFactory(address(factory)).create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, tokenConfigs, @@ -88,7 +90,7 @@ contract RoundingDirectionStablePoolEdgeCasesTest is StablePoolContractsDeployer name: name, symbol: symbol, amplificationParameter: 2000, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/StablePool.t.sol b/pkg/pool-stable/test/foundry/StablePool.t.sol index 9b5e7d6b5..addab0d93 100644 --- a/pkg/pool-stable/test/foundry/StablePool.t.sol +++ b/pkg/pool-stable/test/foundry/StablePool.t.sol @@ -30,6 +30,7 @@ contract StablePoolTest is BasePoolTest, StablePoolContractsDeployer { using CastingHelpers for address[]; using ArrayHelpers for *; + string constant POOL_VERSION = "Pool v1"; uint256 constant DEFAULT_AMP_FACTOR = 200; uint256 constant TOKEN_AMOUNT = 1e3 * 1e18; @@ -42,12 +43,13 @@ contract StablePoolTest is BasePoolTest, StablePoolContractsDeployer { poolMaxSwapFeePercentage = 10e16; } + function createPoolFactory() internal override returns (address) { + return address(deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function createPool() internal override returns (address newPool, bytes memory poolArgs) { string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - string memory poolVersion = "Pool v1"; - - factory = deployStablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); TokenConfig[] memory tokenConfigs = new TokenConfig[](2); IERC20[] memory sortedTokens = InputHelpers.sortTokens( @@ -62,9 +64,9 @@ contract StablePoolTest is BasePoolTest, StablePoolContractsDeployer { PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = StablePoolFactory(address(factory)).create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, tokenConfigs, @@ -83,7 +85,7 @@ contract StablePoolTest is BasePoolTest, StablePoolContractsDeployer { name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-stable/test/foundry/fuzz/AddAndRemoveLiquidityStable.medusa.sol b/pkg/pool-stable/test/foundry/fuzz/AddAndRemoveLiquidityStable.medusa.sol index 45d897495..3434cf306 100644 --- a/pkg/pool-stable/test/foundry/fuzz/AddAndRemoveLiquidityStable.medusa.sol +++ b/pkg/pool-stable/test/foundry/fuzz/AddAndRemoveLiquidityStable.medusa.sol @@ -26,10 +26,7 @@ contract AddAndRemoveLiquidityStableMedusaTest is AddAndRemoveLiquidityMedusaTes maxRateTolerance = 0; } - function createPool( - IERC20[] memory tokens, - uint256[] memory initialBalances - ) internal override returns (address newPool) { + function createPool(IERC20[] memory tokens, uint256[] memory initialBalances) internal override returns (address) { StablePoolFactory factory = new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); PoolRoleAccounts memory roleAccounts; diff --git a/pkg/pool-weighted/test/foundry/BigWeightedPool.t.sol b/pkg/pool-weighted/test/foundry/BigWeightedPool.t.sol index 2cdc2ebf3..1fb426ca9 100644 --- a/pkg/pool-weighted/test/foundry/BigWeightedPool.t.sol +++ b/pkg/pool-weighted/test/foundry/BigWeightedPool.t.sol @@ -21,6 +21,7 @@ import { WeightedPool } from "../../contracts/WeightedPool.sol"; import { WeightedPoolContractsDeployer } from "./utils/WeightedPoolContractsDeployer.sol"; contract BigWeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { + string constant POOL_VERSION = "Pool v1"; uint256 constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 constant TOKEN_AMOUNT = 1e3 * 1e18; @@ -40,12 +41,14 @@ contract BigWeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { poolMaxSwapFeePercentage = 10e16; } + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function createPool() internal override returns (address newPool, bytes memory poolArgs) { string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - string memory poolVersion = "Pool v1"; - factory = deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); PoolRoleAccounts memory roleAccounts; uint256 numTokens = vault.getMaximumPoolTokens(); @@ -61,9 +64,9 @@ contract BigWeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { } // Allow pools created by `factory` to use PoolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = WeightedPoolFactory(address(factory)).create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(bigPoolTokens), @@ -84,7 +87,7 @@ contract BigWeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { symbol: symbol, numTokens: bigPoolTokens.length, normalizedWeights: weights, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-weighted/test/foundry/E2ESwapRateProvider.t.sol b/pkg/pool-weighted/test/foundry/E2ESwapRateProvider.t.sol index 2a178636d..0ec0d3c2d 100644 --- a/pkg/pool-weighted/test/foundry/E2ESwapRateProvider.t.sol +++ b/pkg/pool-weighted/test/foundry/E2ESwapRateProvider.t.sol @@ -40,6 +40,10 @@ contract E2eSwapRateProviderWeightedTest is super.setUp(); } + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1")); + } + function _createPool( address[] memory tokens, string memory label @@ -54,18 +58,12 @@ contract E2eSwapRateProviderWeightedTest is rateProviders[tokenAIdx] = IRateProvider(address(rateProviderTokenA)); rateProviders[tokenBIdx] = IRateProvider(address(rateProviderTokenB)); - WeightedPoolFactory factory = deployWeightedPoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - "Pool v1" - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( "50/50 Weighted Pool", "50_50WP", vault.buildTokenConfig(tokens.asIERC20(), rateProviders), diff --git a/pkg/pool-weighted/test/foundry/E2eBatchSwap.t.sol b/pkg/pool-weighted/test/foundry/E2eBatchSwap.t.sol index aee0021d1..8bc39a94b 100644 --- a/pkg/pool-weighted/test/foundry/E2eBatchSwap.t.sol +++ b/pkg/pool-weighted/test/foundry/E2eBatchSwap.t.sol @@ -22,6 +22,7 @@ contract E2eBatchSwapWeightedTest is WeightedPoolContractsDeployer, E2eBatchSwap using ArrayHelpers for *; using CastingHelpers for address[]; + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_SWAP_FEE_WEIGHTED = 1e16; // 1% uint256 internal poolCreationNonce; @@ -54,6 +55,10 @@ contract E2eBatchSwapWeightedTest is WeightedPoolContractsDeployer, E2eBatchSwap maxSwapAmountTokenD = poolInitAmount / 10; } + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by E2eSwapTest tests. function _createPool( address[] memory tokens, @@ -61,17 +66,10 @@ contract E2eBatchSwapWeightedTest is WeightedPoolContractsDeployer, E2eBatchSwap ) internal virtual override returns (address newPool, bytes memory poolArgs) { string memory name = "50/50 Weighted Pool"; string memory symbol = "50_50WP"; - string memory poolVersion = "Pool v1"; - WeightedPoolFactory factory = deployWeightedPoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -98,7 +96,7 @@ contract E2eBatchSwapWeightedTest is WeightedPoolContractsDeployer, E2eBatchSwap symbol: symbol, numTokens: tokens.length, normalizedWeights: [uint256(50e16), uint256(50e16)].toMemoryArray(), - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-weighted/test/foundry/E2eSwap.t.sol b/pkg/pool-weighted/test/foundry/E2eSwap.t.sol index 175ae9b8c..9b658cda0 100644 --- a/pkg/pool-weighted/test/foundry/E2eSwap.t.sol +++ b/pkg/pool-weighted/test/foundry/E2eSwap.t.sol @@ -29,6 +29,7 @@ contract E2eSwapWeightedTest is E2eSwapTest, WeightedPoolContractsDeployer { using CastingHelpers for address[]; using FixedPoint for uint256; + string internal constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 internal poolCreationNonce; @@ -276,6 +277,10 @@ contract E2eSwapWeightedTest is E2eSwapTest, WeightedPoolContractsDeployer { assertApproxEqRel(amountIn, tokenAAmountIn, 0.00001e16, "Swap fees are not symmetric for ExactIn and ExactOut"); } + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by E2eSwapTest tests. function _createPool( address[] memory tokens, @@ -283,20 +288,13 @@ contract E2eSwapWeightedTest is E2eSwapTest, WeightedPoolContractsDeployer { ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "50/50 Weighted Pool"; string memory symbol = "50_50WP"; - string memory poolVersion = "Pool v1"; - WeightedPoolFactory factory = deployWeightedPoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -323,7 +321,7 @@ contract E2eSwapWeightedTest is E2eSwapTest, WeightedPoolContractsDeployer { symbol: symbol, numTokens: tokens.length, normalizedWeights: [uint256(50e16), uint256(50e16)].toMemoryArray(), - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-weighted/test/foundry/FungibilityWeighted.t.sol b/pkg/pool-weighted/test/foundry/FungibilityWeighted.t.sol index 53b332206..6150fdc81 100644 --- a/pkg/pool-weighted/test/foundry/FungibilityWeighted.t.sol +++ b/pkg/pool-weighted/test/foundry/FungibilityWeighted.t.sol @@ -21,8 +21,13 @@ contract FungibilityWeightedTest is WeightedPoolContractsDeployer, FungibilityTe using ArrayHelpers for *; using CastingHelpers for address[]; + string constant POOL_VERSION = "Pool v1"; uint256 internal poolCreationNonce; + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + /// @notice Overrides BaseVaultTest _createPool(). This pool is used by FungibilityTest. function _createPool( address[] memory tokens, @@ -30,20 +35,13 @@ contract FungibilityWeightedTest is WeightedPoolContractsDeployer, FungibilityTe ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "80/20 Weighted Pool"; string memory symbol = "80_20WP"; - string memory poolVersion = "Pool v1"; - WeightedPoolFactory factory = deployWeightedPoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - poolVersion - ); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks. - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -64,7 +62,7 @@ contract FungibilityWeightedTest is WeightedPoolContractsDeployer, FungibilityTe symbol: symbol, numTokens: tokens.length, normalizedWeights: [uint256(80e16), uint256(20e16)].toMemoryArray(), - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/pool-weighted/test/foundry/WeightedPool.t.sol b/pkg/pool-weighted/test/foundry/WeightedPool.t.sol index 12c4106fb..edce0d2f9 100644 --- a/pkg/pool-weighted/test/foundry/WeightedPool.t.sol +++ b/pkg/pool-weighted/test/foundry/WeightedPool.t.sol @@ -23,6 +23,7 @@ import { InputHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpers import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/ArrayHelpers.sol"; import { WeightedMath } from "@balancer-labs/v3-solidity-utils/contracts/math/WeightedMath.sol"; import { BasePoolTest } from "@balancer-labs/v3-vault/test/foundry/utils/BasePoolTest.sol"; +import { PoolFactoryMock } from "@balancer-labs/v3-vault/contracts/test/PoolFactoryMock.sol"; import { PoolHooksMock } from "@balancer-labs/v3-vault/contracts/test/PoolHooksMock.sol"; import { WeightedPoolFactory } from "../../contracts/WeightedPoolFactory.sol"; @@ -33,6 +34,7 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { using CastingHelpers for address[]; using ArrayHelpers for *; + string constant POOL_VERSION = "Pool v1"; uint256 constant DEFAULT_SWAP_FEE = 1e16; // 1% uint256 constant TOKEN_AMOUNT = 1e3 * 1e18; @@ -54,10 +56,13 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { poolMaxSwapFeePercentage = 10e16; } + function createPoolFactory() internal override returns (address) { + return address(deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function createPool() internal override returns (address newPool, bytes memory poolArgs) { string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - string memory poolVersion = "Pool v1"; IERC20[] memory sortedTokens = InputHelpers.sortTokens( [address(dai), address(usdc)].toMemoryArray().asIERC20() @@ -67,14 +72,13 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { tokenAmounts.push(TOKEN_AMOUNT); } - factory = deployWeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); weights = [uint256(50e16), uint256(50e16)].toMemoryArray(); PoolRoleAccounts memory roleAccounts; // Allow pools created by `factory` to use poolHooksMock hooks - PoolHooksMock(poolHooksContract).allowFactory(address(factory)); + PoolHooksMock(poolHooksContract).allowFactory(poolFactory); - newPool = WeightedPoolFactory(address(factory)).create( + newPool = WeightedPoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(sortedTokens), @@ -94,7 +98,7 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { symbol: symbol, numTokens: sortedTokens.length, normalizedWeights: weights, - version: poolVersion + version: POOL_VERSION }), vault ); @@ -123,7 +127,7 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { PoolRoleAccounts memory roleAccounts; - address lowFeeWeightedPool = WeightedPoolFactory(address(factory)).create( + address lowFeeWeightedPool = WeightedPoolFactory(poolFactory).create( "ERC20 Pool", "ERC20POOL", tokenConfigs, @@ -137,7 +141,7 @@ contract WeightedPoolTest is WeightedPoolContractsDeployer, BasePoolTest { ); vm.expectRevert(IVaultErrors.SwapFeePercentageTooLow.selector); - factoryMock.registerTestPool(lowFeeWeightedPool, tokenConfigs); + PoolFactoryMock(poolFactory).registerTestPool(lowFeeWeightedPool, tokenConfigs); } function testGetWeightedPoolImmutableData() public view { diff --git a/pkg/pool-weighted/test/foundry/fuzz/AddAndRemoveLiquidityWeighted.medusa.sol b/pkg/pool-weighted/test/foundry/fuzz/AddAndRemoveLiquidityWeighted.medusa.sol index 9d77ced91..42211dd76 100644 --- a/pkg/pool-weighted/test/foundry/fuzz/AddAndRemoveLiquidityWeighted.medusa.sol +++ b/pkg/pool-weighted/test/foundry/fuzz/AddAndRemoveLiquidityWeighted.medusa.sol @@ -31,10 +31,7 @@ contract AddAndRemoveLiquidityWeightedMedusaTest is AddAndRemoveLiquidityMedusaT maxRateTolerance = 10; } - function createPool( - IERC20[] memory tokens, - uint256[] memory initialBalances - ) internal override returns (address newPool) { + function createPool(IERC20[] memory tokens, uint256[] memory initialBalances) internal override returns (address) { uint256[] memory weights = new uint256[](3); weights[0] = _WEIGHT1; weights[1] = _WEIGHT2; diff --git a/pkg/vault/test/foundry/BigPoolData.t.sol b/pkg/vault/test/foundry/BigPoolData.t.sol index 6a46a8c47..65456f11f 100644 --- a/pkg/vault/test/foundry/BigPoolData.t.sol +++ b/pkg/vault/test/foundry/BigPoolData.t.sol @@ -17,7 +17,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract BigPoolDataTest is BaseVaultTest { using FixedPoint for uint256; @@ -51,7 +51,7 @@ contract BigPoolDataTest is BaseVaultTest { _approveForPool(IERC20(newPool)); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig(bigPoolTokens, bigPoolRateProviders), poolHooksContract, diff --git a/pkg/vault/test/foundry/CompositeLiquidityRouterERC4626Pool.t.sol b/pkg/vault/test/foundry/CompositeLiquidityRouterERC4626Pool.t.sol index 100e94a15..d09da8588 100644 --- a/pkg/vault/test/foundry/CompositeLiquidityRouterERC4626Pool.t.sol +++ b/pkg/vault/test/foundry/CompositeLiquidityRouterERC4626Pool.t.sol @@ -21,7 +21,7 @@ import { VaultContractsDeployer } from "./utils/VaultContractsDeployer.sol"; import { BaseERC4626BufferTest } from "./utils/BaseERC4626BufferTest.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract CompositeLiquidityRouterERC4626PoolTest is BaseERC4626BufferTest { using ArrayHelpers for *; @@ -1327,7 +1327,7 @@ contract CompositeLiquidityRouterERC4626PoolTest is BaseERC4626BufferTest { newPool = address(deployPoolMock(IVault(address(vault)), "PARTIAL ERC4626 Pool", "PART-ERC4626P")); - factoryMock.registerTestPool(newPool, tokenConfig, poolHooksContract); + PoolFactoryMock(poolFactory).registerTestPool(newPool, tokenConfig, poolHooksContract); vm.label(newPool, "partial erc4626 pool"); diff --git a/pkg/vault/test/foundry/DynamicFeePoolTest.t.sol b/pkg/vault/test/foundry/DynamicFeePoolTest.t.sol index 08263a671..0f87afa19 100644 --- a/pkg/vault/test/foundry/DynamicFeePoolTest.t.sol +++ b/pkg/vault/test/foundry/DynamicFeePoolTest.t.sol @@ -17,6 +17,7 @@ import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/Ar import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { PoolHooksMock } from "../../contracts/test/PoolHooksMock.sol"; import { PoolConfigBits, PoolConfigLib } from "../../contracts/lib/PoolConfigLib.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; @@ -68,7 +69,7 @@ contract DynamicFeePoolTest is BaseVaultTest { liquidityManagement.enableAddLiquidityCustom = true; liquidityManagement.enableRemoveLiquidityCustom = true; - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( address(newPool), vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/vault/test/foundry/E2eBatchSwap.t.sol b/pkg/vault/test/foundry/E2eBatchSwap.t.sol index 3596ecad8..c71bfcca0 100644 --- a/pkg/vault/test/foundry/E2eBatchSwap.t.sol +++ b/pkg/vault/test/foundry/E2eBatchSwap.t.sol @@ -78,7 +78,7 @@ contract E2eBatchSwapTest is BaseVaultTest { (poolB, ) = _createPool([address(tokenB), address(tokenC)].toMemoryArray(), "poolB"); _initPool(poolB, [poolInitAmount, poolInitAmount].toMemoryArray(), 0); // Create poolC. - (poolC, ) = _createPool([address(tokenC), address(tokenD)].toMemoryArray(), "PoolC"); + (poolC, ) = _createPool([address(tokenC), address(tokenD)].toMemoryArray(), "poolC"); _initPool(poolC, [poolInitAmount, poolInitAmount].toMemoryArray(), 0); vm.stopPrank(); diff --git a/pkg/vault/test/foundry/E2eSwap.t.sol b/pkg/vault/test/foundry/E2eSwap.t.sol index 67aabc3ee..8467721cf 100644 --- a/pkg/vault/test/foundry/E2eSwap.t.sol +++ b/pkg/vault/test/foundry/E2eSwap.t.sol @@ -57,20 +57,6 @@ contract E2eSwapTest is BaseVaultTest { BaseVaultTest.setUp(); - // Tokens must be set before other variables, so the variables can be calculated based on tokens. - setUpTokens(); - decimalsTokenA = IERC20Metadata(address(tokenA)).decimals(); - decimalsTokenB = IERC20Metadata(address(tokenB)).decimals(); - - (tokenAIdx, tokenBIdx) = getSortedIndexes(address(tokenA), address(tokenB)); - - // Pool Init Amount values are needed to set up variables that rely on the initial pool state. - setPoolInitAmounts(); - - setUpVariables(); - calculateMinAndMaxSwapAmounts(); - createAndInitCustomPool(); - // Donate tokens to vault as a shortcut to change the pool balances without the need to pass through add/remove // liquidity operations. (No need to deal with BPTs, pranking LPs, guardrails, etc). _donateToVault(); @@ -104,14 +90,29 @@ contract E2eSwapTest is BaseVaultTest { * pool after the BaseVaultTest setUp finishes. */ - function createAndInitCustomPool() internal virtual { + function createPool() internal virtual override returns (address newPool, bytes memory poolArgs) { + // Tokens must be set before other variables, so the variables can be calculated based on tokens. + setUpTokens(); + decimalsTokenA = IERC20Metadata(address(tokenA)).decimals(); + decimalsTokenB = IERC20Metadata(address(tokenB)).decimals(); + + (tokenAIdx, tokenBIdx) = getSortedIndexes(address(tokenA), address(tokenB)); + + // Pool Init Amount values are needed to set up variables that rely on the initial pool state. + setPoolInitAmounts(); + + setUpVariables(); + calculateMinAndMaxSwapAmounts(); + address[] memory tokens = new address[](2); tokens[tokenAIdx] = address(tokenA); tokens[tokenBIdx] = address(tokenB); - (pool, ) = _createPool(tokens, "custom-pool"); + (newPool, poolArgs) = _createPool(tokens, "custom-pool"); setPoolInitAmounts(); + } + function initPool() internal override { uint256[] memory initAmounts = new uint256[](2); initAmounts[tokenAIdx] = poolInitAmountTokenA; initAmounts[tokenBIdx] = poolInitAmountTokenB; diff --git a/pkg/vault/test/foundry/E2eSwapRateProvider.t.sol b/pkg/vault/test/foundry/E2eSwapRateProvider.t.sol index 8c8c88f8e..0bdc20b4f 100644 --- a/pkg/vault/test/foundry/E2eSwapRateProvider.t.sol +++ b/pkg/vault/test/foundry/E2eSwapRateProvider.t.sol @@ -12,6 +12,7 @@ import { CastingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpe import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol"; import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { VaultContractsDeployer } from "./utils/VaultContractsDeployer.sol"; import { E2eSwapTest } from "./E2eSwap.t.sol"; @@ -23,6 +24,16 @@ contract E2eSwapRateProviderTest is VaultContractsDeployer, E2eSwapTest { RateProviderMock internal rateProviderTokenA; RateProviderMock internal rateProviderTokenB; + function createPool() internal virtual override returns (address newPool, bytes memory poolArgs) { + rateProviderTokenA = deployRateProviderMock(); + rateProviderTokenB = deployRateProviderMock(); + // Mock rates, so all tests that keep the rate constant use a rate different than 1. + rateProviderTokenA.mockRate(5.2453235e18); + rateProviderTokenB.mockRate(0.4362784e18); + + return super.createPool(); + } + function _createPool( address[] memory tokens, string memory label @@ -30,20 +41,14 @@ contract E2eSwapRateProviderTest is VaultContractsDeployer, E2eSwapTest { string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - newPool = factoryMock.createPool(name, symbol); + newPool = PoolFactoryMock(poolFactory).createPool(name, symbol); vm.label(newPool, label); - rateProviderTokenA = deployRateProviderMock(); - rateProviderTokenB = deployRateProviderMock(); - // Mock rates, so all tests that keep the rate constant use a rate different than 1. - rateProviderTokenA.mockRate(5.2453235e18); - rateProviderTokenB.mockRate(0.4362784e18); - IRateProvider[] memory rateProviders = new IRateProvider[](2); rateProviders[tokenAIdx] = IRateProvider(address(rateProviderTokenA)); rateProviders[tokenBIdx] = IRateProvider(address(rateProviderTokenB)); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig(tokens.asIERC20(), rateProviders), poolHooksContract, diff --git a/pkg/vault/test/foundry/GetBptRate.t.sol b/pkg/vault/test/foundry/GetBptRate.t.sol index 408b66585..6d09691b3 100644 --- a/pkg/vault/test/foundry/GetBptRate.t.sol +++ b/pkg/vault/test/foundry/GetBptRate.t.sol @@ -40,13 +40,16 @@ contract GetBptRateTest is BaseVaultTest { (daiIdx, usdcIdx) = getSortedIndexes(address(dai), address(usdc)); } + function createPoolFactory() internal override returns (address) { + return address(new WeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Weighted Pool v1")); + } + function _createPool( address[] memory tokens, string memory label ) internal virtual override returns (address newPool, bytes memory poolArgs) { PoolRoleAccounts memory roleAccounts; - factory = new WeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Weighted Pool v1"); weights = [uint256(50e16), uint256(50e16)].toMemoryArray(); RateProviderMock rateProviderDai = deployRateProviderMock(); @@ -59,7 +62,7 @@ contract GetBptRateTest is BaseVaultTest { rateProviders[0] = IRateProvider(rateProviderDai); rateProviders[1] = IRateProvider(rateProviderUsdc); - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( "ERC20 Pool", "ERC20POOL", vault.buildTokenConfig(tokens.asIERC20(), rateProviders), diff --git a/pkg/vault/test/foundry/HookAdjustedLiquidity.t.sol b/pkg/vault/test/foundry/HookAdjustedLiquidity.t.sol index 865fa4fb3..90730a284 100644 --- a/pkg/vault/test/foundry/HookAdjustedLiquidity.t.sol +++ b/pkg/vault/test/foundry/HookAdjustedLiquidity.t.sol @@ -17,6 +17,7 @@ import { BalancerPoolToken } from "../../contracts/BalancerPoolToken.sol"; import { PoolHooksMock } from "../../contracts/test/PoolHooksMock.sol"; import { BasePoolMath } from "../../contracts/BasePoolMath.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; @@ -69,7 +70,7 @@ contract HookAdjustedLiquidityTest is BaseVaultTest { LiquidityManagement memory liquidityManagement; liquidityManagement.disableUnbalancedLiquidity = true; - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/vault/test/foundry/HookAdjustedSwap.t.sol b/pkg/vault/test/foundry/HookAdjustedSwap.t.sol index 2594ff75f..0a9b2fbb0 100644 --- a/pkg/vault/test/foundry/HookAdjustedSwap.t.sol +++ b/pkg/vault/test/foundry/HookAdjustedSwap.t.sol @@ -14,6 +14,7 @@ import { CastingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpe import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { PoolHooksMock } from "../../contracts/test/PoolHooksMock.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; @@ -59,7 +60,7 @@ contract HookAdjustedSwapTest is BaseVaultTest { LiquidityManagement memory liquidityManagement; liquidityManagement.disableUnbalancedLiquidity = true; - factoryMock.registerPool( + PoolFactoryMock(poolFactory).registerPool( newPool, vault.buildTokenConfig(tokens.asIERC20()), roleAccounts, diff --git a/pkg/vault/test/foundry/HooksAlteringBalances.t.sol b/pkg/vault/test/foundry/HooksAlteringBalances.t.sol index 73430fbfd..942629bfd 100644 --- a/pkg/vault/test/foundry/HooksAlteringBalances.t.sol +++ b/pkg/vault/test/foundry/HooksAlteringBalances.t.sol @@ -16,7 +16,7 @@ import { CastingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpe import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { PoolHooksMock } from "../../contracts/test/PoolHooksMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract HooksAlteringBalancesTest is BaseVaultTest { using CastingHelpers for address[]; @@ -53,7 +53,7 @@ contract HooksAlteringBalancesTest is BaseVaultTest { newPool = address(deployPoolMock(IVault(address(vault)), name, symbol)); vm.label(newPool, "pool"); - factoryMock.registerTestPool(newPool, tokenConfig, poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool(newPool, tokenConfig, poolHooksContract, lp); poolArgs = abi.encode(vault, name, symbol); } diff --git a/pkg/vault/test/foundry/HooksAlteringRates.t.sol b/pkg/vault/test/foundry/HooksAlteringRates.t.sol index 4ad1b855c..58f7e5575 100644 --- a/pkg/vault/test/foundry/HooksAlteringRates.t.sol +++ b/pkg/vault/test/foundry/HooksAlteringRates.t.sol @@ -18,7 +18,7 @@ import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { PoolHooksMock } from "../../contracts/test/PoolHooksMock.sol"; import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract HooksAlteringRatesTest is BaseVaultTest { using CastingHelpers for address[]; @@ -54,7 +54,7 @@ contract HooksAlteringRatesTest is BaseVaultTest { newPool = address(deployPoolMock(IVault(address(vault)), name, symbol)); vm.label(newPool, "pool"); - factoryMock.registerTestPool(newPool, tokenConfig, poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool(newPool, tokenConfig, poolHooksContract, lp); poolArgs = abi.encode(vault, name, symbol); } @@ -102,7 +102,7 @@ contract HooksAlteringRatesTest is BaseVaultTest { PoolMock newPool = deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL"); vm.label(address(newPool), "new-pool"); - factoryMock.registerTestPool(address(newPool), tokenConfig, poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool(address(newPool), tokenConfig, poolHooksContract, lp); HooksConfig memory config = vault.getHooksConfig(address(newPool)); config.shouldCallBeforeInitialize = true; diff --git a/pkg/vault/test/foundry/LinearPoolExtremeAmounts.t.sol b/pkg/vault/test/foundry/LinearPoolExtremeAmounts.t.sol index 5c081a8ab..76f32dba9 100644 --- a/pkg/vault/test/foundry/LinearPoolExtremeAmounts.t.sol +++ b/pkg/vault/test/foundry/LinearPoolExtremeAmounts.t.sol @@ -7,6 +7,7 @@ import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/Ar import { CastingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpers/CastingHelpers.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseExtremeAmountsTest } from "./utils/BaseExtremeAmountsTest.sol"; contract LinearPoolExtremeAmountsTest is BaseExtremeAmountsTest { @@ -26,7 +27,12 @@ contract LinearPoolExtremeAmountsTest is BaseExtremeAmountsTest { newPool = address(new PoolMock(IVault(address(vault)), name, symbol)); vm.label(newPool, label); - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens.asIERC20()), address(0), lp); + PoolFactoryMock(poolFactory).registerTestPool( + newPool, + vault.buildTokenConfig(tokens.asIERC20()), + address(0), + lp + ); poolArgs = abi.encode(vault, name, symbol); } diff --git a/pkg/vault/test/foundry/PoolData.t.sol b/pkg/vault/test/foundry/PoolData.t.sol index 7c87d69b2..c59c90730 100644 --- a/pkg/vault/test/foundry/PoolData.t.sol +++ b/pkg/vault/test/foundry/PoolData.t.sol @@ -15,7 +15,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract PoolDataTest is BaseVaultTest { using CastingHelpers for address[]; @@ -43,7 +43,7 @@ contract PoolDataTest is BaseVaultTest { newPool = address(deployPoolMock(IVault(address(vault)), name, symbol)); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig([address(dai), address(wsteth)].toMemoryArray().asIERC20(), rateProviders), poolHooksContract, diff --git a/pkg/vault/test/foundry/PoolPause.t.sol b/pkg/vault/test/foundry/PoolPause.t.sol index b0f4fb0ce..a590842e5 100644 --- a/pkg/vault/test/foundry/PoolPause.t.sol +++ b/pkg/vault/test/foundry/PoolPause.t.sol @@ -42,7 +42,7 @@ contract PoolPauseTest is BaseVaultTest { pool = address(deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL")); - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( pool, tokenConfig, 0, @@ -55,7 +55,7 @@ contract PoolPauseTest is BaseVaultTest { // Pass zero for the pause manager. unmanagedPool = deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL"); - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( address(unmanagedPool), tokenConfig, 0, @@ -67,7 +67,7 @@ contract PoolPauseTest is BaseVaultTest { permissionlessPool = deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL"); - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( address(permissionlessPool), tokenConfig, 0, @@ -79,7 +79,7 @@ contract PoolPauseTest is BaseVaultTest { infinityPool = deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL"); - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( address(infinityPool), tokenConfig, 0, diff --git a/pkg/vault/test/foundry/PoolSwapManager.t.sol b/pkg/vault/test/foundry/PoolSwapManager.t.sol index 77b13d646..60fb89177 100644 --- a/pkg/vault/test/foundry/PoolSwapManager.t.sol +++ b/pkg/vault/test/foundry/PoolSwapManager.t.sol @@ -42,7 +42,7 @@ contract PoolSwapManagerTest is BaseVaultTest { pool = address(deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL")); // Make admin the swap fee manager. - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( pool, tokenConfig, 0, @@ -55,7 +55,7 @@ contract PoolSwapManagerTest is BaseVaultTest { unmanagedPool = deployPoolMock(IVault(address(vault)), "Unmanaged Pool", "UNMANAGED"); // Pass zero for the swap fee manager. - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( address(unmanagedPool), tokenConfig, 0, @@ -69,7 +69,7 @@ contract PoolSwapManagerTest is BaseVaultTest { otherPool = deployPoolMock(IVault(address(vault)), "Other Pool", "OTHER"); // Pass zero for the swap fee manager. - factoryMock.registerGeneralTestPool( + PoolFactoryMock(poolFactory).registerGeneralTestPool( address(otherPool), tokenConfig, 0, diff --git a/pkg/vault/test/foundry/ProtocolFeeController.t.sol b/pkg/vault/test/foundry/ProtocolFeeController.t.sol index 73fac68ab..d143c1031 100644 --- a/pkg/vault/test/foundry/ProtocolFeeController.t.sol +++ b/pkg/vault/test/foundry/ProtocolFeeController.t.sol @@ -21,7 +21,7 @@ import { ProtocolFeeControllerMock } from "../../contracts/test/ProtocolFeeContr import { ProtocolFeeController } from "../../contracts/ProtocolFeeController.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract ProtocolFeeControllerTest is BaseVaultTest { using FixedPoint for uint256; @@ -730,7 +730,7 @@ contract ProtocolFeeControllerTest is BaseVaultTest { function testWithdrawalWithNoCreator() public { PoolMock newPool = deployPoolMock(IVault(address(vault)), "ERC20 Pool", "ERC20POOL"); - factoryMock.registerTestPool(address(newPool), vault.buildTokenConfig(tokens)); + PoolFactoryMock(poolFactory).registerTestPool(address(newPool), vault.buildTokenConfig(tokens)); vm.expectRevert(abi.encodeWithSelector(IProtocolFeeController.PoolCreatorNotRegistered.selector, newPool)); vm.prank(alice); diff --git a/pkg/vault/test/foundry/ProtocolFeeExemption.t.sol b/pkg/vault/test/foundry/ProtocolFeeExemption.t.sol index 7d65c0ff9..69026eb1d 100644 --- a/pkg/vault/test/foundry/ProtocolFeeExemption.t.sol +++ b/pkg/vault/test/foundry/ProtocolFeeExemption.t.sol @@ -13,7 +13,7 @@ import { TokenConfig, PoolConfig, PoolRoleAccounts } from "@balancer-labs/v3-int import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract ProtocolFeeExemptionTest is BaseVaultTest { uint256 internal GLOBAL_SWAP_FEE = 50e16; @@ -58,7 +58,15 @@ contract ProtocolFeeExemptionTest is BaseVaultTest { tokenConfig[usdcIdx].token = IERC20(usdc); pool = address(deployPoolMock(IVault(address(vault)), "Non-Exempt Pool", "NOT-EXEMPT")); - factoryMock.registerGeneralTestPool(pool, tokenConfig, 0, 365 days, false, roleAccounts, address(0)); + PoolFactoryMock(poolFactory).registerGeneralTestPool( + pool, + tokenConfig, + 0, + 365 days, + false, + roleAccounts, + address(0) + ); PoolConfig memory poolConfigBits = vault.getPoolConfig(pool); @@ -72,7 +80,15 @@ contract ProtocolFeeExemptionTest is BaseVaultTest { tokenConfig[usdcIdx].token = IERC20(usdc); pool = address(deployPoolMock(IVault(address(vault)), "Exempt Pool", "EXEMPT")); - factoryMock.registerGeneralTestPool(pool, tokenConfig, 0, 365 days, true, roleAccounts, address(0)); + PoolFactoryMock(poolFactory).registerGeneralTestPool( + pool, + tokenConfig, + 0, + 365 days, + true, + roleAccounts, + address(0) + ); PoolConfig memory poolConfigBits = vault.getPoolConfig(pool); diff --git a/pkg/vault/test/foundry/Router.t.sol b/pkg/vault/test/foundry/Router.t.sol index 6b49b630a..0c9347356 100644 --- a/pkg/vault/test/foundry/Router.t.sol +++ b/pkg/vault/test/foundry/Router.t.sol @@ -28,7 +28,7 @@ import { RouterCommon } from "../../contracts/RouterCommon.sol"; import { BasePoolMath } from "../../contracts/BasePoolMath.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract RouterTest is BaseVaultTest { using CastingHelpers for address[]; @@ -78,7 +78,7 @@ contract RouterTest is BaseVaultTest { paysYieldFees[0] = true; paysYieldFees[1] = true; - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig( [address(dai), address(usdc)].toMemoryArray().asIERC20(), @@ -93,7 +93,7 @@ contract RouterTest is BaseVaultTest { wethPool = deployPoolMock(IVault(address(vault)), "ERC20 weth Pool", "ERC20POOL"); vm.label(address(wethPool), "wethPool"); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( address(wethPool), vault.buildTokenConfig([address(dai), address(weth)].toMemoryArray().asIERC20()), poolHooksContract, @@ -111,7 +111,7 @@ contract RouterTest is BaseVaultTest { wethPoolNoInit = deployPoolMock(IVault(address(vault)), "ERC20 weth Pool", "ERC20POOL"); vm.label(address(wethPoolNoInit), "wethPoolNoInit"); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( address(wethPoolNoInit), vault.buildTokenConfig([address(weth), address(dai)].toMemoryArray().asIERC20()), poolHooksContract, @@ -145,7 +145,7 @@ contract RouterTest is BaseVaultTest { (IERC20[] memory tokens, , , ) = vault.getPoolTokenInfo(pool); - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens), address(0), lp); + PoolFactoryMock(poolFactory).registerTestPool(newPool, vault.buildTokenConfig(tokens), address(0), lp); vm.expectRevert(PackedTokenBalance.BalanceOverflow.selector); vm.prank(lp); diff --git a/pkg/vault/test/foundry/RouterQueriesDiffRates.t.sol b/pkg/vault/test/foundry/RouterQueriesDiffRates.t.sol index 563c48c45..462d22be6 100644 --- a/pkg/vault/test/foundry/RouterQueriesDiffRates.t.sol +++ b/pkg/vault/test/foundry/RouterQueriesDiffRates.t.sol @@ -16,6 +16,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; import { BasePoolMath } from "../../contracts/BasePoolMath.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; @@ -49,14 +50,17 @@ contract RouterQueriesDiffRatesTest is BaseVaultTest { string memory name = "TestPool"; string memory symbol = "TEST"; - newPool = factoryMock.createPool(name, symbol); + newPool = PoolFactoryMock(poolFactory).createPool(name, symbol); vm.label(newPool, label); rateProviders = new IRateProvider[](2); rateProviders[0] = IRateProvider(address(deployRateProviderMock())); rateProviders[1] = IRateProvider(address(deployRateProviderMock())); - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens.asIERC20(), rateProviders)); + PoolFactoryMock(poolFactory).registerTestPool( + newPool, + vault.buildTokenConfig(tokens.asIERC20(), rateProviders) + ); poolArgs = abi.encode(vault, name, symbol); } diff --git a/pkg/vault/test/foundry/StablePoolExtremeAmounts.t.sol b/pkg/vault/test/foundry/StablePoolExtremeAmounts.t.sol index bfa4f4f7f..7a6ac6840 100644 --- a/pkg/vault/test/foundry/StablePoolExtremeAmounts.t.sol +++ b/pkg/vault/test/foundry/StablePoolExtremeAmounts.t.sol @@ -15,25 +15,27 @@ import { BaseExtremeAmountsTest } from "./utils/BaseExtremeAmountsTest.sol"; contract StablePoolExtremeAmountsTest is BaseExtremeAmountsTest { using CastingHelpers for *; + string constant POOL_VERSION = "Pool v1"; uint256 internal constant DEFAULT_AMP_FACTOR = 200; function setUp() public virtual override { BaseExtremeAmountsTest.setUp(); } + function createPoolFactory() internal override returns (address) { + return address(new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", POOL_VERSION)); + } + function _createPool( address[] memory tokens, string memory label ) internal override returns (address newPool, bytes memory poolArgs) { string memory name = "Stable Pool"; string memory symbol = "STABLE"; - string memory poolVersion = "Pool v1"; - - StablePoolFactory factory = new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", poolVersion); PoolRoleAccounts memory roleAccounts; - newPool = factory.create( + newPool = StablePoolFactory(poolFactory).create( name, symbol, vault.buildTokenConfig(tokens.asIERC20()), @@ -52,7 +54,7 @@ contract StablePoolExtremeAmountsTest is BaseExtremeAmountsTest { name: name, symbol: symbol, amplificationParameter: DEFAULT_AMP_FACTOR, - version: poolVersion + version: POOL_VERSION }), vault ); diff --git a/pkg/vault/test/foundry/UnbalancedLiquidityBounds.t.sol b/pkg/vault/test/foundry/UnbalancedLiquidityBounds.t.sol index d0f2da783..ee956b580 100644 --- a/pkg/vault/test/foundry/UnbalancedLiquidityBounds.t.sol +++ b/pkg/vault/test/foundry/UnbalancedLiquidityBounds.t.sol @@ -13,6 +13,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { PoolMockFlexibleInvariantRatio } from "../../contracts/test/PoolMockFlexibleInvariantRatio.sol"; import { BasePoolMath } from "../../contracts/BasePoolMath.sol"; +import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; @@ -33,7 +34,12 @@ contract UnbalancedLiquidityBounds is BaseVaultTest { newPool = address(deployPoolMockFlexibleInvariantRatio(IVault(address(vault)), "", "")); vm.label(newPool, label); - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens.asIERC20()), poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool( + newPool, + vault.buildTokenConfig(tokens.asIERC20()), + poolHooksContract, + lp + ); poolArgs = abi.encode(vault, "", ""); } diff --git a/pkg/vault/test/foundry/VaultLiquidityRate.t.sol b/pkg/vault/test/foundry/VaultLiquidityRate.t.sol index a78c8104e..eb3ac371b 100644 --- a/pkg/vault/test/foundry/VaultLiquidityRate.t.sol +++ b/pkg/vault/test/foundry/VaultLiquidityRate.t.sol @@ -19,7 +19,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract VaultLiquidityWithRatesTest is BaseVaultTest { using CastingHelpers for address[]; @@ -60,7 +60,12 @@ contract VaultLiquidityWithRatesTest is BaseVaultTest { tokens[daiIdx] = dai; tokens[wstethIdx] = wsteth; - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens, rateProviders), poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool( + newPool, + vault.buildTokenConfig(tokens, rateProviders), + poolHooksContract, + lp + ); poolArgs = abi.encode(vault, name, symbol); } diff --git a/pkg/vault/test/foundry/VaultSwapRate.t.sol b/pkg/vault/test/foundry/VaultSwapRate.t.sol index 99fd90997..f3a278337 100644 --- a/pkg/vault/test/foundry/VaultSwapRate.t.sol +++ b/pkg/vault/test/foundry/VaultSwapRate.t.sol @@ -16,7 +16,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract VaultSwapWithRatesTest is BaseVaultTest { using CastingHelpers for address[]; @@ -45,7 +45,7 @@ contract VaultSwapWithRatesTest is BaseVaultTest { newPool = address(deployPoolMock(IVault(address(vault)), name, symbol)); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig([address(wsteth), address(dai)].toMemoryArray().asIERC20(), rateProviders), poolHooksContract, diff --git a/pkg/vault/test/foundry/VaultTokens.t.sol b/pkg/vault/test/foundry/VaultTokens.t.sol index 9d3e636cf..0a34dbe05 100644 --- a/pkg/vault/test/foundry/VaultTokens.t.sol +++ b/pkg/vault/test/foundry/VaultTokens.t.sol @@ -27,8 +27,6 @@ import { PoolMock } from "../../contracts/test/PoolMock.sol"; import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract VaultTokenTest is BaseVaultTest { - PoolFactoryMock poolFactory; - ERC4626TestToken cDAI; // For two-token pools with waDAI/waUSDC, keep track of sorted token order. @@ -44,8 +42,6 @@ contract VaultTokenTest is BaseVaultTest { cDAI = new ERC4626TestToken(dai, "Wrapped cDAI", "cDAI", 18); - poolFactory = deployPoolFactoryMock(vault, 365 days); - // Allow pools from factory poolFactory to use the hook PoolHooksMock. PoolHooksMock(poolHooksContract).allowFactory(address(poolFactory)); @@ -150,6 +146,12 @@ contract VaultTokenTest is BaseVaultTest { LiquidityManagement memory liquidityManagement; PoolRoleAccounts memory roleAccounts; - poolFactory.registerPool(pool, tokenConfig, roleAccounts, poolHooksContract, liquidityManagement); + PoolFactoryMock(poolFactory).registerPool( + pool, + tokenConfig, + roleAccounts, + poolHooksContract, + liquidityManagement + ); } } diff --git a/pkg/vault/test/foundry/WeightedPoolExtremeAmounts.t.sol b/pkg/vault/test/foundry/WeightedPoolExtremeAmounts.t.sol index d9792681f..3e856d431 100644 --- a/pkg/vault/test/foundry/WeightedPoolExtremeAmounts.t.sol +++ b/pkg/vault/test/foundry/WeightedPoolExtremeAmounts.t.sol @@ -22,19 +22,17 @@ contract WeightedPoolExtremeAmountsTest is BaseExtremeAmountsTest { BaseExtremeAmountsTest.setUp(); } + function createPoolFactory() internal override returns (address) { + return address(new WeightedPoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Weighted Pool v1")); + } + function _createPool( address[] memory tokens, string memory label ) internal override returns (address newPool, bytes memory poolArgs) { - WeightedPoolFactory factory = new WeightedPoolFactory( - IVault(address(vault)), - 365 days, - "Factory v1", - "Weighted Pool v1" - ); PoolRoleAccounts memory roleAccounts; - newPool = factory.create( + newPool = WeightedPoolFactory(poolFactory).create( "50/50 Weighted Pool", "50_50WP", vault.buildTokenConfig(tokens.asIERC20()), diff --git a/pkg/vault/test/foundry/YieldFees.t.sol b/pkg/vault/test/foundry/YieldFees.t.sol index 0a28498f2..694117e08 100644 --- a/pkg/vault/test/foundry/YieldFees.t.sol +++ b/pkg/vault/test/foundry/YieldFees.t.sol @@ -16,7 +16,7 @@ import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/Fixe import { RateProviderMock } from "../../contracts/test/RateProviderMock.sol"; import { PoolMock } from "../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "./utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "./utils/BaseVaultTest.sol"; contract YieldFeesTest is BaseVaultTest { using CastingHelpers for address[]; @@ -55,7 +55,7 @@ contract YieldFeesTest is BaseVaultTest { newPool = address(deployPoolMock(IVault(address(vault)), name, symbol)); - factoryMock.registerTestPool( + PoolFactoryMock(poolFactory).registerTestPool( newPool, vault.buildTokenConfig( [address(wsteth), address(dai)].toMemoryArray().asIERC20(), diff --git a/pkg/vault/test/foundry/fork/YieldBearingPoolSwapBase.t.sol b/pkg/vault/test/foundry/fork/YieldBearingPoolSwapBase.t.sol index 2e9c78a6d..3e9539e20 100644 --- a/pkg/vault/test/foundry/fork/YieldBearingPoolSwapBase.t.sol +++ b/pkg/vault/test/foundry/fork/YieldBearingPoolSwapBase.t.sol @@ -18,7 +18,7 @@ import { ScalingHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpe import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol"; import { PoolMock } from "../../../contracts/test/PoolMock.sol"; -import { BaseVaultTest } from "../utils/BaseVaultTest.sol"; +import { PoolFactoryMock, BaseVaultTest } from "../utils/BaseVaultTest.sol"; abstract contract YieldBearingPoolSwapBase is BaseVaultTest { using SafeERC20 for IERC20; @@ -903,7 +903,7 @@ abstract contract YieldBearingPoolSwapBase is BaseVaultTest { PoolMock newPool = deployPoolMock(IVault(address(vault)), "Yield-Bearing Pool", "YBPOOL"); - factoryMock.registerTestPool(address(newPool), tokenConfig, poolHooksContract); + PoolFactoryMock(poolFactory).registerTestPool(address(newPool), tokenConfig, poolHooksContract); vm.label(address(newPool), "yield-bearing pool"); yieldBearingPool = address(newPool); diff --git a/pkg/vault/test/foundry/utils/BaseERC4626BufferTest.sol b/pkg/vault/test/foundry/utils/BaseERC4626BufferTest.sol index 06e47f4ca..7083360bd 100644 --- a/pkg/vault/test/foundry/utils/BaseERC4626BufferTest.sol +++ b/pkg/vault/test/foundry/utils/BaseERC4626BufferTest.sol @@ -16,6 +16,7 @@ import { ArrayHelpers } from "@balancer-labs/v3-solidity-utils/contracts/test/Ar import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol"; import { PoolMock } from "../../../contracts/test/PoolMock.sol"; +import { PoolFactoryMock } from "../../../contracts/test/PoolFactoryMock.sol"; import { BaseVaultTest } from "./BaseVaultTest.sol"; abstract contract BaseERC4626BufferTest is BaseVaultTest { @@ -50,7 +51,7 @@ abstract contract BaseERC4626BufferTest is BaseVaultTest { newPool = address(new PoolMock(IVault(address(vault)), name, symbol)); vm.label(newPool, name); - factoryMock.registerTestPool(newPool, tokenConfig, poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool(newPool, tokenConfig, poolHooksContract, lp); poolArgs = abi.encode(vault, name, symbol); } diff --git a/pkg/vault/test/foundry/utils/BasePoolTest.sol b/pkg/vault/test/foundry/utils/BasePoolTest.sol index d06eb66c0..dbfd57ae4 100644 --- a/pkg/vault/test/foundry/utils/BasePoolTest.sol +++ b/pkg/vault/test/foundry/utils/BasePoolTest.sol @@ -20,8 +20,6 @@ import { BaseVaultTest } from "vault/test/foundry/utils/BaseVaultTest.sol"; abstract contract BasePoolTest is BaseVaultTest { using FixedPoint for uint256; - IBasePoolFactory public factory; - uint256 public constant DELTA = 1e9; IERC20[] internal poolTokens; @@ -53,7 +51,7 @@ abstract contract BasePoolTest is BaseVaultTest { } function testPoolAddress() public view { - address calculatedPoolAddress = factory.getDeploymentAddress(poolArguments, ZERO_BYTES32); + address calculatedPoolAddress = IBasePoolFactory(poolFactory).getDeploymentAddress(poolArguments, ZERO_BYTES32); assertEq(pool, calculatedPoolAddress, "Pool address mismatch"); } diff --git a/pkg/vault/test/foundry/utils/BaseVaultTest.sol b/pkg/vault/test/foundry/utils/BaseVaultTest.sol index 2497ac61e..393deb249 100644 --- a/pkg/vault/test/foundry/utils/BaseVaultTest.sol +++ b/pkg/vault/test/foundry/utils/BaseVaultTest.sol @@ -84,7 +84,6 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes RouterMock internal router; BatchRouterMock internal batchRouter; BufferRouterMock internal bufferRouter; - PoolFactoryMock internal factoryMock; RateProviderMock internal rateProvider; CompositeLiquidityRouterMock internal compositeLiquidityRouter; BasicAuthorizerMock internal authorizer; @@ -97,6 +96,8 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes bytes internal poolArguments; // Pool Hooks. address internal poolHooksContract; + // Pool factory. + address internal poolFactory; // Default amount to use in tests for user operations. uint256 internal defaultAmount = 1e3 * 1e18; @@ -150,8 +151,6 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes vm.label(address(vaultAdmin), "vaultAdmin"); authorizer = BasicAuthorizerMock(address(vault.getAuthorizer())); vm.label(address(authorizer), "authorizer"); - factoryMock = PoolFactoryMock(address(vault.getPoolFactoryMock())); - vm.label(address(factoryMock), "factory"); router = deployRouterMock(IVault(address(vault)), weth, permit2); vm.label(address(router), "router"); batchRouter = deployBatchRouterMock(IVault(address(vault)), weth, permit2); @@ -163,6 +162,7 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes feeController = vault.getProtocolFeeController(); vm.label(address(feeController), "fee controller"); + poolFactory = createPoolFactory(); poolHooksContract = createHook(); (pool, poolArguments) = createPool(); @@ -240,6 +240,13 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes return router.initialize(poolToInit, tokens, amountsIn, minBptOut, false, bytes("")); } + function createPoolFactory() internal virtual returns (address) { + PoolFactoryMock factoryMock = PoolFactoryMock(address(vault.getPoolFactoryMock())); + vm.label(address(factoryMock), "factory"); + + return address(factoryMock); + } + function createPool() internal virtual returns (address, bytes memory) { return _createPool([address(dai), address(usdc)].toMemoryArray(), "pool"); } @@ -251,10 +258,15 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes string memory name = "ERC20 Pool"; string memory symbol = "ERC20POOL"; - newPool = factoryMock.createPool(name, symbol); + newPool = PoolFactoryMock(poolFactory).createPool(name, symbol); vm.label(newPool, label); - factoryMock.registerTestPool(newPool, vault.buildTokenConfig(tokens.asIERC20()), poolHooksContract, lp); + PoolFactoryMock(poolFactory).registerTestPool( + newPool, + vault.buildTokenConfig(tokens.asIERC20()), + poolHooksContract, + lp + ); poolArgs = abi.encode(vault, name, symbol); } @@ -268,7 +280,7 @@ abstract contract BaseVaultTest is VaultContractsDeployer, VaultStorage, BaseTes function _createHook(HookFlags memory hookFlags) internal virtual returns (address) { PoolHooksMock newHook = deployPoolHooksMock(IVault(address(vault))); // Allow pools built with factoryMock to use the poolHooksMock. - newHook.allowFactory(address(factoryMock)); + newHook.allowFactory(poolFactory); // Configure pool hook flags. newHook.setHookFlags(hookFlags); vm.label(address(newHook), "pool hooks");