@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,278 @@
1
+ [
2
+ {
3
+ "inputs": [],
4
+ "name": "BytesLibSliceOutOfBounds",
5
+ "type": "error"
6
+ },
7
+ {
8
+ "inputs": [],
9
+ "name": "BytesLibSliceOverflow",
10
+ "type": "error"
11
+ },
12
+ {
13
+ "inputs": [],
14
+ "name": "BytesLibToAddressOutOfBounds",
15
+ "type": "error"
16
+ },
17
+ {
18
+ "inputs": [],
19
+ "name": "BytesLibToBoolOutOfBounds",
20
+ "type": "error"
21
+ },
22
+ {
23
+ "inputs": [],
24
+ "name": "MathOverflowedMulDiv",
25
+ "type": "error"
26
+ },
27
+ {
28
+ "inputs": [],
29
+ "name": "QuoterInvalidAddLiquidity",
30
+ "type": "error"
31
+ },
32
+ {
33
+ "inputs": [],
34
+ "name": "QuoterInvalidSwap",
35
+ "type": "error"
36
+ },
37
+ {
38
+ "inputs": [
39
+ {
40
+ "internalType": "uint8",
41
+ "name": "bits",
42
+ "type": "uint8"
43
+ },
44
+ {
45
+ "internalType": "uint256",
46
+ "name": "value",
47
+ "type": "uint256"
48
+ }
49
+ ],
50
+ "name": "SafeCastOverflowedUintDowncast",
51
+ "type": "error"
52
+ },
53
+ {
54
+ "inputs": [
55
+ {
56
+ "internalType": "int256",
57
+ "name": "tick",
58
+ "type": "int256"
59
+ }
60
+ ],
61
+ "name": "TickMaxExceeded",
62
+ "type": "error"
63
+ },
64
+ {
65
+ "inputs": [
66
+ {
67
+ "internalType": "contract IMaverickV2Pool",
68
+ "name": "pool",
69
+ "type": "address"
70
+ },
71
+ {
72
+ "components": [
73
+ {
74
+ "internalType": "uint8",
75
+ "name": "kind",
76
+ "type": "uint8"
77
+ },
78
+ {
79
+ "internalType": "int32[]",
80
+ "name": "ticks",
81
+ "type": "int32[]"
82
+ },
83
+ {
84
+ "internalType": "uint128[]",
85
+ "name": "amounts",
86
+ "type": "uint128[]"
87
+ }
88
+ ],
89
+ "internalType": "struct IMaverickV2Pool.AddLiquidityParams",
90
+ "name": "params",
91
+ "type": "tuple"
92
+ }
93
+ ],
94
+ "name": "calculateAddLiquidity",
95
+ "outputs": [
96
+ {
97
+ "internalType": "uint256",
98
+ "name": "amountA",
99
+ "type": "uint256"
100
+ },
101
+ {
102
+ "internalType": "uint256",
103
+ "name": "amountB",
104
+ "type": "uint256"
105
+ },
106
+ {
107
+ "internalType": "uint256",
108
+ "name": "gasEstimate",
109
+ "type": "uint256"
110
+ }
111
+ ],
112
+ "stateMutability": "nonpayable",
113
+ "type": "function"
114
+ },
115
+ {
116
+ "inputs": [
117
+ {
118
+ "internalType": "bytes",
119
+ "name": "path",
120
+ "type": "bytes"
121
+ },
122
+ {
123
+ "internalType": "uint256",
124
+ "name": "amount",
125
+ "type": "uint256"
126
+ },
127
+ {
128
+ "internalType": "bool",
129
+ "name": "exactOutput",
130
+ "type": "bool"
131
+ }
132
+ ],
133
+ "name": "calculateMultiHopSwap",
134
+ "outputs": [
135
+ {
136
+ "internalType": "uint256",
137
+ "name": "returnAmount",
138
+ "type": "uint256"
139
+ },
140
+ {
141
+ "internalType": "uint256",
142
+ "name": "gasEstimate",
143
+ "type": "uint256"
144
+ }
145
+ ],
146
+ "stateMutability": "nonpayable",
147
+ "type": "function"
148
+ },
149
+ {
150
+ "inputs": [
151
+ {
152
+ "internalType": "contract IMaverickV2Pool",
153
+ "name": "pool",
154
+ "type": "address"
155
+ },
156
+ {
157
+ "internalType": "uint128",
158
+ "name": "amount",
159
+ "type": "uint128"
160
+ },
161
+ {
162
+ "internalType": "bool",
163
+ "name": "tokenAIn",
164
+ "type": "bool"
165
+ },
166
+ {
167
+ "internalType": "bool",
168
+ "name": "exactOutput",
169
+ "type": "bool"
170
+ },
171
+ {
172
+ "internalType": "int32",
173
+ "name": "tickLimit",
174
+ "type": "int32"
175
+ }
176
+ ],
177
+ "name": "calculateSwap",
178
+ "outputs": [
179
+ {
180
+ "internalType": "uint256",
181
+ "name": "amountIn",
182
+ "type": "uint256"
183
+ },
184
+ {
185
+ "internalType": "uint256",
186
+ "name": "amountOut",
187
+ "type": "uint256"
188
+ },
189
+ {
190
+ "internalType": "uint256",
191
+ "name": "gasEstimate",
192
+ "type": "uint256"
193
+ }
194
+ ],
195
+ "stateMutability": "nonpayable",
196
+ "type": "function"
197
+ },
198
+ {
199
+ "inputs": [
200
+ {
201
+ "internalType": "contract IERC20",
202
+ "name": "",
203
+ "type": "address"
204
+ },
205
+ {
206
+ "internalType": "contract IERC20",
207
+ "name": "",
208
+ "type": "address"
209
+ },
210
+ {
211
+ "internalType": "uint256",
212
+ "name": "amountA",
213
+ "type": "uint256"
214
+ },
215
+ {
216
+ "internalType": "uint256",
217
+ "name": "amountB",
218
+ "type": "uint256"
219
+ },
220
+ {
221
+ "internalType": "bytes",
222
+ "name": "",
223
+ "type": "bytes"
224
+ }
225
+ ],
226
+ "name": "maverickV2AddLiquidityCallback",
227
+ "outputs": [],
228
+ "stateMutability": "pure",
229
+ "type": "function"
230
+ },
231
+ {
232
+ "inputs": [
233
+ {
234
+ "internalType": "contract IERC20",
235
+ "name": "",
236
+ "type": "address"
237
+ },
238
+ {
239
+ "internalType": "uint256",
240
+ "name": "amountIn",
241
+ "type": "uint256"
242
+ },
243
+ {
244
+ "internalType": "uint256",
245
+ "name": "amountOut",
246
+ "type": "uint256"
247
+ },
248
+ {
249
+ "internalType": "bytes",
250
+ "name": "",
251
+ "type": "bytes"
252
+ }
253
+ ],
254
+ "name": "maverickV2SwapCallback",
255
+ "outputs": [],
256
+ "stateMutability": "pure",
257
+ "type": "function"
258
+ },
259
+ {
260
+ "inputs": [
261
+ {
262
+ "internalType": "contract IMaverickV2Pool",
263
+ "name": "pool",
264
+ "type": "address"
265
+ }
266
+ ],
267
+ "name": "poolSqrtPrice",
268
+ "outputs": [
269
+ {
270
+ "internalType": "uint256",
271
+ "name": "sqrtPrice",
272
+ "type": "uint256"
273
+ }
274
+ ],
275
+ "stateMutability": "view",
276
+ "type": "function"
277
+ }
278
+ ]
package/src/dex/index.ts CHANGED
@@ -66,6 +66,7 @@ import { Camelot } from './camelot/camelot';
66
66
  import { Hashflow } from './hashflow/hashflow';
67
67
  import { SolidlyEthereum } from './solidly/solidly-ethereum';
68
68
  import { MaverickV1 } from './maverick-v1/maverick-v1';
69
+ import { MaverickV2 } from './maverick-v2/maverick-v2';
69
70
  import { QuickSwapV3 } from './quickswap/quickswap-v3';
70
71
  import { ThenaFusion } from './quickswap/thena-fusion';
71
72
  import { TraderJoeV2 } from './trader-joe-v2';
@@ -152,6 +153,7 @@ const Dexes = [
152
153
  WstETH,
153
154
  Hashflow,
154
155
  MaverickV1,
156
+ MaverickV2,
155
157
  Camelot,
156
158
  SwaapV2,
157
159
  AngleStakedStable,
@@ -0,0 +1,28 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ import { Network } from '../../constants';
4
+
5
+ export const MAV_V2_BASE_GAS_COST = 50_000;
6
+ export const MAV_V2_TICK_GAS_COST = 10_000;
7
+ export const MAVERICK_API_URL = `https://v2-api.mav.xyz/`;
8
+
9
+ export const MaverickV2Config: DexConfigMap<DexParams> = {
10
+ MaverickV2: {
11
+ [Network.BASE]: {
12
+ quoterAddress: `0xb40AfdB85a07f37aE217E7D6462e609900dD8D7A`,
13
+ poolLensAddress: `0x942646b0A8B42Af1e1044439013436a9a3e080b5`,
14
+ },
15
+ [Network.MAINNET]: {
16
+ quoterAddress: `0xb40AfdB85a07f37aE217E7D6462e609900dD8D7A`,
17
+ poolLensAddress: `0x942646b0A8B42Af1e1044439013436a9a3e080b5`,
18
+ },
19
+ [Network.BSC]: {
20
+ quoterAddress: `0xb40AfdB85a07f37aE217E7D6462e609900dD8D7A`,
21
+ poolLensAddress: `0x942646b0A8B42Af1e1044439013436a9a3e080b5`,
22
+ },
23
+ [Network.ARBITRUM]: {
24
+ quoterAddress: `0xb40AfdB85a07f37aE217E7D6462e609900dD8D7A`,
25
+ poolLensAddress: `0x942646b0A8B42Af1e1044439013436a9a3e080b5`,
26
+ },
27
+ },
28
+ };
@@ -0,0 +1,152 @@
1
+ import { BI_MAX_UINT256, BI_POWS } from '../../../bigint-constants';
2
+ import { _require } from '../../../utils';
3
+
4
+ export class MaverickBasicMath {
5
+ static MAX_POW_RELATIVE_ERROR = BI_POWS[4];
6
+
7
+ static abs(x: bigint) {
8
+ return x < 0n ? -x : x;
9
+ }
10
+
11
+ static min(a: bigint, b: bigint): bigint {
12
+ return a < b ? a : b;
13
+ }
14
+
15
+ static max(a: bigint, b: bigint): bigint {
16
+ return a >= b ? a : b;
17
+ }
18
+
19
+ static clip(x: bigint, y: bigint): bigint {
20
+ return x < y ? 0n : x - y;
21
+ }
22
+
23
+ static mulDivFloor(x: bigint, y: bigint, k: bigint): bigint {
24
+ return this.mulDiv(x, y, this.max(1n, k));
25
+ }
26
+
27
+ static mulmod(x: bigint, y: bigint, k: bigint): bigint {
28
+ return (x * y) % k;
29
+ }
30
+
31
+ static mulFloor(x: bigint, y: bigint): bigint {
32
+ return this.mulDiv(x, y, BI_POWS[18]);
33
+ }
34
+
35
+ static mulDivCeil(x: bigint, y: bigint, k: bigint): bigint {
36
+ let result = this.mulDivFloor(x, y, k);
37
+ if (this.mulmod(x, y, this.max(1n, k)) != 0n) result = result + 1n;
38
+ return result;
39
+ }
40
+
41
+ static sqrt(x: bigint) {
42
+ let y = x;
43
+
44
+ let z = 181n;
45
+
46
+ if (y >= 0x10000000000000000000000000000000000) {
47
+ y >>= 128n;
48
+ z <<= 64n;
49
+ }
50
+
51
+ if (y >= 0x1000000000000000000) {
52
+ y >>= 64n;
53
+ z <<= 32n;
54
+ }
55
+
56
+ if (y >= 0x10000000000) {
57
+ y >>= 32n;
58
+ z <<= 16n;
59
+ }
60
+
61
+ if (y >= 0x1000000) {
62
+ y >>= 16n;
63
+ z <<= 8n;
64
+ }
65
+
66
+ z = (z * (y + 65536n)) >> 18n;
67
+ z = (x / z + z) >> 1n;
68
+ z = (x / z + z) >> 1n;
69
+ z = (x / z + z) >> 1n;
70
+ z = (x / z + z) >> 1n;
71
+ z = (x / z + z) >> 1n;
72
+ z = (x / z + z) >> 1n;
73
+ z = (x / z + z) >> 1n;
74
+
75
+ return x / z < z ? z - 1n : z;
76
+ }
77
+
78
+ static divDown(x: bigint, y: bigint): bigint {
79
+ return this.mulDivDown(x, BI_POWS[18], y);
80
+ }
81
+
82
+ static divUp(x: bigint, y: bigint): bigint {
83
+ return this.mulDivUp(x, BI_POWS[18], y);
84
+ }
85
+
86
+ static mulUp(x: bigint, y: bigint): bigint {
87
+ return this.mulDivUp(x, y, BI_POWS[18]);
88
+ }
89
+
90
+ static mulDown(x: bigint, y: bigint): bigint {
91
+ return this.mulDivDown(x, y, BI_POWS[18]);
92
+ }
93
+
94
+ static invFloor(x: bigint): bigint {
95
+ return BI_POWS[36] / x;
96
+ }
97
+
98
+ static invCeil(denominator: bigint): bigint {
99
+ return (BI_POWS[36] - 1n) / denominator + 1n;
100
+ }
101
+
102
+ static mulDivDown(x: bigint, y: bigint, denominator: bigint): bigint {
103
+ let z = x * y;
104
+
105
+ if (denominator === 0n) {
106
+ denominator = 1n;
107
+ }
108
+
109
+ if (denominator === 0n && !(y === 0n || x <= BI_MAX_UINT256 / y)) {
110
+ throw new Error('MATH: MUL_DIV_DOWN_OVERFLOW');
111
+ }
112
+
113
+ return z / denominator;
114
+ }
115
+
116
+ static mulDiv(x: bigint, y: bigint, denominator: bigint): bigint {
117
+ const result = (x * y) / denominator;
118
+
119
+ _require(
120
+ result <= BI_MAX_UINT256,
121
+ '',
122
+ { result, BI_MAX_UINT: BI_MAX_UINT256 },
123
+ 'result <= BI_MAX_UINT256',
124
+ );
125
+
126
+ return result;
127
+ }
128
+
129
+ static divCeil(x: bigint, y: bigint): bigint {
130
+ return this.mulDivCeil(x, BI_POWS[18], y);
131
+ }
132
+
133
+ static mulCeil(x: bigint, y: bigint): bigint {
134
+ return this.mulDivCeil(x, y, BI_POWS[18]);
135
+ }
136
+
137
+ static mulDivUp(x: bigint, y: bigint, denominator: bigint): bigint {
138
+ let z = x * y;
139
+
140
+ if (z === 0n) {
141
+ return 0n;
142
+ }
143
+
144
+ return (z - 1n) / denominator + 1n;
145
+ }
146
+
147
+ static floorD8Unchecked(val: bigint): bigint {
148
+ let val32 = val / BI_POWS[8];
149
+ let check = val < 0 && val % BI_POWS[8] != 0n;
150
+ return check ? val32 - 1n : val32;
151
+ }
152
+ }