forked from alchemistcoin/alchemist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniswap.ts
65 lines (52 loc) · 1.64 KB
/
uniswap.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import IUniswapV2Factory from '@uniswap/v2-core/build/IUniswapV2Factory.json'
import IUniswapV2Pair from '@uniswap/v2-core/build/IUniswapV2Pair.json'
import { constants } from 'ethers'
import { formatEther } from 'ethers/lib/utils'
import { task } from 'hardhat/config'
task('create-uni-pool', 'create a uniswap pool')
.addPositionalParam('tokenA')
.addPositionalParam('tokenB')
.setAction(async (args, { ethers, run, network }) => {
// log config
console.log('Network')
console.log(' ', network.name)
console.log('Task Args')
console.log(args)
// compile
await run('compile')
// get signer
const signer = (await ethers.getSigners())[0]
console.log('Signer')
console.log(' at', signer.address)
console.log(' ETH', formatEther(await signer.getBalance()))
// load contracts
const tokenA = await ethers.getContractAt(
'IERC20Detailed',
args.tokenA,
signer,
)
const tokenB = await ethers.getContractAt(
'IERC20Detailed',
args.tokenB,
signer,
)
const uniFactory = await ethers.getContractAt(
IUniswapV2Factory.abi,
'0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f',
signer,
)
// deploy pair
if (
(await uniFactory.getPair(tokenA.address, tokenB.address)) ===
constants.AddressZero
) {
await (await uniFactory.createPair(tokenA.address, tokenB.address)).wait()
}
const pair = await ethers.getContractAt(
IUniswapV2Pair.abi,
await uniFactory.getPair(tokenA.address, tokenB.address),
signer,
)
console.log('Deployed UniswapPair')
console.log(' at', pair.address)
})