mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-08-03 12:44:08 +00:00
Watch pool mint event. (#125)
This commit is contained in:
parent
f7df56bb75
commit
538e4b7591
@ -164,6 +164,21 @@ export class Indexer {
|
|||||||
const { sqrtPriceX96, tick } = logDescription.args;
|
const { sqrtPriceX96, tick } = logDescription.args;
|
||||||
eventProps = { sqrtPriceX96: sqrtPriceX96.toString(), tick };
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import './tasks/deploy-factory';
|
|||||||
import './tasks/deploy-token';
|
import './tasks/deploy-token';
|
||||||
import './tasks/create-pool';
|
import './tasks/create-pool';
|
||||||
import './tasks/initialize-pool';
|
import './tasks/initialize-pool';
|
||||||
|
import './tasks/mint-pool';
|
||||||
|
|
||||||
const config: HardhatUserConfig = {
|
const config: HardhatUserConfig = {
|
||||||
solidity: "0.8.0",
|
solidity: "0.8.0",
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
"deploy:factory": "hardhat deploy-factory",
|
"deploy:factory": "hardhat deploy-factory",
|
||||||
"deploy:token": "hardhat deploy-token",
|
"deploy:token": "hardhat deploy-token",
|
||||||
"create:pool": "hardhat create-pool",
|
"create:pool": "hardhat create-pool",
|
||||||
"initialize:pool": "hardhat initialize-pool"
|
"initialize:pool": "hardhat initialize-pool",
|
||||||
|
"mint:pool": "hardhat mint-pool"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
|
46
packages/uniswap/tasks/mint-pool.ts
Normal file
46
packages/uniswap/tasks/mint-pool.ts
Normal 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));
|
||||||
|
});
|
@ -70,6 +70,6 @@
|
|||||||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
||||||
"resolveJsonModule": true
|
"resolveJsonModule": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*", "tasks/*"],
|
||||||
"exclude": ["src/**/*.test.ts"]
|
"exclude": ["src/**/*.test.ts"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user