diff --git a/src/core/contracts/AlgebraFactory.sol b/src/core/contracts/AlgebraFactory.sol index 837aa19e..bb883993 100644 --- a/src/core/contracts/AlgebraFactory.sol +++ b/src/core/contracts/AlgebraFactory.sol @@ -97,8 +97,8 @@ contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerabl } /// @inheritdoc IAlgebraFactory - function createPool(address tokenA, address tokenB) external override nonReentrant returns (address pool) { - return _createPool(address(0), msg.sender, tokenA, tokenB, ''); + function createPool(address tokenA, address tokenB, bytes calldata data) external override nonReentrant returns (address pool) { + return _createPool(address(0), msg.sender, tokenA, tokenB, data); } /// @inheritdoc IAlgebraFactory @@ -124,7 +124,7 @@ contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerabl address plugin; if (deployer == address(0)) { if (address(defaultPluginFactory) != address(0)) { - plugin = defaultPluginFactory.beforeCreatePoolHook(computePoolAddress(token0, token1), creator, address(0), token0, token1, ''); + plugin = defaultPluginFactory.beforeCreatePoolHook(computePoolAddress(token0, token1), creator, address(0), token0, token1, data); } } else { plugin = IAlgebraPluginFactory(msg.sender).beforeCreatePoolHook( diff --git a/src/core/contracts/interfaces/IAlgebraFactory.sol b/src/core/contracts/interfaces/IAlgebraFactory.sol index d8ad28dd..44d2f506 100644 --- a/src/core/contracts/interfaces/IAlgebraFactory.sol +++ b/src/core/contracts/interfaces/IAlgebraFactory.sol @@ -147,10 +147,11 @@ interface IAlgebraFactory { /// @notice Creates a pool for the given two tokens /// @param tokenA One of the two tokens in the desired pool /// @param tokenB The other of the two tokens in the desired pool + /// @param data Data for plugin creation /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. /// The call will revert if the pool already exists or the token arguments are invalid. /// @return pool The address of the newly created pool - function createPool(address tokenA, address tokenB) external returns (address pool); + function createPool(address tokenA, address tokenB, bytes calldata data) external returns (address pool); /// @notice Creates a custom pool for the given two tokens using `deployer` contract /// @param deployer The address of plugin deployer, also used for custom pool address calculation diff --git a/src/core/test/AlgebraFactory.spec.ts b/src/core/test/AlgebraFactory.spec.ts index dda721b3..7843aafc 100644 --- a/src/core/test/AlgebraFactory.spec.ts +++ b/src/core/test/AlgebraFactory.spec.ts @@ -97,7 +97,7 @@ describe('AlgebraFactory', () => { }); it('pool bytecode size [ @skip-on-coverage ]', async () => { - await factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1]); + await factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1], '0x'); const poolAddress = getCreate2Address( await poolDeployer.getAddress(), [TEST_ADDRESSES[0], TEST_ADDRESSES[1]], @@ -108,12 +108,12 @@ describe('AlgebraFactory', () => { async function createAndCheckPool(tokens: [string, string]) { const create2Address = getCreate2Address(await poolDeployer.getAddress(), tokens, poolBytecode); - const create = factory.createPool(tokens[0], tokens[1]); + const create = factory.createPool(tokens[0], tokens[1], '0x'); await expect(create).to.emit(factory, 'Pool'); - await expect(factory.createPool(tokens[0], tokens[1])).to.be.reverted; - await expect(factory.createPool(tokens[1], tokens[0])).to.be.reverted; + await expect(factory.createPool(tokens[0], tokens[1], '0x')).to.be.reverted; + await expect(factory.createPool(tokens[1], tokens[0], '0x')).to.be.reverted; expect(await factory.poolByPair(tokens[0], tokens[1]), 'getPool in order').to.eq(create2Address); expect(await factory.poolByPair(tokens[1], tokens[0]), 'getPool in reverse').to.eq(create2Address); @@ -198,22 +198,22 @@ describe('AlgebraFactory', () => { }); it('fails if token a == token b', async () => { - await expect(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[0])).to.be.reverted; + await expect(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[0], '0x')).to.be.reverted; }); it('fails if token a is 0 or token b is 0', async () => { - await expect(factory.createPool(TEST_ADDRESSES[0], ZeroAddress)).to.be.reverted; - await expect(factory.createPool(ZeroAddress, TEST_ADDRESSES[0])).to.be.reverted; - expect(factory.createPool(ZeroAddress, ZeroAddress)).to.be.revertedWithoutReason; + await expect(factory.createPool(TEST_ADDRESSES[0], ZeroAddress, '0x')).to.be.reverted; + await expect(factory.createPool(ZeroAddress, TEST_ADDRESSES[0], '0x')).to.be.reverted; + expect(factory.createPool(ZeroAddress, ZeroAddress, '0x')).to.be.revertedWithoutReason; }); it('gas [ @skip-on-coverage ]', async () => { - await snapshotGasCost(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1])); + await snapshotGasCost(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1], '0x')); }); it('gas for second pool [ @skip-on-coverage ]', async () => { - await factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1]); - await snapshotGasCost(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[2])); + await factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[1], '0x'); + await snapshotGasCost(factory.createPool(TEST_ADDRESSES[0], TEST_ADDRESSES[2], '0x')); }); }); diff --git a/src/periphery/contracts/base/PoolInitializer.sol b/src/periphery/contracts/base/PoolInitializer.sol index 377f4928..0c59de7b 100644 --- a/src/periphery/contracts/base/PoolInitializer.sol +++ b/src/periphery/contracts/base/PoolInitializer.sol @@ -32,7 +32,7 @@ abstract contract PoolInitializer is IPoolInitializer, PeripheryImmutableState { if (pool == address(0)) { if (deployer == address(0)) { - pool = _factory.createPool(token0, token1); + pool = _factory.createPool(token0, token1, ''); _initializePool(pool, sqrtPriceX96); } diff --git a/src/periphery/test/NonfungiblePositionManager.spec.ts b/src/periphery/test/NonfungiblePositionManager.spec.ts index 31d3d0dd..eb7fe87a 100644 --- a/src/periphery/test/NonfungiblePositionManager.spec.ts +++ b/src/periphery/test/NonfungiblePositionManager.spec.ts @@ -102,7 +102,7 @@ describe('NonfungiblePositionManager', () => { await tokens[0].getAddress(), await tokens[1].getAddress(), ]); - await factory.createPool(tokens[0], tokens[1]); + await factory.createPool(tokens[0], tokens[1], '0x'); const code = await wallet.provider.getCode(expectedAddress); expect(code).to.not.eq('0x'); await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(2, 1)); @@ -113,7 +113,7 @@ describe('NonfungiblePositionManager', () => { await tokens[0].getAddress(), await tokens[1].getAddress(), ]); - await factory.createPool(tokens[0], tokens[1]); + await factory.createPool(tokens[0], tokens[1], '0x'); const pool = new ethers.Contract(expectedAddress, IAlgebraPoolABI, wallet); await pool.initialize(encodePriceSqrt(3, 1));