@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,328 +1,328 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
DummyDexHelper,
|
|
6
|
-
DummyLimitOrderProvider,
|
|
7
|
-
} from '../../dex-helper/index';
|
|
8
|
-
import { Network, SwapSide } from '../../constants';
|
|
9
|
-
import { BI_POWS } from '../../bigint-constants';
|
|
10
|
-
import { ParaSwapLimitOrders } from './paraswap-limit-orders';
|
|
11
|
-
import {
|
|
12
|
-
checkPoolPrices,
|
|
13
|
-
checkPoolsLiquidity,
|
|
14
|
-
checkConstantPoolPrices,
|
|
15
|
-
} from '../../../tests/utils';
|
|
16
|
-
import { Tokens } from '../../../tests/constants-e2e';
|
|
17
|
-
|
|
18
|
-
const network = Network.MAINNET;
|
|
19
|
-
const TokenASymbol = 'WETH';
|
|
20
|
-
const TokenA = Tokens[network][TokenASymbol];
|
|
21
|
-
|
|
22
|
-
const TokenBSymbol = 'USDC';
|
|
23
|
-
const TokenB = Tokens[network][TokenBSymbol];
|
|
24
|
-
|
|
25
|
-
const amounts = [
|
|
26
|
-
0n,
|
|
27
|
-
1n * BI_POWS[TokenA.decimals],
|
|
28
|
-
2n * BI_POWS[TokenA.decimals],
|
|
29
|
-
3n * BI_POWS[TokenA.decimals],
|
|
30
|
-
4n * BI_POWS[TokenA.decimals],
|
|
31
|
-
5n * BI_POWS[TokenA.decimals],
|
|
32
|
-
6n * BI_POWS[TokenA.decimals],
|
|
33
|
-
7n * BI_POWS[TokenA.decimals],
|
|
34
|
-
75n * BI_POWS[TokenA.decimals - 1],
|
|
35
|
-
8n * BI_POWS[TokenA.decimals],
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const expectedPricesOnSell = [
|
|
39
|
-
0n,
|
|
40
|
-
100000000n,
|
|
41
|
-
197500000n,
|
|
42
|
-
295000000n,
|
|
43
|
-
391000000n,
|
|
44
|
-
487000000n,
|
|
45
|
-
583000000n,
|
|
46
|
-
675000000n,
|
|
47
|
-
722750000n,
|
|
48
|
-
770500000n,
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const amountsBuy = [
|
|
52
|
-
0n,
|
|
53
|
-
100n * BI_POWS[TokenB.decimals],
|
|
54
|
-
200n * BI_POWS[TokenB.decimals],
|
|
55
|
-
300n * BI_POWS[TokenB.decimals],
|
|
56
|
-
400n * BI_POWS[TokenB.decimals],
|
|
57
|
-
500n * BI_POWS[TokenB.decimals],
|
|
58
|
-
600n * BI_POWS[TokenB.decimals],
|
|
59
|
-
700n * BI_POWS[TokenB.decimals],
|
|
60
|
-
825n * BI_POWS[TokenB.decimals],
|
|
61
|
-
950n * BI_POWS[TokenB.decimals],
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const expectedPricesOnBuy = [
|
|
65
|
-
0n,
|
|
66
|
-
1000000000000000000n,
|
|
67
|
-
2025641025641025642n,
|
|
68
|
-
3052083333333333334n,
|
|
69
|
-
4093750000000000000n,
|
|
70
|
-
5135416666666666667n,
|
|
71
|
-
6177083333333333334n,
|
|
72
|
-
7261780104712041885n,
|
|
73
|
-
8570680628272251309n,
|
|
74
|
-
9879581151832460733n,
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
const dexKey = 'ParaSwapLimitOrders';
|
|
78
|
-
|
|
79
|
-
const tokenABKey = DummyLimitOrderProvider.getOrderBookCacheKey(
|
|
80
|
-
network,
|
|
81
|
-
TokenA.address,
|
|
82
|
-
TokenB.address,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const dummyOrderBook = {
|
|
86
|
-
[tokenABKey]: [
|
|
87
|
-
// Orders: Maker = USDC, Taker = WETH
|
|
88
|
-
{
|
|
89
|
-
swappableMakerBalance: (100n * BI_POWS[TokenB.decimals]).toString(),
|
|
90
|
-
swappableTakerBalance: (1n * BI_POWS[TokenA.decimals]).toString(),
|
|
91
|
-
isFillOrKill: false,
|
|
92
|
-
makerAmount: (100n * BI_POWS[TokenB.decimals]).toString(),
|
|
93
|
-
takerAmount: (1n * BI_POWS[TokenA.decimals]).toString(),
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
swappableMakerBalance: (195n * BI_POWS[TokenB.decimals]).toString(),
|
|
97
|
-
swappableTakerBalance: (2n * BI_POWS[TokenA.decimals]).toString(),
|
|
98
|
-
isFillOrKill: false,
|
|
99
|
-
makerAmount: (195n * BI_POWS[TokenB.decimals]).toString(),
|
|
100
|
-
takerAmount: (2n * BI_POWS[TokenA.decimals]).toString(),
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
swappableMakerBalance: (480n * BI_POWS[TokenB.decimals]).toString(),
|
|
104
|
-
swappableTakerBalance: (5n * BI_POWS[TokenA.decimals]).toString(),
|
|
105
|
-
isFillOrKill: false,
|
|
106
|
-
makerAmount: (480n * BI_POWS[TokenB.decimals]).toString(),
|
|
107
|
-
takerAmount: (5n * BI_POWS[TokenA.decimals]).toString(),
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
swappableMakerBalance: (955n * BI_POWS[TokenB.decimals]).toString(),
|
|
111
|
-
swappableTakerBalance: (10n * BI_POWS[TokenA.decimals]).toString(),
|
|
112
|
-
isFillOrKill: false,
|
|
113
|
-
makerAmount: (955n * BI_POWS[TokenB.decimals]).toString(),
|
|
114
|
-
takerAmount: (10n * BI_POWS[TokenA.decimals]).toString(),
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
describe('ParaSwapLimitOrders', function () {
|
|
120
|
-
let dummyLimitOrderProvider: DummyLimitOrderProvider;
|
|
121
|
-
let dexHelper: DummyDexHelper;
|
|
122
|
-
let blockNumber: number;
|
|
123
|
-
let paraSwapLimitOrders: ParaSwapLimitOrders;
|
|
124
|
-
|
|
125
|
-
beforeEach(async () => {
|
|
126
|
-
dexHelper = new DummyDexHelper(network);
|
|
127
|
-
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
128
|
-
paraSwapLimitOrders = new ParaSwapLimitOrders(network, dexKey, dexHelper);
|
|
129
|
-
dummyLimitOrderProvider = new DummyLimitOrderProvider();
|
|
130
|
-
dummyLimitOrderProvider.setOrderBook(
|
|
131
|
-
network,
|
|
132
|
-
TokenA.address,
|
|
133
|
-
TokenB.address,
|
|
134
|
-
dummyOrderBook[tokenABKey],
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
paraSwapLimitOrders.limitOrderProvider = dummyLimitOrderProvider;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('getPoolIdentifiers and getPricesVolume SELL Unswappable amount', async function () {
|
|
141
|
-
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
142
|
-
TokenA,
|
|
143
|
-
TokenB,
|
|
144
|
-
SwapSide.SELL,
|
|
145
|
-
blockNumber,
|
|
146
|
-
);
|
|
147
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
148
|
-
|
|
149
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
150
|
-
|
|
151
|
-
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
152
|
-
TokenA,
|
|
153
|
-
TokenB,
|
|
154
|
-
[0n, 20n * BI_POWS[TokenA.decimals], 260n * BI_POWS[TokenA.decimals]],
|
|
155
|
-
SwapSide.SELL,
|
|
156
|
-
blockNumber,
|
|
157
|
-
pools,
|
|
158
|
-
);
|
|
159
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
160
|
-
|
|
161
|
-
expect(poolPrices![0].prices[1].toString()).toEqual('0');
|
|
162
|
-
expect(poolPrices![0].prices[2].toString()).toEqual('0');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
166
|
-
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
167
|
-
TokenA,
|
|
168
|
-
TokenB,
|
|
169
|
-
SwapSide.SELL,
|
|
170
|
-
blockNumber,
|
|
171
|
-
);
|
|
172
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
173
|
-
|
|
174
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
175
|
-
|
|
176
|
-
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
177
|
-
TokenA,
|
|
178
|
-
TokenB,
|
|
179
|
-
amounts,
|
|
180
|
-
SwapSide.SELL,
|
|
181
|
-
blockNumber,
|
|
182
|
-
pools,
|
|
183
|
-
);
|
|
184
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
185
|
-
|
|
186
|
-
expect(poolPrices).not.toBeNull();
|
|
187
|
-
if (paraSwapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
188
|
-
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
189
|
-
} else {
|
|
190
|
-
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Check pricing values
|
|
194
|
-
for (let i = 0; i < expectedPricesOnSell.length; i++) {
|
|
195
|
-
expect(poolPrices![0].prices[i].toString()).toEqual(
|
|
196
|
-
expectedPricesOnSell[i].toString(),
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
it('getPoolIdentifiers and getPricesVolume BUY Unswappable amount', async function () {
|
|
201
|
-
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
202
|
-
TokenA,
|
|
203
|
-
TokenB,
|
|
204
|
-
SwapSide.BUY,
|
|
205
|
-
blockNumber,
|
|
206
|
-
);
|
|
207
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
208
|
-
|
|
209
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
210
|
-
|
|
211
|
-
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
212
|
-
TokenA,
|
|
213
|
-
TokenB,
|
|
214
|
-
[
|
|
215
|
-
0n,
|
|
216
|
-
1700n * BI_POWS[TokenB.decimals],
|
|
217
|
-
2000000n * BI_POWS[TokenB.decimals],
|
|
218
|
-
],
|
|
219
|
-
SwapSide.BUY,
|
|
220
|
-
blockNumber,
|
|
221
|
-
pools,
|
|
222
|
-
);
|
|
223
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
224
|
-
|
|
225
|
-
expect(poolPrices![0].prices[1].toString()).toEqual('0');
|
|
226
|
-
expect(poolPrices![0].prices[2].toString()).toEqual('0');
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
230
|
-
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
231
|
-
TokenA,
|
|
232
|
-
TokenB,
|
|
233
|
-
SwapSide.BUY,
|
|
234
|
-
blockNumber,
|
|
235
|
-
);
|
|
236
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
237
|
-
|
|
238
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
239
|
-
|
|
240
|
-
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
241
|
-
TokenA,
|
|
242
|
-
TokenB,
|
|
243
|
-
amountsBuy,
|
|
244
|
-
SwapSide.BUY,
|
|
245
|
-
blockNumber,
|
|
246
|
-
pools,
|
|
247
|
-
);
|
|
248
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
249
|
-
|
|
250
|
-
expect(poolPrices).not.toBeNull();
|
|
251
|
-
if (paraSwapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
252
|
-
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
253
|
-
} else {
|
|
254
|
-
checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
for (let i = 0; i < expectedPricesOnBuy.length; i++) {
|
|
258
|
-
expect(poolPrices![0].prices[i].toString()).toEqual(
|
|
259
|
-
expectedPricesOnBuy[i].toString(),
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('getPoolIdentifiers and getPricesVolume if not enough orders to fill unit', async function () {
|
|
265
|
-
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
266
|
-
TokenA,
|
|
267
|
-
TokenB,
|
|
268
|
-
SwapSide.SELL,
|
|
269
|
-
blockNumber,
|
|
270
|
-
);
|
|
271
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
272
|
-
|
|
273
|
-
expect(pools.length).toBeGreaterThan(0);
|
|
274
|
-
|
|
275
|
-
const orderBookWithoutUnit = [
|
|
276
|
-
{
|
|
277
|
-
swappableMakerBalance: (5n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
278
|
-
swappableTakerBalance: (1n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
279
|
-
makerAmount: (5n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
280
|
-
takerAmount: (1n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
281
|
-
isFillOrKill: false,
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
swappableMakerBalance: (7n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
285
|
-
swappableTakerBalance: (2n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
286
|
-
makerAmount: (7n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
287
|
-
takerAmount: (2n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
288
|
-
isFillOrKill: false,
|
|
289
|
-
},
|
|
290
|
-
];
|
|
291
|
-
|
|
292
|
-
dummyLimitOrderProvider.setOrderBook(
|
|
293
|
-
network,
|
|
294
|
-
TokenA.address,
|
|
295
|
-
TokenB.address,
|
|
296
|
-
orderBookWithoutUnit,
|
|
297
|
-
);
|
|
298
|
-
paraSwapLimitOrders.limitOrderProvider = dummyLimitOrderProvider;
|
|
299
|
-
const _amountsToCheck = [0n, 3n * BI_POWS[TokenA.decimals - 1]];
|
|
300
|
-
|
|
301
|
-
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
302
|
-
TokenA,
|
|
303
|
-
TokenB,
|
|
304
|
-
_amountsToCheck,
|
|
305
|
-
SwapSide.SELL,
|
|
306
|
-
blockNumber,
|
|
307
|
-
pools,
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
311
|
-
|
|
312
|
-
checkPoolPrices(poolPrices!, _amountsToCheck, SwapSide.SELL, dexKey);
|
|
313
|
-
|
|
314
|
-
expect(poolPrices![0].unit.toString()).toEqual('4000000');
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('getTopPoolsForToken', async function () {
|
|
318
|
-
// TODO: Add getTopPools when we support it
|
|
319
|
-
// const poolLiquidity = await paraswapLimitOrders.getTopPoolsForToken(
|
|
320
|
-
// TokenA.address,
|
|
321
|
-
// 10,
|
|
322
|
-
// );
|
|
323
|
-
// console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
324
|
-
// if (!paraswapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
325
|
-
// checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
|
|
326
|
-
// }
|
|
327
|
-
});
|
|
328
|
-
});
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DummyDexHelper,
|
|
6
|
+
DummyLimitOrderProvider,
|
|
7
|
+
} from '../../dex-helper/index';
|
|
8
|
+
import { Network, SwapSide } from '../../constants';
|
|
9
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
10
|
+
import { ParaSwapLimitOrders } from './paraswap-limit-orders';
|
|
11
|
+
import {
|
|
12
|
+
checkPoolPrices,
|
|
13
|
+
checkPoolsLiquidity,
|
|
14
|
+
checkConstantPoolPrices,
|
|
15
|
+
} from '../../../tests/utils';
|
|
16
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
17
|
+
|
|
18
|
+
const network = Network.MAINNET;
|
|
19
|
+
const TokenASymbol = 'WETH';
|
|
20
|
+
const TokenA = Tokens[network][TokenASymbol];
|
|
21
|
+
|
|
22
|
+
const TokenBSymbol = 'USDC';
|
|
23
|
+
const TokenB = Tokens[network][TokenBSymbol];
|
|
24
|
+
|
|
25
|
+
const amounts = [
|
|
26
|
+
0n,
|
|
27
|
+
1n * BI_POWS[TokenA.decimals],
|
|
28
|
+
2n * BI_POWS[TokenA.decimals],
|
|
29
|
+
3n * BI_POWS[TokenA.decimals],
|
|
30
|
+
4n * BI_POWS[TokenA.decimals],
|
|
31
|
+
5n * BI_POWS[TokenA.decimals],
|
|
32
|
+
6n * BI_POWS[TokenA.decimals],
|
|
33
|
+
7n * BI_POWS[TokenA.decimals],
|
|
34
|
+
75n * BI_POWS[TokenA.decimals - 1],
|
|
35
|
+
8n * BI_POWS[TokenA.decimals],
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const expectedPricesOnSell = [
|
|
39
|
+
0n,
|
|
40
|
+
100000000n,
|
|
41
|
+
197500000n,
|
|
42
|
+
295000000n,
|
|
43
|
+
391000000n,
|
|
44
|
+
487000000n,
|
|
45
|
+
583000000n,
|
|
46
|
+
675000000n,
|
|
47
|
+
722750000n,
|
|
48
|
+
770500000n,
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const amountsBuy = [
|
|
52
|
+
0n,
|
|
53
|
+
100n * BI_POWS[TokenB.decimals],
|
|
54
|
+
200n * BI_POWS[TokenB.decimals],
|
|
55
|
+
300n * BI_POWS[TokenB.decimals],
|
|
56
|
+
400n * BI_POWS[TokenB.decimals],
|
|
57
|
+
500n * BI_POWS[TokenB.decimals],
|
|
58
|
+
600n * BI_POWS[TokenB.decimals],
|
|
59
|
+
700n * BI_POWS[TokenB.decimals],
|
|
60
|
+
825n * BI_POWS[TokenB.decimals],
|
|
61
|
+
950n * BI_POWS[TokenB.decimals],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const expectedPricesOnBuy = [
|
|
65
|
+
0n,
|
|
66
|
+
1000000000000000000n,
|
|
67
|
+
2025641025641025642n,
|
|
68
|
+
3052083333333333334n,
|
|
69
|
+
4093750000000000000n,
|
|
70
|
+
5135416666666666667n,
|
|
71
|
+
6177083333333333334n,
|
|
72
|
+
7261780104712041885n,
|
|
73
|
+
8570680628272251309n,
|
|
74
|
+
9879581151832460733n,
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const dexKey = 'ParaSwapLimitOrders';
|
|
78
|
+
|
|
79
|
+
const tokenABKey = DummyLimitOrderProvider.getOrderBookCacheKey(
|
|
80
|
+
network,
|
|
81
|
+
TokenA.address,
|
|
82
|
+
TokenB.address,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const dummyOrderBook = {
|
|
86
|
+
[tokenABKey]: [
|
|
87
|
+
// Orders: Maker = USDC, Taker = WETH
|
|
88
|
+
{
|
|
89
|
+
swappableMakerBalance: (100n * BI_POWS[TokenB.decimals]).toString(),
|
|
90
|
+
swappableTakerBalance: (1n * BI_POWS[TokenA.decimals]).toString(),
|
|
91
|
+
isFillOrKill: false,
|
|
92
|
+
makerAmount: (100n * BI_POWS[TokenB.decimals]).toString(),
|
|
93
|
+
takerAmount: (1n * BI_POWS[TokenA.decimals]).toString(),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
swappableMakerBalance: (195n * BI_POWS[TokenB.decimals]).toString(),
|
|
97
|
+
swappableTakerBalance: (2n * BI_POWS[TokenA.decimals]).toString(),
|
|
98
|
+
isFillOrKill: false,
|
|
99
|
+
makerAmount: (195n * BI_POWS[TokenB.decimals]).toString(),
|
|
100
|
+
takerAmount: (2n * BI_POWS[TokenA.decimals]).toString(),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
swappableMakerBalance: (480n * BI_POWS[TokenB.decimals]).toString(),
|
|
104
|
+
swappableTakerBalance: (5n * BI_POWS[TokenA.decimals]).toString(),
|
|
105
|
+
isFillOrKill: false,
|
|
106
|
+
makerAmount: (480n * BI_POWS[TokenB.decimals]).toString(),
|
|
107
|
+
takerAmount: (5n * BI_POWS[TokenA.decimals]).toString(),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
swappableMakerBalance: (955n * BI_POWS[TokenB.decimals]).toString(),
|
|
111
|
+
swappableTakerBalance: (10n * BI_POWS[TokenA.decimals]).toString(),
|
|
112
|
+
isFillOrKill: false,
|
|
113
|
+
makerAmount: (955n * BI_POWS[TokenB.decimals]).toString(),
|
|
114
|
+
takerAmount: (10n * BI_POWS[TokenA.decimals]).toString(),
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
describe('ParaSwapLimitOrders', function () {
|
|
120
|
+
let dummyLimitOrderProvider: DummyLimitOrderProvider;
|
|
121
|
+
let dexHelper: DummyDexHelper;
|
|
122
|
+
let blockNumber: number;
|
|
123
|
+
let paraSwapLimitOrders: ParaSwapLimitOrders;
|
|
124
|
+
|
|
125
|
+
beforeEach(async () => {
|
|
126
|
+
dexHelper = new DummyDexHelper(network);
|
|
127
|
+
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
128
|
+
paraSwapLimitOrders = new ParaSwapLimitOrders(network, dexKey, dexHelper);
|
|
129
|
+
dummyLimitOrderProvider = new DummyLimitOrderProvider();
|
|
130
|
+
dummyLimitOrderProvider.setOrderBook(
|
|
131
|
+
network,
|
|
132
|
+
TokenA.address,
|
|
133
|
+
TokenB.address,
|
|
134
|
+
dummyOrderBook[tokenABKey],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
paraSwapLimitOrders.limitOrderProvider = dummyLimitOrderProvider;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('getPoolIdentifiers and getPricesVolume SELL Unswappable amount', async function () {
|
|
141
|
+
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
142
|
+
TokenA,
|
|
143
|
+
TokenB,
|
|
144
|
+
SwapSide.SELL,
|
|
145
|
+
blockNumber,
|
|
146
|
+
);
|
|
147
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
148
|
+
|
|
149
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
150
|
+
|
|
151
|
+
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
152
|
+
TokenA,
|
|
153
|
+
TokenB,
|
|
154
|
+
[0n, 20n * BI_POWS[TokenA.decimals], 260n * BI_POWS[TokenA.decimals]],
|
|
155
|
+
SwapSide.SELL,
|
|
156
|
+
blockNumber,
|
|
157
|
+
pools,
|
|
158
|
+
);
|
|
159
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
160
|
+
|
|
161
|
+
expect(poolPrices![0].prices[1].toString()).toEqual('0');
|
|
162
|
+
expect(poolPrices![0].prices[2].toString()).toEqual('0');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
166
|
+
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
167
|
+
TokenA,
|
|
168
|
+
TokenB,
|
|
169
|
+
SwapSide.SELL,
|
|
170
|
+
blockNumber,
|
|
171
|
+
);
|
|
172
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
173
|
+
|
|
174
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
175
|
+
|
|
176
|
+
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
177
|
+
TokenA,
|
|
178
|
+
TokenB,
|
|
179
|
+
amounts,
|
|
180
|
+
SwapSide.SELL,
|
|
181
|
+
blockNumber,
|
|
182
|
+
pools,
|
|
183
|
+
);
|
|
184
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
185
|
+
|
|
186
|
+
expect(poolPrices).not.toBeNull();
|
|
187
|
+
if (paraSwapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
188
|
+
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
189
|
+
} else {
|
|
190
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Check pricing values
|
|
194
|
+
for (let i = 0; i < expectedPricesOnSell.length; i++) {
|
|
195
|
+
expect(poolPrices![0].prices[i].toString()).toEqual(
|
|
196
|
+
expectedPricesOnSell[i].toString(),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
it('getPoolIdentifiers and getPricesVolume BUY Unswappable amount', async function () {
|
|
201
|
+
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
202
|
+
TokenA,
|
|
203
|
+
TokenB,
|
|
204
|
+
SwapSide.BUY,
|
|
205
|
+
blockNumber,
|
|
206
|
+
);
|
|
207
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
208
|
+
|
|
209
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
210
|
+
|
|
211
|
+
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
212
|
+
TokenA,
|
|
213
|
+
TokenB,
|
|
214
|
+
[
|
|
215
|
+
0n,
|
|
216
|
+
1700n * BI_POWS[TokenB.decimals],
|
|
217
|
+
2000000n * BI_POWS[TokenB.decimals],
|
|
218
|
+
],
|
|
219
|
+
SwapSide.BUY,
|
|
220
|
+
blockNumber,
|
|
221
|
+
pools,
|
|
222
|
+
);
|
|
223
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
224
|
+
|
|
225
|
+
expect(poolPrices![0].prices[1].toString()).toEqual('0');
|
|
226
|
+
expect(poolPrices![0].prices[2].toString()).toEqual('0');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
230
|
+
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
231
|
+
TokenA,
|
|
232
|
+
TokenB,
|
|
233
|
+
SwapSide.BUY,
|
|
234
|
+
blockNumber,
|
|
235
|
+
);
|
|
236
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
237
|
+
|
|
238
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
239
|
+
|
|
240
|
+
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
241
|
+
TokenA,
|
|
242
|
+
TokenB,
|
|
243
|
+
amountsBuy,
|
|
244
|
+
SwapSide.BUY,
|
|
245
|
+
blockNumber,
|
|
246
|
+
pools,
|
|
247
|
+
);
|
|
248
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
249
|
+
|
|
250
|
+
expect(poolPrices).not.toBeNull();
|
|
251
|
+
if (paraSwapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
252
|
+
checkConstantPoolPrices(poolPrices!, amounts, dexKey);
|
|
253
|
+
} else {
|
|
254
|
+
checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
for (let i = 0; i < expectedPricesOnBuy.length; i++) {
|
|
258
|
+
expect(poolPrices![0].prices[i].toString()).toEqual(
|
|
259
|
+
expectedPricesOnBuy[i].toString(),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('getPoolIdentifiers and getPricesVolume if not enough orders to fill unit', async function () {
|
|
265
|
+
const pools = await paraSwapLimitOrders.getPoolIdentifiers(
|
|
266
|
+
TokenA,
|
|
267
|
+
TokenB,
|
|
268
|
+
SwapSide.SELL,
|
|
269
|
+
blockNumber,
|
|
270
|
+
);
|
|
271
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
272
|
+
|
|
273
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
274
|
+
|
|
275
|
+
const orderBookWithoutUnit = [
|
|
276
|
+
{
|
|
277
|
+
swappableMakerBalance: (5n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
278
|
+
swappableTakerBalance: (1n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
279
|
+
makerAmount: (5n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
280
|
+
takerAmount: (1n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
281
|
+
isFillOrKill: false,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
swappableMakerBalance: (7n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
285
|
+
swappableTakerBalance: (2n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
286
|
+
makerAmount: (7n * BI_POWS[TokenB.decimals - 1]).toString(),
|
|
287
|
+
takerAmount: (2n * BI_POWS[TokenA.decimals - 1]).toString(),
|
|
288
|
+
isFillOrKill: false,
|
|
289
|
+
},
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
dummyLimitOrderProvider.setOrderBook(
|
|
293
|
+
network,
|
|
294
|
+
TokenA.address,
|
|
295
|
+
TokenB.address,
|
|
296
|
+
orderBookWithoutUnit,
|
|
297
|
+
);
|
|
298
|
+
paraSwapLimitOrders.limitOrderProvider = dummyLimitOrderProvider;
|
|
299
|
+
const _amountsToCheck = [0n, 3n * BI_POWS[TokenA.decimals - 1]];
|
|
300
|
+
|
|
301
|
+
const poolPrices = await paraSwapLimitOrders.getPricesVolume(
|
|
302
|
+
TokenA,
|
|
303
|
+
TokenB,
|
|
304
|
+
_amountsToCheck,
|
|
305
|
+
SwapSide.SELL,
|
|
306
|
+
blockNumber,
|
|
307
|
+
pools,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
311
|
+
|
|
312
|
+
checkPoolPrices(poolPrices!, _amountsToCheck, SwapSide.SELL, dexKey);
|
|
313
|
+
|
|
314
|
+
expect(poolPrices![0].unit.toString()).toEqual('4000000');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('getTopPoolsForToken', async function () {
|
|
318
|
+
// TODO: Add getTopPools when we support it
|
|
319
|
+
// const poolLiquidity = await paraswapLimitOrders.getTopPoolsForToken(
|
|
320
|
+
// TokenA.address,
|
|
321
|
+
// 10,
|
|
322
|
+
// );
|
|
323
|
+
// console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
324
|
+
// if (!paraswapLimitOrders.hasConstantPriceLargeAmounts) {
|
|
325
|
+
// checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
|
|
326
|
+
// }
|
|
327
|
+
});
|
|
328
|
+
});
|