@strkfarm/sdk 1.1.8 → 1.1.10
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/dist/cli.js +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.browser.global.js +1241 -74
- package/dist/index.browser.mjs +1396 -227
- package/dist/index.d.ts +169 -30
- package/dist/index.js +1412 -239
- package/dist/index.mjs +1397 -228
- package/package.json +1 -1
- package/src/data/vesu-multiple.abi.json +475 -0
- package/src/dataTypes/_bignumber.ts +13 -0
- package/src/interfaces/common.tsx +2 -1
- package/src/modules/ekubo-quoter.ts +127 -0
- package/src/modules/index.ts +1 -0
- package/src/strategies/ekubo-cl-vault.tsx +25 -11
- package/src/strategies/index.ts +2 -1
- package/src/strategies/universal-adapters/adapter-utils.ts +3 -0
- package/src/strategies/universal-adapters/baseAdapter.ts +3 -3
- package/src/strategies/universal-adapters/vesu-adapter.ts +244 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +497 -0
- package/src/strategies/universal-strategy.tsx +142 -60
- package/src/utils/index.ts +3 -1
- package/src/utils/logger.node.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"type": "impl",
|
|
4
|
+
"name": "LockerImpl",
|
|
5
|
+
"interface_name": "ekubo::interfaces::core::ILocker"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"type": "struct",
|
|
9
|
+
"name": "core::array::Span::<core::felt252>",
|
|
10
|
+
"members": [
|
|
11
|
+
{
|
|
12
|
+
"name": "snapshot",
|
|
13
|
+
"type": "@core::array::Array::<core::felt252>"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "interface",
|
|
19
|
+
"name": "ekubo::interfaces::core::ILocker",
|
|
20
|
+
"items": [
|
|
21
|
+
{
|
|
22
|
+
"type": "function",
|
|
23
|
+
"name": "locked",
|
|
24
|
+
"inputs": [
|
|
25
|
+
{
|
|
26
|
+
"name": "id",
|
|
27
|
+
"type": "core::integer::u32"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "data",
|
|
31
|
+
"type": "core::array::Span::<core::felt252>"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"outputs": [
|
|
35
|
+
{
|
|
36
|
+
"type": "core::array::Span::<core::felt252>"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"state_mutability": "external"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "impl",
|
|
45
|
+
"name": "MultiplyImpl",
|
|
46
|
+
"interface_name": "vesu_periphery::multiply::IMultiply"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "struct",
|
|
50
|
+
"name": "ekubo::types::keys::PoolKey",
|
|
51
|
+
"members": [
|
|
52
|
+
{
|
|
53
|
+
"name": "token0",
|
|
54
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "token1",
|
|
58
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "fee",
|
|
62
|
+
"type": "core::integer::u128"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "tick_spacing",
|
|
66
|
+
"type": "core::integer::u128"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "extension",
|
|
70
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"type": "struct",
|
|
76
|
+
"name": "core::integer::u256",
|
|
77
|
+
"members": [
|
|
78
|
+
{
|
|
79
|
+
"name": "low",
|
|
80
|
+
"type": "core::integer::u128"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "high",
|
|
84
|
+
"type": "core::integer::u128"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"type": "struct",
|
|
90
|
+
"name": "vesu_periphery::swap::RouteNode",
|
|
91
|
+
"members": [
|
|
92
|
+
{
|
|
93
|
+
"name": "pool_key",
|
|
94
|
+
"type": "ekubo::types::keys::PoolKey"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "sqrt_ratio_limit",
|
|
98
|
+
"type": "core::integer::u256"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "skip_ahead",
|
|
102
|
+
"type": "core::integer::u128"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"type": "enum",
|
|
108
|
+
"name": "core::bool",
|
|
109
|
+
"variants": [
|
|
110
|
+
{
|
|
111
|
+
"name": "False",
|
|
112
|
+
"type": "()"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"name": "True",
|
|
116
|
+
"type": "()"
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"type": "struct",
|
|
122
|
+
"name": "ekubo::types::i129::i129",
|
|
123
|
+
"members": [
|
|
124
|
+
{
|
|
125
|
+
"name": "mag",
|
|
126
|
+
"type": "core::integer::u128"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "sign",
|
|
130
|
+
"type": "core::bool"
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"type": "struct",
|
|
136
|
+
"name": "vesu_periphery::swap::TokenAmount",
|
|
137
|
+
"members": [
|
|
138
|
+
{
|
|
139
|
+
"name": "token",
|
|
140
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "amount",
|
|
144
|
+
"type": "ekubo::types::i129::i129"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"type": "struct",
|
|
150
|
+
"name": "vesu_periphery::swap::Swap",
|
|
151
|
+
"members": [
|
|
152
|
+
{
|
|
153
|
+
"name": "route",
|
|
154
|
+
"type": "core::array::Array::<vesu_periphery::swap::RouteNode>"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "token_amount",
|
|
158
|
+
"type": "vesu_periphery::swap::TokenAmount"
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"type": "struct",
|
|
164
|
+
"name": "vesu_periphery::multiply::IncreaseLeverParams",
|
|
165
|
+
"members": [
|
|
166
|
+
{
|
|
167
|
+
"name": "pool_id",
|
|
168
|
+
"type": "core::felt252"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"name": "collateral_asset",
|
|
172
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"name": "debt_asset",
|
|
176
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"name": "user",
|
|
180
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": "add_margin",
|
|
184
|
+
"type": "core::integer::u128"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"name": "margin_swap",
|
|
188
|
+
"type": "core::array::Array::<vesu_periphery::swap::Swap>"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"name": "margin_swap_limit_amount",
|
|
192
|
+
"type": "core::integer::u128"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "lever_swap",
|
|
196
|
+
"type": "core::array::Array::<vesu_periphery::swap::Swap>"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"name": "lever_swap_limit_amount",
|
|
200
|
+
"type": "core::integer::u128"
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"type": "struct",
|
|
206
|
+
"name": "vesu_periphery::multiply::DecreaseLeverParams",
|
|
207
|
+
"members": [
|
|
208
|
+
{
|
|
209
|
+
"name": "pool_id",
|
|
210
|
+
"type": "core::felt252"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "collateral_asset",
|
|
214
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "debt_asset",
|
|
218
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "user",
|
|
222
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"name": "sub_margin",
|
|
226
|
+
"type": "core::integer::u128"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"name": "recipient",
|
|
230
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "lever_swap",
|
|
234
|
+
"type": "core::array::Array::<vesu_periphery::swap::Swap>"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "lever_swap_limit_amount",
|
|
238
|
+
"type": "core::integer::u128"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"name": "lever_swap_weights",
|
|
242
|
+
"type": "core::array::Array::<core::integer::u128>"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "withdraw_swap",
|
|
246
|
+
"type": "core::array::Array::<vesu_periphery::swap::Swap>"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"name": "withdraw_swap_limit_amount",
|
|
250
|
+
"type": "core::integer::u128"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
"name": "withdraw_swap_weights",
|
|
254
|
+
"type": "core::array::Array::<core::integer::u128>"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"name": "close_position",
|
|
258
|
+
"type": "core::bool"
|
|
259
|
+
}
|
|
260
|
+
]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"type": "enum",
|
|
264
|
+
"name": "vesu_periphery::multiply::ModifyLeverAction",
|
|
265
|
+
"variants": [
|
|
266
|
+
{
|
|
267
|
+
"name": "IncreaseLever",
|
|
268
|
+
"type": "vesu_periphery::multiply::IncreaseLeverParams"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"name": "DecreaseLever",
|
|
272
|
+
"type": "vesu_periphery::multiply::DecreaseLeverParams"
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"type": "struct",
|
|
278
|
+
"name": "vesu_periphery::multiply::ModifyLeverParams",
|
|
279
|
+
"members": [
|
|
280
|
+
{
|
|
281
|
+
"name": "action",
|
|
282
|
+
"type": "vesu_periphery::multiply::ModifyLeverAction"
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"type": "struct",
|
|
288
|
+
"name": "alexandria_math::i257::i257",
|
|
289
|
+
"members": [
|
|
290
|
+
{
|
|
291
|
+
"name": "abs",
|
|
292
|
+
"type": "core::integer::u256"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"name": "is_negative",
|
|
296
|
+
"type": "core::bool"
|
|
297
|
+
}
|
|
298
|
+
]
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"type": "struct",
|
|
302
|
+
"name": "vesu_periphery::multiply::ModifyLeverResponse",
|
|
303
|
+
"members": [
|
|
304
|
+
{
|
|
305
|
+
"name": "collateral_delta",
|
|
306
|
+
"type": "alexandria_math::i257::i257"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
"name": "debt_delta",
|
|
310
|
+
"type": "alexandria_math::i257::i257"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"name": "margin_delta",
|
|
314
|
+
"type": "alexandria_math::i257::i257"
|
|
315
|
+
}
|
|
316
|
+
]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
"type": "interface",
|
|
320
|
+
"name": "vesu_periphery::multiply::IMultiply",
|
|
321
|
+
"items": [
|
|
322
|
+
{
|
|
323
|
+
"type": "function",
|
|
324
|
+
"name": "modify_lever",
|
|
325
|
+
"inputs": [
|
|
326
|
+
{
|
|
327
|
+
"name": "modify_lever_params",
|
|
328
|
+
"type": "vesu_periphery::multiply::ModifyLeverParams"
|
|
329
|
+
}
|
|
330
|
+
],
|
|
331
|
+
"outputs": [
|
|
332
|
+
{
|
|
333
|
+
"type": "vesu_periphery::multiply::ModifyLeverResponse"
|
|
334
|
+
}
|
|
335
|
+
],
|
|
336
|
+
"state_mutability": "external"
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"type": "struct",
|
|
342
|
+
"name": "ekubo::interfaces::core::ICoreDispatcher",
|
|
343
|
+
"members": [
|
|
344
|
+
{
|
|
345
|
+
"name": "contract_address",
|
|
346
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
347
|
+
}
|
|
348
|
+
]
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"type": "struct",
|
|
352
|
+
"name": "vesu::singleton::ISingletonDispatcher",
|
|
353
|
+
"members": [
|
|
354
|
+
{
|
|
355
|
+
"name": "contract_address",
|
|
356
|
+
"type": "core::starknet::contract_address::ContractAddress"
|
|
357
|
+
}
|
|
358
|
+
]
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
"type": "constructor",
|
|
362
|
+
"name": "constructor",
|
|
363
|
+
"inputs": [
|
|
364
|
+
{
|
|
365
|
+
"name": "core",
|
|
366
|
+
"type": "ekubo::interfaces::core::ICoreDispatcher"
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
"name": "singleton",
|
|
370
|
+
"type": "vesu::singleton::ISingletonDispatcher"
|
|
371
|
+
}
|
|
372
|
+
]
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"type": "event",
|
|
376
|
+
"name": "vesu_periphery::multiply::Multiply::IncreaseLever",
|
|
377
|
+
"kind": "struct",
|
|
378
|
+
"members": [
|
|
379
|
+
{
|
|
380
|
+
"name": "pool_id",
|
|
381
|
+
"type": "core::felt252",
|
|
382
|
+
"kind": "key"
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
"name": "collateral_asset",
|
|
386
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
387
|
+
"kind": "key"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"name": "debt_asset",
|
|
391
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
392
|
+
"kind": "key"
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"name": "user",
|
|
396
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
397
|
+
"kind": "key"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "margin",
|
|
401
|
+
"type": "core::integer::u256",
|
|
402
|
+
"kind": "data"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"name": "collateral_delta",
|
|
406
|
+
"type": "core::integer::u256",
|
|
407
|
+
"kind": "data"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
"name": "debt_delta",
|
|
411
|
+
"type": "core::integer::u256",
|
|
412
|
+
"kind": "data"
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
"type": "event",
|
|
418
|
+
"name": "vesu_periphery::multiply::Multiply::DecreaseLever",
|
|
419
|
+
"kind": "struct",
|
|
420
|
+
"members": [
|
|
421
|
+
{
|
|
422
|
+
"name": "pool_id",
|
|
423
|
+
"type": "core::felt252",
|
|
424
|
+
"kind": "key"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
"name": "collateral_asset",
|
|
428
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
429
|
+
"kind": "key"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
"name": "debt_asset",
|
|
433
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
434
|
+
"kind": "key"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
"name": "user",
|
|
438
|
+
"type": "core::starknet::contract_address::ContractAddress",
|
|
439
|
+
"kind": "key"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
"name": "margin",
|
|
443
|
+
"type": "core::integer::u256",
|
|
444
|
+
"kind": "data"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"name": "collateral_delta",
|
|
448
|
+
"type": "core::integer::u256",
|
|
449
|
+
"kind": "data"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
"name": "debt_delta",
|
|
453
|
+
"type": "core::integer::u256",
|
|
454
|
+
"kind": "data"
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"type": "event",
|
|
460
|
+
"name": "vesu_periphery::multiply::Multiply::Event",
|
|
461
|
+
"kind": "enum",
|
|
462
|
+
"variants": [
|
|
463
|
+
{
|
|
464
|
+
"name": "IncreaseLever",
|
|
465
|
+
"type": "vesu_periphery::multiply::Multiply::IncreaseLever",
|
|
466
|
+
"kind": "nested"
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
"name": "DecreaseLever",
|
|
470
|
+
"type": "vesu_periphery::multiply::Multiply::DecreaseLever",
|
|
471
|
+
"kind": "nested"
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
}
|
|
475
|
+
]
|
|
@@ -76,6 +76,19 @@ export class _Web3Number<T extends _Web3Number<T>> extends BigNumber {
|
|
|
76
76
|
const answer = _value.greaterThanOrEqualTo(_valueMe) ? _value : _valueMe;
|
|
77
77
|
return this.construct(answer.toString(), this.decimals);
|
|
78
78
|
}
|
|
79
|
+
|
|
80
|
+
abs(): T {
|
|
81
|
+
console.warn(`abs: this: ${this}`);
|
|
82
|
+
return this.construct(Math.abs(this.toNumber()).toFixed(12), this.decimals);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
toI129(): { mag: bigint, sign: 0 | 1 } {
|
|
86
|
+
const sign = this.isNegative() ? 1 : 0;
|
|
87
|
+
return {
|
|
88
|
+
mag: BigInt(this.toWei()) * (this.isNegative() ? -1n : 1n),
|
|
89
|
+
sign: sign,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
BigNumber.config({ DECIMAL_PLACES: 18, ROUNDING_MODE: BigNumber.ROUND_DOWN });
|
|
@@ -96,7 +96,8 @@ export interface IStrategyMetadata<T> {
|
|
|
96
96
|
points?: {multiplier: number, logo: string, toolTip?: string}[];
|
|
97
97
|
docs?: string;
|
|
98
98
|
investmentSteps: string[];
|
|
99
|
-
curator?: { name: string, logo: string }
|
|
99
|
+
curator?: { name: string, logo: string },
|
|
100
|
+
isPreview?: boolean
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
export interface IInvestmentFlow {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
2
|
+
import { IConfig, TokenInfo } from "@/interfaces/common";
|
|
3
|
+
import { Swap } from "@/strategies";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
|
|
6
|
+
export interface EkuboRouteNode {
|
|
7
|
+
pool_key: {
|
|
8
|
+
token0: string;
|
|
9
|
+
token1: string;
|
|
10
|
+
fee: string;
|
|
11
|
+
tick_spacing: number;
|
|
12
|
+
extension: string;
|
|
13
|
+
};
|
|
14
|
+
sqrt_ratio_limit: string; // hex
|
|
15
|
+
skip_ahead: number;
|
|
16
|
+
}
|
|
17
|
+
export interface EkuboSplit {
|
|
18
|
+
amount_specified: string;
|
|
19
|
+
amount_calculated: string;
|
|
20
|
+
route: EkuboRouteNode[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface EkuboQuote {
|
|
24
|
+
total_calculated: string; // raw amount in string num
|
|
25
|
+
price_impact: number; // in non-decimal form
|
|
26
|
+
splits: EkuboSplit[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export class EkuboQuoter {
|
|
31
|
+
ENDPOINT = 'https://quoter-mainnet-api.ekubo.org/{{AMOUNT}}/{{TOKEN_FROM_ADDRESS}}/{{TOKEN_TO_ADDRESS}}'; // e.g. ETH/USDC'
|
|
32
|
+
|
|
33
|
+
constructor(private readonly config: IConfig) {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param fromToken
|
|
38
|
+
* @param toToken
|
|
39
|
+
* @param amount Can be negative too, which would mean to get exact amount out
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
async getQuote(fromToken: string, toToken: string, amount: Web3Number): Promise<EkuboQuote> {
|
|
43
|
+
let _fromToken = amount.gt(0) ? fromToken : toToken;
|
|
44
|
+
let _toToken = amount.gt(0) ? toToken : fromToken;
|
|
45
|
+
|
|
46
|
+
const quote = await axios.get(this.ENDPOINT.replace("{{AMOUNT}}", amount.toWei()).replace("{{TOKEN_FROM_ADDRESS}}", _fromToken).replace("{{TOKEN_TO_ADDRESS}}", _toToken));
|
|
47
|
+
console.log(`Ekubo quote from ${_fromToken} to ${_toToken} for ${amount.toString()}: ${JSON.stringify(quote.data)}`);
|
|
48
|
+
return quote.data as EkuboQuote;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Formats Ekubo response for Vesu multiple use
|
|
53
|
+
* @param quote
|
|
54
|
+
* @param fromTokenInfo
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getVesuMultiplyQuote(quote: EkuboQuote, fromTokenInfo: TokenInfo, toTokenInfo: TokenInfo): Swap[] {
|
|
58
|
+
return quote.splits.map(split => {
|
|
59
|
+
const isNegativeAmount = BigInt(split.amount_specified) < 0n;
|
|
60
|
+
const token = isNegativeAmount ? toTokenInfo : fromTokenInfo;
|
|
61
|
+
return {
|
|
62
|
+
route: split.route.map(_route => ({
|
|
63
|
+
pool_key: {
|
|
64
|
+
token0: ContractAddr.from(_route.pool_key.token0),
|
|
65
|
+
token1: ContractAddr.from(_route.pool_key.token1),
|
|
66
|
+
fee: _route.pool_key.fee,
|
|
67
|
+
tick_spacing: _route.pool_key.tick_spacing.toString(),
|
|
68
|
+
extension: _route.pool_key.extension
|
|
69
|
+
},
|
|
70
|
+
sqrt_ratio_limit: Web3Number.fromWei(_route.sqrt_ratio_limit, 18), // just for use, any decimal works
|
|
71
|
+
skip_ahead: Web3Number.fromWei(_route.skip_ahead, 0) // no decimal for this
|
|
72
|
+
})),
|
|
73
|
+
token_amount: {
|
|
74
|
+
token: token.address,
|
|
75
|
+
amount: Web3Number.fromWei(split.amount_specified, token.decimals)
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// {
|
|
83
|
+
// "total_calculated": "828686582951171934715731",
|
|
84
|
+
// "price_impact": 0.0402043860710308,
|
|
85
|
+
// "splits": [
|
|
86
|
+
// {
|
|
87
|
+
// "amount_specified": "500000000000000000",
|
|
88
|
+
// "amount_calculated": "416221102677759239180488",
|
|
89
|
+
// "route": [
|
|
90
|
+
// {
|
|
91
|
+
// "pool_key": {
|
|
92
|
+
// "token0": "0x4daa17763b286d1e59b97c283c0b8c949994c361e426a28f743c67bdfe9a32f",
|
|
93
|
+
// "token1": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
|
|
94
|
+
// "fee": "0x20c49ba5e353f80000000000000000",
|
|
95
|
+
// "tick_spacing": 1000,
|
|
96
|
+
// "extension": "0x0"
|
|
97
|
+
// },
|
|
98
|
+
// "sqrt_ratio_limit": "0x13284b8acc81b88350a0144d679130",
|
|
99
|
+
// "skip_ahead": 25
|
|
100
|
+
// },
|
|
101
|
+
// {
|
|
102
|
+
// "pool_key": {
|
|
103
|
+
// "token0": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
104
|
+
// "token1": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
|
|
105
|
+
// "fee": "0x0",
|
|
106
|
+
// "tick_spacing": 1028,
|
|
107
|
+
// "extension": "0x0"
|
|
108
|
+
// },
|
|
109
|
+
// "sqrt_ratio_limit": "0x6b8ec3c36efc69f79fa760b7bfd",
|
|
110
|
+
// "skip_ahead": 0
|
|
111
|
+
// },
|
|
112
|
+
// {
|
|
113
|
+
// "pool_key": {
|
|
114
|
+
// "token0": "0x28d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a",
|
|
115
|
+
// "token1": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
|
|
116
|
+
// "fee": "0x68db8bac710cb4000000000000000",
|
|
117
|
+
// "tick_spacing": 200,
|
|
118
|
+
// "extension": "0x0"
|
|
119
|
+
// },
|
|
120
|
+
// "sqrt_ratio_limit": "0x111ef62dbb6cbdc45f9d47a1014cd6dd9",
|
|
121
|
+
// "skip_ahead": 0
|
|
122
|
+
// }
|
|
123
|
+
// ]
|
|
124
|
+
// },
|
|
125
|
+
// ...otherSplits
|
|
126
|
+
// ]
|
|
127
|
+
// }
|
package/src/modules/index.ts
CHANGED