@paraswap/dex-lib 3.4.2-balancer-v2-single-swap.0 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -377
- package/build/config.js +9 -5
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra.js +25 -25
- package/build/dex/balancer-v1/balancer-v1.js +34 -34
- package/build/dex/balancer-v2/balancer-v2.d.ts +1 -1
- package/build/dex/balancer-v2/balancer-v2.js +65 -78
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/camelot/camelot.js +27 -27
- package/build/dex/kyberdmm/kyberdmm.js +27 -27
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +25 -25
- package/build/dex/solidly/solidly.js +27 -27
- package/build/dex/solidly-v3/solidly-v3.js +25 -25
- package/build/dex/swaap-v2/config.js +15 -0
- package/build/dex/swaap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +26 -26
- package/build/dex/uniswap-v3/uniswap-v3.js +25 -25
- package/funding.json +5 -5
- package/package.json +1 -1
- package/src/config.ts +500 -496
- package/src/constants.ts +67 -67
- package/src/dex/aave-v2/aave-v2.ts +409 -409
- package/src/dex/aave-v3/aave-v3.ts +320 -320
- package/src/dex/algebra/algebra.ts +1180 -1180
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +347 -347
- package/src/dex/augustus-rfq.ts +180 -180
- package/src/dex/bProtocol/bProtocol.ts +108 -108
- package/src/dex/balancer-v1/balancer-v1.ts +572 -572
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1699 -1699
- package/src/dex/balancer-v2/balancer-v2.ts +1669 -1701
- package/src/dex/bancor/bancor.ts +128 -128
- package/src/dex/camelot/camelot.ts +873 -873
- package/src/dex/compound/compound.ts +107 -107
- package/src/dex/curve-v1/config.ts +1179 -1179
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +507 -507
- package/src/dex/curve-v1/curve-v1.ts +1315 -1315
- package/src/dex/curve-v1-factory/config.ts +1018 -1018
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +1288 -1288
- package/src/dex/curve-v2/curve-v2.ts +440 -440
- package/src/dex/dexalot/dexalot.ts +1100 -1100
- package/src/dex/dodo-v1/dodo-v1.ts +132 -132
- package/src/dex/dodo-v2.ts +266 -266
- package/src/dex/etherfi.ts +239 -239
- package/src/dex/generic-rfq/generic-rfq.ts +431 -431
- package/src/dex/gmx/gmx.ts +321 -321
- package/src/dex/hashflow/hashflow.ts +1135 -1135
- package/src/dex/idex.ts +254 -254
- package/src/dex/index.ts +357 -357
- package/src/dex/jarvis-v6/jarvis-v6.ts +509 -509
- package/src/dex/jarvis.ts +262 -262
- package/src/dex/kyberdmm/kyberdmm.ts +649 -649
- package/src/dex/lido/lido.ts +110 -110
- package/src/dex/maker-psm/maker-psm.ts +592 -592
- package/src/dex/maverick-v1/maverick-v1.ts +537 -537
- package/src/dex/nerve/config.ts +635 -635
- package/src/dex/nerve/nerve-e2e.test.ts +731 -731
- package/src/dex/nerve/nerve-events.test.ts +911 -911
- package/src/dex/nerve/nerve.ts +467 -467
- package/src/dex/onebit/onebit.ts +113 -113
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1150 -1150
- package/src/dex/paraswap-limit-orders/config.ts +60 -60
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +137 -137
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +328 -328
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +631 -631
- package/src/dex/polygon-migrator/polygon-migrator.ts +194 -194
- package/src/dex/quick-perps/quick-perps.ts +337 -337
- package/src/dex/quickswap/config.ts +16 -16
- package/src/dex/quickswap/quickswap-e2e.test.ts +384 -384
- package/src/dex/smoothy/smoothy.ts +110 -110
- package/src/dex/solidly/config.ts +225 -225
- package/src/dex/solidly/solidly-e2e.test.ts +1421 -1421
- package/src/dex/solidly/solidly-integration.test.ts +1753 -1753
- package/src/dex/solidly/solidly.ts +687 -687
- package/src/dex/solidly-v3/solidly-v3.ts +968 -968
- package/src/dex/spark/spark.ts +284 -284
- package/src/dex/stable-pool/stable-pool.ts +129 -129
- package/src/dex/swaap-v2/config.ts +15 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
- package/src/dex/swaap-v2/swaap-v2.ts +1056 -1056
- package/src/dex/swell/swell.ts +312 -312
- package/src/dex/synthetix/synthetix.ts +420 -420
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +180 -180
- package/src/dex/uniswap-v2/config.ts +637 -637
- package/src/dex/uniswap-v2/constants.ts +58 -58
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +1257 -1257
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +42 -42
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +1295 -1295
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +1834 -1834
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +871 -871
- package/src/dex/uniswap-v2/uniswap-v2.ts +1117 -1117
- package/src/dex/uniswap-v3/uniswap-v3.ts +1501 -1501
- package/src/dex/uniswap-v3.ts +242 -242
- package/src/dex/weth/config.ts +73 -73
- package/src/dex/weth/weth.ts +230 -230
- package/src/dex/wombat/wombat.ts +467 -467
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +529 -529
- package/src/dex/wsteth/wsteth.ts +304 -304
- package/src/dex/zerox/index.ts +328 -328
- package/src/executor/Executor01BytecodeBuilder.ts +474 -474
- package/src/executor/Executor02BytecodeBuilder.ts +1392 -1392
- package/src/executor/ExecutorBytecodeBuilder.ts +390 -390
- package/src/executor/ExecutorDetector.ts +131 -131
- package/src/executor/constants.ts +66 -66
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +1478 -1478
- package/src/executor/utils.ts +62 -62
- package/src/router/simpleswap.ts +366 -366
- package/src/types.ts +342 -342
- package/tests/constants-e2e.ts +1632 -1622
- package/tests/generate-new-limit-order.ts +107 -107
|
@@ -1,1753 +1,1753 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { DummyDexHelper } from '../../dex-helper';
|
|
6
|
-
import { Network, SwapSide } from '../../constants';
|
|
7
|
-
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
8
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
-
import { Solidly } from './solidly';
|
|
10
|
-
import { Tokens } from '../../../tests/constants-e2e';
|
|
11
|
-
import { Interface, Result } from '@ethersproject/abi';
|
|
12
|
-
import solidlyPairABI from '../../abi/solidly/SolidlyPair.json';
|
|
13
|
-
import { SpiritSwapV2 } from './forks-override/spiritSwapV2';
|
|
14
|
-
import { Chronos } from './forks-override/chronos';
|
|
15
|
-
import { Ramses } from './forks-override/ramses';
|
|
16
|
-
import * as util from 'util';
|
|
17
|
-
import { VelodromeV2 } from './forks-override/velodromeV2';
|
|
18
|
-
import { Equalizer } from './forks-override/equalizer';
|
|
19
|
-
import { Velocimeter } from './forks-override/velocimeter';
|
|
20
|
-
import { Usdfi } from './forks-override/usdfi';
|
|
21
|
-
import { PharaohV1 } from './forks-override/pharaohV1';
|
|
22
|
-
|
|
23
|
-
const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
|
|
24
|
-
const amounts6 = [0n, BI_POWS[6], 2000000n];
|
|
25
|
-
|
|
26
|
-
function getReaderCalldata(
|
|
27
|
-
exchangeAddress: string,
|
|
28
|
-
readerIface: Interface,
|
|
29
|
-
amounts: bigint[],
|
|
30
|
-
funcName: string,
|
|
31
|
-
tokenIn: string,
|
|
32
|
-
) {
|
|
33
|
-
return amounts.map(amount => ({
|
|
34
|
-
target: exchangeAddress,
|
|
35
|
-
callData: readerIface.encodeFunctionData(funcName, [amount, tokenIn]),
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function decodeReaderResult(
|
|
40
|
-
results: Result,
|
|
41
|
-
readerIface: Interface,
|
|
42
|
-
funcName: string,
|
|
43
|
-
) {
|
|
44
|
-
return results.map(result => {
|
|
45
|
-
const parsed = readerIface.decodeFunctionResult(funcName, result);
|
|
46
|
-
return BigInt(parsed[0]._hex);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const constructCheckOnChainPricing =
|
|
51
|
-
(dexHelper: DummyDexHelper) =>
|
|
52
|
-
async (
|
|
53
|
-
solidly: Solidly,
|
|
54
|
-
funcName: string,
|
|
55
|
-
blockNumber: number,
|
|
56
|
-
prices: bigint[],
|
|
57
|
-
exchangeAddress: string,
|
|
58
|
-
tokenIn: string,
|
|
59
|
-
amounts: bigint[],
|
|
60
|
-
) => {
|
|
61
|
-
const readerIface = new Interface(solidlyPairABI as any);
|
|
62
|
-
|
|
63
|
-
const readerCallData = getReaderCalldata(
|
|
64
|
-
exchangeAddress,
|
|
65
|
-
readerIface,
|
|
66
|
-
amounts.slice(1),
|
|
67
|
-
funcName,
|
|
68
|
-
tokenIn,
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const readerResult = (
|
|
72
|
-
await dexHelper.multiContract.methods
|
|
73
|
-
.aggregate(readerCallData)
|
|
74
|
-
.call({}, blockNumber)
|
|
75
|
-
).returnData;
|
|
76
|
-
const expectedPrices = [0n].concat(
|
|
77
|
-
decodeReaderResult(readerResult, readerIface, funcName),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
console.log('ON-CHAIN PRICES: ', expectedPrices);
|
|
81
|
-
|
|
82
|
-
expect(prices.map(p => p.toString())).toEqual(
|
|
83
|
-
expectedPrices.map(p => p.toString()),
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
describe('Solidly integration tests', () => {
|
|
88
|
-
describe('Fantom', () => {
|
|
89
|
-
const network = Network.FANTOM;
|
|
90
|
-
const dexHelper = new DummyDexHelper(network);
|
|
91
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
92
|
-
|
|
93
|
-
describe('Solidly', function () {
|
|
94
|
-
const dexKey = 'Solidly';
|
|
95
|
-
const solidly = new Solidly(network, dexKey, dexHelper);
|
|
96
|
-
|
|
97
|
-
describe('UniswapV2 like pool', function () {
|
|
98
|
-
const TokenASymbol = 'WFTM';
|
|
99
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
100
|
-
const TokenBSymbol = 'FUSDT';
|
|
101
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
102
|
-
|
|
103
|
-
const amounts = amounts18;
|
|
104
|
-
|
|
105
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
106
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
107
|
-
const pools = await solidly.getPoolIdentifiers(
|
|
108
|
-
tokenA,
|
|
109
|
-
tokenB,
|
|
110
|
-
SwapSide.SELL,
|
|
111
|
-
blocknumber,
|
|
112
|
-
);
|
|
113
|
-
console.log(
|
|
114
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
115
|
-
pools,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
119
|
-
|
|
120
|
-
const poolPrices = await solidly.getPricesVolume(
|
|
121
|
-
tokenA,
|
|
122
|
-
tokenB,
|
|
123
|
-
amounts,
|
|
124
|
-
SwapSide.SELL,
|
|
125
|
-
blocknumber,
|
|
126
|
-
pools,
|
|
127
|
-
);
|
|
128
|
-
console.log(
|
|
129
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
130
|
-
poolPrices,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
expect(poolPrices).not.toBeNull();
|
|
134
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
135
|
-
|
|
136
|
-
// Check if onchain pricing equals to calculated ones
|
|
137
|
-
|
|
138
|
-
for (const poolPrice of poolPrices || []) {
|
|
139
|
-
await checkOnChainPricing(
|
|
140
|
-
solidly,
|
|
141
|
-
'getAmountOut',
|
|
142
|
-
blocknumber,
|
|
143
|
-
poolPrice.prices,
|
|
144
|
-
poolPrice.poolAddresses![0],
|
|
145
|
-
tokenA.address,
|
|
146
|
-
amounts,
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('getTopPoolsForToken', async function () {
|
|
152
|
-
const poolLiquidity = await solidly.getTopPoolsForToken(
|
|
153
|
-
tokenA.address,
|
|
154
|
-
10,
|
|
155
|
-
);
|
|
156
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
157
|
-
|
|
158
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe('Curve like stable pool', function () {
|
|
163
|
-
const TokenASymbol = 'FUSDT';
|
|
164
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
165
|
-
const TokenBSymbol = 'USDC';
|
|
166
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
167
|
-
|
|
168
|
-
const amounts = amounts18; // amounts6;
|
|
169
|
-
|
|
170
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
171
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
172
|
-
const pools = await solidly.getPoolIdentifiers(
|
|
173
|
-
tokenA,
|
|
174
|
-
tokenB,
|
|
175
|
-
SwapSide.SELL,
|
|
176
|
-
blocknumber,
|
|
177
|
-
);
|
|
178
|
-
console.log(
|
|
179
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
180
|
-
pools,
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
184
|
-
|
|
185
|
-
const poolPrices = await solidly.getPricesVolume(
|
|
186
|
-
tokenA,
|
|
187
|
-
tokenB,
|
|
188
|
-
amounts,
|
|
189
|
-
SwapSide.SELL,
|
|
190
|
-
blocknumber,
|
|
191
|
-
pools,
|
|
192
|
-
);
|
|
193
|
-
console.log(
|
|
194
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
195
|
-
poolPrices,
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
expect(poolPrices).not.toBeNull();
|
|
199
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
200
|
-
|
|
201
|
-
// Check if onchain pricing equals to calculated ones
|
|
202
|
-
for (const poolPrice of poolPrices || []) {
|
|
203
|
-
await checkOnChainPricing(
|
|
204
|
-
solidly,
|
|
205
|
-
'getAmountOut',
|
|
206
|
-
blocknumber,
|
|
207
|
-
poolPrice.prices,
|
|
208
|
-
poolPrice.poolAddresses![0],
|
|
209
|
-
tokenA.address,
|
|
210
|
-
amounts,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('getTopPoolsForToken', async function () {
|
|
216
|
-
const poolLiquidity = await solidly.getTopPoolsForToken(
|
|
217
|
-
tokenA.address,
|
|
218
|
-
10,
|
|
219
|
-
);
|
|
220
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
221
|
-
|
|
222
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe('SpiritSwapV2', function () {
|
|
228
|
-
const dexKey = 'SpiritSwapV2';
|
|
229
|
-
const spiritSwapV2 = new SpiritSwapV2(network, dexKey, dexHelper);
|
|
230
|
-
|
|
231
|
-
describe('UniswapV2 like pool', function () {
|
|
232
|
-
const TokenASymbol = 'WFTM';
|
|
233
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
234
|
-
const TokenBSymbol = 'FUSDT';
|
|
235
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
236
|
-
|
|
237
|
-
const amounts = amounts18;
|
|
238
|
-
|
|
239
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
240
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
241
|
-
const pools = await spiritSwapV2.getPoolIdentifiers(
|
|
242
|
-
tokenA,
|
|
243
|
-
tokenB,
|
|
244
|
-
SwapSide.SELL,
|
|
245
|
-
blocknumber,
|
|
246
|
-
);
|
|
247
|
-
console.log(
|
|
248
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
249
|
-
pools,
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
253
|
-
|
|
254
|
-
const poolPrices = await spiritSwapV2.getPricesVolume(
|
|
255
|
-
tokenA,
|
|
256
|
-
tokenB,
|
|
257
|
-
amounts,
|
|
258
|
-
SwapSide.SELL,
|
|
259
|
-
blocknumber,
|
|
260
|
-
pools,
|
|
261
|
-
);
|
|
262
|
-
console.log(
|
|
263
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
264
|
-
poolPrices,
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
expect(poolPrices).not.toBeNull();
|
|
268
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
269
|
-
|
|
270
|
-
// Check if onchain pricing equals to calculated ones
|
|
271
|
-
|
|
272
|
-
for (const poolPrice of poolPrices || []) {
|
|
273
|
-
await checkOnChainPricing(
|
|
274
|
-
spiritSwapV2,
|
|
275
|
-
'getAmountOut',
|
|
276
|
-
blocknumber,
|
|
277
|
-
poolPrice.prices,
|
|
278
|
-
poolPrice.poolAddresses![0],
|
|
279
|
-
tokenA.address,
|
|
280
|
-
amounts,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('getTopPoolsForToken', async function () {
|
|
286
|
-
const poolLiquidity = await spiritSwapV2.getTopPoolsForToken(
|
|
287
|
-
tokenA.address,
|
|
288
|
-
10,
|
|
289
|
-
);
|
|
290
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
291
|
-
|
|
292
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
describe('Curve like stable pool', function () {
|
|
297
|
-
const TokenASymbol = 'FUSDT';
|
|
298
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
299
|
-
const TokenBSymbol = 'USDC';
|
|
300
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
301
|
-
|
|
302
|
-
const amounts = amounts18; // amounts6;
|
|
303
|
-
|
|
304
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
305
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
306
|
-
const pools = await spiritSwapV2.getPoolIdentifiers(
|
|
307
|
-
tokenA,
|
|
308
|
-
tokenB,
|
|
309
|
-
SwapSide.SELL,
|
|
310
|
-
blocknumber,
|
|
311
|
-
);
|
|
312
|
-
console.log(
|
|
313
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
314
|
-
pools,
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
318
|
-
|
|
319
|
-
const poolPrices = await spiritSwapV2.getPricesVolume(
|
|
320
|
-
tokenA,
|
|
321
|
-
tokenB,
|
|
322
|
-
amounts,
|
|
323
|
-
SwapSide.SELL,
|
|
324
|
-
blocknumber,
|
|
325
|
-
pools,
|
|
326
|
-
);
|
|
327
|
-
console.log(
|
|
328
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
329
|
-
poolPrices,
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
expect(poolPrices).not.toBeNull();
|
|
333
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
334
|
-
|
|
335
|
-
// Check if onchain pricing equals to calculated ones
|
|
336
|
-
for (const poolPrice of poolPrices || []) {
|
|
337
|
-
await checkOnChainPricing(
|
|
338
|
-
spiritSwapV2,
|
|
339
|
-
'getAmountOut',
|
|
340
|
-
blocknumber,
|
|
341
|
-
poolPrice.prices,
|
|
342
|
-
poolPrice.poolAddresses![0],
|
|
343
|
-
tokenA.address,
|
|
344
|
-
amounts,
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('getTopPoolsForToken', async function () {
|
|
350
|
-
const poolLiquidity = await spiritSwapV2.getTopPoolsForToken(
|
|
351
|
-
tokenA.address,
|
|
352
|
-
10,
|
|
353
|
-
);
|
|
354
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
355
|
-
|
|
356
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
describe('Equalizer', () => {
|
|
362
|
-
const dexKey = 'Equalizer';
|
|
363
|
-
const equalizer = new Equalizer(network, dexKey, dexHelper);
|
|
364
|
-
|
|
365
|
-
describe('UniswapV2 like pool', function () {
|
|
366
|
-
const TokenASymbol = 'WFTM';
|
|
367
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
368
|
-
const TokenBSymbol = 'FUSDT';
|
|
369
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
370
|
-
|
|
371
|
-
const amounts = amounts18;
|
|
372
|
-
|
|
373
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
374
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
375
|
-
const pools = await equalizer.getPoolIdentifiers(
|
|
376
|
-
tokenA,
|
|
377
|
-
tokenB,
|
|
378
|
-
SwapSide.SELL,
|
|
379
|
-
blocknumber,
|
|
380
|
-
);
|
|
381
|
-
console.log(
|
|
382
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
383
|
-
pools,
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
387
|
-
|
|
388
|
-
const poolPrices = await equalizer.getPricesVolume(
|
|
389
|
-
tokenA,
|
|
390
|
-
tokenB,
|
|
391
|
-
amounts,
|
|
392
|
-
SwapSide.SELL,
|
|
393
|
-
blocknumber,
|
|
394
|
-
pools,
|
|
395
|
-
);
|
|
396
|
-
console.log(
|
|
397
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
398
|
-
poolPrices,
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
expect(poolPrices).not.toBeNull();
|
|
402
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
403
|
-
|
|
404
|
-
// Check if onchain pricing equals to calculated ones
|
|
405
|
-
|
|
406
|
-
for (const poolPrice of poolPrices || []) {
|
|
407
|
-
await checkOnChainPricing(
|
|
408
|
-
equalizer,
|
|
409
|
-
'getAmountOut',
|
|
410
|
-
blocknumber,
|
|
411
|
-
poolPrice.prices,
|
|
412
|
-
poolPrice.poolAddresses![0],
|
|
413
|
-
tokenA.address,
|
|
414
|
-
amounts,
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
describe('Curve like stable pool', function () {
|
|
421
|
-
const TokenASymbol = 'FUSDT';
|
|
422
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
423
|
-
const TokenBSymbol = 'USDC';
|
|
424
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
425
|
-
|
|
426
|
-
const amounts = amounts6; // amounts6;
|
|
427
|
-
|
|
428
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
429
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
430
|
-
const pools = await equalizer.getPoolIdentifiers(
|
|
431
|
-
tokenA,
|
|
432
|
-
tokenB,
|
|
433
|
-
SwapSide.SELL,
|
|
434
|
-
blocknumber,
|
|
435
|
-
);
|
|
436
|
-
console.log(
|
|
437
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
438
|
-
pools,
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
442
|
-
|
|
443
|
-
const poolPrices = await equalizer.getPricesVolume(
|
|
444
|
-
tokenA,
|
|
445
|
-
tokenB,
|
|
446
|
-
amounts,
|
|
447
|
-
SwapSide.SELL,
|
|
448
|
-
blocknumber,
|
|
449
|
-
pools,
|
|
450
|
-
);
|
|
451
|
-
console.log(
|
|
452
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
453
|
-
poolPrices,
|
|
454
|
-
);
|
|
455
|
-
|
|
456
|
-
expect(poolPrices).not.toBeNull();
|
|
457
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
458
|
-
|
|
459
|
-
// Check if onchain pricing equals to calculated ones
|
|
460
|
-
for (const poolPrice of poolPrices || []) {
|
|
461
|
-
await checkOnChainPricing(
|
|
462
|
-
equalizer,
|
|
463
|
-
'getAmountOut',
|
|
464
|
-
blocknumber,
|
|
465
|
-
poolPrice.prices,
|
|
466
|
-
poolPrice.poolAddresses![0],
|
|
467
|
-
tokenA.address,
|
|
468
|
-
amounts,
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
describe('FTM -> EQUAL', () => {
|
|
475
|
-
const TokenASymbol = 'WFTM';
|
|
476
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
477
|
-
const TokenBSymbol = 'EQUAL';
|
|
478
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
479
|
-
|
|
480
|
-
const amounts = [0n, 10000000n];
|
|
481
|
-
|
|
482
|
-
console.log('AMOUNTS: ', amounts);
|
|
483
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
484
|
-
// const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
485
|
-
const blocknumber = 67666611;
|
|
486
|
-
const pools = await equalizer.getPoolIdentifiers(
|
|
487
|
-
tokenA,
|
|
488
|
-
tokenB,
|
|
489
|
-
SwapSide.SELL,
|
|
490
|
-
blocknumber,
|
|
491
|
-
);
|
|
492
|
-
console.log(
|
|
493
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
494
|
-
pools,
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
498
|
-
|
|
499
|
-
const poolPrices = await equalizer.getPricesVolume(
|
|
500
|
-
tokenA,
|
|
501
|
-
tokenB,
|
|
502
|
-
amounts,
|
|
503
|
-
SwapSide.SELL,
|
|
504
|
-
blocknumber,
|
|
505
|
-
pools,
|
|
506
|
-
);
|
|
507
|
-
console.log(
|
|
508
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
509
|
-
poolPrices,
|
|
510
|
-
);
|
|
511
|
-
|
|
512
|
-
expect(poolPrices).not.toBeNull();
|
|
513
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
514
|
-
|
|
515
|
-
// Check if onchain pricing equals to calculated ones
|
|
516
|
-
for (const poolPrice of poolPrices || []) {
|
|
517
|
-
await checkOnChainPricing(
|
|
518
|
-
equalizer,
|
|
519
|
-
'getAmountOut',
|
|
520
|
-
blocknumber,
|
|
521
|
-
poolPrice.prices,
|
|
522
|
-
poolPrice.poolAddresses![0],
|
|
523
|
-
tokenA.address,
|
|
524
|
-
amounts,
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
describe('Velocimeter', () => {
|
|
532
|
-
const dexKey = 'Velocimeter';
|
|
533
|
-
const velocimeter = new Velocimeter(network, dexKey, dexHelper);
|
|
534
|
-
|
|
535
|
-
describe('UniswapV2 like pool', function () {
|
|
536
|
-
const TokenASymbol = 'WFTM';
|
|
537
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
538
|
-
const TokenBSymbol = 'lzUSDC';
|
|
539
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
540
|
-
|
|
541
|
-
const amounts = amounts18;
|
|
542
|
-
|
|
543
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
544
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
545
|
-
const pools = await velocimeter.getPoolIdentifiers(
|
|
546
|
-
tokenA,
|
|
547
|
-
tokenB,
|
|
548
|
-
SwapSide.SELL,
|
|
549
|
-
blocknumber,
|
|
550
|
-
);
|
|
551
|
-
console.log(
|
|
552
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
553
|
-
pools,
|
|
554
|
-
);
|
|
555
|
-
|
|
556
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
557
|
-
|
|
558
|
-
const poolPrices = await velocimeter.getPricesVolume(
|
|
559
|
-
tokenA,
|
|
560
|
-
tokenB,
|
|
561
|
-
amounts,
|
|
562
|
-
SwapSide.SELL,
|
|
563
|
-
blocknumber,
|
|
564
|
-
pools,
|
|
565
|
-
);
|
|
566
|
-
console.log(
|
|
567
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
568
|
-
poolPrices,
|
|
569
|
-
);
|
|
570
|
-
|
|
571
|
-
expect(poolPrices).not.toBeNull();
|
|
572
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
573
|
-
|
|
574
|
-
// Check if onchain pricing equals to calculated ones
|
|
575
|
-
|
|
576
|
-
for (const poolPrice of poolPrices || []) {
|
|
577
|
-
await checkOnChainPricing(
|
|
578
|
-
velocimeter,
|
|
579
|
-
'getAmountOut',
|
|
580
|
-
blocknumber,
|
|
581
|
-
poolPrice.prices,
|
|
582
|
-
poolPrice.poolAddresses![0],
|
|
583
|
-
tokenA.address,
|
|
584
|
-
amounts,
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
describe('Curve like stable pool', function () {
|
|
591
|
-
const TokenASymbol = 'lzUSDC';
|
|
592
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
593
|
-
const TokenBSymbol = 'axlUSDC';
|
|
594
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
595
|
-
|
|
596
|
-
const amounts = amounts6; // amounts6;
|
|
597
|
-
|
|
598
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
599
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
600
|
-
const pools = await velocimeter.getPoolIdentifiers(
|
|
601
|
-
tokenA,
|
|
602
|
-
tokenB,
|
|
603
|
-
SwapSide.SELL,
|
|
604
|
-
blocknumber,
|
|
605
|
-
);
|
|
606
|
-
console.log(
|
|
607
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
608
|
-
pools,
|
|
609
|
-
);
|
|
610
|
-
|
|
611
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
612
|
-
|
|
613
|
-
const poolPrices = await velocimeter.getPricesVolume(
|
|
614
|
-
tokenA,
|
|
615
|
-
tokenB,
|
|
616
|
-
amounts,
|
|
617
|
-
SwapSide.SELL,
|
|
618
|
-
blocknumber,
|
|
619
|
-
pools,
|
|
620
|
-
);
|
|
621
|
-
console.log(
|
|
622
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
623
|
-
poolPrices,
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
expect(poolPrices).not.toBeNull();
|
|
627
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
628
|
-
|
|
629
|
-
// Check if onchain pricing equals to calculated ones
|
|
630
|
-
for (const poolPrice of poolPrices || []) {
|
|
631
|
-
await checkOnChainPricing(
|
|
632
|
-
velocimeter,
|
|
633
|
-
'getAmountOut',
|
|
634
|
-
blocknumber,
|
|
635
|
-
poolPrice.prices,
|
|
636
|
-
poolPrice.poolAddresses![0],
|
|
637
|
-
tokenA.address,
|
|
638
|
-
amounts,
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
describe('FTM -> FVM', () => {
|
|
645
|
-
const TokenASymbol = 'WFTM';
|
|
646
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
647
|
-
const TokenBSymbol = 'FVM';
|
|
648
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
649
|
-
|
|
650
|
-
const amounts = [0n, 10000000n];
|
|
651
|
-
|
|
652
|
-
console.log('AMOUNTS: ', amounts);
|
|
653
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
654
|
-
// const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
655
|
-
const blocknumber = 67666611;
|
|
656
|
-
const pools = await velocimeter.getPoolIdentifiers(
|
|
657
|
-
tokenA,
|
|
658
|
-
tokenB,
|
|
659
|
-
SwapSide.SELL,
|
|
660
|
-
blocknumber,
|
|
661
|
-
);
|
|
662
|
-
console.log(
|
|
663
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
664
|
-
pools,
|
|
665
|
-
);
|
|
666
|
-
|
|
667
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
668
|
-
|
|
669
|
-
const poolPrices = await velocimeter.getPricesVolume(
|
|
670
|
-
tokenA,
|
|
671
|
-
tokenB,
|
|
672
|
-
amounts,
|
|
673
|
-
SwapSide.SELL,
|
|
674
|
-
blocknumber,
|
|
675
|
-
pools,
|
|
676
|
-
);
|
|
677
|
-
console.log(
|
|
678
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
679
|
-
poolPrices,
|
|
680
|
-
);
|
|
681
|
-
|
|
682
|
-
expect(poolPrices).not.toBeNull();
|
|
683
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
684
|
-
|
|
685
|
-
// Check if onchain pricing equals to calculated ones
|
|
686
|
-
for (const poolPrice of poolPrices || []) {
|
|
687
|
-
await checkOnChainPricing(
|
|
688
|
-
velocimeter,
|
|
689
|
-
'getAmountOut',
|
|
690
|
-
blocknumber,
|
|
691
|
-
poolPrice.prices,
|
|
692
|
-
poolPrice.poolAddresses![0],
|
|
693
|
-
tokenA.address,
|
|
694
|
-
amounts,
|
|
695
|
-
);
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
describe('Polygon', () => {
|
|
703
|
-
const network = Network.POLYGON;
|
|
704
|
-
const dexHelper = new DummyDexHelper(network);
|
|
705
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
706
|
-
|
|
707
|
-
describe('Dystopia', function () {
|
|
708
|
-
const dexKey = 'Dystopia';
|
|
709
|
-
const dystopia = new Solidly(network, dexKey, dexHelper);
|
|
710
|
-
|
|
711
|
-
describe('UniswapV2 like pool', function () {
|
|
712
|
-
const TokenASymbol = 'WETH';
|
|
713
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
714
|
-
const TokenBSymbol = 'WMATIC';
|
|
715
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
716
|
-
|
|
717
|
-
const amounts = amounts18;
|
|
718
|
-
|
|
719
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
720
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
721
|
-
const pools = await dystopia.getPoolIdentifiers(
|
|
722
|
-
tokenA,
|
|
723
|
-
tokenB,
|
|
724
|
-
SwapSide.SELL,
|
|
725
|
-
blocknumber,
|
|
726
|
-
);
|
|
727
|
-
console.log(
|
|
728
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
729
|
-
pools,
|
|
730
|
-
);
|
|
731
|
-
|
|
732
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
733
|
-
|
|
734
|
-
const poolPrices = await dystopia.getPricesVolume(
|
|
735
|
-
tokenA,
|
|
736
|
-
tokenB,
|
|
737
|
-
amounts,
|
|
738
|
-
SwapSide.SELL,
|
|
739
|
-
blocknumber,
|
|
740
|
-
pools,
|
|
741
|
-
);
|
|
742
|
-
console.log(
|
|
743
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
744
|
-
poolPrices,
|
|
745
|
-
);
|
|
746
|
-
|
|
747
|
-
expect(poolPrices).not.toBeNull();
|
|
748
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
749
|
-
|
|
750
|
-
// Check if onchain pricing equals to calculated ones
|
|
751
|
-
|
|
752
|
-
for (const poolPrice of poolPrices || []) {
|
|
753
|
-
await checkOnChainPricing(
|
|
754
|
-
dystopia,
|
|
755
|
-
'getAmountOut',
|
|
756
|
-
blocknumber,
|
|
757
|
-
poolPrice.prices,
|
|
758
|
-
poolPrice.poolAddresses![0],
|
|
759
|
-
tokenA.address,
|
|
760
|
-
amounts,
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
it('getTopPoolsForToken', async function () {
|
|
766
|
-
const poolLiquidity = await dystopia.getTopPoolsForToken(
|
|
767
|
-
tokenA.address,
|
|
768
|
-
10,
|
|
769
|
-
);
|
|
770
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
771
|
-
|
|
772
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
773
|
-
});
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
describe('Curve like stable pool', function () {
|
|
777
|
-
const TokenASymbol = 'DAI'; // 'USDT';
|
|
778
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
779
|
-
const TokenBSymbol = 'USDC';
|
|
780
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
781
|
-
|
|
782
|
-
const amounts = amounts18; // amounts6;
|
|
783
|
-
|
|
784
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
785
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
786
|
-
const pools = await dystopia.getPoolIdentifiers(
|
|
787
|
-
tokenA,
|
|
788
|
-
tokenB,
|
|
789
|
-
SwapSide.SELL,
|
|
790
|
-
blocknumber,
|
|
791
|
-
);
|
|
792
|
-
console.log(
|
|
793
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
794
|
-
pools,
|
|
795
|
-
);
|
|
796
|
-
|
|
797
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
798
|
-
|
|
799
|
-
const poolPrices = await dystopia.getPricesVolume(
|
|
800
|
-
tokenA,
|
|
801
|
-
tokenB,
|
|
802
|
-
amounts,
|
|
803
|
-
SwapSide.SELL,
|
|
804
|
-
blocknumber,
|
|
805
|
-
pools,
|
|
806
|
-
);
|
|
807
|
-
console.log(
|
|
808
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
809
|
-
poolPrices,
|
|
810
|
-
);
|
|
811
|
-
|
|
812
|
-
expect(poolPrices).not.toBeNull();
|
|
813
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
814
|
-
|
|
815
|
-
// Check if onchain pricing equals to calculated ones
|
|
816
|
-
for (const poolPrice of poolPrices || []) {
|
|
817
|
-
await checkOnChainPricing(
|
|
818
|
-
dystopia,
|
|
819
|
-
'getAmountOut',
|
|
820
|
-
blocknumber,
|
|
821
|
-
poolPrice.prices,
|
|
822
|
-
poolPrice.poolAddresses![0],
|
|
823
|
-
tokenA.address,
|
|
824
|
-
amounts,
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
it('getTopPoolsForToken', async function () {
|
|
830
|
-
const poolLiquidity = await dystopia.getTopPoolsForToken(
|
|
831
|
-
tokenA.address,
|
|
832
|
-
10,
|
|
833
|
-
);
|
|
834
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
835
|
-
|
|
836
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
837
|
-
});
|
|
838
|
-
});
|
|
839
|
-
});
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
describe('BSC', () => {
|
|
843
|
-
const network = Network.BSC;
|
|
844
|
-
const dexHelper = new DummyDexHelper(network);
|
|
845
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
846
|
-
|
|
847
|
-
describe('Usdfi', function () {
|
|
848
|
-
const dexKey = 'Usdfi';
|
|
849
|
-
const usdfi = new Usdfi(network, dexKey, dexHelper);
|
|
850
|
-
|
|
851
|
-
describe('UniswapV2 like pool', function () {
|
|
852
|
-
const TokenASymbol = 'USDFI';
|
|
853
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
854
|
-
const TokenBSymbol = 'USDT';
|
|
855
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
856
|
-
|
|
857
|
-
const amounts = amounts18;
|
|
858
|
-
|
|
859
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
860
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
861
|
-
const pools = await usdfi.getPoolIdentifiers(
|
|
862
|
-
tokenA,
|
|
863
|
-
tokenB,
|
|
864
|
-
SwapSide.SELL,
|
|
865
|
-
blocknumber,
|
|
866
|
-
);
|
|
867
|
-
console.log(
|
|
868
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
869
|
-
pools,
|
|
870
|
-
);
|
|
871
|
-
|
|
872
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
873
|
-
|
|
874
|
-
const poolPrices = await usdfi.getPricesVolume(
|
|
875
|
-
tokenA,
|
|
876
|
-
tokenB,
|
|
877
|
-
amounts,
|
|
878
|
-
SwapSide.SELL,
|
|
879
|
-
blocknumber,
|
|
880
|
-
pools,
|
|
881
|
-
);
|
|
882
|
-
console.log(
|
|
883
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
884
|
-
poolPrices,
|
|
885
|
-
);
|
|
886
|
-
|
|
887
|
-
expect(poolPrices).not.toBeNull();
|
|
888
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
889
|
-
|
|
890
|
-
// Check if onchain pricing equals to calculated ones
|
|
891
|
-
|
|
892
|
-
for (const poolPrice of poolPrices || []) {
|
|
893
|
-
await checkOnChainPricing(
|
|
894
|
-
usdfi,
|
|
895
|
-
'getAmountOut',
|
|
896
|
-
blocknumber,
|
|
897
|
-
poolPrice.prices,
|
|
898
|
-
poolPrice.poolAddresses![0],
|
|
899
|
-
tokenA.address,
|
|
900
|
-
amounts,
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
|
|
905
|
-
it('getTopPoolsForToken', async function () {
|
|
906
|
-
const poolLiquidity = await usdfi.getTopPoolsForToken(
|
|
907
|
-
tokenA.address,
|
|
908
|
-
10,
|
|
909
|
-
);
|
|
910
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
911
|
-
|
|
912
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
913
|
-
});
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
describe('Curve like stable pool', function () {
|
|
917
|
-
const TokenASymbol = 'USDT';
|
|
918
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
919
|
-
const TokenBSymbol = 'BUSD';
|
|
920
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
921
|
-
|
|
922
|
-
const amounts = amounts6;
|
|
923
|
-
|
|
924
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
925
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
926
|
-
const pools = await usdfi.getPoolIdentifiers(
|
|
927
|
-
tokenA,
|
|
928
|
-
tokenB,
|
|
929
|
-
SwapSide.SELL,
|
|
930
|
-
blocknumber,
|
|
931
|
-
);
|
|
932
|
-
console.log(
|
|
933
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
934
|
-
pools,
|
|
935
|
-
);
|
|
936
|
-
|
|
937
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
938
|
-
|
|
939
|
-
const poolPrices = await usdfi.getPricesVolume(
|
|
940
|
-
tokenA,
|
|
941
|
-
tokenB,
|
|
942
|
-
amounts,
|
|
943
|
-
SwapSide.SELL,
|
|
944
|
-
blocknumber,
|
|
945
|
-
pools,
|
|
946
|
-
);
|
|
947
|
-
console.log(
|
|
948
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
949
|
-
poolPrices,
|
|
950
|
-
);
|
|
951
|
-
|
|
952
|
-
expect(poolPrices).not.toBeNull();
|
|
953
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
954
|
-
|
|
955
|
-
// Check if onchain pricing equals to calculated ones
|
|
956
|
-
for (const poolPrice of poolPrices || []) {
|
|
957
|
-
await checkOnChainPricing(
|
|
958
|
-
usdfi,
|
|
959
|
-
'getAmountOut',
|
|
960
|
-
blocknumber,
|
|
961
|
-
poolPrice.prices,
|
|
962
|
-
poolPrice.poolAddresses![0],
|
|
963
|
-
tokenA.address,
|
|
964
|
-
amounts,
|
|
965
|
-
);
|
|
966
|
-
}
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
it('getTopPoolsForToken', async function () {
|
|
970
|
-
const poolLiquidity = await usdfi.getTopPoolsForToken(
|
|
971
|
-
tokenA.address,
|
|
972
|
-
10,
|
|
973
|
-
);
|
|
974
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
975
|
-
|
|
976
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
977
|
-
});
|
|
978
|
-
});
|
|
979
|
-
|
|
980
|
-
describe('FRAX -> frxETH', () => {
|
|
981
|
-
const TokenASymbol = 'FRAX';
|
|
982
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
983
|
-
const TokenBSymbol = 'frxETH';
|
|
984
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
985
|
-
|
|
986
|
-
const amounts = amounts18;
|
|
987
|
-
|
|
988
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
989
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
990
|
-
const pools = await usdfi.getPoolIdentifiers(
|
|
991
|
-
tokenA,
|
|
992
|
-
tokenB,
|
|
993
|
-
SwapSide.SELL,
|
|
994
|
-
blocknumber,
|
|
995
|
-
);
|
|
996
|
-
console.log(
|
|
997
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
998
|
-
pools,
|
|
999
|
-
);
|
|
1000
|
-
|
|
1001
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1002
|
-
|
|
1003
|
-
const poolPrices = await usdfi.getPricesVolume(
|
|
1004
|
-
tokenA,
|
|
1005
|
-
tokenB,
|
|
1006
|
-
amounts,
|
|
1007
|
-
SwapSide.SELL,
|
|
1008
|
-
blocknumber,
|
|
1009
|
-
pools,
|
|
1010
|
-
);
|
|
1011
|
-
console.log(
|
|
1012
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1013
|
-
poolPrices,
|
|
1014
|
-
);
|
|
1015
|
-
|
|
1016
|
-
expect(poolPrices).not.toBeNull();
|
|
1017
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1018
|
-
|
|
1019
|
-
// Check if onchain pricing equals to calculated ones
|
|
1020
|
-
for (const poolPrice of poolPrices || []) {
|
|
1021
|
-
await checkOnChainPricing(
|
|
1022
|
-
usdfi,
|
|
1023
|
-
'getAmountOut',
|
|
1024
|
-
blocknumber,
|
|
1025
|
-
poolPrice.prices,
|
|
1026
|
-
poolPrice.poolAddresses![0],
|
|
1027
|
-
tokenA.address,
|
|
1028
|
-
amounts,
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
});
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
describe('Arbitrum', () => {
|
|
1037
|
-
const network = Network.ARBITRUM;
|
|
1038
|
-
const dexHelper = new DummyDexHelper(network);
|
|
1039
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1040
|
-
|
|
1041
|
-
describe('Chronos', function () {
|
|
1042
|
-
const dexKey = 'Chronos';
|
|
1043
|
-
const chronos = new Chronos(network, dexKey, dexHelper);
|
|
1044
|
-
|
|
1045
|
-
describe('UniswapV2 like pool', function () {
|
|
1046
|
-
const TokenASymbol = 'USDC';
|
|
1047
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1048
|
-
const TokenBSymbol = 'WETH';
|
|
1049
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1050
|
-
|
|
1051
|
-
const amounts = amounts18;
|
|
1052
|
-
|
|
1053
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1054
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1055
|
-
const pools = await chronos.getPoolIdentifiers(
|
|
1056
|
-
tokenA,
|
|
1057
|
-
tokenB,
|
|
1058
|
-
SwapSide.SELL,
|
|
1059
|
-
blocknumber,
|
|
1060
|
-
);
|
|
1061
|
-
console.log(
|
|
1062
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1063
|
-
pools,
|
|
1064
|
-
);
|
|
1065
|
-
|
|
1066
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1067
|
-
|
|
1068
|
-
const poolPrices = await chronos.getPricesVolume(
|
|
1069
|
-
tokenA,
|
|
1070
|
-
tokenB,
|
|
1071
|
-
amounts,
|
|
1072
|
-
SwapSide.SELL,
|
|
1073
|
-
blocknumber,
|
|
1074
|
-
pools,
|
|
1075
|
-
);
|
|
1076
|
-
console.log(
|
|
1077
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1078
|
-
poolPrices,
|
|
1079
|
-
);
|
|
1080
|
-
|
|
1081
|
-
expect(poolPrices).not.toBeNull();
|
|
1082
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1083
|
-
|
|
1084
|
-
// Check if onchain pricing equals to calculated ones
|
|
1085
|
-
|
|
1086
|
-
for (const poolPrice of poolPrices || []) {
|
|
1087
|
-
await checkOnChainPricing(
|
|
1088
|
-
chronos,
|
|
1089
|
-
'getAmountOut',
|
|
1090
|
-
blocknumber,
|
|
1091
|
-
poolPrice.prices,
|
|
1092
|
-
poolPrice.poolAddresses![0],
|
|
1093
|
-
tokenA.address,
|
|
1094
|
-
amounts,
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
|
|
1099
|
-
it('getTopPoolsForToken', async function () {
|
|
1100
|
-
const poolLiquidity = await chronos.getTopPoolsForToken(
|
|
1101
|
-
tokenA.address,
|
|
1102
|
-
10,
|
|
1103
|
-
);
|
|
1104
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1105
|
-
|
|
1106
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1107
|
-
});
|
|
1108
|
-
});
|
|
1109
|
-
|
|
1110
|
-
describe('Curve like stable pool', function () {
|
|
1111
|
-
const TokenASymbol = 'USDT';
|
|
1112
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1113
|
-
const TokenBSymbol = 'USDC';
|
|
1114
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1115
|
-
|
|
1116
|
-
const amounts = amounts6;
|
|
1117
|
-
|
|
1118
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1119
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1120
|
-
const pools = await chronos.getPoolIdentifiers(
|
|
1121
|
-
tokenA,
|
|
1122
|
-
tokenB,
|
|
1123
|
-
SwapSide.SELL,
|
|
1124
|
-
blocknumber,
|
|
1125
|
-
);
|
|
1126
|
-
console.log(
|
|
1127
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1128
|
-
pools,
|
|
1129
|
-
);
|
|
1130
|
-
|
|
1131
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1132
|
-
|
|
1133
|
-
const poolPrices = await chronos.getPricesVolume(
|
|
1134
|
-
tokenA,
|
|
1135
|
-
tokenB,
|
|
1136
|
-
amounts,
|
|
1137
|
-
SwapSide.SELL,
|
|
1138
|
-
blocknumber,
|
|
1139
|
-
pools,
|
|
1140
|
-
);
|
|
1141
|
-
console.log(
|
|
1142
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1143
|
-
poolPrices,
|
|
1144
|
-
);
|
|
1145
|
-
|
|
1146
|
-
expect(poolPrices).not.toBeNull();
|
|
1147
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1148
|
-
|
|
1149
|
-
// Check if onchain pricing equals to calculated ones
|
|
1150
|
-
for (const poolPrice of poolPrices || []) {
|
|
1151
|
-
await checkOnChainPricing(
|
|
1152
|
-
chronos,
|
|
1153
|
-
'getAmountOut',
|
|
1154
|
-
blocknumber,
|
|
1155
|
-
poolPrice.prices,
|
|
1156
|
-
poolPrice.poolAddresses![0],
|
|
1157
|
-
tokenA.address,
|
|
1158
|
-
amounts,
|
|
1159
|
-
);
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
|
|
1163
|
-
it('getTopPoolsForToken', async function () {
|
|
1164
|
-
const poolLiquidity = await chronos.getTopPoolsForToken(
|
|
1165
|
-
tokenA.address,
|
|
1166
|
-
10,
|
|
1167
|
-
);
|
|
1168
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1169
|
-
|
|
1170
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1171
|
-
});
|
|
1172
|
-
});
|
|
1173
|
-
});
|
|
1174
|
-
|
|
1175
|
-
describe('Ramses', function () {
|
|
1176
|
-
const dexKey = 'Ramses';
|
|
1177
|
-
const ramses = new Ramses(network, dexKey, dexHelper);
|
|
1178
|
-
|
|
1179
|
-
describe('UniswapV2 like pool', function () {
|
|
1180
|
-
const TokenASymbol = 'USDCe';
|
|
1181
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1182
|
-
const TokenBSymbol = 'WETH';
|
|
1183
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1184
|
-
|
|
1185
|
-
const amounts = amounts18;
|
|
1186
|
-
|
|
1187
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1188
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1189
|
-
const pools = await ramses.getPoolIdentifiers(
|
|
1190
|
-
tokenA,
|
|
1191
|
-
tokenB,
|
|
1192
|
-
SwapSide.SELL,
|
|
1193
|
-
blocknumber,
|
|
1194
|
-
);
|
|
1195
|
-
console.log(
|
|
1196
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1197
|
-
pools,
|
|
1198
|
-
);
|
|
1199
|
-
|
|
1200
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1201
|
-
|
|
1202
|
-
console.log('AMOUNTS: ', amounts);
|
|
1203
|
-
|
|
1204
|
-
const poolPrices = await ramses.getPricesVolume(
|
|
1205
|
-
tokenA,
|
|
1206
|
-
tokenB,
|
|
1207
|
-
amounts,
|
|
1208
|
-
SwapSide.SELL,
|
|
1209
|
-
blocknumber,
|
|
1210
|
-
pools,
|
|
1211
|
-
);
|
|
1212
|
-
console.log(
|
|
1213
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1214
|
-
util.inspect(poolPrices, false, null, true),
|
|
1215
|
-
);
|
|
1216
|
-
|
|
1217
|
-
expect(poolPrices).not.toBeNull();
|
|
1218
|
-
// checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1219
|
-
|
|
1220
|
-
// Check if onchain pricing equals to calculated ones
|
|
1221
|
-
|
|
1222
|
-
for (const poolPrice of poolPrices || []) {
|
|
1223
|
-
await checkOnChainPricing(
|
|
1224
|
-
ramses,
|
|
1225
|
-
'getAmountOut',
|
|
1226
|
-
blocknumber,
|
|
1227
|
-
poolPrice.prices,
|
|
1228
|
-
poolPrice.poolAddresses![0],
|
|
1229
|
-
tokenA.address,
|
|
1230
|
-
amounts,
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
|
|
1235
|
-
it('getTopPoolsForToken', async function () {
|
|
1236
|
-
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
1237
|
-
tokenA.address,
|
|
1238
|
-
10,
|
|
1239
|
-
);
|
|
1240
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1241
|
-
|
|
1242
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1243
|
-
});
|
|
1244
|
-
});
|
|
1245
|
-
|
|
1246
|
-
describe('Curve like stable pool', function () {
|
|
1247
|
-
const TokenASymbol = 'USDT';
|
|
1248
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1249
|
-
const TokenBSymbol = 'USDCe';
|
|
1250
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1251
|
-
|
|
1252
|
-
const amounts = amounts6;
|
|
1253
|
-
|
|
1254
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1255
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1256
|
-
const pools = await ramses.getPoolIdentifiers(
|
|
1257
|
-
tokenA,
|
|
1258
|
-
tokenB,
|
|
1259
|
-
SwapSide.SELL,
|
|
1260
|
-
blocknumber,
|
|
1261
|
-
);
|
|
1262
|
-
console.log(
|
|
1263
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1264
|
-
pools,
|
|
1265
|
-
);
|
|
1266
|
-
|
|
1267
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1268
|
-
|
|
1269
|
-
const poolPrices = await ramses.getPricesVolume(
|
|
1270
|
-
tokenA,
|
|
1271
|
-
tokenB,
|
|
1272
|
-
amounts,
|
|
1273
|
-
SwapSide.SELL,
|
|
1274
|
-
blocknumber,
|
|
1275
|
-
pools,
|
|
1276
|
-
);
|
|
1277
|
-
console.log(
|
|
1278
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1279
|
-
poolPrices,
|
|
1280
|
-
);
|
|
1281
|
-
|
|
1282
|
-
expect(poolPrices).not.toBeNull();
|
|
1283
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1284
|
-
|
|
1285
|
-
// Check if onchain pricing equals to calculated ones
|
|
1286
|
-
for (const poolPrice of poolPrices || []) {
|
|
1287
|
-
await checkOnChainPricing(
|
|
1288
|
-
ramses,
|
|
1289
|
-
'getAmountOut',
|
|
1290
|
-
blocknumber,
|
|
1291
|
-
poolPrice.prices,
|
|
1292
|
-
poolPrice.poolAddresses![0],
|
|
1293
|
-
tokenA.address,
|
|
1294
|
-
amounts,
|
|
1295
|
-
);
|
|
1296
|
-
}
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
it('getTopPoolsForToken', async function () {
|
|
1300
|
-
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
1301
|
-
tokenA.address,
|
|
1302
|
-
10,
|
|
1303
|
-
);
|
|
1304
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1305
|
-
|
|
1306
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1307
|
-
});
|
|
1308
|
-
});
|
|
1309
|
-
});
|
|
1310
|
-
});
|
|
1311
|
-
|
|
1312
|
-
describe('Avalanche', () => {
|
|
1313
|
-
const network = Network.AVALANCHE;
|
|
1314
|
-
const dexHelper = new DummyDexHelper(network);
|
|
1315
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1316
|
-
|
|
1317
|
-
describe('PharaohV1', function () {
|
|
1318
|
-
const dexKey = 'PharaohV1';
|
|
1319
|
-
const pharaohV1 = new PharaohV1(network, dexKey, dexHelper);
|
|
1320
|
-
|
|
1321
|
-
describe('UniswapV2 like pool', function () {
|
|
1322
|
-
const TokenASymbol = 'USDC';
|
|
1323
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1324
|
-
const TokenBSymbol = 'WAVAX';
|
|
1325
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1326
|
-
|
|
1327
|
-
const amounts = amounts18;
|
|
1328
|
-
|
|
1329
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1330
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1331
|
-
const pools = await pharaohV1.getPoolIdentifiers(
|
|
1332
|
-
tokenA,
|
|
1333
|
-
tokenB,
|
|
1334
|
-
SwapSide.SELL,
|
|
1335
|
-
blocknumber,
|
|
1336
|
-
);
|
|
1337
|
-
console.log(
|
|
1338
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1339
|
-
pools,
|
|
1340
|
-
);
|
|
1341
|
-
|
|
1342
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1343
|
-
|
|
1344
|
-
console.log('AMOUNTS: ', amounts);
|
|
1345
|
-
|
|
1346
|
-
const poolPrices = await pharaohV1.getPricesVolume(
|
|
1347
|
-
tokenA,
|
|
1348
|
-
tokenB,
|
|
1349
|
-
amounts,
|
|
1350
|
-
SwapSide.SELL,
|
|
1351
|
-
blocknumber,
|
|
1352
|
-
pools,
|
|
1353
|
-
);
|
|
1354
|
-
console.log(
|
|
1355
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1356
|
-
util.inspect(poolPrices, false, null, true),
|
|
1357
|
-
);
|
|
1358
|
-
|
|
1359
|
-
expect(poolPrices).not.toBeNull();
|
|
1360
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1361
|
-
|
|
1362
|
-
// Check if onchain pricing equals to calculated ones
|
|
1363
|
-
|
|
1364
|
-
for (const poolPrice of poolPrices || []) {
|
|
1365
|
-
await checkOnChainPricing(
|
|
1366
|
-
pharaohV1,
|
|
1367
|
-
'getAmountOut',
|
|
1368
|
-
blocknumber,
|
|
1369
|
-
poolPrice.prices,
|
|
1370
|
-
poolPrice.poolAddresses![0],
|
|
1371
|
-
tokenA.address,
|
|
1372
|
-
amounts,
|
|
1373
|
-
);
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
|
|
1377
|
-
it('getTopPoolsForToken', async function () {
|
|
1378
|
-
const poolLiquidity = await pharaohV1.getTopPoolsForToken(
|
|
1379
|
-
tokenA.address,
|
|
1380
|
-
10,
|
|
1381
|
-
);
|
|
1382
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1383
|
-
|
|
1384
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1385
|
-
});
|
|
1386
|
-
});
|
|
1387
|
-
|
|
1388
|
-
describe('Curve like stable pool', function () {
|
|
1389
|
-
const TokenASymbol = 'USDT';
|
|
1390
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1391
|
-
const TokenBSymbol = 'USDC';
|
|
1392
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1393
|
-
|
|
1394
|
-
const amounts = amounts6;
|
|
1395
|
-
|
|
1396
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1397
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1398
|
-
const pools = await pharaohV1.getPoolIdentifiers(
|
|
1399
|
-
tokenA,
|
|
1400
|
-
tokenB,
|
|
1401
|
-
SwapSide.SELL,
|
|
1402
|
-
blocknumber,
|
|
1403
|
-
);
|
|
1404
|
-
console.log(
|
|
1405
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1406
|
-
pools,
|
|
1407
|
-
);
|
|
1408
|
-
|
|
1409
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1410
|
-
|
|
1411
|
-
const poolPrices = await pharaohV1.getPricesVolume(
|
|
1412
|
-
tokenA,
|
|
1413
|
-
tokenB,
|
|
1414
|
-
amounts,
|
|
1415
|
-
SwapSide.SELL,
|
|
1416
|
-
blocknumber,
|
|
1417
|
-
pools,
|
|
1418
|
-
);
|
|
1419
|
-
console.log(
|
|
1420
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1421
|
-
poolPrices,
|
|
1422
|
-
);
|
|
1423
|
-
|
|
1424
|
-
expect(poolPrices).not.toBeNull();
|
|
1425
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1426
|
-
|
|
1427
|
-
// Check if onchain pricing equals to calculated ones
|
|
1428
|
-
for (const poolPrice of poolPrices || []) {
|
|
1429
|
-
await checkOnChainPricing(
|
|
1430
|
-
pharaohV1,
|
|
1431
|
-
'getAmountOut',
|
|
1432
|
-
blocknumber,
|
|
1433
|
-
poolPrice.prices,
|
|
1434
|
-
poolPrice.poolAddresses![0],
|
|
1435
|
-
tokenA.address,
|
|
1436
|
-
amounts,
|
|
1437
|
-
);
|
|
1438
|
-
}
|
|
1439
|
-
});
|
|
1440
|
-
|
|
1441
|
-
it('getTopPoolsForToken', async function () {
|
|
1442
|
-
const poolLiquidity = await pharaohV1.getTopPoolsForToken(
|
|
1443
|
-
tokenA.address,
|
|
1444
|
-
10,
|
|
1445
|
-
);
|
|
1446
|
-
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1447
|
-
|
|
1448
|
-
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1449
|
-
});
|
|
1450
|
-
});
|
|
1451
|
-
});
|
|
1452
|
-
});
|
|
1453
|
-
|
|
1454
|
-
describe('Optimism', () => {
|
|
1455
|
-
const network = Network.OPTIMISM;
|
|
1456
|
-
const dexHelper = new DummyDexHelper(network);
|
|
1457
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1458
|
-
|
|
1459
|
-
describe('VelodromeV2', () => {
|
|
1460
|
-
const dexKey = 'VelodromeV2';
|
|
1461
|
-
const velodromeV2 = new VelodromeV2(network, dexKey, dexHelper);
|
|
1462
|
-
|
|
1463
|
-
describe('UniswapV2 like pool', function () {
|
|
1464
|
-
const TokenASymbol = 'USDC';
|
|
1465
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1466
|
-
const TokenBSymbol = 'WETH';
|
|
1467
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1468
|
-
|
|
1469
|
-
const amounts = amounts18;
|
|
1470
|
-
|
|
1471
|
-
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
1472
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1473
|
-
const pools = await velodromeV2.getPoolIdentifiers(
|
|
1474
|
-
tokenA,
|
|
1475
|
-
tokenB,
|
|
1476
|
-
SwapSide.SELL,
|
|
1477
|
-
blocknumber,
|
|
1478
|
-
);
|
|
1479
|
-
console.log(
|
|
1480
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1481
|
-
pools,
|
|
1482
|
-
);
|
|
1483
|
-
|
|
1484
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1485
|
-
|
|
1486
|
-
const poolPrices = await velodromeV2.getPricesVolume(
|
|
1487
|
-
tokenA,
|
|
1488
|
-
tokenB,
|
|
1489
|
-
amounts,
|
|
1490
|
-
SwapSide.SELL,
|
|
1491
|
-
blocknumber,
|
|
1492
|
-
pools,
|
|
1493
|
-
);
|
|
1494
|
-
console.log(
|
|
1495
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1496
|
-
poolPrices,
|
|
1497
|
-
);
|
|
1498
|
-
|
|
1499
|
-
expect(poolPrices).not.toBeNull();
|
|
1500
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1501
|
-
|
|
1502
|
-
// Check if onchain pricing equals to calculated ones
|
|
1503
|
-
|
|
1504
|
-
for (const poolPrice of poolPrices || []) {
|
|
1505
|
-
await checkOnChainPricing(
|
|
1506
|
-
velodromeV2,
|
|
1507
|
-
'getAmountOut',
|
|
1508
|
-
blocknumber,
|
|
1509
|
-
poolPrice.prices,
|
|
1510
|
-
poolPrice.poolAddresses![0],
|
|
1511
|
-
tokenA.address,
|
|
1512
|
-
amounts,
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1515
|
-
});
|
|
1516
|
-
});
|
|
1517
|
-
|
|
1518
|
-
describe('Curve like stable pool', function () {
|
|
1519
|
-
const TokenASymbol = 'USDT';
|
|
1520
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1521
|
-
const TokenBSymbol = 'USDC';
|
|
1522
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1523
|
-
|
|
1524
|
-
const amounts = amounts6;
|
|
1525
|
-
|
|
1526
|
-
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
1527
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1528
|
-
const pools = await velodromeV2.getPoolIdentifiers(
|
|
1529
|
-
tokenA,
|
|
1530
|
-
tokenB,
|
|
1531
|
-
SwapSide.SELL,
|
|
1532
|
-
blocknumber,
|
|
1533
|
-
);
|
|
1534
|
-
console.log(
|
|
1535
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1536
|
-
pools,
|
|
1537
|
-
);
|
|
1538
|
-
|
|
1539
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1540
|
-
|
|
1541
|
-
const poolPrices = await velodromeV2.getPricesVolume(
|
|
1542
|
-
tokenA,
|
|
1543
|
-
tokenB,
|
|
1544
|
-
amounts,
|
|
1545
|
-
SwapSide.SELL,
|
|
1546
|
-
blocknumber,
|
|
1547
|
-
pools,
|
|
1548
|
-
);
|
|
1549
|
-
console.log(
|
|
1550
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1551
|
-
poolPrices,
|
|
1552
|
-
);
|
|
1553
|
-
|
|
1554
|
-
expect(poolPrices).not.toBeNull();
|
|
1555
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1556
|
-
|
|
1557
|
-
// Check if onchain pricing equals to calculated ones
|
|
1558
|
-
for (const poolPrice of poolPrices || []) {
|
|
1559
|
-
await checkOnChainPricing(
|
|
1560
|
-
velodromeV2,
|
|
1561
|
-
'getAmountOut',
|
|
1562
|
-
blocknumber,
|
|
1563
|
-
poolPrice.prices,
|
|
1564
|
-
poolPrice.poolAddresses![0],
|
|
1565
|
-
tokenA.address,
|
|
1566
|
-
amounts,
|
|
1567
|
-
);
|
|
1568
|
-
}
|
|
1569
|
-
});
|
|
1570
|
-
});
|
|
1571
|
-
});
|
|
1572
|
-
});
|
|
1573
|
-
|
|
1574
|
-
describe('Base', () => {
|
|
1575
|
-
const network = Network.BASE;
|
|
1576
|
-
const dexHelper = new DummyDexHelper(network);
|
|
1577
|
-
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1578
|
-
|
|
1579
|
-
describe('Equalizer', () => {
|
|
1580
|
-
const dexKey = 'Equalizer';
|
|
1581
|
-
const equalizer = new Equalizer(network, dexKey, dexHelper);
|
|
1582
|
-
|
|
1583
|
-
describe('UniswapV2 like pool', function () {
|
|
1584
|
-
const TokenASymbol = 'USDbC';
|
|
1585
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1586
|
-
const TokenBSymbol = 'ETH';
|
|
1587
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1588
|
-
|
|
1589
|
-
const amounts = amounts18;
|
|
1590
|
-
|
|
1591
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1592
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1593
|
-
const pools = await equalizer.getPoolIdentifiers(
|
|
1594
|
-
tokenA,
|
|
1595
|
-
tokenB,
|
|
1596
|
-
SwapSide.SELL,
|
|
1597
|
-
blocknumber,
|
|
1598
|
-
);
|
|
1599
|
-
console.log(
|
|
1600
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1601
|
-
pools,
|
|
1602
|
-
);
|
|
1603
|
-
|
|
1604
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1605
|
-
|
|
1606
|
-
const poolPrices = await equalizer.getPricesVolume(
|
|
1607
|
-
tokenA,
|
|
1608
|
-
tokenB,
|
|
1609
|
-
amounts,
|
|
1610
|
-
SwapSide.SELL,
|
|
1611
|
-
blocknumber,
|
|
1612
|
-
pools,
|
|
1613
|
-
);
|
|
1614
|
-
console.log(
|
|
1615
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1616
|
-
poolPrices,
|
|
1617
|
-
);
|
|
1618
|
-
|
|
1619
|
-
expect(poolPrices).not.toBeNull();
|
|
1620
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1621
|
-
|
|
1622
|
-
// Check if onchain pricing equals to calculated ones
|
|
1623
|
-
|
|
1624
|
-
for (const poolPrice of poolPrices || []) {
|
|
1625
|
-
await checkOnChainPricing(
|
|
1626
|
-
equalizer,
|
|
1627
|
-
'getAmountOut',
|
|
1628
|
-
blocknumber,
|
|
1629
|
-
poolPrice.prices,
|
|
1630
|
-
poolPrice.poolAddresses![0],
|
|
1631
|
-
tokenA.address,
|
|
1632
|
-
amounts,
|
|
1633
|
-
);
|
|
1634
|
-
}
|
|
1635
|
-
});
|
|
1636
|
-
});
|
|
1637
|
-
});
|
|
1638
|
-
|
|
1639
|
-
describe('Velocimeter', () => {
|
|
1640
|
-
const dexKey = 'Velocimeter';
|
|
1641
|
-
const velocimeter = new Velocimeter(network, dexKey, dexHelper);
|
|
1642
|
-
|
|
1643
|
-
describe('UniswapV2 like pool', function () {
|
|
1644
|
-
const TokenASymbol = 'WETH';
|
|
1645
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1646
|
-
const TokenBSymbol = 'USDbC';
|
|
1647
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1648
|
-
|
|
1649
|
-
const amounts = amounts18;
|
|
1650
|
-
|
|
1651
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1652
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1653
|
-
const pools = await velocimeter.getPoolIdentifiers(
|
|
1654
|
-
tokenA,
|
|
1655
|
-
tokenB,
|
|
1656
|
-
SwapSide.SELL,
|
|
1657
|
-
blocknumber,
|
|
1658
|
-
);
|
|
1659
|
-
console.log(
|
|
1660
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1661
|
-
pools,
|
|
1662
|
-
);
|
|
1663
|
-
|
|
1664
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1665
|
-
|
|
1666
|
-
const poolPrices = await velocimeter.getPricesVolume(
|
|
1667
|
-
tokenA,
|
|
1668
|
-
tokenB,
|
|
1669
|
-
amounts,
|
|
1670
|
-
SwapSide.SELL,
|
|
1671
|
-
blocknumber,
|
|
1672
|
-
pools,
|
|
1673
|
-
);
|
|
1674
|
-
console.log(
|
|
1675
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1676
|
-
poolPrices,
|
|
1677
|
-
);
|
|
1678
|
-
|
|
1679
|
-
expect(poolPrices).not.toBeNull();
|
|
1680
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1681
|
-
|
|
1682
|
-
// Check if onchain pricing equals to calculated ones
|
|
1683
|
-
|
|
1684
|
-
for (const poolPrice of poolPrices || []) {
|
|
1685
|
-
await checkOnChainPricing(
|
|
1686
|
-
velocimeter,
|
|
1687
|
-
'getAmountOut',
|
|
1688
|
-
blocknumber,
|
|
1689
|
-
poolPrice.prices,
|
|
1690
|
-
poolPrice.poolAddresses![0],
|
|
1691
|
-
tokenA.address,
|
|
1692
|
-
amounts,
|
|
1693
|
-
);
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
});
|
|
1697
|
-
|
|
1698
|
-
describe('Curve like stable pool', function () {
|
|
1699
|
-
const TokenASymbol = 'USDbC';
|
|
1700
|
-
const tokenA = Tokens[network][TokenASymbol];
|
|
1701
|
-
const TokenBSymbol = 'USDC';
|
|
1702
|
-
const tokenB = Tokens[network][TokenBSymbol];
|
|
1703
|
-
|
|
1704
|
-
const amounts = amounts6; // amounts6;
|
|
1705
|
-
|
|
1706
|
-
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1707
|
-
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1708
|
-
const pools = await velocimeter.getPoolIdentifiers(
|
|
1709
|
-
tokenA,
|
|
1710
|
-
tokenB,
|
|
1711
|
-
SwapSide.SELL,
|
|
1712
|
-
blocknumber,
|
|
1713
|
-
);
|
|
1714
|
-
console.log(
|
|
1715
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1716
|
-
pools,
|
|
1717
|
-
);
|
|
1718
|
-
|
|
1719
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
1720
|
-
|
|
1721
|
-
const poolPrices = await velocimeter.getPricesVolume(
|
|
1722
|
-
tokenA,
|
|
1723
|
-
tokenB,
|
|
1724
|
-
amounts,
|
|
1725
|
-
SwapSide.SELL,
|
|
1726
|
-
blocknumber,
|
|
1727
|
-
pools,
|
|
1728
|
-
);
|
|
1729
|
-
console.log(
|
|
1730
|
-
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1731
|
-
poolPrices,
|
|
1732
|
-
);
|
|
1733
|
-
|
|
1734
|
-
expect(poolPrices).not.toBeNull();
|
|
1735
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1736
|
-
|
|
1737
|
-
// Check if onchain pricing equals to calculated ones
|
|
1738
|
-
for (const poolPrice of poolPrices || []) {
|
|
1739
|
-
await checkOnChainPricing(
|
|
1740
|
-
velocimeter,
|
|
1741
|
-
'getAmountOut',
|
|
1742
|
-
blocknumber,
|
|
1743
|
-
poolPrice.prices,
|
|
1744
|
-
poolPrice.poolAddresses![0],
|
|
1745
|
-
tokenA.address,
|
|
1746
|
-
amounts,
|
|
1747
|
-
);
|
|
1748
|
-
}
|
|
1749
|
-
});
|
|
1750
|
-
});
|
|
1751
|
-
});
|
|
1752
|
-
});
|
|
1753
|
-
});
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { DummyDexHelper } from '../../dex-helper';
|
|
6
|
+
import { Network, SwapSide } from '../../constants';
|
|
7
|
+
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
8
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
+
import { Solidly } from './solidly';
|
|
10
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
11
|
+
import { Interface, Result } from '@ethersproject/abi';
|
|
12
|
+
import solidlyPairABI from '../../abi/solidly/SolidlyPair.json';
|
|
13
|
+
import { SpiritSwapV2 } from './forks-override/spiritSwapV2';
|
|
14
|
+
import { Chronos } from './forks-override/chronos';
|
|
15
|
+
import { Ramses } from './forks-override/ramses';
|
|
16
|
+
import * as util from 'util';
|
|
17
|
+
import { VelodromeV2 } from './forks-override/velodromeV2';
|
|
18
|
+
import { Equalizer } from './forks-override/equalizer';
|
|
19
|
+
import { Velocimeter } from './forks-override/velocimeter';
|
|
20
|
+
import { Usdfi } from './forks-override/usdfi';
|
|
21
|
+
import { PharaohV1 } from './forks-override/pharaohV1';
|
|
22
|
+
|
|
23
|
+
const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
|
|
24
|
+
const amounts6 = [0n, BI_POWS[6], 2000000n];
|
|
25
|
+
|
|
26
|
+
function getReaderCalldata(
|
|
27
|
+
exchangeAddress: string,
|
|
28
|
+
readerIface: Interface,
|
|
29
|
+
amounts: bigint[],
|
|
30
|
+
funcName: string,
|
|
31
|
+
tokenIn: string,
|
|
32
|
+
) {
|
|
33
|
+
return amounts.map(amount => ({
|
|
34
|
+
target: exchangeAddress,
|
|
35
|
+
callData: readerIface.encodeFunctionData(funcName, [amount, tokenIn]),
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function decodeReaderResult(
|
|
40
|
+
results: Result,
|
|
41
|
+
readerIface: Interface,
|
|
42
|
+
funcName: string,
|
|
43
|
+
) {
|
|
44
|
+
return results.map(result => {
|
|
45
|
+
const parsed = readerIface.decodeFunctionResult(funcName, result);
|
|
46
|
+
return BigInt(parsed[0]._hex);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const constructCheckOnChainPricing =
|
|
51
|
+
(dexHelper: DummyDexHelper) =>
|
|
52
|
+
async (
|
|
53
|
+
solidly: Solidly,
|
|
54
|
+
funcName: string,
|
|
55
|
+
blockNumber: number,
|
|
56
|
+
prices: bigint[],
|
|
57
|
+
exchangeAddress: string,
|
|
58
|
+
tokenIn: string,
|
|
59
|
+
amounts: bigint[],
|
|
60
|
+
) => {
|
|
61
|
+
const readerIface = new Interface(solidlyPairABI as any);
|
|
62
|
+
|
|
63
|
+
const readerCallData = getReaderCalldata(
|
|
64
|
+
exchangeAddress,
|
|
65
|
+
readerIface,
|
|
66
|
+
amounts.slice(1),
|
|
67
|
+
funcName,
|
|
68
|
+
tokenIn,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const readerResult = (
|
|
72
|
+
await dexHelper.multiContract.methods
|
|
73
|
+
.aggregate(readerCallData)
|
|
74
|
+
.call({}, blockNumber)
|
|
75
|
+
).returnData;
|
|
76
|
+
const expectedPrices = [0n].concat(
|
|
77
|
+
decodeReaderResult(readerResult, readerIface, funcName),
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
console.log('ON-CHAIN PRICES: ', expectedPrices);
|
|
81
|
+
|
|
82
|
+
expect(prices.map(p => p.toString())).toEqual(
|
|
83
|
+
expectedPrices.map(p => p.toString()),
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe('Solidly integration tests', () => {
|
|
88
|
+
describe('Fantom', () => {
|
|
89
|
+
const network = Network.FANTOM;
|
|
90
|
+
const dexHelper = new DummyDexHelper(network);
|
|
91
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
92
|
+
|
|
93
|
+
describe('Solidly', function () {
|
|
94
|
+
const dexKey = 'Solidly';
|
|
95
|
+
const solidly = new Solidly(network, dexKey, dexHelper);
|
|
96
|
+
|
|
97
|
+
describe('UniswapV2 like pool', function () {
|
|
98
|
+
const TokenASymbol = 'WFTM';
|
|
99
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
100
|
+
const TokenBSymbol = 'FUSDT';
|
|
101
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
102
|
+
|
|
103
|
+
const amounts = amounts18;
|
|
104
|
+
|
|
105
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
106
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
107
|
+
const pools = await solidly.getPoolIdentifiers(
|
|
108
|
+
tokenA,
|
|
109
|
+
tokenB,
|
|
110
|
+
SwapSide.SELL,
|
|
111
|
+
blocknumber,
|
|
112
|
+
);
|
|
113
|
+
console.log(
|
|
114
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
115
|
+
pools,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
119
|
+
|
|
120
|
+
const poolPrices = await solidly.getPricesVolume(
|
|
121
|
+
tokenA,
|
|
122
|
+
tokenB,
|
|
123
|
+
amounts,
|
|
124
|
+
SwapSide.SELL,
|
|
125
|
+
blocknumber,
|
|
126
|
+
pools,
|
|
127
|
+
);
|
|
128
|
+
console.log(
|
|
129
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
130
|
+
poolPrices,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(poolPrices).not.toBeNull();
|
|
134
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
135
|
+
|
|
136
|
+
// Check if onchain pricing equals to calculated ones
|
|
137
|
+
|
|
138
|
+
for (const poolPrice of poolPrices || []) {
|
|
139
|
+
await checkOnChainPricing(
|
|
140
|
+
solidly,
|
|
141
|
+
'getAmountOut',
|
|
142
|
+
blocknumber,
|
|
143
|
+
poolPrice.prices,
|
|
144
|
+
poolPrice.poolAddresses![0],
|
|
145
|
+
tokenA.address,
|
|
146
|
+
amounts,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('getTopPoolsForToken', async function () {
|
|
152
|
+
const poolLiquidity = await solidly.getTopPoolsForToken(
|
|
153
|
+
tokenA.address,
|
|
154
|
+
10,
|
|
155
|
+
);
|
|
156
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
157
|
+
|
|
158
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('Curve like stable pool', function () {
|
|
163
|
+
const TokenASymbol = 'FUSDT';
|
|
164
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
165
|
+
const TokenBSymbol = 'USDC';
|
|
166
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
167
|
+
|
|
168
|
+
const amounts = amounts18; // amounts6;
|
|
169
|
+
|
|
170
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
171
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
172
|
+
const pools = await solidly.getPoolIdentifiers(
|
|
173
|
+
tokenA,
|
|
174
|
+
tokenB,
|
|
175
|
+
SwapSide.SELL,
|
|
176
|
+
blocknumber,
|
|
177
|
+
);
|
|
178
|
+
console.log(
|
|
179
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
180
|
+
pools,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
184
|
+
|
|
185
|
+
const poolPrices = await solidly.getPricesVolume(
|
|
186
|
+
tokenA,
|
|
187
|
+
tokenB,
|
|
188
|
+
amounts,
|
|
189
|
+
SwapSide.SELL,
|
|
190
|
+
blocknumber,
|
|
191
|
+
pools,
|
|
192
|
+
);
|
|
193
|
+
console.log(
|
|
194
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
195
|
+
poolPrices,
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
expect(poolPrices).not.toBeNull();
|
|
199
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
200
|
+
|
|
201
|
+
// Check if onchain pricing equals to calculated ones
|
|
202
|
+
for (const poolPrice of poolPrices || []) {
|
|
203
|
+
await checkOnChainPricing(
|
|
204
|
+
solidly,
|
|
205
|
+
'getAmountOut',
|
|
206
|
+
blocknumber,
|
|
207
|
+
poolPrice.prices,
|
|
208
|
+
poolPrice.poolAddresses![0],
|
|
209
|
+
tokenA.address,
|
|
210
|
+
amounts,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('getTopPoolsForToken', async function () {
|
|
216
|
+
const poolLiquidity = await solidly.getTopPoolsForToken(
|
|
217
|
+
tokenA.address,
|
|
218
|
+
10,
|
|
219
|
+
);
|
|
220
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
221
|
+
|
|
222
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('SpiritSwapV2', function () {
|
|
228
|
+
const dexKey = 'SpiritSwapV2';
|
|
229
|
+
const spiritSwapV2 = new SpiritSwapV2(network, dexKey, dexHelper);
|
|
230
|
+
|
|
231
|
+
describe('UniswapV2 like pool', function () {
|
|
232
|
+
const TokenASymbol = 'WFTM';
|
|
233
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
234
|
+
const TokenBSymbol = 'FUSDT';
|
|
235
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
236
|
+
|
|
237
|
+
const amounts = amounts18;
|
|
238
|
+
|
|
239
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
240
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
241
|
+
const pools = await spiritSwapV2.getPoolIdentifiers(
|
|
242
|
+
tokenA,
|
|
243
|
+
tokenB,
|
|
244
|
+
SwapSide.SELL,
|
|
245
|
+
blocknumber,
|
|
246
|
+
);
|
|
247
|
+
console.log(
|
|
248
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
249
|
+
pools,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
253
|
+
|
|
254
|
+
const poolPrices = await spiritSwapV2.getPricesVolume(
|
|
255
|
+
tokenA,
|
|
256
|
+
tokenB,
|
|
257
|
+
amounts,
|
|
258
|
+
SwapSide.SELL,
|
|
259
|
+
blocknumber,
|
|
260
|
+
pools,
|
|
261
|
+
);
|
|
262
|
+
console.log(
|
|
263
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
264
|
+
poolPrices,
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
expect(poolPrices).not.toBeNull();
|
|
268
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
269
|
+
|
|
270
|
+
// Check if onchain pricing equals to calculated ones
|
|
271
|
+
|
|
272
|
+
for (const poolPrice of poolPrices || []) {
|
|
273
|
+
await checkOnChainPricing(
|
|
274
|
+
spiritSwapV2,
|
|
275
|
+
'getAmountOut',
|
|
276
|
+
blocknumber,
|
|
277
|
+
poolPrice.prices,
|
|
278
|
+
poolPrice.poolAddresses![0],
|
|
279
|
+
tokenA.address,
|
|
280
|
+
amounts,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('getTopPoolsForToken', async function () {
|
|
286
|
+
const poolLiquidity = await spiritSwapV2.getTopPoolsForToken(
|
|
287
|
+
tokenA.address,
|
|
288
|
+
10,
|
|
289
|
+
);
|
|
290
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
291
|
+
|
|
292
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
describe('Curve like stable pool', function () {
|
|
297
|
+
const TokenASymbol = 'FUSDT';
|
|
298
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
299
|
+
const TokenBSymbol = 'USDC';
|
|
300
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
301
|
+
|
|
302
|
+
const amounts = amounts18; // amounts6;
|
|
303
|
+
|
|
304
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
305
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
306
|
+
const pools = await spiritSwapV2.getPoolIdentifiers(
|
|
307
|
+
tokenA,
|
|
308
|
+
tokenB,
|
|
309
|
+
SwapSide.SELL,
|
|
310
|
+
blocknumber,
|
|
311
|
+
);
|
|
312
|
+
console.log(
|
|
313
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
314
|
+
pools,
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
318
|
+
|
|
319
|
+
const poolPrices = await spiritSwapV2.getPricesVolume(
|
|
320
|
+
tokenA,
|
|
321
|
+
tokenB,
|
|
322
|
+
amounts,
|
|
323
|
+
SwapSide.SELL,
|
|
324
|
+
blocknumber,
|
|
325
|
+
pools,
|
|
326
|
+
);
|
|
327
|
+
console.log(
|
|
328
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
329
|
+
poolPrices,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
expect(poolPrices).not.toBeNull();
|
|
333
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
334
|
+
|
|
335
|
+
// Check if onchain pricing equals to calculated ones
|
|
336
|
+
for (const poolPrice of poolPrices || []) {
|
|
337
|
+
await checkOnChainPricing(
|
|
338
|
+
spiritSwapV2,
|
|
339
|
+
'getAmountOut',
|
|
340
|
+
blocknumber,
|
|
341
|
+
poolPrice.prices,
|
|
342
|
+
poolPrice.poolAddresses![0],
|
|
343
|
+
tokenA.address,
|
|
344
|
+
amounts,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('getTopPoolsForToken', async function () {
|
|
350
|
+
const poolLiquidity = await spiritSwapV2.getTopPoolsForToken(
|
|
351
|
+
tokenA.address,
|
|
352
|
+
10,
|
|
353
|
+
);
|
|
354
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
355
|
+
|
|
356
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
describe('Equalizer', () => {
|
|
362
|
+
const dexKey = 'Equalizer';
|
|
363
|
+
const equalizer = new Equalizer(network, dexKey, dexHelper);
|
|
364
|
+
|
|
365
|
+
describe('UniswapV2 like pool', function () {
|
|
366
|
+
const TokenASymbol = 'WFTM';
|
|
367
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
368
|
+
const TokenBSymbol = 'FUSDT';
|
|
369
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
370
|
+
|
|
371
|
+
const amounts = amounts18;
|
|
372
|
+
|
|
373
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
374
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
375
|
+
const pools = await equalizer.getPoolIdentifiers(
|
|
376
|
+
tokenA,
|
|
377
|
+
tokenB,
|
|
378
|
+
SwapSide.SELL,
|
|
379
|
+
blocknumber,
|
|
380
|
+
);
|
|
381
|
+
console.log(
|
|
382
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
383
|
+
pools,
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
387
|
+
|
|
388
|
+
const poolPrices = await equalizer.getPricesVolume(
|
|
389
|
+
tokenA,
|
|
390
|
+
tokenB,
|
|
391
|
+
amounts,
|
|
392
|
+
SwapSide.SELL,
|
|
393
|
+
blocknumber,
|
|
394
|
+
pools,
|
|
395
|
+
);
|
|
396
|
+
console.log(
|
|
397
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
398
|
+
poolPrices,
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
expect(poolPrices).not.toBeNull();
|
|
402
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
403
|
+
|
|
404
|
+
// Check if onchain pricing equals to calculated ones
|
|
405
|
+
|
|
406
|
+
for (const poolPrice of poolPrices || []) {
|
|
407
|
+
await checkOnChainPricing(
|
|
408
|
+
equalizer,
|
|
409
|
+
'getAmountOut',
|
|
410
|
+
blocknumber,
|
|
411
|
+
poolPrice.prices,
|
|
412
|
+
poolPrice.poolAddresses![0],
|
|
413
|
+
tokenA.address,
|
|
414
|
+
amounts,
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
describe('Curve like stable pool', function () {
|
|
421
|
+
const TokenASymbol = 'FUSDT';
|
|
422
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
423
|
+
const TokenBSymbol = 'USDC';
|
|
424
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
425
|
+
|
|
426
|
+
const amounts = amounts6; // amounts6;
|
|
427
|
+
|
|
428
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
429
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
430
|
+
const pools = await equalizer.getPoolIdentifiers(
|
|
431
|
+
tokenA,
|
|
432
|
+
tokenB,
|
|
433
|
+
SwapSide.SELL,
|
|
434
|
+
blocknumber,
|
|
435
|
+
);
|
|
436
|
+
console.log(
|
|
437
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
438
|
+
pools,
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
442
|
+
|
|
443
|
+
const poolPrices = await equalizer.getPricesVolume(
|
|
444
|
+
tokenA,
|
|
445
|
+
tokenB,
|
|
446
|
+
amounts,
|
|
447
|
+
SwapSide.SELL,
|
|
448
|
+
blocknumber,
|
|
449
|
+
pools,
|
|
450
|
+
);
|
|
451
|
+
console.log(
|
|
452
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
453
|
+
poolPrices,
|
|
454
|
+
);
|
|
455
|
+
|
|
456
|
+
expect(poolPrices).not.toBeNull();
|
|
457
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
458
|
+
|
|
459
|
+
// Check if onchain pricing equals to calculated ones
|
|
460
|
+
for (const poolPrice of poolPrices || []) {
|
|
461
|
+
await checkOnChainPricing(
|
|
462
|
+
equalizer,
|
|
463
|
+
'getAmountOut',
|
|
464
|
+
blocknumber,
|
|
465
|
+
poolPrice.prices,
|
|
466
|
+
poolPrice.poolAddresses![0],
|
|
467
|
+
tokenA.address,
|
|
468
|
+
amounts,
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
describe('FTM -> EQUAL', () => {
|
|
475
|
+
const TokenASymbol = 'WFTM';
|
|
476
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
477
|
+
const TokenBSymbol = 'EQUAL';
|
|
478
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
479
|
+
|
|
480
|
+
const amounts = [0n, 10000000n];
|
|
481
|
+
|
|
482
|
+
console.log('AMOUNTS: ', amounts);
|
|
483
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
484
|
+
// const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
485
|
+
const blocknumber = 67666611;
|
|
486
|
+
const pools = await equalizer.getPoolIdentifiers(
|
|
487
|
+
tokenA,
|
|
488
|
+
tokenB,
|
|
489
|
+
SwapSide.SELL,
|
|
490
|
+
blocknumber,
|
|
491
|
+
);
|
|
492
|
+
console.log(
|
|
493
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
494
|
+
pools,
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
498
|
+
|
|
499
|
+
const poolPrices = await equalizer.getPricesVolume(
|
|
500
|
+
tokenA,
|
|
501
|
+
tokenB,
|
|
502
|
+
amounts,
|
|
503
|
+
SwapSide.SELL,
|
|
504
|
+
blocknumber,
|
|
505
|
+
pools,
|
|
506
|
+
);
|
|
507
|
+
console.log(
|
|
508
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
509
|
+
poolPrices,
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
expect(poolPrices).not.toBeNull();
|
|
513
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
514
|
+
|
|
515
|
+
// Check if onchain pricing equals to calculated ones
|
|
516
|
+
for (const poolPrice of poolPrices || []) {
|
|
517
|
+
await checkOnChainPricing(
|
|
518
|
+
equalizer,
|
|
519
|
+
'getAmountOut',
|
|
520
|
+
blocknumber,
|
|
521
|
+
poolPrice.prices,
|
|
522
|
+
poolPrice.poolAddresses![0],
|
|
523
|
+
tokenA.address,
|
|
524
|
+
amounts,
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
describe('Velocimeter', () => {
|
|
532
|
+
const dexKey = 'Velocimeter';
|
|
533
|
+
const velocimeter = new Velocimeter(network, dexKey, dexHelper);
|
|
534
|
+
|
|
535
|
+
describe('UniswapV2 like pool', function () {
|
|
536
|
+
const TokenASymbol = 'WFTM';
|
|
537
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
538
|
+
const TokenBSymbol = 'lzUSDC';
|
|
539
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
540
|
+
|
|
541
|
+
const amounts = amounts18;
|
|
542
|
+
|
|
543
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
544
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
545
|
+
const pools = await velocimeter.getPoolIdentifiers(
|
|
546
|
+
tokenA,
|
|
547
|
+
tokenB,
|
|
548
|
+
SwapSide.SELL,
|
|
549
|
+
blocknumber,
|
|
550
|
+
);
|
|
551
|
+
console.log(
|
|
552
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
553
|
+
pools,
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
557
|
+
|
|
558
|
+
const poolPrices = await velocimeter.getPricesVolume(
|
|
559
|
+
tokenA,
|
|
560
|
+
tokenB,
|
|
561
|
+
amounts,
|
|
562
|
+
SwapSide.SELL,
|
|
563
|
+
blocknumber,
|
|
564
|
+
pools,
|
|
565
|
+
);
|
|
566
|
+
console.log(
|
|
567
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
568
|
+
poolPrices,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
expect(poolPrices).not.toBeNull();
|
|
572
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
573
|
+
|
|
574
|
+
// Check if onchain pricing equals to calculated ones
|
|
575
|
+
|
|
576
|
+
for (const poolPrice of poolPrices || []) {
|
|
577
|
+
await checkOnChainPricing(
|
|
578
|
+
velocimeter,
|
|
579
|
+
'getAmountOut',
|
|
580
|
+
blocknumber,
|
|
581
|
+
poolPrice.prices,
|
|
582
|
+
poolPrice.poolAddresses![0],
|
|
583
|
+
tokenA.address,
|
|
584
|
+
amounts,
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
describe('Curve like stable pool', function () {
|
|
591
|
+
const TokenASymbol = 'lzUSDC';
|
|
592
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
593
|
+
const TokenBSymbol = 'axlUSDC';
|
|
594
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
595
|
+
|
|
596
|
+
const amounts = amounts6; // amounts6;
|
|
597
|
+
|
|
598
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
599
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
600
|
+
const pools = await velocimeter.getPoolIdentifiers(
|
|
601
|
+
tokenA,
|
|
602
|
+
tokenB,
|
|
603
|
+
SwapSide.SELL,
|
|
604
|
+
blocknumber,
|
|
605
|
+
);
|
|
606
|
+
console.log(
|
|
607
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
608
|
+
pools,
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
612
|
+
|
|
613
|
+
const poolPrices = await velocimeter.getPricesVolume(
|
|
614
|
+
tokenA,
|
|
615
|
+
tokenB,
|
|
616
|
+
amounts,
|
|
617
|
+
SwapSide.SELL,
|
|
618
|
+
blocknumber,
|
|
619
|
+
pools,
|
|
620
|
+
);
|
|
621
|
+
console.log(
|
|
622
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
623
|
+
poolPrices,
|
|
624
|
+
);
|
|
625
|
+
|
|
626
|
+
expect(poolPrices).not.toBeNull();
|
|
627
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
628
|
+
|
|
629
|
+
// Check if onchain pricing equals to calculated ones
|
|
630
|
+
for (const poolPrice of poolPrices || []) {
|
|
631
|
+
await checkOnChainPricing(
|
|
632
|
+
velocimeter,
|
|
633
|
+
'getAmountOut',
|
|
634
|
+
blocknumber,
|
|
635
|
+
poolPrice.prices,
|
|
636
|
+
poolPrice.poolAddresses![0],
|
|
637
|
+
tokenA.address,
|
|
638
|
+
amounts,
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
describe('FTM -> FVM', () => {
|
|
645
|
+
const TokenASymbol = 'WFTM';
|
|
646
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
647
|
+
const TokenBSymbol = 'FVM';
|
|
648
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
649
|
+
|
|
650
|
+
const amounts = [0n, 10000000n];
|
|
651
|
+
|
|
652
|
+
console.log('AMOUNTS: ', amounts);
|
|
653
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
654
|
+
// const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
655
|
+
const blocknumber = 67666611;
|
|
656
|
+
const pools = await velocimeter.getPoolIdentifiers(
|
|
657
|
+
tokenA,
|
|
658
|
+
tokenB,
|
|
659
|
+
SwapSide.SELL,
|
|
660
|
+
blocknumber,
|
|
661
|
+
);
|
|
662
|
+
console.log(
|
|
663
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
664
|
+
pools,
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
668
|
+
|
|
669
|
+
const poolPrices = await velocimeter.getPricesVolume(
|
|
670
|
+
tokenA,
|
|
671
|
+
tokenB,
|
|
672
|
+
amounts,
|
|
673
|
+
SwapSide.SELL,
|
|
674
|
+
blocknumber,
|
|
675
|
+
pools,
|
|
676
|
+
);
|
|
677
|
+
console.log(
|
|
678
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
679
|
+
poolPrices,
|
|
680
|
+
);
|
|
681
|
+
|
|
682
|
+
expect(poolPrices).not.toBeNull();
|
|
683
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
684
|
+
|
|
685
|
+
// Check if onchain pricing equals to calculated ones
|
|
686
|
+
for (const poolPrice of poolPrices || []) {
|
|
687
|
+
await checkOnChainPricing(
|
|
688
|
+
velocimeter,
|
|
689
|
+
'getAmountOut',
|
|
690
|
+
blocknumber,
|
|
691
|
+
poolPrice.prices,
|
|
692
|
+
poolPrice.poolAddresses![0],
|
|
693
|
+
tokenA.address,
|
|
694
|
+
amounts,
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
describe('Polygon', () => {
|
|
703
|
+
const network = Network.POLYGON;
|
|
704
|
+
const dexHelper = new DummyDexHelper(network);
|
|
705
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
706
|
+
|
|
707
|
+
describe('Dystopia', function () {
|
|
708
|
+
const dexKey = 'Dystopia';
|
|
709
|
+
const dystopia = new Solidly(network, dexKey, dexHelper);
|
|
710
|
+
|
|
711
|
+
describe('UniswapV2 like pool', function () {
|
|
712
|
+
const TokenASymbol = 'WETH';
|
|
713
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
714
|
+
const TokenBSymbol = 'WMATIC';
|
|
715
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
716
|
+
|
|
717
|
+
const amounts = amounts18;
|
|
718
|
+
|
|
719
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
720
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
721
|
+
const pools = await dystopia.getPoolIdentifiers(
|
|
722
|
+
tokenA,
|
|
723
|
+
tokenB,
|
|
724
|
+
SwapSide.SELL,
|
|
725
|
+
blocknumber,
|
|
726
|
+
);
|
|
727
|
+
console.log(
|
|
728
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
729
|
+
pools,
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
733
|
+
|
|
734
|
+
const poolPrices = await dystopia.getPricesVolume(
|
|
735
|
+
tokenA,
|
|
736
|
+
tokenB,
|
|
737
|
+
amounts,
|
|
738
|
+
SwapSide.SELL,
|
|
739
|
+
blocknumber,
|
|
740
|
+
pools,
|
|
741
|
+
);
|
|
742
|
+
console.log(
|
|
743
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
744
|
+
poolPrices,
|
|
745
|
+
);
|
|
746
|
+
|
|
747
|
+
expect(poolPrices).not.toBeNull();
|
|
748
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
749
|
+
|
|
750
|
+
// Check if onchain pricing equals to calculated ones
|
|
751
|
+
|
|
752
|
+
for (const poolPrice of poolPrices || []) {
|
|
753
|
+
await checkOnChainPricing(
|
|
754
|
+
dystopia,
|
|
755
|
+
'getAmountOut',
|
|
756
|
+
blocknumber,
|
|
757
|
+
poolPrice.prices,
|
|
758
|
+
poolPrice.poolAddresses![0],
|
|
759
|
+
tokenA.address,
|
|
760
|
+
amounts,
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
it('getTopPoolsForToken', async function () {
|
|
766
|
+
const poolLiquidity = await dystopia.getTopPoolsForToken(
|
|
767
|
+
tokenA.address,
|
|
768
|
+
10,
|
|
769
|
+
);
|
|
770
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
771
|
+
|
|
772
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
describe('Curve like stable pool', function () {
|
|
777
|
+
const TokenASymbol = 'DAI'; // 'USDT';
|
|
778
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
779
|
+
const TokenBSymbol = 'USDC';
|
|
780
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
781
|
+
|
|
782
|
+
const amounts = amounts18; // amounts6;
|
|
783
|
+
|
|
784
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
785
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
786
|
+
const pools = await dystopia.getPoolIdentifiers(
|
|
787
|
+
tokenA,
|
|
788
|
+
tokenB,
|
|
789
|
+
SwapSide.SELL,
|
|
790
|
+
blocknumber,
|
|
791
|
+
);
|
|
792
|
+
console.log(
|
|
793
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
794
|
+
pools,
|
|
795
|
+
);
|
|
796
|
+
|
|
797
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
798
|
+
|
|
799
|
+
const poolPrices = await dystopia.getPricesVolume(
|
|
800
|
+
tokenA,
|
|
801
|
+
tokenB,
|
|
802
|
+
amounts,
|
|
803
|
+
SwapSide.SELL,
|
|
804
|
+
blocknumber,
|
|
805
|
+
pools,
|
|
806
|
+
);
|
|
807
|
+
console.log(
|
|
808
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
809
|
+
poolPrices,
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
expect(poolPrices).not.toBeNull();
|
|
813
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
814
|
+
|
|
815
|
+
// Check if onchain pricing equals to calculated ones
|
|
816
|
+
for (const poolPrice of poolPrices || []) {
|
|
817
|
+
await checkOnChainPricing(
|
|
818
|
+
dystopia,
|
|
819
|
+
'getAmountOut',
|
|
820
|
+
blocknumber,
|
|
821
|
+
poolPrice.prices,
|
|
822
|
+
poolPrice.poolAddresses![0],
|
|
823
|
+
tokenA.address,
|
|
824
|
+
amounts,
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
it('getTopPoolsForToken', async function () {
|
|
830
|
+
const poolLiquidity = await dystopia.getTopPoolsForToken(
|
|
831
|
+
tokenA.address,
|
|
832
|
+
10,
|
|
833
|
+
);
|
|
834
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
835
|
+
|
|
836
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
837
|
+
});
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
describe('BSC', () => {
|
|
843
|
+
const network = Network.BSC;
|
|
844
|
+
const dexHelper = new DummyDexHelper(network);
|
|
845
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
846
|
+
|
|
847
|
+
describe('Usdfi', function () {
|
|
848
|
+
const dexKey = 'Usdfi';
|
|
849
|
+
const usdfi = new Usdfi(network, dexKey, dexHelper);
|
|
850
|
+
|
|
851
|
+
describe('UniswapV2 like pool', function () {
|
|
852
|
+
const TokenASymbol = 'USDFI';
|
|
853
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
854
|
+
const TokenBSymbol = 'USDT';
|
|
855
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
856
|
+
|
|
857
|
+
const amounts = amounts18;
|
|
858
|
+
|
|
859
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
860
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
861
|
+
const pools = await usdfi.getPoolIdentifiers(
|
|
862
|
+
tokenA,
|
|
863
|
+
tokenB,
|
|
864
|
+
SwapSide.SELL,
|
|
865
|
+
blocknumber,
|
|
866
|
+
);
|
|
867
|
+
console.log(
|
|
868
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
869
|
+
pools,
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
873
|
+
|
|
874
|
+
const poolPrices = await usdfi.getPricesVolume(
|
|
875
|
+
tokenA,
|
|
876
|
+
tokenB,
|
|
877
|
+
amounts,
|
|
878
|
+
SwapSide.SELL,
|
|
879
|
+
blocknumber,
|
|
880
|
+
pools,
|
|
881
|
+
);
|
|
882
|
+
console.log(
|
|
883
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
884
|
+
poolPrices,
|
|
885
|
+
);
|
|
886
|
+
|
|
887
|
+
expect(poolPrices).not.toBeNull();
|
|
888
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
889
|
+
|
|
890
|
+
// Check if onchain pricing equals to calculated ones
|
|
891
|
+
|
|
892
|
+
for (const poolPrice of poolPrices || []) {
|
|
893
|
+
await checkOnChainPricing(
|
|
894
|
+
usdfi,
|
|
895
|
+
'getAmountOut',
|
|
896
|
+
blocknumber,
|
|
897
|
+
poolPrice.prices,
|
|
898
|
+
poolPrice.poolAddresses![0],
|
|
899
|
+
tokenA.address,
|
|
900
|
+
amounts,
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it('getTopPoolsForToken', async function () {
|
|
906
|
+
const poolLiquidity = await usdfi.getTopPoolsForToken(
|
|
907
|
+
tokenA.address,
|
|
908
|
+
10,
|
|
909
|
+
);
|
|
910
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
911
|
+
|
|
912
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
describe('Curve like stable pool', function () {
|
|
917
|
+
const TokenASymbol = 'USDT';
|
|
918
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
919
|
+
const TokenBSymbol = 'BUSD';
|
|
920
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
921
|
+
|
|
922
|
+
const amounts = amounts6;
|
|
923
|
+
|
|
924
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
925
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
926
|
+
const pools = await usdfi.getPoolIdentifiers(
|
|
927
|
+
tokenA,
|
|
928
|
+
tokenB,
|
|
929
|
+
SwapSide.SELL,
|
|
930
|
+
blocknumber,
|
|
931
|
+
);
|
|
932
|
+
console.log(
|
|
933
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
934
|
+
pools,
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
938
|
+
|
|
939
|
+
const poolPrices = await usdfi.getPricesVolume(
|
|
940
|
+
tokenA,
|
|
941
|
+
tokenB,
|
|
942
|
+
amounts,
|
|
943
|
+
SwapSide.SELL,
|
|
944
|
+
blocknumber,
|
|
945
|
+
pools,
|
|
946
|
+
);
|
|
947
|
+
console.log(
|
|
948
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
949
|
+
poolPrices,
|
|
950
|
+
);
|
|
951
|
+
|
|
952
|
+
expect(poolPrices).not.toBeNull();
|
|
953
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
954
|
+
|
|
955
|
+
// Check if onchain pricing equals to calculated ones
|
|
956
|
+
for (const poolPrice of poolPrices || []) {
|
|
957
|
+
await checkOnChainPricing(
|
|
958
|
+
usdfi,
|
|
959
|
+
'getAmountOut',
|
|
960
|
+
blocknumber,
|
|
961
|
+
poolPrice.prices,
|
|
962
|
+
poolPrice.poolAddresses![0],
|
|
963
|
+
tokenA.address,
|
|
964
|
+
amounts,
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it('getTopPoolsForToken', async function () {
|
|
970
|
+
const poolLiquidity = await usdfi.getTopPoolsForToken(
|
|
971
|
+
tokenA.address,
|
|
972
|
+
10,
|
|
973
|
+
);
|
|
974
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
975
|
+
|
|
976
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
977
|
+
});
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
describe('FRAX -> frxETH', () => {
|
|
981
|
+
const TokenASymbol = 'FRAX';
|
|
982
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
983
|
+
const TokenBSymbol = 'frxETH';
|
|
984
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
985
|
+
|
|
986
|
+
const amounts = amounts18;
|
|
987
|
+
|
|
988
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
989
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
990
|
+
const pools = await usdfi.getPoolIdentifiers(
|
|
991
|
+
tokenA,
|
|
992
|
+
tokenB,
|
|
993
|
+
SwapSide.SELL,
|
|
994
|
+
blocknumber,
|
|
995
|
+
);
|
|
996
|
+
console.log(
|
|
997
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
998
|
+
pools,
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1002
|
+
|
|
1003
|
+
const poolPrices = await usdfi.getPricesVolume(
|
|
1004
|
+
tokenA,
|
|
1005
|
+
tokenB,
|
|
1006
|
+
amounts,
|
|
1007
|
+
SwapSide.SELL,
|
|
1008
|
+
blocknumber,
|
|
1009
|
+
pools,
|
|
1010
|
+
);
|
|
1011
|
+
console.log(
|
|
1012
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1013
|
+
poolPrices,
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
expect(poolPrices).not.toBeNull();
|
|
1017
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1018
|
+
|
|
1019
|
+
// Check if onchain pricing equals to calculated ones
|
|
1020
|
+
for (const poolPrice of poolPrices || []) {
|
|
1021
|
+
await checkOnChainPricing(
|
|
1022
|
+
usdfi,
|
|
1023
|
+
'getAmountOut',
|
|
1024
|
+
blocknumber,
|
|
1025
|
+
poolPrice.prices,
|
|
1026
|
+
poolPrice.poolAddresses![0],
|
|
1027
|
+
tokenA.address,
|
|
1028
|
+
amounts,
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
describe('Arbitrum', () => {
|
|
1037
|
+
const network = Network.ARBITRUM;
|
|
1038
|
+
const dexHelper = new DummyDexHelper(network);
|
|
1039
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1040
|
+
|
|
1041
|
+
describe('Chronos', function () {
|
|
1042
|
+
const dexKey = 'Chronos';
|
|
1043
|
+
const chronos = new Chronos(network, dexKey, dexHelper);
|
|
1044
|
+
|
|
1045
|
+
describe('UniswapV2 like pool', function () {
|
|
1046
|
+
const TokenASymbol = 'USDC';
|
|
1047
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1048
|
+
const TokenBSymbol = 'WETH';
|
|
1049
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1050
|
+
|
|
1051
|
+
const amounts = amounts18;
|
|
1052
|
+
|
|
1053
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1054
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1055
|
+
const pools = await chronos.getPoolIdentifiers(
|
|
1056
|
+
tokenA,
|
|
1057
|
+
tokenB,
|
|
1058
|
+
SwapSide.SELL,
|
|
1059
|
+
blocknumber,
|
|
1060
|
+
);
|
|
1061
|
+
console.log(
|
|
1062
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1063
|
+
pools,
|
|
1064
|
+
);
|
|
1065
|
+
|
|
1066
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1067
|
+
|
|
1068
|
+
const poolPrices = await chronos.getPricesVolume(
|
|
1069
|
+
tokenA,
|
|
1070
|
+
tokenB,
|
|
1071
|
+
amounts,
|
|
1072
|
+
SwapSide.SELL,
|
|
1073
|
+
blocknumber,
|
|
1074
|
+
pools,
|
|
1075
|
+
);
|
|
1076
|
+
console.log(
|
|
1077
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1078
|
+
poolPrices,
|
|
1079
|
+
);
|
|
1080
|
+
|
|
1081
|
+
expect(poolPrices).not.toBeNull();
|
|
1082
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1083
|
+
|
|
1084
|
+
// Check if onchain pricing equals to calculated ones
|
|
1085
|
+
|
|
1086
|
+
for (const poolPrice of poolPrices || []) {
|
|
1087
|
+
await checkOnChainPricing(
|
|
1088
|
+
chronos,
|
|
1089
|
+
'getAmountOut',
|
|
1090
|
+
blocknumber,
|
|
1091
|
+
poolPrice.prices,
|
|
1092
|
+
poolPrice.poolAddresses![0],
|
|
1093
|
+
tokenA.address,
|
|
1094
|
+
amounts,
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
it('getTopPoolsForToken', async function () {
|
|
1100
|
+
const poolLiquidity = await chronos.getTopPoolsForToken(
|
|
1101
|
+
tokenA.address,
|
|
1102
|
+
10,
|
|
1103
|
+
);
|
|
1104
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1105
|
+
|
|
1106
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
describe('Curve like stable pool', function () {
|
|
1111
|
+
const TokenASymbol = 'USDT';
|
|
1112
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1113
|
+
const TokenBSymbol = 'USDC';
|
|
1114
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1115
|
+
|
|
1116
|
+
const amounts = amounts6;
|
|
1117
|
+
|
|
1118
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1119
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1120
|
+
const pools = await chronos.getPoolIdentifiers(
|
|
1121
|
+
tokenA,
|
|
1122
|
+
tokenB,
|
|
1123
|
+
SwapSide.SELL,
|
|
1124
|
+
blocknumber,
|
|
1125
|
+
);
|
|
1126
|
+
console.log(
|
|
1127
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1128
|
+
pools,
|
|
1129
|
+
);
|
|
1130
|
+
|
|
1131
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1132
|
+
|
|
1133
|
+
const poolPrices = await chronos.getPricesVolume(
|
|
1134
|
+
tokenA,
|
|
1135
|
+
tokenB,
|
|
1136
|
+
amounts,
|
|
1137
|
+
SwapSide.SELL,
|
|
1138
|
+
blocknumber,
|
|
1139
|
+
pools,
|
|
1140
|
+
);
|
|
1141
|
+
console.log(
|
|
1142
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1143
|
+
poolPrices,
|
|
1144
|
+
);
|
|
1145
|
+
|
|
1146
|
+
expect(poolPrices).not.toBeNull();
|
|
1147
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1148
|
+
|
|
1149
|
+
// Check if onchain pricing equals to calculated ones
|
|
1150
|
+
for (const poolPrice of poolPrices || []) {
|
|
1151
|
+
await checkOnChainPricing(
|
|
1152
|
+
chronos,
|
|
1153
|
+
'getAmountOut',
|
|
1154
|
+
blocknumber,
|
|
1155
|
+
poolPrice.prices,
|
|
1156
|
+
poolPrice.poolAddresses![0],
|
|
1157
|
+
tokenA.address,
|
|
1158
|
+
amounts,
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it('getTopPoolsForToken', async function () {
|
|
1164
|
+
const poolLiquidity = await chronos.getTopPoolsForToken(
|
|
1165
|
+
tokenA.address,
|
|
1166
|
+
10,
|
|
1167
|
+
);
|
|
1168
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1169
|
+
|
|
1170
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
describe('Ramses', function () {
|
|
1176
|
+
const dexKey = 'Ramses';
|
|
1177
|
+
const ramses = new Ramses(network, dexKey, dexHelper);
|
|
1178
|
+
|
|
1179
|
+
describe('UniswapV2 like pool', function () {
|
|
1180
|
+
const TokenASymbol = 'USDCe';
|
|
1181
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1182
|
+
const TokenBSymbol = 'WETH';
|
|
1183
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1184
|
+
|
|
1185
|
+
const amounts = amounts18;
|
|
1186
|
+
|
|
1187
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1188
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1189
|
+
const pools = await ramses.getPoolIdentifiers(
|
|
1190
|
+
tokenA,
|
|
1191
|
+
tokenB,
|
|
1192
|
+
SwapSide.SELL,
|
|
1193
|
+
blocknumber,
|
|
1194
|
+
);
|
|
1195
|
+
console.log(
|
|
1196
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1197
|
+
pools,
|
|
1198
|
+
);
|
|
1199
|
+
|
|
1200
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1201
|
+
|
|
1202
|
+
console.log('AMOUNTS: ', amounts);
|
|
1203
|
+
|
|
1204
|
+
const poolPrices = await ramses.getPricesVolume(
|
|
1205
|
+
tokenA,
|
|
1206
|
+
tokenB,
|
|
1207
|
+
amounts,
|
|
1208
|
+
SwapSide.SELL,
|
|
1209
|
+
blocknumber,
|
|
1210
|
+
pools,
|
|
1211
|
+
);
|
|
1212
|
+
console.log(
|
|
1213
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1214
|
+
util.inspect(poolPrices, false, null, true),
|
|
1215
|
+
);
|
|
1216
|
+
|
|
1217
|
+
expect(poolPrices).not.toBeNull();
|
|
1218
|
+
// checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1219
|
+
|
|
1220
|
+
// Check if onchain pricing equals to calculated ones
|
|
1221
|
+
|
|
1222
|
+
for (const poolPrice of poolPrices || []) {
|
|
1223
|
+
await checkOnChainPricing(
|
|
1224
|
+
ramses,
|
|
1225
|
+
'getAmountOut',
|
|
1226
|
+
blocknumber,
|
|
1227
|
+
poolPrice.prices,
|
|
1228
|
+
poolPrice.poolAddresses![0],
|
|
1229
|
+
tokenA.address,
|
|
1230
|
+
amounts,
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
it('getTopPoolsForToken', async function () {
|
|
1236
|
+
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
1237
|
+
tokenA.address,
|
|
1238
|
+
10,
|
|
1239
|
+
);
|
|
1240
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1241
|
+
|
|
1242
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
describe('Curve like stable pool', function () {
|
|
1247
|
+
const TokenASymbol = 'USDT';
|
|
1248
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1249
|
+
const TokenBSymbol = 'USDCe';
|
|
1250
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1251
|
+
|
|
1252
|
+
const amounts = amounts6;
|
|
1253
|
+
|
|
1254
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1255
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1256
|
+
const pools = await ramses.getPoolIdentifiers(
|
|
1257
|
+
tokenA,
|
|
1258
|
+
tokenB,
|
|
1259
|
+
SwapSide.SELL,
|
|
1260
|
+
blocknumber,
|
|
1261
|
+
);
|
|
1262
|
+
console.log(
|
|
1263
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1264
|
+
pools,
|
|
1265
|
+
);
|
|
1266
|
+
|
|
1267
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1268
|
+
|
|
1269
|
+
const poolPrices = await ramses.getPricesVolume(
|
|
1270
|
+
tokenA,
|
|
1271
|
+
tokenB,
|
|
1272
|
+
amounts,
|
|
1273
|
+
SwapSide.SELL,
|
|
1274
|
+
blocknumber,
|
|
1275
|
+
pools,
|
|
1276
|
+
);
|
|
1277
|
+
console.log(
|
|
1278
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1279
|
+
poolPrices,
|
|
1280
|
+
);
|
|
1281
|
+
|
|
1282
|
+
expect(poolPrices).not.toBeNull();
|
|
1283
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1284
|
+
|
|
1285
|
+
// Check if onchain pricing equals to calculated ones
|
|
1286
|
+
for (const poolPrice of poolPrices || []) {
|
|
1287
|
+
await checkOnChainPricing(
|
|
1288
|
+
ramses,
|
|
1289
|
+
'getAmountOut',
|
|
1290
|
+
blocknumber,
|
|
1291
|
+
poolPrice.prices,
|
|
1292
|
+
poolPrice.poolAddresses![0],
|
|
1293
|
+
tokenA.address,
|
|
1294
|
+
amounts,
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
it('getTopPoolsForToken', async function () {
|
|
1300
|
+
const poolLiquidity = await ramses.getTopPoolsForToken(
|
|
1301
|
+
tokenA.address,
|
|
1302
|
+
10,
|
|
1303
|
+
);
|
|
1304
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1305
|
+
|
|
1306
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
describe('Avalanche', () => {
|
|
1313
|
+
const network = Network.AVALANCHE;
|
|
1314
|
+
const dexHelper = new DummyDexHelper(network);
|
|
1315
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1316
|
+
|
|
1317
|
+
describe('PharaohV1', function () {
|
|
1318
|
+
const dexKey = 'PharaohV1';
|
|
1319
|
+
const pharaohV1 = new PharaohV1(network, dexKey, dexHelper);
|
|
1320
|
+
|
|
1321
|
+
describe('UniswapV2 like pool', function () {
|
|
1322
|
+
const TokenASymbol = 'USDC';
|
|
1323
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1324
|
+
const TokenBSymbol = 'WAVAX';
|
|
1325
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1326
|
+
|
|
1327
|
+
const amounts = amounts18;
|
|
1328
|
+
|
|
1329
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1330
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1331
|
+
const pools = await pharaohV1.getPoolIdentifiers(
|
|
1332
|
+
tokenA,
|
|
1333
|
+
tokenB,
|
|
1334
|
+
SwapSide.SELL,
|
|
1335
|
+
blocknumber,
|
|
1336
|
+
);
|
|
1337
|
+
console.log(
|
|
1338
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1339
|
+
pools,
|
|
1340
|
+
);
|
|
1341
|
+
|
|
1342
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1343
|
+
|
|
1344
|
+
console.log('AMOUNTS: ', amounts);
|
|
1345
|
+
|
|
1346
|
+
const poolPrices = await pharaohV1.getPricesVolume(
|
|
1347
|
+
tokenA,
|
|
1348
|
+
tokenB,
|
|
1349
|
+
amounts,
|
|
1350
|
+
SwapSide.SELL,
|
|
1351
|
+
blocknumber,
|
|
1352
|
+
pools,
|
|
1353
|
+
);
|
|
1354
|
+
console.log(
|
|
1355
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1356
|
+
util.inspect(poolPrices, false, null, true),
|
|
1357
|
+
);
|
|
1358
|
+
|
|
1359
|
+
expect(poolPrices).not.toBeNull();
|
|
1360
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1361
|
+
|
|
1362
|
+
// Check if onchain pricing equals to calculated ones
|
|
1363
|
+
|
|
1364
|
+
for (const poolPrice of poolPrices || []) {
|
|
1365
|
+
await checkOnChainPricing(
|
|
1366
|
+
pharaohV1,
|
|
1367
|
+
'getAmountOut',
|
|
1368
|
+
blocknumber,
|
|
1369
|
+
poolPrice.prices,
|
|
1370
|
+
poolPrice.poolAddresses![0],
|
|
1371
|
+
tokenA.address,
|
|
1372
|
+
amounts,
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
|
|
1377
|
+
it('getTopPoolsForToken', async function () {
|
|
1378
|
+
const poolLiquidity = await pharaohV1.getTopPoolsForToken(
|
|
1379
|
+
tokenA.address,
|
|
1380
|
+
10,
|
|
1381
|
+
);
|
|
1382
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1383
|
+
|
|
1384
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
describe('Curve like stable pool', function () {
|
|
1389
|
+
const TokenASymbol = 'USDT';
|
|
1390
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1391
|
+
const TokenBSymbol = 'USDC';
|
|
1392
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1393
|
+
|
|
1394
|
+
const amounts = amounts6;
|
|
1395
|
+
|
|
1396
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1397
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1398
|
+
const pools = await pharaohV1.getPoolIdentifiers(
|
|
1399
|
+
tokenA,
|
|
1400
|
+
tokenB,
|
|
1401
|
+
SwapSide.SELL,
|
|
1402
|
+
blocknumber,
|
|
1403
|
+
);
|
|
1404
|
+
console.log(
|
|
1405
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1406
|
+
pools,
|
|
1407
|
+
);
|
|
1408
|
+
|
|
1409
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1410
|
+
|
|
1411
|
+
const poolPrices = await pharaohV1.getPricesVolume(
|
|
1412
|
+
tokenA,
|
|
1413
|
+
tokenB,
|
|
1414
|
+
amounts,
|
|
1415
|
+
SwapSide.SELL,
|
|
1416
|
+
blocknumber,
|
|
1417
|
+
pools,
|
|
1418
|
+
);
|
|
1419
|
+
console.log(
|
|
1420
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1421
|
+
poolPrices,
|
|
1422
|
+
);
|
|
1423
|
+
|
|
1424
|
+
expect(poolPrices).not.toBeNull();
|
|
1425
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1426
|
+
|
|
1427
|
+
// Check if onchain pricing equals to calculated ones
|
|
1428
|
+
for (const poolPrice of poolPrices || []) {
|
|
1429
|
+
await checkOnChainPricing(
|
|
1430
|
+
pharaohV1,
|
|
1431
|
+
'getAmountOut',
|
|
1432
|
+
blocknumber,
|
|
1433
|
+
poolPrice.prices,
|
|
1434
|
+
poolPrice.poolAddresses![0],
|
|
1435
|
+
tokenA.address,
|
|
1436
|
+
amounts,
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
|
|
1441
|
+
it('getTopPoolsForToken', async function () {
|
|
1442
|
+
const poolLiquidity = await pharaohV1.getTopPoolsForToken(
|
|
1443
|
+
tokenA.address,
|
|
1444
|
+
10,
|
|
1445
|
+
);
|
|
1446
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
1447
|
+
|
|
1448
|
+
checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
|
|
1449
|
+
});
|
|
1450
|
+
});
|
|
1451
|
+
});
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
describe('Optimism', () => {
|
|
1455
|
+
const network = Network.OPTIMISM;
|
|
1456
|
+
const dexHelper = new DummyDexHelper(network);
|
|
1457
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1458
|
+
|
|
1459
|
+
describe('VelodromeV2', () => {
|
|
1460
|
+
const dexKey = 'VelodromeV2';
|
|
1461
|
+
const velodromeV2 = new VelodromeV2(network, dexKey, dexHelper);
|
|
1462
|
+
|
|
1463
|
+
describe('UniswapV2 like pool', function () {
|
|
1464
|
+
const TokenASymbol = 'USDC';
|
|
1465
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1466
|
+
const TokenBSymbol = 'WETH';
|
|
1467
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1468
|
+
|
|
1469
|
+
const amounts = amounts18;
|
|
1470
|
+
|
|
1471
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
1472
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1473
|
+
const pools = await velodromeV2.getPoolIdentifiers(
|
|
1474
|
+
tokenA,
|
|
1475
|
+
tokenB,
|
|
1476
|
+
SwapSide.SELL,
|
|
1477
|
+
blocknumber,
|
|
1478
|
+
);
|
|
1479
|
+
console.log(
|
|
1480
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1481
|
+
pools,
|
|
1482
|
+
);
|
|
1483
|
+
|
|
1484
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1485
|
+
|
|
1486
|
+
const poolPrices = await velodromeV2.getPricesVolume(
|
|
1487
|
+
tokenA,
|
|
1488
|
+
tokenB,
|
|
1489
|
+
amounts,
|
|
1490
|
+
SwapSide.SELL,
|
|
1491
|
+
blocknumber,
|
|
1492
|
+
pools,
|
|
1493
|
+
);
|
|
1494
|
+
console.log(
|
|
1495
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1496
|
+
poolPrices,
|
|
1497
|
+
);
|
|
1498
|
+
|
|
1499
|
+
expect(poolPrices).not.toBeNull();
|
|
1500
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1501
|
+
|
|
1502
|
+
// Check if onchain pricing equals to calculated ones
|
|
1503
|
+
|
|
1504
|
+
for (const poolPrice of poolPrices || []) {
|
|
1505
|
+
await checkOnChainPricing(
|
|
1506
|
+
velodromeV2,
|
|
1507
|
+
'getAmountOut',
|
|
1508
|
+
blocknumber,
|
|
1509
|
+
poolPrice.prices,
|
|
1510
|
+
poolPrice.poolAddresses![0],
|
|
1511
|
+
tokenA.address,
|
|
1512
|
+
amounts,
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
});
|
|
1517
|
+
|
|
1518
|
+
describe('Curve like stable pool', function () {
|
|
1519
|
+
const TokenASymbol = 'USDT';
|
|
1520
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1521
|
+
const TokenBSymbol = 'USDC';
|
|
1522
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1523
|
+
|
|
1524
|
+
const amounts = amounts6;
|
|
1525
|
+
|
|
1526
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
1527
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1528
|
+
const pools = await velodromeV2.getPoolIdentifiers(
|
|
1529
|
+
tokenA,
|
|
1530
|
+
tokenB,
|
|
1531
|
+
SwapSide.SELL,
|
|
1532
|
+
blocknumber,
|
|
1533
|
+
);
|
|
1534
|
+
console.log(
|
|
1535
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1536
|
+
pools,
|
|
1537
|
+
);
|
|
1538
|
+
|
|
1539
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1540
|
+
|
|
1541
|
+
const poolPrices = await velodromeV2.getPricesVolume(
|
|
1542
|
+
tokenA,
|
|
1543
|
+
tokenB,
|
|
1544
|
+
amounts,
|
|
1545
|
+
SwapSide.SELL,
|
|
1546
|
+
blocknumber,
|
|
1547
|
+
pools,
|
|
1548
|
+
);
|
|
1549
|
+
console.log(
|
|
1550
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1551
|
+
poolPrices,
|
|
1552
|
+
);
|
|
1553
|
+
|
|
1554
|
+
expect(poolPrices).not.toBeNull();
|
|
1555
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1556
|
+
|
|
1557
|
+
// Check if onchain pricing equals to calculated ones
|
|
1558
|
+
for (const poolPrice of poolPrices || []) {
|
|
1559
|
+
await checkOnChainPricing(
|
|
1560
|
+
velodromeV2,
|
|
1561
|
+
'getAmountOut',
|
|
1562
|
+
blocknumber,
|
|
1563
|
+
poolPrice.prices,
|
|
1564
|
+
poolPrice.poolAddresses![0],
|
|
1565
|
+
tokenA.address,
|
|
1566
|
+
amounts,
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
});
|
|
1571
|
+
});
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
describe('Base', () => {
|
|
1575
|
+
const network = Network.BASE;
|
|
1576
|
+
const dexHelper = new DummyDexHelper(network);
|
|
1577
|
+
const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
|
|
1578
|
+
|
|
1579
|
+
describe('Equalizer', () => {
|
|
1580
|
+
const dexKey = 'Equalizer';
|
|
1581
|
+
const equalizer = new Equalizer(network, dexKey, dexHelper);
|
|
1582
|
+
|
|
1583
|
+
describe('UniswapV2 like pool', function () {
|
|
1584
|
+
const TokenASymbol = 'USDbC';
|
|
1585
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1586
|
+
const TokenBSymbol = 'ETH';
|
|
1587
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1588
|
+
|
|
1589
|
+
const amounts = amounts18;
|
|
1590
|
+
|
|
1591
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1592
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1593
|
+
const pools = await equalizer.getPoolIdentifiers(
|
|
1594
|
+
tokenA,
|
|
1595
|
+
tokenB,
|
|
1596
|
+
SwapSide.SELL,
|
|
1597
|
+
blocknumber,
|
|
1598
|
+
);
|
|
1599
|
+
console.log(
|
|
1600
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1601
|
+
pools,
|
|
1602
|
+
);
|
|
1603
|
+
|
|
1604
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1605
|
+
|
|
1606
|
+
const poolPrices = await equalizer.getPricesVolume(
|
|
1607
|
+
tokenA,
|
|
1608
|
+
tokenB,
|
|
1609
|
+
amounts,
|
|
1610
|
+
SwapSide.SELL,
|
|
1611
|
+
blocknumber,
|
|
1612
|
+
pools,
|
|
1613
|
+
);
|
|
1614
|
+
console.log(
|
|
1615
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1616
|
+
poolPrices,
|
|
1617
|
+
);
|
|
1618
|
+
|
|
1619
|
+
expect(poolPrices).not.toBeNull();
|
|
1620
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1621
|
+
|
|
1622
|
+
// Check if onchain pricing equals to calculated ones
|
|
1623
|
+
|
|
1624
|
+
for (const poolPrice of poolPrices || []) {
|
|
1625
|
+
await checkOnChainPricing(
|
|
1626
|
+
equalizer,
|
|
1627
|
+
'getAmountOut',
|
|
1628
|
+
blocknumber,
|
|
1629
|
+
poolPrice.prices,
|
|
1630
|
+
poolPrice.poolAddresses![0],
|
|
1631
|
+
tokenA.address,
|
|
1632
|
+
amounts,
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
describe('Velocimeter', () => {
|
|
1640
|
+
const dexKey = 'Velocimeter';
|
|
1641
|
+
const velocimeter = new Velocimeter(network, dexKey, dexHelper);
|
|
1642
|
+
|
|
1643
|
+
describe('UniswapV2 like pool', function () {
|
|
1644
|
+
const TokenASymbol = 'WETH';
|
|
1645
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1646
|
+
const TokenBSymbol = 'USDbC';
|
|
1647
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1648
|
+
|
|
1649
|
+
const amounts = amounts18;
|
|
1650
|
+
|
|
1651
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1652
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1653
|
+
const pools = await velocimeter.getPoolIdentifiers(
|
|
1654
|
+
tokenA,
|
|
1655
|
+
tokenB,
|
|
1656
|
+
SwapSide.SELL,
|
|
1657
|
+
blocknumber,
|
|
1658
|
+
);
|
|
1659
|
+
console.log(
|
|
1660
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1661
|
+
pools,
|
|
1662
|
+
);
|
|
1663
|
+
|
|
1664
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1665
|
+
|
|
1666
|
+
const poolPrices = await velocimeter.getPricesVolume(
|
|
1667
|
+
tokenA,
|
|
1668
|
+
tokenB,
|
|
1669
|
+
amounts,
|
|
1670
|
+
SwapSide.SELL,
|
|
1671
|
+
blocknumber,
|
|
1672
|
+
pools,
|
|
1673
|
+
);
|
|
1674
|
+
console.log(
|
|
1675
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1676
|
+
poolPrices,
|
|
1677
|
+
);
|
|
1678
|
+
|
|
1679
|
+
expect(poolPrices).not.toBeNull();
|
|
1680
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1681
|
+
|
|
1682
|
+
// Check if onchain pricing equals to calculated ones
|
|
1683
|
+
|
|
1684
|
+
for (const poolPrice of poolPrices || []) {
|
|
1685
|
+
await checkOnChainPricing(
|
|
1686
|
+
velocimeter,
|
|
1687
|
+
'getAmountOut',
|
|
1688
|
+
blocknumber,
|
|
1689
|
+
poolPrice.prices,
|
|
1690
|
+
poolPrice.poolAddresses![0],
|
|
1691
|
+
tokenA.address,
|
|
1692
|
+
amounts,
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
});
|
|
1697
|
+
|
|
1698
|
+
describe('Curve like stable pool', function () {
|
|
1699
|
+
const TokenASymbol = 'USDbC';
|
|
1700
|
+
const tokenA = Tokens[network][TokenASymbol];
|
|
1701
|
+
const TokenBSymbol = 'USDC';
|
|
1702
|
+
const tokenB = Tokens[network][TokenBSymbol];
|
|
1703
|
+
|
|
1704
|
+
const amounts = amounts6; // amounts6;
|
|
1705
|
+
|
|
1706
|
+
it('getPoolIdentifiers and getPricesVolume', async function () {
|
|
1707
|
+
const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
1708
|
+
const pools = await velocimeter.getPoolIdentifiers(
|
|
1709
|
+
tokenA,
|
|
1710
|
+
tokenB,
|
|
1711
|
+
SwapSide.SELL,
|
|
1712
|
+
blocknumber,
|
|
1713
|
+
);
|
|
1714
|
+
console.log(
|
|
1715
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
|
|
1716
|
+
pools,
|
|
1717
|
+
);
|
|
1718
|
+
|
|
1719
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
1720
|
+
|
|
1721
|
+
const poolPrices = await velocimeter.getPricesVolume(
|
|
1722
|
+
tokenA,
|
|
1723
|
+
tokenB,
|
|
1724
|
+
amounts,
|
|
1725
|
+
SwapSide.SELL,
|
|
1726
|
+
blocknumber,
|
|
1727
|
+
pools,
|
|
1728
|
+
);
|
|
1729
|
+
console.log(
|
|
1730
|
+
`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
|
|
1731
|
+
poolPrices,
|
|
1732
|
+
);
|
|
1733
|
+
|
|
1734
|
+
expect(poolPrices).not.toBeNull();
|
|
1735
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
1736
|
+
|
|
1737
|
+
// Check if onchain pricing equals to calculated ones
|
|
1738
|
+
for (const poolPrice of poolPrices || []) {
|
|
1739
|
+
await checkOnChainPricing(
|
|
1740
|
+
velocimeter,
|
|
1741
|
+
'getAmountOut',
|
|
1742
|
+
blocknumber,
|
|
1743
|
+
poolPrice.prices,
|
|
1744
|
+
poolPrice.poolAddresses![0],
|
|
1745
|
+
tokenA.address,
|
|
1746
|
+
amounts,
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
});
|
|
1751
|
+
});
|
|
1752
|
+
});
|
|
1753
|
+
});
|