diff --git a/packages/uni-watcher/src/indexer.ts b/packages/uni-watcher/src/indexer.ts index 1174a347..ac63c29c 100644 --- a/packages/uni-watcher/src/indexer.ts +++ b/packages/uni-watcher/src/indexer.ts @@ -164,6 +164,21 @@ export class Indexer { const { sqrtPriceX96, tick } = logDescription.args; eventProps = { sqrtPriceX96: sqrtPriceX96.toString(), tick }; + break; + } + case 'Mint': { + eventName = logDescription.name; + const { sender, owner, tickLower, tickUpper, amount, amount0, amount1 } = logDescription.args; + eventProps = { + sender, + owner, + tickLower, + tickUpper, + amount: amount.toString(), + amount0: amount0.toString(), + amount1: amount1.toString() + }; + break; } } diff --git a/packages/uniswap/hardhat.config.ts b/packages/uniswap/hardhat.config.ts index 121a3a88..c36943a4 100644 --- a/packages/uniswap/hardhat.config.ts +++ b/packages/uniswap/hardhat.config.ts @@ -7,6 +7,7 @@ import './tasks/deploy-factory'; import './tasks/deploy-token'; import './tasks/create-pool'; import './tasks/initialize-pool'; +import './tasks/mint-pool'; const config: HardhatUserConfig = { solidity: "0.8.0", diff --git a/packages/uniswap/package.json b/packages/uniswap/package.json index dd7054a0..125a14b9 100644 --- a/packages/uniswap/package.json +++ b/packages/uniswap/package.json @@ -9,7 +9,8 @@ "deploy:factory": "hardhat deploy-factory", "deploy:token": "hardhat deploy-token", "create:pool": "hardhat create-pool", - "initialize:pool": "hardhat initialize-pool" + "initialize:pool": "hardhat initialize-pool", + "mint:pool": "hardhat mint-pool" }, "devDependencies": { "@nomiclabs/hardhat-ethers": "^2.0.2", diff --git a/packages/uniswap/tasks/mint-pool.ts b/packages/uniswap/tasks/mint-pool.ts new file mode 100644 index 00000000..c7610219 --- /dev/null +++ b/packages/uniswap/tasks/mint-pool.ts @@ -0,0 +1,46 @@ +import { task, types } from "hardhat/config"; +import { + abi as POOL_ABI, +} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json' +import { + abi as ERC20_ABI +} from '@uniswap/v3-core/artifacts/contracts/interfaces/IERC20Minimal.sol/IERC20Minimal.json'; + +import { ContractTransaction } from "ethers"; +import '@nomiclabs/hardhat-ethers'; + +const getMinTick = (tickSpacing: number) => Math.ceil(-887272 / tickSpacing) * tickSpacing; +const getMaxTick = (tickSpacing: number) => Math.floor(887272 / tickSpacing) * tickSpacing; + +const APPROVE_AMOUNT = BigInt(1000000000000000000); + +task("mint-pool", "Adds liquidity for the given position to the pool") + .addParam('pool', 'Address of pool contract', undefined, types.string) + .addParam('recipient', 'Address for which the liquidity will be created', undefined, types.string) + .addParam('tickLower', 'Lower tick of the position in which to add liquidity', undefined, types.string) + .addParam('tickUpper', 'Upper tick of the position in which to add liquidity', undefined, types.string) + .addParam('amount', 'Amount of liquidity to mint', undefined, types.string) + .setAction(async (args, hre) => { + const { pool: poolAddress, recipient, tickLower, tickUpper, amount } = args + const [signer] = await hre.ethers.getSigners(); + + const pool = new hre.ethers.Contract(poolAddress, POOL_ABI, signer); + const token0Address = await pool.token0(); + const token1Address = await pool.token1(); + const tickSpacing = await pool.tickSpacing(); + + console.log(token0Address, token1Address, tickSpacing, getMinTick(tickSpacing), getMaxTick(tickSpacing)); + + const token0 = new hre.ethers.Contract(token0Address, ERC20_ABI, signer); + const token1 = new hre.ethers.Contract(token1Address, ERC20_ABI, signer); + + const t0 = await token0.approve(poolAddress, APPROVE_AMOUNT); + await t0.wait(); + + const t1 = await token1.approve(poolAddress, APPROVE_AMOUNT); + await t1.wait(); + + const transaction: ContractTransaction = await pool.mint(recipient, BigInt(tickLower), BigInt(tickUpper), BigInt(amount), '0x00'); + const receipt = await transaction.wait(); + console.log(JSON.stringify(receipt)); + }); diff --git a/packages/uniswap/tsconfig.json b/packages/uniswap/tsconfig.json index 881acc90..a709b635 100644 --- a/packages/uniswap/tsconfig.json +++ b/packages/uniswap/tsconfig.json @@ -70,6 +70,6 @@ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ "resolveJsonModule": true }, - "include": ["src/**/*"], + "include": ["src/**/*", "tasks/*"], "exclude": ["src/**/*.test.ts"] }