-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quickswap.test.ts
168 lines (135 loc) · 4.87 KB
/
Quickswap.test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import "dotenv/config";
import { expect } from "chai";
import { ethers, waffle, deployments } from "hardhat";
import { getUniswapV2Router02 } from "./utils/contracts/periphery";
import IERC20MetadataArtifact from "@openzeppelin/contracts/build/contracts/IERC20Metadata.json";
import { getTwentyMinuteDeadline } from "./utils/deadline";
import {
ChainId,
JSBI,
Fetcher,
Token,
TokenAmount,
Pair,
Trade,
} from "quickswap-sdk";
describe("UniswapSlidingWindowOracle", () => {
let uniswapV2Router02: any;
let provider: any;
before(async () => {
provider = waffle.provider;
});
beforeEach(async () => {
uniswapV2Router02 = await getUniswapV2Router02(provider);
});
it.skip("should swap myst for fid", async () => {
const amounts = await uniswapV2Router02.getAmountsOut(
ethers.utils.parseEther("1"),
[
"0x1379E8886A944d2D9d440b3d88DF536Aea08d9F3",
"0x9A4Eb698e5DE3D3Df0a68F681789072DE1E50222",
]
);
console.log("amounts", amounts);
});
it.skip("should swap usdc to fidira", async () => {
// const deadline = await getTwentyMinuteDeadline();
/*
const amounts = await uniswapV2Router02.getAmountsIn("100000000", [ uniswapV2Router02.WETH(), "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"]);
await uniswapV2Router02.swapETHForExactTokens("100000000", [ await uniswapV2Router02.WETH(), "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"], await provider.getSigner().getAddress(), deadline, { value: amounts[0] });
*/
const wmatic = new ethers.Contract(
await uniswapV2Router02.WETH(),
IERC20MetadataArtifact.abi,
provider
);
const weth = new ethers.Contract(
"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
IERC20MetadataArtifact.abi,
provider
);
const usdc = new ethers.Contract(
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
IERC20MetadataArtifact.abi,
provider
);
const fid = new ethers.Contract(
"0x9A4Eb698e5DE3D3Df0a68F681789072DE1E50222",
IERC20MetadataArtifact.abi,
provider
);
const signedUsdc = usdc.connect(provider.getSigner());
await signedUsdc.approve(uniswapV2Router02.address, "100000000");
const token0 = new Token(
ChainId.MATIC,
wmatic.address,
await wmatic.decimals(),
await wmatic.symbol(),
await wmatic.name()
);
const token1 = new Token(
ChainId.MATIC,
weth.address,
await weth.decimals(),
await weth.symbol(),
await weth.name()
);
const token2 = new Token(
ChainId.MATIC,
usdc.address,
await usdc.decimals(),
await usdc.symbol(),
await usdc.name()
);
const token3 = new Token(
ChainId.MATIC,
fid.address,
await fid.decimals(),
await fid.symbol(),
await fid.name()
);
console.log(Pair.getAddress(token0, token1));
// const pair = new Pair(new TokenAmount(token0, JSBI.BigInt(amounts[0])), new TokenAmount(token1, JSBI.BigInt(amounts[1])))
const provider2: any = new ethers.providers.JsonRpcProvider(
"https://polygon-mainnet.g.alchemy.com/v2/EJxLOv_k16MhE4_0Qw1QHf7RQtQHcvP2"
);
const pairs = [];
pairs.push(await Fetcher.fetchPairData(token0, token1, provider2));
pairs.push(await Fetcher.fetchPairData(token2, token0, provider2));
pairs.push(await Fetcher.fetchPairData(token2, token1, provider2));
pairs.push(await Fetcher.fetchPairData(token0, token3, provider2));
pairs.push(await Fetcher.fetchPairData(token1, token3, provider2));
pairs.push(await Fetcher.fetchPairData(token2, token3, provider2));
console.log(await Fetcher.fetchPairData(token2, token3, provider2));
const bestTrades = Trade.bestTradeExactIn(
pairs,
new TokenAmount(token2, JSBI.BigInt("1000000")),
token3
);
for (var i = 0; i < bestTrades.length; i++) {
console.log(bestTrades[i].route);
}
const amounts2 = await uniswapV2Router02.getAmountsOut("100000000", [
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"0x9A4Eb698e5DE3D3Df0a68F681789072DE1E50222",
]);
console.log("direct", amounts2);
const amounts3 = await uniswapV2Router02.getAmountsOut("100000000", [
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
"0x9A4Eb698e5DE3D3Df0a68F681789072DE1E50222",
]);
console.log(
"indirect",
amounts3[0].toString(),
amounts3[1].toString(),
amounts3[2].toString()
);
/*
await uniswapV2Router02.swapExactTokensForTokens("100000000", amounts3[2], [ "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
"0x9A4Eb698e5DE3D3Df0a68F681789072DE1E50222" ], await provider.getSigner().getAddress(), deadline);
const balance = await fid.balanceOf(await provider.getSigner().getAddress());
console.log("balance", balance.toString());
*/
});
});