From 6aabb5da0b60a72c93c12d4270a33f5432fbe193 Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Mon, 30 Sep 2024 19:02:14 -0400 Subject: [PATCH 1/2] feat: add createpool script --- .gitignore | 3 +- script/CreatePool.s.sol | 65 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 script/CreatePool.s.sol diff --git a/.gitignore b/.gitignore index f4ebe6d33..0abcc6df4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ cache/ foundry-out/ .vscode/ broadcast/*/*/dry-run/*.json -broadcast/*/*/run-[0-9]*.json \ No newline at end of file +broadcast/*/*/run-[0-9]*.json +broadcast/ diff --git a/script/CreatePool.s.sol b/script/CreatePool.s.sol new file mode 100644 index 000000000..a0ea10d5a --- /dev/null +++ b/script/CreatePool.s.sol @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import "forge-std/console2.sol"; +import "forge-std/Script.sol"; + +import {ERC20} from "solmate/src/tokens/ERC20.sol"; +import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; +import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol"; +import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; +import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; +import {LiquidityAmounts} from "@uniswap/v4-core/test/utils/LiquidityAmounts.sol"; +import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol"; +import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol"; +import {LiquidityOperations} from "../test/shared/LiquidityOperations.sol"; +import {StateView} from "../src/lens/StateView.sol"; +import {PositionConfig} from "../test/shared/PositionConfig.sol"; +import {IPositionManager} from "../src/interfaces/IPositionManager.sol"; +import {PositionManager} from "../src/PositionManager.sol"; +import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol"; + +contract CreatePool is Script, LiquidityOperations { + // native + Currency constant token0 = Currency.wrap(address(0)); + uint256 constant amount0Desired = 0.001 ether; + Currency constant token1 = Currency.wrap(0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238); + uint256 constant amount1Desired = 3000000; + uint160 public constant SQRT_PRICE_1_1 = 79228162514264337593543950336; + uint24 constant fee = 500; + int24 constant tickSpacing = 40; + uint160 constant sqrtPriceX96 = SQRT_PRICE_1_1; + int24 tickLower = -4000; + int24 tickUpper = 4000; + + function setUp() public {} + + function run(IPoolManager poolManager, IPositionManager posm, IAllowanceTransfer permit2, address recipient) + public + { + PoolKey memory key = PoolKey(token0, token1, fee, tickSpacing, IHooks(address(0))); + PositionConfig memory config = PositionConfig({poolKey: key, tickLower: tickLower, tickUpper: tickUpper}); + uint256 tokenId = posm.nextTokenId(); + + uint256 liquidityToAdd = LiquidityAmounts.getLiquidityForAmounts( + SQRT_PRICE_1_1, + TickMath.getSqrtPriceAtTick(tickLower), + TickMath.getSqrtPriceAtTick(tickUpper), + amount0Desired, + amount1Desired + ); + bytes memory calls = getMintEncoded(config, liquidityToAdd, recipient, new bytes(0)); + + vm.startBroadcast(); + ERC20(Currency.unwrap(token1)).approve(address(permit2), type(uint256).max); + + poolManager.initialize(key, sqrtPriceX96, new bytes(0)); + permit2.approve(Currency.unwrap(token0), address(posm), type(uint160).max, type(uint48).max); + permit2.approve(Currency.unwrap(token1), address(posm), type(uint160).max, type(uint48).max); + + posm.modifyLiquidities{ value: amount0Desired }(calls, block.timestamp + 100000); + + + vm.stopBroadcast(); + } +} From 82fbae5e87e2abaf36ce3fbd31b006f6b3d662f0 Mon Sep 17 00:00:00 2001 From: Mark Toda Date: Mon, 30 Sep 2024 19:05:01 -0400 Subject: [PATCH 2/2] fix: lint --- script/CreatePool.s.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script/CreatePool.s.sol b/script/CreatePool.s.sol index a0ea10d5a..75782551f 100644 --- a/script/CreatePool.s.sol +++ b/script/CreatePool.s.sol @@ -57,8 +57,7 @@ contract CreatePool is Script, LiquidityOperations { permit2.approve(Currency.unwrap(token0), address(posm), type(uint160).max, type(uint48).max); permit2.approve(Currency.unwrap(token1), address(posm), type(uint160).max, type(uint48).max); - posm.modifyLiquidities{ value: amount0Desired }(calls, block.timestamp + 100000); - + posm.modifyLiquidities{value: amount0Desired}(calls, block.timestamp + 100000); vm.stopBroadcast(); }