Watch pool mint event. (#125)

This commit is contained in:
Ashwin Phatak 2021-07-08 17:40:40 +05:30 committed by GitHub
parent f7df56bb75
commit 538e4b7591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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",

View File

@ -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",

View File

@ -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));
});

View File

@ -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"]
}