watcher-ts/packages/uniswap/tasks/create-pool.ts
Ashwin Phatak da758aceaa
Script to deploy uniswap contracts locally for testing (#118)
* Initial setup with hardhat.

* Deploy Factory contract.

* Deploy tokens and create pool using factory contract.

* Deploy contract to private network.

* Implement separate scripts for deploying Factory, Token and Pool.

Co-authored-by: nikugogoi <95nikass@gmail.com>
2021-07-05 11:05:45 +05:30

28 lines
1.2 KiB
TypeScript

import { task, types } from "hardhat/config";
import {
abi as FACTORY_ABI,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'
import { ContractTransaction } from "ethers";
task("create-pool", "Creates pool using Factory contract")
.addParam('factory', 'Address of factory contract', undefined, types.string)
.addParam('token0', 'Address of first token contract', undefined, types.string)
.addParam('token1', 'Address of second token contract', undefined, types.string)
.addParam('fee', "The pool's fee", undefined, types.int)
.setAction(async (args, hre) => {
const { factory: factoryAddress, token0, token1, fee } = args
const [signer] = await hre.ethers.getSigners();
const factory = new hre.ethers.Contract(factoryAddress, FACTORY_ABI, signer);
const transaction: ContractTransaction = await factory.createPool(token0, token1, fee)
const receipt = await transaction.wait();
if (receipt.events) {
const poolCreatedEvent = receipt.events.find(el => el.event === 'PoolCreated');
if (poolCreatedEvent && poolCreatedEvent.args) {
const { pool } = poolCreatedEvent.args;
console.log('Pool deployed to:', pool);
}
}
});