-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
61 lines (45 loc) · 2.08 KB
/
index.js
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
require("dotenv").config();
const { INTERVAL, FACTORY_ADDRESS, QUOTER_ADDRESS, TOKEN_IN_ADDRESS, TOKEN_OUT_ADDRESS, NETWORK, INFURA_API_KEY } = process.env;
const { ChainId, Token } = require("@uniswap/sdk-core");
const WETH_TOKEN = new Token(ChainId.MAINNET, TOKEN_IN_ADDRESS, 18, 'WETH', 'Wrapped Ether');
const USDT_TOKEN = new Token(ChainId.MAINNET, TOKEN_OUT_ADDRESS, 6, 'USDT', 'Tether');
const { ethers } = require("ethers");
const provider = new ethers.InfuraProvider(NETWORK, INFURA_API_KEY);
async function preparationCycle() {
const { computePoolAddress, FeeAmount } = require("@uniswap/v3-sdk")
const currentPoolAddress = computePoolAddress({
factoryAddress: FACTORY_ADDRESS,
tokenA: WETH_TOKEN,
tokenB: USDT_TOKEN,
fee: FeeAmount.MEDIUM,
})
const IUniswapV3PoolABI = require("@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json");
const poolContract = new ethers.Contract(currentPoolAddress, IUniswapV3PoolABI.abi, provider);
const result = getTokenOrder(TOKEN_IN_ADDRESS, TOKEN_OUT_ADDRESS);
result.fee = await poolContract.fee();
return result;
}
function getTokenOrder(tokenIn, tokenOut) {
if (ethers.toBigInt(tokenIn) <= ethers.toBigInt(tokenOut))
return { token0: tokenIn, token1: tokenOut };
else
return { token0: tokenOut, token1: tokenIn };
}
async function executionCycle(token0, token1, fee) {
const Quoter = require("@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json");
const quoterContract = new ethers.Contract(QUOTER_ADDRESS, Quoter.abi, provider);
const quotedAmountOut = await quoterContract.quoteExactInputSingle.staticCall(
token0,
token1,
fee,
ethers.parseEther("1"),
0
)
console.log("WETH 1 is equals to USDT " + ethers.formatUnits(quotedAmountOut, 6));
}
(async () => {
console.log("Running");
const { token0, token1, fee } = await preparationCycle();
setInterval(() => executionCycle(token0, token1, fee), INTERVAL);
executionCycle(token0, token1, fee);
})();