-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdo1.ts
78 lines (66 loc) · 2.05 KB
/
vdo1.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
66
67
68
69
70
71
72
73
74
75
76
77
78
import { ethers } from 'ethers'
import { CurrentConfig } from './config'
import { computePoolAddress } from '@uniswap/v3-sdk'
import Quoter from './ABI/Quoter.json'
import IUniswapV3PoolABI from './ABI/IUniswapV3Pool.json'
import {
POOL_FACTORY_CONTRACT_ADDRESS,
QUOTER_CONTRACT_ADDRESS,
} from './libs/constants'
import { getProvider } from './libs/providers'
import { toReadableAmount, fromReadableAmount } from './libs/conversion'
//const provider = 'https://mainnet.infura.io/v3/819e8d5c4e5e4e3dbc5ed6630346bd7a'
const Provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/')
export async function quote(): Promise<string> {
const quoterContract = new ethers.Contract(
QUOTER_CONTRACT_ADDRESS,
Quoter.abi,
Provider
)
const poolConstants = await getPoolConstants()
const quotedAmountOut = await quoterContract.callStatic.quoteExactInputSingle(
poolConstants.token1,
poolConstants.token0,
poolConstants.fee,
fromReadableAmount(
CurrentConfig.tokens.amountIn,
CurrentConfig.tokens.in.decimals
).toString(),
0
)
console.log('Quoted Amount Out:', quotedAmountOut.toString())
return toReadableAmount(quotedAmountOut, CurrentConfig.tokens.out.decimals)
}
async function getPoolConstants(): Promise<{
token0: string
token1: string
fee: number
}> {
const currentPoolAddress = computePoolAddress({
factoryAddress: POOL_FACTORY_CONTRACT_ADDRESS,
tokenA: CurrentConfig.tokens.in,
tokenB: CurrentConfig.tokens.out,
fee: CurrentConfig.tokens.poolFee,
})
const poolContract = new ethers.Contract(
currentPoolAddress,
IUniswapV3PoolABI.abi,
Provider
)
const [token0, token1, fee] = await Promise.all([
poolContract.token0(),
poolContract.token1(),
poolContract.fee(),
])
//console.log(poolContract)
console.log('Token0:', token0)
console.log('Token1:', token1)
console.log('Fee:', fee)
return {
token0,
token1,
fee,
}
}
//getPoolConstants();
quote();