@paraswap/dex-lib 3.6.2 → 3.6.3

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.
Files changed (109) hide show
  1. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  2. package/build/dex/aave-v1/aave-v1.js +0 -23
  3. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  4. package/build/dex/compound.js +1 -1
  5. package/build/dex/compound.js.map +1 -1
  6. package/build/dex/etherfi/etherfi.d.ts +26 -0
  7. package/build/dex/etherfi/etherfi.js +96 -0
  8. package/build/dex/etherfi/etherfi.js.map +1 -0
  9. package/build/dex/index.js +2 -0
  10. package/build/dex/index.js.map +1 -1
  11. package/build/dex/maverick-v2/config.d.ts +2 -2
  12. package/build/dex/maverick-v2/config.js +16 -9
  13. package/build/dex/maverick-v2/config.js.map +1 -1
  14. package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js +3 -3
  15. package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js.map +1 -1
  16. package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js +4 -4
  17. package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js.map +1 -1
  18. package/build/dex/maverick-v2/maverick-math/maverick-math.js +3 -3
  19. package/build/dex/maverick-v2/maverick-math/maverick-math.js.map +1 -1
  20. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +13 -13
  21. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -1
  22. package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js +1 -1
  23. package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js.map +1 -1
  24. package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js +4 -4
  25. package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js.map +1 -1
  26. package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js +3 -3
  27. package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js.map +1 -1
  28. package/build/dex/maverick-v2/maverick-v2-pool.d.ts +12 -9
  29. package/build/dex/maverick-v2/maverick-v2-pool.js +71 -16
  30. package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -1
  31. package/build/dex/maverick-v2/maverick-v2.d.ts +4 -8
  32. package/build/dex/maverick-v2/maverick-v2.js +62 -90
  33. package/build/dex/maverick-v2/maverick-v2.js.map +1 -1
  34. package/build/dex/maverick-v2/types.d.ts +1 -2
  35. package/build/dex/platypus/platypus.d.ts +1 -2
  36. package/build/dex/platypus/platypus.js +0 -45
  37. package/build/dex/platypus/platypus.js.map +1 -1
  38. package/build/dex/sdai/config.d.ts +11 -0
  39. package/build/dex/sdai/config.js +21 -0
  40. package/build/dex/sdai/config.js.map +1 -0
  41. package/build/dex/sdai/constants.d.ts +2 -0
  42. package/build/dex/sdai/constants.js +6 -0
  43. package/build/dex/sdai/constants.js.map +1 -0
  44. package/build/dex/sdai/scripts/validate-state.js +102 -0
  45. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  46. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  47. package/build/dex/sdai/sdai-pool.js +85 -0
  48. package/build/dex/sdai/sdai-pool.js.map +1 -0
  49. package/build/dex/sdai/sdai.d.ts +51 -0
  50. package/build/dex/sdai/sdai.js +172 -0
  51. package/build/dex/sdai/sdai.js.map +1 -0
  52. package/build/dex/sdai/types.d.ts +21 -0
  53. package/build/dex/sdai/types.js +11 -0
  54. package/build/dex/sdai/types.js.map +1 -0
  55. package/build/dex/sdai/utils.d.ts +4 -0
  56. package/build/dex/sdai/utils.js +39 -0
  57. package/build/dex/sdai/utils.js.map +1 -0
  58. package/build/dex/stable-pool.js +8 -1
  59. package/build/dex/stable-pool.js.map +1 -1
  60. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  61. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  62. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/abi/maverick-v2/MaverickV2Pool.json +1234 -0
  65. package/src/abi/maverick-v2/MaverickV2PoolLens.json +1232 -0
  66. package/src/abi/maverick-v2/MaverickV2Quoter.json +278 -0
  67. package/src/dex/index.ts +2 -0
  68. package/src/dex/maverick-v2/config.ts +28 -0
  69. package/src/dex/maverick-v2/maverick-math/maverick-basic-math.ts +152 -0
  70. package/src/dex/maverick-v2/maverick-math/maverick-bin-math.ts +288 -0
  71. package/src/dex/maverick-v2/maverick-math/maverick-delta-math.ts +32 -0
  72. package/src/dex/maverick-v2/maverick-math/maverick-math.ts +30 -0
  73. package/src/dex/maverick-v2/maverick-math/maverick-pool-lib.ts +42 -0
  74. package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +709 -0
  75. package/src/dex/maverick-v2/maverick-math/maverick-swap-math.ts +199 -0
  76. package/src/dex/maverick-v2/maverick-math/maverick-tick-math.ts +171 -0
  77. package/src/dex/maverick-v2/maverick-math/maverick-twa-math.ts +54 -0
  78. package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +193 -0
  79. package/src/dex/maverick-v2/maverick-v2-events.test.ts +112 -0
  80. package/src/dex/maverick-v2/maverick-v2-integration.test.ts +283 -0
  81. package/src/dex/maverick-v2/maverick-v2-pool.ts +346 -0
  82. package/src/dex/maverick-v2/maverick-v2.ts +380 -0
  83. package/src/dex/maverick-v2/types.ts +151 -0
  84. package/tests/constants-e2e.ts +2 -2
  85. package/.vscode/launch.json +0 -53
  86. package/.vscode/settings.json +0 -2
  87. package/.vscode/tasks.json +0 -15
  88. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  89. package/build/abi/wombat/pool.json +0 -1289
  90. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  91. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  92. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  93. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  94. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  95. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  96. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  97. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  98. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  99. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  100. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  101. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  102. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  103. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  104. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  105. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  106. package/src/dex/maker-psm/scripts/gem.abi.json +0 -136
  107. package/src/dex/maker-psm/scripts/validate-state.ts +0 -221
  108. package/src/dex/maker-psm/scripts/vat.abi.json +0 -243
  109. /package/build/dex/{solidly-v3/scripts/check-event-pool-event.d.ts → sdai/scripts/validate-state.d.ts} +0 -0
@@ -0,0 +1,112 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { MaverickV2EventPool } from './maverick-v2-pool';
6
+ import { Network } from '../../constants';
7
+ import { Address } from '../../types';
8
+ import { DummyDexHelper } from '../../dex-helper/index';
9
+ import { testEventSubscriber } from '../../../tests/utils-events';
10
+ import { PoolState } from './types';
11
+ import { Tokens } from '../../../tests/constants-e2e';
12
+
13
+ jest.setTimeout(50 * 1000);
14
+
15
+ async function fetchPoolState(
16
+ maverickV2Pool: MaverickV2EventPool,
17
+ blockNumber: number,
18
+ poolAddress: string,
19
+ ): Promise<PoolState> {
20
+ return maverickV2Pool.generateState(blockNumber);
21
+ }
22
+
23
+ // eventName -> blockNumbers
24
+ type EventMappings = Record<string, number[]>;
25
+
26
+ describe('MaverickV2 EventPool Mainnet', function () {
27
+ const dexKey = 'MaverickV2';
28
+ const network = Network.BASE;
29
+ const tokens = Tokens[network];
30
+ const dexHelper = new DummyDexHelper(network);
31
+ const logger = dexHelper.getLogger(dexKey);
32
+ let maverickV2Pool: MaverickV2EventPool;
33
+
34
+ // poolAddress -> EventMappings
35
+ const eventsToTest: Record<Address, EventMappings> = {
36
+ '0xe789204A908Fc586743f7b8acbEE9194E5e2Ea73': {
37
+ Swap: [
38
+ 14716574, 14845131, 14845133, 14845136, 14845138, 14845141, 14845144,
39
+ 14845146, 14845149, 14845151, 14845154, 14845206, 14845209, 14845212,
40
+ 14845215, 14845217, 14845220, 14845223, 14845225, 14845228, 14845231,
41
+ 14845274, 14845277, 14845279, 14845282, 14845285, 14845287, 14845290,
42
+ 14845293, 14845295, 14845298, 14845301, 14845362, 14845364, 14845367,
43
+ 14845370, 14845373, 14845375, 14845378, 14845381, 14845383, 14845386,
44
+ 14845389, 14845413, 14845416, 14845419, 14845421, 14845424, 14845427,
45
+ 14845429, 14845432, 14845435, 14845437, 14845440,
46
+ ],
47
+ AddLiquidity: [
48
+ 14762449, 14845350, 14845402, 14845120, 14845195, 14718361, 14845262,
49
+ 14716574,
50
+ ],
51
+ RemoveLiquidity: [14845359, 14845203, 14845128, 14845410, 14845271],
52
+ },
53
+ };
54
+
55
+ const pools: any = {
56
+ '0xe789204A908Fc586743f7b8acbEE9194E5e2Ea73': {
57
+ tokenA: tokens.DAI,
58
+ tokenB: tokens.USDC,
59
+ feeA: 1000000000000,
60
+ feeB: 1000000000000,
61
+ tickSpacing: 8,
62
+ protocolFee: 0,
63
+ lookback: 360000,
64
+ activeTick: 0,
65
+ },
66
+ };
67
+
68
+ Object.entries(eventsToTest).forEach(
69
+ ([poolAddress, events]: [string, EventMappings]) => {
70
+ describe(`Events for ${poolAddress}`, () => {
71
+ beforeEach(() => {
72
+ let pool = pools[poolAddress];
73
+ maverickV2Pool = new MaverickV2EventPool(
74
+ dexKey,
75
+ network,
76
+ dexHelper,
77
+ logger,
78
+ pool.tokenA,
79
+ pool.tokenB,
80
+ pool.feeA,
81
+ pool.feeB,
82
+ pool.tickSpacing,
83
+ pool.protocolFee,
84
+ pool.lookback,
85
+ pool.activeTick,
86
+ poolAddress,
87
+ '0x8cf8d1159d8381433556974238c34EB7599321c4',
88
+ );
89
+ });
90
+ Object.entries(events).forEach(
91
+ ([eventName, blockNumbers]: [string, number[]]) => {
92
+ describe(`${eventName}`, () => {
93
+ blockNumbers.forEach((blockNumber: number) => {
94
+ it(`State after ${blockNumber}`, async function () {
95
+ await testEventSubscriber(
96
+ maverickV2Pool,
97
+ maverickV2Pool.addressesSubscribed,
98
+ (_blockNumber: number) =>
99
+ fetchPoolState(maverickV2Pool, _blockNumber, poolAddress),
100
+ blockNumber,
101
+ `${dexKey}_${poolAddress}`,
102
+ dexHelper.provider,
103
+ );
104
+ });
105
+ });
106
+ });
107
+ },
108
+ );
109
+ });
110
+ },
111
+ );
112
+ });
@@ -0,0 +1,283 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { Interface, Result } from '@ethersproject/abi';
6
+ import { DummyDexHelper } from '../../dex-helper/index';
7
+ import { Network, SwapSide } from '../../constants';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { MaverickV2 } from './maverick-v2';
10
+ import {
11
+ checkPoolPrices,
12
+ checkPoolsLiquidity,
13
+ checkConstantPoolPrices,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+ import { MaverickV2Data } from './types';
17
+ import { ExchangePrices, PoolPrices } from '../../types';
18
+ import MaverickV2QuoterABI from '../../abi/maverick-v2/MaverickV2Quoter.json';
19
+ import { MaverickV2Config } from './config';
20
+ import { AbiItem } from 'web3-utils';
21
+
22
+ /*
23
+ README
24
+ ======
25
+
26
+ This test script adds tests for MaverickV2 general integration
27
+ with the DEX interface. The test cases below are example tests.
28
+ It is recommended to add tests which cover MaverickV2 specific
29
+ logic.
30
+
31
+ You can run this individual test script by running:
32
+ `npx jest src/dex/<dex-name>/<dex-name>-integration.test.ts`
33
+
34
+ (This comment should be removed from the final implementation)
35
+ */
36
+
37
+ const network = Network.BASE;
38
+ const dexKey = 'MaverickV2';
39
+ const dexHelper = new DummyDexHelper(network);
40
+
41
+ function calculateSwap(
42
+ network: Network,
43
+ pool: PoolPrices<MaverickV2Data>,
44
+ blockNumber: number,
45
+ poolAddress: string,
46
+ srcToken: string,
47
+ side: SwapSide,
48
+ amount: bigint,
49
+ ) {
50
+ srcToken = dexHelper.config.wrapETH(srcToken);
51
+
52
+ let quoterContract = new dexHelper.web3Provider.eth.Contract(
53
+ MaverickV2QuoterABI as AbiItem[],
54
+ MaverickV2Config[dexKey][network].quoterAddress,
55
+ );
56
+
57
+ return new Promise((resolve, reject) => {
58
+ quoterContract.methods
59
+ .calculateSwap(
60
+ poolAddress,
61
+ amount,
62
+ pool.data.tokenA.toLowerCase() === srcToken.toLowerCase(),
63
+ side === SwapSide.BUY,
64
+ pool.data.tokenA.toLowerCase() === srcToken.toLowerCase()
65
+ ? 1000000n
66
+ : -1000000n,
67
+ )
68
+ .call({}, blockNumber, (err: any, result: any) => {
69
+ if (err) {
70
+ console.log({
71
+ pool,
72
+ blockNumber,
73
+ poolAddress,
74
+ srcToken,
75
+ side,
76
+ amount,
77
+ });
78
+ reject(err);
79
+ } else {
80
+ resolve(result);
81
+ }
82
+ });
83
+ });
84
+ }
85
+
86
+ async function checkOnChainPricing(
87
+ maverickV2: MaverickV2,
88
+ funcName: string,
89
+ blockNumber: number,
90
+ pools: ExchangePrices<MaverickV2Data>,
91
+ amounts: bigint[],
92
+ side: SwapSide,
93
+ srcToken: string,
94
+ ) {
95
+ await Promise.all(
96
+ pools.map(async pool => {
97
+ const poolAddress = pool.data.pool;
98
+ const calls = amounts.slice(1).map(amount => {
99
+ return calculateSwap(
100
+ network,
101
+ pool,
102
+ blockNumber,
103
+ poolAddress,
104
+ srcToken,
105
+ side,
106
+ amount,
107
+ );
108
+ });
109
+
110
+ const results = await Promise.all(calls);
111
+
112
+ const expectedPrices = [0n].concat(
113
+ results.map((result: any) => {
114
+ if (!result) return BigInt(0);
115
+
116
+ return BigInt(
117
+ side === SwapSide.SELL ? result.amountOut : result.amountIn,
118
+ );
119
+ }),
120
+ );
121
+
122
+ expect(pool.prices).toEqual(expectedPrices);
123
+ }),
124
+ );
125
+ }
126
+
127
+ async function testPricingOnNetwork(
128
+ maverickV2: MaverickV2,
129
+ network: Network,
130
+ dexKey: string,
131
+ blockNumber: number,
132
+ srcTokenSymbol: string,
133
+ destTokenSymbol: string,
134
+ side: SwapSide,
135
+ amounts: bigint[],
136
+ funcNameToCheck: string,
137
+ ) {
138
+ const networkTokens = Tokens[network];
139
+ const pools = await maverickV2.getPoolIdentifiers(
140
+ networkTokens[srcTokenSymbol],
141
+ networkTokens[destTokenSymbol],
142
+ side,
143
+ blockNumber,
144
+ );
145
+ console.log(
146
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
147
+ pools,
148
+ );
149
+
150
+ expect(pools.length).toBeGreaterThan(0);
151
+
152
+ const poolPrices = await maverickV2.getPricesVolume(
153
+ networkTokens[srcTokenSymbol],
154
+ networkTokens[destTokenSymbol],
155
+ amounts,
156
+ side,
157
+ blockNumber,
158
+ pools,
159
+ );
160
+ console.log(
161
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
162
+ poolPrices,
163
+ );
164
+
165
+ expect(poolPrices).not.toBeNull();
166
+ if (maverickV2.hasConstantPriceLargeAmounts) {
167
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
168
+ } else {
169
+ checkPoolPrices(poolPrices!, amounts, side, dexKey);
170
+ }
171
+
172
+ // Check if onchain pricing equals to calculated ones
173
+ await checkOnChainPricing(
174
+ maverickV2,
175
+ funcNameToCheck,
176
+ blockNumber,
177
+ poolPrices!,
178
+ amounts,
179
+ side,
180
+ Tokens[network][srcTokenSymbol].address,
181
+ );
182
+ }
183
+
184
+ describe('MaverickV2', function () {
185
+ const dexKey = 'MaverickV2';
186
+ let blockNumber: number;
187
+ let maverickV2: MaverickV2;
188
+ const network = Network.BASE;
189
+
190
+ describe(network, () => {
191
+ const dexHelper = new DummyDexHelper(network);
192
+
193
+ const tokens = Tokens[network];
194
+
195
+ const srcTokenSymbol = 'ETH';
196
+ const destTokenSymbol = 'USDC';
197
+
198
+ const srcDecimals = tokens[srcTokenSymbol].decimals;
199
+ const destDecimals = tokens[destTokenSymbol].decimals;
200
+
201
+ const amountsForSell = [
202
+ 0n,
203
+ 1n * BI_POWS[srcDecimals],
204
+ 2n * BI_POWS[srcDecimals],
205
+ 3n * BI_POWS[srcDecimals],
206
+ 4n * BI_POWS[srcDecimals],
207
+ 5n * BI_POWS[srcDecimals],
208
+ 6n * BI_POWS[srcDecimals],
209
+ 7n * BI_POWS[srcDecimals],
210
+ 8n * BI_POWS[srcDecimals],
211
+ // 9n * BI_POWS[srcDecimals],
212
+ // 10n * BI_POWS[srcDecimals],
213
+ ];
214
+
215
+ const amountsForBuy = [
216
+ 0n,
217
+ 1n * BI_POWS[destDecimals],
218
+ 2n * BI_POWS[destDecimals],
219
+ 3n * BI_POWS[destDecimals],
220
+ 4n * BI_POWS[destDecimals],
221
+ 5n * BI_POWS[destDecimals],
222
+ 6n * BI_POWS[destDecimals],
223
+ 7n * BI_POWS[destDecimals],
224
+ 8n * BI_POWS[destDecimals],
225
+ // 9n * BI_POWS[destDecimals],
226
+ // 10n * BI_POWS[destDecimals],
227
+ ];
228
+
229
+ beforeAll(async () => {
230
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
231
+ maverickV2 = new MaverickV2(network, dexKey, dexHelper);
232
+ await maverickV2.initializePricing(blockNumber);
233
+ });
234
+
235
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
236
+ await testPricingOnNetwork(
237
+ maverickV2,
238
+ network,
239
+ dexKey,
240
+ blockNumber,
241
+ srcTokenSymbol,
242
+ destTokenSymbol,
243
+ SwapSide.SELL,
244
+ amountsForSell,
245
+ 'calculatePrice',
246
+ );
247
+ });
248
+
249
+ // it('getPoolIdentifiers and getPricesVolume BUY', async function () {
250
+ // await testPricingOnNetwork(
251
+ // maverickV2,
252
+ // network,
253
+ // dexKey,
254
+ // blockNumber,
255
+ // srcTokenSymbol,
256
+ // destTokenSymbol,
257
+ // SwapSide.BUY,
258
+ // amountsForBuy,
259
+ // 'calculatePrice',
260
+ // );
261
+ // });
262
+
263
+ it('getTopPoolsForToken', async function () {
264
+ const newMaverickV2 = new MaverickV2(network, dexKey, dexHelper);
265
+ if (newMaverickV2.updatePoolState) {
266
+ await newMaverickV2.updatePoolState();
267
+ }
268
+ const poolLiquidity = await newMaverickV2.getTopPoolsForToken(
269
+ tokens[srcTokenSymbol].address,
270
+ 10,
271
+ );
272
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
273
+
274
+ if (!newMaverickV2.hasConstantPriceLargeAmounts) {
275
+ checkPoolsLiquidity(
276
+ poolLiquidity,
277
+ tokens[srcTokenSymbol].address,
278
+ dexKey,
279
+ );
280
+ }
281
+ });
282
+ });
283
+ });