@gearbox-protocol/sdk 14.12.0-next.31 → 14.12.0-next.33
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/cjs/dev/withdrawalAbi.js +64 -70
- package/dist/cjs/dev/withdrawalUtils.js +1 -1
- package/dist/cjs/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
- package/dist/cjs/plugins/adapters/contracts/MidasGatewayAdapterContract.js +45 -44
- package/dist/cjs/preview/preview/buildDelayedPreview.js +5 -1
- package/dist/cjs/preview/preview/detectCloseOrRepay.js +2 -2
- package/dist/cjs/preview/preview/previewCloseOrRepayCreditAccount.js +17 -2
- package/dist/cjs/rewards/rewards/extra-apy.js +8 -4
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/esm/dev/withdrawalAbi.js +64 -70
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
- package/dist/esm/plugins/adapters/contracts/MidasGatewayAdapterContract.js +47 -45
- package/dist/esm/preview/preview/buildDelayedPreview.js +5 -1
- package/dist/esm/preview/preview/detectCloseOrRepay.js +2 -2
- package/dist/esm/preview/preview/previewCloseOrRepayCreditAccount.js +22 -3
- package/dist/esm/rewards/rewards/extra-apy.js +8 -4
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/types/dev/withdrawalAbi.d.ts +53 -57
- package/dist/types/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.d.ts +33 -219
- package/dist/types/plugins/adapters/contracts/MidasGatewayAdapterContract.d.ts +44 -232
- package/dist/types/preview/preview/detectCloseOrRepay.d.ts +5 -3
- package/dist/types/preview/preview/types.d.ts +6 -4
- package/dist/types/rewards/rewards/extra-apy.d.ts +3 -1
- package/package.json +1 -1
|
@@ -23,45 +23,6 @@ __export(iMidasGatewayAdapterV311_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(iMidasGatewayAdapterV311_exports);
|
|
25
25
|
const iMidasGatewayAdapterV311Abi = [
|
|
26
|
-
{
|
|
27
|
-
type: "function",
|
|
28
|
-
name: "allowedInputTokens",
|
|
29
|
-
inputs: [],
|
|
30
|
-
outputs: [
|
|
31
|
-
{
|
|
32
|
-
name: "",
|
|
33
|
-
type: "address[]",
|
|
34
|
-
internalType: "address[]"
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
stateMutability: "view"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: "function",
|
|
41
|
-
name: "allowedOutputTokens",
|
|
42
|
-
inputs: [],
|
|
43
|
-
outputs: [
|
|
44
|
-
{
|
|
45
|
-
name: "",
|
|
46
|
-
type: "address[]",
|
|
47
|
-
internalType: "address[]"
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
|
-
stateMutability: "view"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
type: "function",
|
|
54
|
-
name: "allowedPhantomTokens",
|
|
55
|
-
inputs: [],
|
|
56
|
-
outputs: [
|
|
57
|
-
{
|
|
58
|
-
name: "",
|
|
59
|
-
type: "address[]",
|
|
60
|
-
internalType: "address[]"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
stateMutability: "view"
|
|
64
|
-
},
|
|
65
26
|
{
|
|
66
27
|
type: "function",
|
|
67
28
|
name: "contractType",
|
|
@@ -92,11 +53,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
92
53
|
type: "function",
|
|
93
54
|
name: "depositInstant",
|
|
94
55
|
inputs: [
|
|
95
|
-
{
|
|
96
|
-
name: "tokenIn",
|
|
97
|
-
type: "address",
|
|
98
|
-
internalType: "address"
|
|
99
|
-
},
|
|
100
56
|
{
|
|
101
57
|
name: "amountToken",
|
|
102
58
|
type: "uint256",
|
|
@@ -126,11 +82,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
126
82
|
type: "function",
|
|
127
83
|
name: "depositInstantDiff",
|
|
128
84
|
inputs: [
|
|
129
|
-
{
|
|
130
|
-
name: "tokenIn",
|
|
131
|
-
type: "address",
|
|
132
|
-
internalType: "address"
|
|
133
|
-
},
|
|
134
85
|
{
|
|
135
86
|
name: "leftoverAmount",
|
|
136
87
|
type: "uint256",
|
|
@@ -188,44 +139,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
188
139
|
],
|
|
189
140
|
stateMutability: "view"
|
|
190
141
|
},
|
|
191
|
-
{
|
|
192
|
-
type: "function",
|
|
193
|
-
name: "isInputTokenAllowed",
|
|
194
|
-
inputs: [
|
|
195
|
-
{
|
|
196
|
-
name: "token",
|
|
197
|
-
type: "address",
|
|
198
|
-
internalType: "address"
|
|
199
|
-
}
|
|
200
|
-
],
|
|
201
|
-
outputs: [
|
|
202
|
-
{
|
|
203
|
-
name: "",
|
|
204
|
-
type: "bool",
|
|
205
|
-
internalType: "bool"
|
|
206
|
-
}
|
|
207
|
-
],
|
|
208
|
-
stateMutability: "view"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
type: "function",
|
|
212
|
-
name: "isOutputTokenAllowed",
|
|
213
|
-
inputs: [
|
|
214
|
-
{
|
|
215
|
-
name: "token",
|
|
216
|
-
type: "address",
|
|
217
|
-
internalType: "address"
|
|
218
|
-
}
|
|
219
|
-
],
|
|
220
|
-
outputs: [
|
|
221
|
-
{
|
|
222
|
-
name: "",
|
|
223
|
-
type: "bool",
|
|
224
|
-
internalType: "bool"
|
|
225
|
-
}
|
|
226
|
-
],
|
|
227
|
-
stateMutability: "view"
|
|
228
|
-
},
|
|
229
142
|
{
|
|
230
143
|
type: "function",
|
|
231
144
|
name: "mToken",
|
|
@@ -241,14 +154,8 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
241
154
|
},
|
|
242
155
|
{
|
|
243
156
|
type: "function",
|
|
244
|
-
name: "
|
|
245
|
-
inputs: [
|
|
246
|
-
{
|
|
247
|
-
name: "outputToken",
|
|
248
|
-
type: "address",
|
|
249
|
-
internalType: "address"
|
|
250
|
-
}
|
|
251
|
-
],
|
|
157
|
+
name: "phantomToken",
|
|
158
|
+
inputs: [],
|
|
252
159
|
outputs: [
|
|
253
160
|
{
|
|
254
161
|
name: "",
|
|
@@ -260,14 +167,8 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
260
167
|
},
|
|
261
168
|
{
|
|
262
169
|
type: "function",
|
|
263
|
-
name: "
|
|
264
|
-
inputs: [
|
|
265
|
-
{
|
|
266
|
-
name: "phantomToken",
|
|
267
|
-
type: "address",
|
|
268
|
-
internalType: "address"
|
|
269
|
-
}
|
|
270
|
-
],
|
|
170
|
+
name: "quoteToken",
|
|
171
|
+
inputs: [],
|
|
271
172
|
outputs: [
|
|
272
173
|
{
|
|
273
174
|
name: "",
|
|
@@ -281,11 +182,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
281
182
|
type: "function",
|
|
282
183
|
name: "redeemInstant",
|
|
283
184
|
inputs: [
|
|
284
|
-
{
|
|
285
|
-
name: "tokenOut",
|
|
286
|
-
type: "address",
|
|
287
|
-
internalType: "address"
|
|
288
|
-
},
|
|
289
185
|
{
|
|
290
186
|
name: "amountMTokenIn",
|
|
291
187
|
type: "uint256",
|
|
@@ -310,11 +206,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
310
206
|
type: "function",
|
|
311
207
|
name: "redeemInstantDiff",
|
|
312
208
|
inputs: [
|
|
313
|
-
{
|
|
314
|
-
name: "tokenOut",
|
|
315
|
-
type: "address",
|
|
316
|
-
internalType: "address"
|
|
317
|
-
},
|
|
318
209
|
{
|
|
319
210
|
name: "leftoverAmount",
|
|
320
211
|
type: "uint256",
|
|
@@ -339,20 +230,10 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
339
230
|
type: "function",
|
|
340
231
|
name: "redeemRequest",
|
|
341
232
|
inputs: [
|
|
342
|
-
{
|
|
343
|
-
name: "tokenOut",
|
|
344
|
-
type: "address",
|
|
345
|
-
internalType: "address"
|
|
346
|
-
},
|
|
347
233
|
{
|
|
348
234
|
name: "amountMTokenIn",
|
|
349
235
|
type: "uint256",
|
|
350
236
|
internalType: "uint256"
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: "extraData",
|
|
354
|
-
type: "bytes",
|
|
355
|
-
internalType: "bytes"
|
|
356
237
|
}
|
|
357
238
|
],
|
|
358
239
|
outputs: [
|
|
@@ -368,15 +249,15 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
368
249
|
type: "function",
|
|
369
250
|
name: "redeemRequest",
|
|
370
251
|
inputs: [
|
|
371
|
-
{
|
|
372
|
-
name: "tokenOut",
|
|
373
|
-
type: "address",
|
|
374
|
-
internalType: "address"
|
|
375
|
-
},
|
|
376
252
|
{
|
|
377
253
|
name: "amountMTokenIn",
|
|
378
254
|
type: "uint256",
|
|
379
255
|
internalType: "uint256"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "extraData",
|
|
259
|
+
type: "bytes",
|
|
260
|
+
internalType: "bytes"
|
|
380
261
|
}
|
|
381
262
|
],
|
|
382
263
|
outputs: [
|
|
@@ -392,11 +273,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
392
273
|
type: "function",
|
|
393
274
|
name: "redeemRequestDiff",
|
|
394
275
|
inputs: [
|
|
395
|
-
{
|
|
396
|
-
name: "tokenOut",
|
|
397
|
-
type: "address",
|
|
398
|
-
internalType: "address"
|
|
399
|
-
},
|
|
400
276
|
{
|
|
401
277
|
name: "leftoverAmount",
|
|
402
278
|
type: "uint256",
|
|
@@ -416,11 +292,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
416
292
|
type: "function",
|
|
417
293
|
name: "redeemRequestDiff",
|
|
418
294
|
inputs: [
|
|
419
|
-
{
|
|
420
|
-
name: "tokenOut",
|
|
421
|
-
type: "address",
|
|
422
|
-
internalType: "address"
|
|
423
|
-
},
|
|
424
295
|
{
|
|
425
296
|
name: "leftoverAmount",
|
|
426
297
|
type: "uint256",
|
|
@@ -467,54 +338,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
467
338
|
],
|
|
468
339
|
stateMutability: "view"
|
|
469
340
|
},
|
|
470
|
-
{
|
|
471
|
-
type: "function",
|
|
472
|
-
name: "setInputTokenAllowedStatusBatch",
|
|
473
|
-
inputs: [
|
|
474
|
-
{
|
|
475
|
-
name: "tokens",
|
|
476
|
-
type: "address[]",
|
|
477
|
-
internalType: "address[]"
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
name: "allowed",
|
|
481
|
-
type: "bool[]",
|
|
482
|
-
internalType: "bool[]"
|
|
483
|
-
}
|
|
484
|
-
],
|
|
485
|
-
outputs: [],
|
|
486
|
-
stateMutability: "nonpayable"
|
|
487
|
-
},
|
|
488
|
-
{
|
|
489
|
-
type: "function",
|
|
490
|
-
name: "setOutputTokenAllowedStatusBatch",
|
|
491
|
-
inputs: [
|
|
492
|
-
{
|
|
493
|
-
name: "configs",
|
|
494
|
-
type: "tuple[]",
|
|
495
|
-
internalType: "struct IMidasGatewayAdapter.MidasAllowedTokenStatus[]",
|
|
496
|
-
components: [
|
|
497
|
-
{
|
|
498
|
-
name: "token",
|
|
499
|
-
type: "address",
|
|
500
|
-
internalType: "address"
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
name: "phantomToken",
|
|
504
|
-
type: "address",
|
|
505
|
-
internalType: "address"
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
name: "allowed",
|
|
509
|
-
type: "bool",
|
|
510
|
-
internalType: "bool"
|
|
511
|
-
}
|
|
512
|
-
]
|
|
513
|
-
}
|
|
514
|
-
],
|
|
515
|
-
outputs: [],
|
|
516
|
-
stateMutability: "nonpayable"
|
|
517
|
-
},
|
|
518
341
|
{
|
|
519
342
|
type: "function",
|
|
520
343
|
name: "targetContract",
|
|
@@ -569,11 +392,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
569
392
|
type: "function",
|
|
570
393
|
name: "withdraw",
|
|
571
394
|
inputs: [
|
|
572
|
-
{
|
|
573
|
-
name: "tokenOut",
|
|
574
|
-
type: "address",
|
|
575
|
-
internalType: "address"
|
|
576
|
-
},
|
|
577
395
|
{
|
|
578
396
|
name: "amount",
|
|
579
397
|
type: "uint256",
|
|
@@ -598,11 +416,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
598
416
|
type: "address",
|
|
599
417
|
internalType: "address"
|
|
600
418
|
},
|
|
601
|
-
{
|
|
602
|
-
name: "tokenOut",
|
|
603
|
-
type: "address",
|
|
604
|
-
internalType: "address"
|
|
605
|
-
},
|
|
606
419
|
{
|
|
607
420
|
name: "amount",
|
|
608
421
|
type: "uint256",
|
|
@@ -642,55 +455,6 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
642
455
|
],
|
|
643
456
|
stateMutability: "nonpayable"
|
|
644
457
|
},
|
|
645
|
-
{
|
|
646
|
-
type: "event",
|
|
647
|
-
name: "SetInputTokenAllowedStatus",
|
|
648
|
-
inputs: [
|
|
649
|
-
{
|
|
650
|
-
name: "token",
|
|
651
|
-
type: "address",
|
|
652
|
-
indexed: true,
|
|
653
|
-
internalType: "address"
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
name: "allowed",
|
|
657
|
-
type: "bool",
|
|
658
|
-
indexed: false,
|
|
659
|
-
internalType: "bool"
|
|
660
|
-
}
|
|
661
|
-
],
|
|
662
|
-
anonymous: false
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
type: "event",
|
|
666
|
-
name: "SetOutputTokenAllowedStatus",
|
|
667
|
-
inputs: [
|
|
668
|
-
{
|
|
669
|
-
name: "token",
|
|
670
|
-
type: "address",
|
|
671
|
-
indexed: true,
|
|
672
|
-
internalType: "address"
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
name: "phantomToken",
|
|
676
|
-
type: "address",
|
|
677
|
-
indexed: true,
|
|
678
|
-
internalType: "address"
|
|
679
|
-
},
|
|
680
|
-
{
|
|
681
|
-
name: "allowed",
|
|
682
|
-
type: "bool",
|
|
683
|
-
indexed: false,
|
|
684
|
-
internalType: "bool"
|
|
685
|
-
}
|
|
686
|
-
],
|
|
687
|
-
anonymous: false
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
type: "error",
|
|
691
|
-
name: "IncorrectArrayLengthException",
|
|
692
|
-
inputs: []
|
|
693
|
-
},
|
|
694
458
|
{
|
|
695
459
|
type: "error",
|
|
696
460
|
name: "IncorrectStakedPhantomTokenException",
|
|
@@ -698,12 +462,7 @@ const iMidasGatewayAdapterV311Abi = [
|
|
|
698
462
|
},
|
|
699
463
|
{
|
|
700
464
|
type: "error",
|
|
701
|
-
name: "
|
|
702
|
-
inputs: []
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
type: "error",
|
|
706
|
-
name: "TokenNotAllowedException",
|
|
465
|
+
name: "PhantomTokenNotSetException",
|
|
707
466
|
inputs: []
|
|
708
467
|
}
|
|
709
468
|
];
|
|
@@ -738,11 +497,6 @@ const iMidasGatewayV311Abi = [
|
|
|
738
497
|
type: "function",
|
|
739
498
|
name: "depositInstant",
|
|
740
499
|
inputs: [
|
|
741
|
-
{
|
|
742
|
-
name: "tokenIn",
|
|
743
|
-
type: "address",
|
|
744
|
-
internalType: "address"
|
|
745
|
-
},
|
|
746
500
|
{
|
|
747
501
|
name: "amountToken",
|
|
748
502
|
type: "uint256",
|
|
@@ -783,11 +537,6 @@ const iMidasGatewayV311Abi = [
|
|
|
783
537
|
name: "account",
|
|
784
538
|
type: "address",
|
|
785
539
|
internalType: "address"
|
|
786
|
-
},
|
|
787
|
-
{
|
|
788
|
-
name: "tokenOut",
|
|
789
|
-
type: "address",
|
|
790
|
-
internalType: "address"
|
|
791
540
|
}
|
|
792
541
|
],
|
|
793
542
|
outputs: [
|
|
@@ -825,13 +574,34 @@ const iMidasGatewayV311Abi = [
|
|
|
825
574
|
},
|
|
826
575
|
{
|
|
827
576
|
type: "function",
|
|
828
|
-
name: "
|
|
829
|
-
inputs: [
|
|
577
|
+
name: "phantomToken",
|
|
578
|
+
inputs: [],
|
|
579
|
+
outputs: [
|
|
830
580
|
{
|
|
831
|
-
name: "
|
|
581
|
+
name: "",
|
|
832
582
|
type: "address",
|
|
833
583
|
internalType: "address"
|
|
834
|
-
}
|
|
584
|
+
}
|
|
585
|
+
],
|
|
586
|
+
stateMutability: "view"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
type: "function",
|
|
590
|
+
name: "quoteToken",
|
|
591
|
+
inputs: [],
|
|
592
|
+
outputs: [
|
|
593
|
+
{
|
|
594
|
+
name: "",
|
|
595
|
+
type: "address",
|
|
596
|
+
internalType: "address"
|
|
597
|
+
}
|
|
598
|
+
],
|
|
599
|
+
stateMutability: "view"
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
type: "function",
|
|
603
|
+
name: "redeemInstant",
|
|
604
|
+
inputs: [
|
|
835
605
|
{
|
|
836
606
|
name: "amountMTokenIn",
|
|
837
607
|
type: "uint256",
|
|
@@ -863,11 +633,6 @@ const iMidasGatewayV311Abi = [
|
|
|
863
633
|
type: "function",
|
|
864
634
|
name: "requestRedeem",
|
|
865
635
|
inputs: [
|
|
866
|
-
{
|
|
867
|
-
name: "tokenOut",
|
|
868
|
-
type: "address",
|
|
869
|
-
internalType: "address"
|
|
870
|
-
},
|
|
871
636
|
{
|
|
872
637
|
name: "amountMTokenIn",
|
|
873
638
|
type: "uint256",
|
|
@@ -930,11 +695,6 @@ const iMidasGatewayV311Abi = [
|
|
|
930
695
|
type: "function",
|
|
931
696
|
name: "withdraw",
|
|
932
697
|
inputs: [
|
|
933
|
-
{
|
|
934
|
-
name: "tokenOut",
|
|
935
|
-
type: "address",
|
|
936
|
-
internalType: "address"
|
|
937
|
-
},
|
|
938
698
|
{
|
|
939
699
|
name: "amount",
|
|
940
700
|
type: "uint256",
|
|
@@ -953,11 +713,6 @@ const iMidasGatewayV311Abi = [
|
|
|
953
713
|
type: "address",
|
|
954
714
|
internalType: "address"
|
|
955
715
|
},
|
|
956
|
-
{
|
|
957
|
-
name: "tokenOut",
|
|
958
|
-
type: "address",
|
|
959
|
-
internalType: "address"
|
|
960
|
-
},
|
|
961
716
|
{
|
|
962
717
|
name: "amount",
|
|
963
718
|
type: "uint256",
|
|
@@ -977,6 +732,11 @@ const iMidasGatewayV311Abi = [
|
|
|
977
732
|
name: "CreditAccountNotEligibleException",
|
|
978
733
|
inputs: []
|
|
979
734
|
},
|
|
735
|
+
{
|
|
736
|
+
type: "error",
|
|
737
|
+
name: "IncompatibleAccessControlsException",
|
|
738
|
+
inputs: []
|
|
739
|
+
},
|
|
980
740
|
{
|
|
981
741
|
type: "error",
|
|
982
742
|
name: "IncompatibleIssuanceAndRedemptionVaultsException",
|
|
@@ -30,9 +30,9 @@ const protocolAbi = import_adapters.iMidasGatewayV311Abi;
|
|
|
30
30
|
class MidasGatewayAdapterContract extends import_AbstractAdapter.AbstractAdapterContract {
|
|
31
31
|
#gateway;
|
|
32
32
|
#mToken;
|
|
33
|
+
#quoteToken;
|
|
34
|
+
#phantomToken;
|
|
33
35
|
#referrerId;
|
|
34
|
-
#allowedInputTokens;
|
|
35
|
-
#allowedOutputTokens;
|
|
36
36
|
constructor(sdk, args) {
|
|
37
37
|
super(sdk, { ...args, abi, protocolAbi });
|
|
38
38
|
if (args.baseParams.serializedParams) {
|
|
@@ -42,21 +42,17 @@ class MidasGatewayAdapterContract extends import_AbstractAdapter.AbstractAdapter
|
|
|
42
42
|
{ type: "address", name: "targetContract" },
|
|
43
43
|
{ type: "address", name: "gateway" },
|
|
44
44
|
{ type: "address", name: "mToken" },
|
|
45
|
-
{ type: "
|
|
46
|
-
{ type: "address
|
|
47
|
-
{ type: "
|
|
48
|
-
{ type: "address[]", name: "allowedPhantomTokens" }
|
|
45
|
+
{ type: "address", name: "quoteToken" },
|
|
46
|
+
{ type: "address", name: "phantomToken" },
|
|
47
|
+
{ type: "bytes32", name: "referrerId" }
|
|
49
48
|
],
|
|
50
49
|
args.baseParams.serializedParams
|
|
51
50
|
);
|
|
52
51
|
this.#gateway = decoded[2];
|
|
53
52
|
this.#mToken = decoded[3];
|
|
54
|
-
this.#
|
|
55
|
-
this.#
|
|
56
|
-
this.#
|
|
57
|
-
token,
|
|
58
|
-
phantomToken: decoded[7][index]
|
|
59
|
-
}));
|
|
53
|
+
this.#quoteToken = decoded[4];
|
|
54
|
+
this.#phantomToken = decoded[5];
|
|
55
|
+
this.#referrerId = decoded[6];
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
58
|
get gateway() {
|
|
@@ -67,67 +63,72 @@ class MidasGatewayAdapterContract extends import_AbstractAdapter.AbstractAdapter
|
|
|
67
63
|
if (!this.#mToken) throw new import_sdk.MissingSerializedParamsError("mToken");
|
|
68
64
|
return this.#mToken;
|
|
69
65
|
}
|
|
66
|
+
get quoteToken() {
|
|
67
|
+
if (!this.#quoteToken) throw new import_sdk.MissingSerializedParamsError("quoteToken");
|
|
68
|
+
return this.#quoteToken;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Redemption phantom token; `zeroAddress` when the gateway was deployed
|
|
72
|
+
* without delayed withdrawals
|
|
73
|
+
*/
|
|
74
|
+
get phantomToken() {
|
|
75
|
+
if (!this.#phantomToken)
|
|
76
|
+
throw new import_sdk.MissingSerializedParamsError("phantomToken");
|
|
77
|
+
return this.#phantomToken;
|
|
78
|
+
}
|
|
70
79
|
get referrerId() {
|
|
71
80
|
if (this.#referrerId === void 0)
|
|
72
81
|
throw new import_sdk.MissingSerializedParamsError("referrerId");
|
|
73
82
|
return this.#referrerId;
|
|
74
83
|
}
|
|
75
|
-
get allowedInputTokens() {
|
|
76
|
-
if (!this.#allowedInputTokens)
|
|
77
|
-
throw new import_sdk.MissingSerializedParamsError("allowedInputTokens");
|
|
78
|
-
return this.#allowedInputTokens;
|
|
79
|
-
}
|
|
80
|
-
get allowedOutputTokens() {
|
|
81
|
-
if (!this.#allowedOutputTokens)
|
|
82
|
-
throw new import_sdk.MissingSerializedParamsError("allowedOutputTokens");
|
|
83
|
-
return this.#allowedOutputTokens;
|
|
84
|
-
}
|
|
85
84
|
stateHuman(raw) {
|
|
86
85
|
return {
|
|
87
86
|
...super.stateHuman(raw),
|
|
88
87
|
gateway: this.#gateway ? this.labelAddress(this.#gateway) : void 0,
|
|
89
88
|
mToken: this.#mToken ? this.labelAddress(this.#mToken) : void 0,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
),
|
|
94
|
-
allowedOutputTokens: this.#allowedOutputTokens?.map((t) => ({
|
|
95
|
-
token: this.labelAddress(t.token),
|
|
96
|
-
phantomToken: this.labelAddress(t.phantomToken)
|
|
97
|
-
}))
|
|
89
|
+
quoteToken: this.#quoteToken ? this.labelAddress(this.#quoteToken) : void 0,
|
|
90
|
+
phantomToken: this.#phantomToken ? this.labelAddress(this.#phantomToken) : void 0,
|
|
91
|
+
referrerId: this.#referrerId
|
|
98
92
|
};
|
|
99
93
|
}
|
|
100
94
|
/**
|
|
101
95
|
* `redeemRequest` (the only request call the withdrawal compressor emits)
|
|
102
|
-
* spends the mToken and mints the phantom token
|
|
103
|
-
*
|
|
104
|
-
*
|
|
96
|
+
* spends the mToken and mints the redemption phantom token; the quote token
|
|
97
|
+
* is received when the redemption is claimed. The 2-arg overload carries
|
|
98
|
+
* the intent `extraData`.
|
|
105
99
|
*/
|
|
106
100
|
parseDelayedWithdrawalRequest(calldata) {
|
|
107
101
|
const decoded = (0, import_viem.decodeFunctionData)({ abi: this.abi, data: calldata });
|
|
108
102
|
if (decoded.functionName !== "redeemRequest") {
|
|
109
103
|
return void 0;
|
|
110
104
|
}
|
|
111
|
-
|
|
112
|
-
const phantomToken = this.allowedOutputTokens.find(
|
|
113
|
-
(t) => (0, import_viem.isAddressEqual)(t.token, tokenOut)
|
|
114
|
-
)?.phantomToken;
|
|
115
|
-
if (!phantomToken) {
|
|
105
|
+
if ((0, import_viem.isAddressEqual)(this.phantomToken, import_viem.zeroAddress)) {
|
|
116
106
|
return void 0;
|
|
117
107
|
}
|
|
118
|
-
|
|
108
|
+
const [, extraData] = decoded.args;
|
|
109
|
+
return {
|
|
110
|
+
phantomToken: this.phantomToken,
|
|
111
|
+
claimToken: this.quoteToken,
|
|
112
|
+
extraData
|
|
113
|
+
};
|
|
119
114
|
}
|
|
120
115
|
async applyBalanceChanges(balances, decoded) {
|
|
121
116
|
switch (decoded.functionName) {
|
|
122
117
|
case "depositInstantDiff": {
|
|
123
|
-
const [
|
|
124
|
-
this.setLeftover(balances,
|
|
118
|
+
const [leftoverAmount] = decoded.args;
|
|
119
|
+
this.setLeftover(balances, this.quoteToken, leftoverAmount);
|
|
125
120
|
break;
|
|
126
121
|
}
|
|
127
|
-
// instant redemption spends the mToken down to the leftover
|
|
128
|
-
// arg is the received token
|
|
122
|
+
// instant redemption spends the mToken down to the leftover
|
|
129
123
|
case "redeemInstantDiff": {
|
|
130
|
-
const [
|
|
124
|
+
const [leftoverAmount] = decoded.args;
|
|
125
|
+
this.setLeftover(balances, this.mToken, leftoverAmount);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
// delayed redemption also spends the mToken down to the leftover (the
|
|
129
|
+
// minted phantom token is accounted for elsewhere)
|
|
130
|
+
case "redeemRequestDiff": {
|
|
131
|
+
const [leftoverAmount] = decoded.args;
|
|
131
132
|
this.setLeftover(balances, this.mToken, leftoverAmount);
|
|
132
133
|
break;
|
|
133
134
|
}
|
|
@@ -111,7 +111,11 @@ function buildClosePreview(post, converter) {
|
|
|
111
111
|
permanent: false,
|
|
112
112
|
creditManager: post.creditManager,
|
|
113
113
|
creditAccount: post.creditAccount,
|
|
114
|
-
|
|
114
|
+
// Oracle estimate denominated in the underlying
|
|
115
|
+
receivedAmount: {
|
|
116
|
+
token: post.underlying,
|
|
117
|
+
balance: import_common_utils.BigIntMath.max(totalValue - post.totalDebt, 0n)
|
|
118
|
+
},
|
|
115
119
|
error: converter.error
|
|
116
120
|
};
|
|
117
121
|
}
|
|
@@ -33,12 +33,12 @@ function isCloseOrRepay(multicall) {
|
|
|
33
33
|
);
|
|
34
34
|
return repaysFullDebt && withdrawsEverything;
|
|
35
35
|
}
|
|
36
|
-
function classifyCloseOrRepay(multicall,
|
|
36
|
+
function classifyCloseOrRepay(multicall, exitTokens) {
|
|
37
37
|
for (const op of multicall) {
|
|
38
38
|
if (op.operation === "AddCollateral") {
|
|
39
39
|
return "repay";
|
|
40
40
|
}
|
|
41
|
-
if (op.operation === "WithdrawCollateral" && !(0, import_viem.isAddressEqual)(op.token,
|
|
41
|
+
if (op.operation === "WithdrawCollateral" && !exitTokens.some((token) => (0, import_viem.isAddressEqual)(op.token, token))) {
|
|
42
42
|
return "repay";
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -30,8 +30,13 @@ async function previewCloseOrRepayCreditAccount(input, operation, permanent, opt
|
|
|
30
30
|
const market = sdk.marketRegister.findByCreditManager(
|
|
31
31
|
operation.creditManager
|
|
32
32
|
);
|
|
33
|
+
const exitTokens = [market.underlying];
|
|
34
|
+
const meta = sdk.tokensMeta.get(market.underlying);
|
|
35
|
+
if (meta && sdk.tokensMeta.isRWAUnderlying(meta)) {
|
|
36
|
+
exitTokens.push(meta.asset);
|
|
37
|
+
}
|
|
33
38
|
const replay = await (0, import_replayMulticall.replayMulticall)(sdk, operation, options);
|
|
34
|
-
const kind = (0, import_detectCloseOrRepay.classifyCloseOrRepay)(operation.multicall,
|
|
39
|
+
const kind = (0, import_detectCloseOrRepay.classifyCloseOrRepay)(operation.multicall, exitTokens);
|
|
35
40
|
return kind === "close" ? previewCloseCreditAccount(input, operation, permanent, replay) : previewRepayCreditAccount(input, operation, permanent, replay);
|
|
36
41
|
}
|
|
37
42
|
function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
@@ -40,6 +45,13 @@ function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
|
40
45
|
operation.creditManager
|
|
41
46
|
);
|
|
42
47
|
const { after, error } = replay;
|
|
48
|
+
let receivedToken = market.underlying;
|
|
49
|
+
for (const m of operation.multicall) {
|
|
50
|
+
if (m.operation === "WithdrawCollateral" && m.amount === import_sdk.MAX_UINT256) {
|
|
51
|
+
receivedToken = m.token;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
43
55
|
return {
|
|
44
56
|
operation: "CloseCreditAccount",
|
|
45
57
|
permanent,
|
|
@@ -47,7 +59,10 @@ function previewCloseCreditAccount(input, operation, permanent, replay) {
|
|
|
47
59
|
creditAccount: operation.creditAccount,
|
|
48
60
|
// On a malformed multicall the withdrawn amount depends on best-effort
|
|
49
61
|
// replayed balances and may be unreliable
|
|
50
|
-
receivedAmount:
|
|
62
|
+
receivedAmount: {
|
|
63
|
+
token: receivedToken,
|
|
64
|
+
balance: after.collateralWithdrawn.getOrZero(receivedToken)
|
|
65
|
+
},
|
|
51
66
|
error
|
|
52
67
|
};
|
|
53
68
|
}
|