diff --git a/src/periphery/contracts/base/PoolInitializer.sol b/src/periphery/contracts/base/PoolInitializer.sol index 0c59de7b..6203e061 100644 --- a/src/periphery/contracts/base/PoolInitializer.sol +++ b/src/periphery/contracts/base/PoolInitializer.sol @@ -19,7 +19,8 @@ abstract contract PoolInitializer is IPoolInitializer, PeripheryImmutableState { address token0, address token1, address deployer, - uint160 sqrtPriceX96 + uint160 sqrtPriceX96, + bytes calldata data ) external payable override returns (address pool) { require(token0 < token1, 'Invalid order of tokens'); @@ -32,7 +33,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, data); _initializePool(pool, sqrtPriceX96); } diff --git a/src/periphery/contracts/interfaces/IPoolInitializer.sol b/src/periphery/contracts/interfaces/IPoolInitializer.sol index a8f8aac5..8fa9bc33 100644 --- a/src/periphery/contracts/interfaces/IPoolInitializer.sol +++ b/src/periphery/contracts/interfaces/IPoolInitializer.sol @@ -13,11 +13,13 @@ interface IPoolInitializer { /// @param token0 The contract address of token0 of the pool /// @param token1 The contract address of token1 of the pool /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value + /// @param data Data for plugin initialization /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary function createAndInitializePoolIfNecessary( address token0, address token1, address deployer, - uint160 sqrtPriceX96 + uint160 sqrtPriceX96, + bytes calldata data ) external payable returns (address pool); } diff --git a/src/periphery/test/NonfungiblePositionManager.spec.ts b/src/periphery/test/NonfungiblePositionManager.spec.ts index eb7fe87a..e20768e6 100644 --- a/src/periphery/test/NonfungiblePositionManager.spec.ts +++ b/src/periphery/test/NonfungiblePositionManager.spec.ts @@ -86,13 +86,13 @@ describe('NonfungiblePositionManager', () => { ]); const code = await wallet.provider.getCode(expectedAddress); expect(code).to.eq('0x'); - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); const codeAfter = await wallet.provider.getCode(expectedAddress); expect(codeAfter).to.not.eq('0x'); }); it('is payable', async () => { - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), { value: 1 }); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x', { value: 1 }); }); it('works if pool is created but not initialized', async () => { @@ -105,7 +105,7 @@ describe('NonfungiblePositionManager', () => { 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)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(2, 1), '0x'); }); it('works if pool is created and initialized', async () => { @@ -121,7 +121,7 @@ describe('NonfungiblePositionManager', () => { if (!wallet.provider) throw new Error('No provider'); const code = await wallet.provider.getCode(expectedAddress); expect(code).to.not.eq('0x'); - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(4, 1)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(4, 1), '0x'); }); it('could theoretically use eth via multicall', async () => { @@ -129,14 +129,14 @@ describe('NonfungiblePositionManager', () => { const createAndInitializePoolIfNecessaryData = nft.interface.encodeFunctionData( 'createAndInitializePoolIfNecessary', - [await token0.getAddress(), await token1.getAddress(), ZERO_ADDRESS, encodePriceSqrt(1, 1)] + [await token0.getAddress(), await token1.getAddress(), ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'] ); await nft.multicall([createAndInitializePoolIfNecessaryData], { value: expandTo18Decimals(1) }); }); it('gas [ @skip-on-coverage ]', async () => { - await snapshotGasCost(nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1))); + await snapshotGasCost(nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x')); }); }); @@ -160,7 +160,7 @@ describe('NonfungiblePositionManager', () => { }); it('fails if cannot transfer', async () => { - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); await tokens[0].approve(nft, 0); await expect( nft.mint({ @@ -180,7 +180,7 @@ describe('NonfungiblePositionManager', () => { }); it('fails if deadline passed', async () => { - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); await nft.setTime(2); await expect( nft.mint({ @@ -204,7 +204,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ token0: tokens[0].getAddress(), @@ -253,7 +254,8 @@ describe('NonfungiblePositionManager', () => { await token0.getAddress(), await token1.getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1), + encodePriceSqrt(1, 1), + '0x' ]); const mintData = nft.interface.encodeFunctionData('mint', [ @@ -293,7 +295,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await snapshotGasCost( @@ -315,7 +318,7 @@ describe('NonfungiblePositionManager', () => { it('gas first mint for pool using eth with zero refund [ @skip-on-coverage ]', async () => { const [token0, token1] = await sortedTokens(wnative, tokens[0]); - await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); await snapshotGasCost( nft.multicall( @@ -344,7 +347,7 @@ describe('NonfungiblePositionManager', () => { it('gas first mint for pool using eth with non-zero refund [ @skip-on-coverage ]', async () => { const [token0, token1] = await sortedTokens(wnative, tokens[0]); - await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); await snapshotGasCost( nft.multicall( @@ -372,7 +375,7 @@ describe('NonfungiblePositionManager', () => { }); it('gas mint on same ticks [ @skip-on-coverage ]', async () => { - await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(tokens[0], tokens[1], ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); await nft.mint({ token0: await tokens[0].getAddress(), @@ -410,7 +413,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -452,7 +456,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -523,7 +528,7 @@ describe('NonfungiblePositionManager', () => { const tokenId = 1; - await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1)); + await nft.createAndInitializePoolIfNecessary(token0, token1, ZERO_ADDRESS, encodePriceSqrt(1, 1), '0x'); const mintData = nft.interface.encodeFunctionData('mint', [ { @@ -577,7 +582,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -701,7 +707,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -849,7 +856,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -930,7 +938,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -986,7 +995,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -1051,7 +1061,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -1111,7 +1122,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -1200,7 +1212,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ @@ -1240,7 +1253,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); // nft 1 earns 25% of fees await nft.mint({ @@ -1297,7 +1311,6 @@ describe('NonfungiblePositionManager', () => { amount0Max: MaxUint128, amount1Max: MaxUint128, }); - console.log(nft1Amount0.toString(), nft1Amount1.toString(), nft2Amount0.toString(), nft2Amount1.toString()); expect(nft1Amount0).to.eq(416); expect(nft1Amount1).to.eq(0); expect(nft2Amount0).to.eq(1250); @@ -1343,7 +1356,8 @@ describe('NonfungiblePositionManager', () => { tokens[0].getAddress(), tokens[1].getAddress(), ZERO_ADDRESS, - encodePriceSqrt(1, 1) + encodePriceSqrt(1, 1), + '0x' ); await nft.mint({ diff --git a/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap b/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap index ff2e5228..447467e0 100644 --- a/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap +++ b/src/periphery/test/__snapshots__/NonfungiblePositionManager.spec.ts.snap @@ -2,38 +2,38 @@ exports[`NonfungiblePositionManager #burn gas [ @skip-on-coverage ] 1`] = `62302`; -exports[`NonfungiblePositionManager #collect gas transfers both [ @skip-on-coverage ] 1`] = `125983`; +exports[`NonfungiblePositionManager #collect gas transfers both [ @skip-on-coverage ] 1`] = `126407`; -exports[`NonfungiblePositionManager #collect gas transfers token0 only [ @skip-on-coverage ] 1`] = `122321`; +exports[`NonfungiblePositionManager #collect gas transfers token0 only [ @skip-on-coverage ] 1`] = `122745`; -exports[`NonfungiblePositionManager #collect gas transfers token1 only [ @skip-on-coverage ] 1`] = `122512`; +exports[`NonfungiblePositionManager #collect gas transfers token1 only [ @skip-on-coverage ] 1`] = `122936`; -exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `5277310`; +exports[`NonfungiblePositionManager #createAndInitializePoolIfNecessary gas [ @skip-on-coverage ] 1`] = `5231043`; -exports[`NonfungiblePositionManager #decreaseLiquidity gas complete decrease [ @skip-on-coverage ] 1`] = `171239`; +exports[`NonfungiblePositionManager #decreaseLiquidity gas complete decrease [ @skip-on-coverage ] 1`] = `171665`; -exports[`NonfungiblePositionManager #decreaseLiquidity gas partial decrease [ @skip-on-coverage ] 1`] = `176207`; +exports[`NonfungiblePositionManager #decreaseLiquidity gas partial decrease [ @skip-on-coverage ] 1`] = `176589`; -exports[`NonfungiblePositionManager #increaseLiquidity gas [ @skip-on-coverage ] 1`] = `182683`; +exports[`NonfungiblePositionManager #increaseLiquidity gas [ @skip-on-coverage ] 1`] = `184149`; -exports[`NonfungiblePositionManager #mint gas first mint for pool [ @skip-on-coverage ] 1`] = `635168`; +exports[`NonfungiblePositionManager #mint gas first mint for pool [ @skip-on-coverage ] 1`] = `636773`; -exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with non-zero refund [ @skip-on-coverage ] 1`] = `649531`; +exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with non-zero refund [ @skip-on-coverage ] 1`] = `651121`; -exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with zero refund [ @skip-on-coverage ] 1`] = `642364`; +exports[`NonfungiblePositionManager #mint gas first mint for pool using eth with zero refund [ @skip-on-coverage ] 1`] = `643954`; -exports[`NonfungiblePositionManager #mint gas mint for same pool, different ticks [ @skip-on-coverage ] 1`] = `440868`; +exports[`NonfungiblePositionManager #mint gas mint for same pool, different ticks [ @skip-on-coverage ] 1`] = `442385`; -exports[`NonfungiblePositionManager #mint gas mint on same ticks [ @skip-on-coverage ] 1`] = `330678`; +exports[`NonfungiblePositionManager #mint gas mint on same ticks [ @skip-on-coverage ] 1`] = `332156`; -exports[`NonfungiblePositionManager #permit owned by eoa gas [ @skip-on-coverage ] 1`] = `60014`; +exports[`NonfungiblePositionManager #permit owned by eoa gas [ @skip-on-coverage ] 1`] = `60003`; -exports[`NonfungiblePositionManager #permit owned by verifying contract gas [ @skip-on-coverage ] 1`] = `63880`; +exports[`NonfungiblePositionManager #permit owned by verifying contract gas [ @skip-on-coverage ] 1`] = `63869`; exports[`NonfungiblePositionManager #transferFrom gas [ @skip-on-coverage ] 1`] = `86323`; exports[`NonfungiblePositionManager #transferFrom gas comes from approved [ @skip-on-coverage ] 1`] = `87247`; -exports[`NonfungiblePositionManager bytecode size [ @skip-on-coverage ] 1`] = `21901`; +exports[`NonfungiblePositionManager bytecode size [ @skip-on-coverage ] 1`] = `22015`; -exports[`NonfungiblePositionManager multicall exit gas [ @skip-on-coverage ] 1`] = `246963`; +exports[`NonfungiblePositionManager multicall exit gas [ @skip-on-coverage ] 1`] = `247432`;