@gearbox-protocol/sdk 14.12.0-next.32 → 14.12.0-next.34

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 (29) hide show
  1. package/dist/cjs/dev/withdrawalAbi.js +64 -70
  2. package/dist/cjs/dev/withdrawalUtils.js +1 -1
  3. package/dist/cjs/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
  4. package/dist/cjs/plugins/adapters/contracts/MidasGatewayAdapterContract.js +45 -44
  5. package/dist/cjs/preview/prerequisites/buildCollateralPrerequisites.js +39 -3
  6. package/dist/cjs/preview/prerequisites/checkPrerequisites.js +2 -1
  7. package/dist/cjs/preview/preview/buildDelayedPreview.js +9 -4
  8. package/dist/cjs/preview/preview/detectCloseOrRepay.js +2 -2
  9. package/dist/cjs/preview/preview/previewCloseOrRepayCreditAccount.js +17 -2
  10. package/dist/cjs/preview/preview/previewOperation.js +4 -1
  11. package/dist/esm/dev/withdrawalAbi.js +64 -70
  12. package/dist/esm/dev/withdrawalUtils.js +1 -1
  13. package/dist/esm/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.js +40 -280
  14. package/dist/esm/plugins/adapters/contracts/MidasGatewayAdapterContract.js +47 -45
  15. package/dist/esm/preview/prerequisites/buildCollateralPrerequisites.js +43 -4
  16. package/dist/esm/preview/prerequisites/checkPrerequisites.js +2 -1
  17. package/dist/esm/preview/preview/buildDelayedPreview.js +9 -4
  18. package/dist/esm/preview/preview/detectCloseOrRepay.js +2 -2
  19. package/dist/esm/preview/preview/previewCloseOrRepayCreditAccount.js +22 -3
  20. package/dist/esm/preview/preview/previewOperation.js +4 -1
  21. package/dist/types/dev/withdrawalAbi.d.ts +53 -57
  22. package/dist/types/plugins/adapters/abi/adapters/iMidasGatewayAdapterV311.d.ts +33 -219
  23. package/dist/types/plugins/adapters/contracts/MidasGatewayAdapterContract.d.ts +44 -232
  24. package/dist/types/preview/prerequisites/buildCollateralPrerequisites.d.ts +1 -0
  25. package/dist/types/preview/prerequisites/types.d.ts +10 -2
  26. package/dist/types/preview/preview/buildDelayedPreview.d.ts +7 -2
  27. package/dist/types/preview/preview/detectCloseOrRepay.d.ts +5 -3
  28. package/dist/types/preview/preview/types.d.ts +6 -4
  29. package/package.json +1 -1
@@ -1,43 +1,4 @@
1
1
  const iMidasGatewayAdapterV311Abi = [
2
- {
3
- type: "function",
4
- name: "allowedInputTokens",
5
- inputs: [],
6
- outputs: [
7
- {
8
- name: "",
9
- type: "address[]",
10
- internalType: "address[]"
11
- }
12
- ],
13
- stateMutability: "view"
14
- },
15
- {
16
- type: "function",
17
- name: "allowedOutputTokens",
18
- inputs: [],
19
- outputs: [
20
- {
21
- name: "",
22
- type: "address[]",
23
- internalType: "address[]"
24
- }
25
- ],
26
- stateMutability: "view"
27
- },
28
- {
29
- type: "function",
30
- name: "allowedPhantomTokens",
31
- inputs: [],
32
- outputs: [
33
- {
34
- name: "",
35
- type: "address[]",
36
- internalType: "address[]"
37
- }
38
- ],
39
- stateMutability: "view"
40
- },
41
2
  {
42
3
  type: "function",
43
4
  name: "contractType",
@@ -68,11 +29,6 @@ const iMidasGatewayAdapterV311Abi = [
68
29
  type: "function",
69
30
  name: "depositInstant",
70
31
  inputs: [
71
- {
72
- name: "tokenIn",
73
- type: "address",
74
- internalType: "address"
75
- },
76
32
  {
77
33
  name: "amountToken",
78
34
  type: "uint256",
@@ -102,11 +58,6 @@ const iMidasGatewayAdapterV311Abi = [
102
58
  type: "function",
103
59
  name: "depositInstantDiff",
104
60
  inputs: [
105
- {
106
- name: "tokenIn",
107
- type: "address",
108
- internalType: "address"
109
- },
110
61
  {
111
62
  name: "leftoverAmount",
112
63
  type: "uint256",
@@ -164,44 +115,6 @@ const iMidasGatewayAdapterV311Abi = [
164
115
  ],
165
116
  stateMutability: "view"
166
117
  },
167
- {
168
- type: "function",
169
- name: "isInputTokenAllowed",
170
- inputs: [
171
- {
172
- name: "token",
173
- type: "address",
174
- internalType: "address"
175
- }
176
- ],
177
- outputs: [
178
- {
179
- name: "",
180
- type: "bool",
181
- internalType: "bool"
182
- }
183
- ],
184
- stateMutability: "view"
185
- },
186
- {
187
- type: "function",
188
- name: "isOutputTokenAllowed",
189
- inputs: [
190
- {
191
- name: "token",
192
- type: "address",
193
- internalType: "address"
194
- }
195
- ],
196
- outputs: [
197
- {
198
- name: "",
199
- type: "bool",
200
- internalType: "bool"
201
- }
202
- ],
203
- stateMutability: "view"
204
- },
205
118
  {
206
119
  type: "function",
207
120
  name: "mToken",
@@ -217,14 +130,8 @@ const iMidasGatewayAdapterV311Abi = [
217
130
  },
218
131
  {
219
132
  type: "function",
220
- name: "outputTokenToPhantomToken",
221
- inputs: [
222
- {
223
- name: "outputToken",
224
- type: "address",
225
- internalType: "address"
226
- }
227
- ],
133
+ name: "phantomToken",
134
+ inputs: [],
228
135
  outputs: [
229
136
  {
230
137
  name: "",
@@ -236,14 +143,8 @@ const iMidasGatewayAdapterV311Abi = [
236
143
  },
237
144
  {
238
145
  type: "function",
239
- name: "phantomTokenToOutputToken",
240
- inputs: [
241
- {
242
- name: "phantomToken",
243
- type: "address",
244
- internalType: "address"
245
- }
246
- ],
146
+ name: "quoteToken",
147
+ inputs: [],
247
148
  outputs: [
248
149
  {
249
150
  name: "",
@@ -257,11 +158,6 @@ const iMidasGatewayAdapterV311Abi = [
257
158
  type: "function",
258
159
  name: "redeemInstant",
259
160
  inputs: [
260
- {
261
- name: "tokenOut",
262
- type: "address",
263
- internalType: "address"
264
- },
265
161
  {
266
162
  name: "amountMTokenIn",
267
163
  type: "uint256",
@@ -286,11 +182,6 @@ const iMidasGatewayAdapterV311Abi = [
286
182
  type: "function",
287
183
  name: "redeemInstantDiff",
288
184
  inputs: [
289
- {
290
- name: "tokenOut",
291
- type: "address",
292
- internalType: "address"
293
- },
294
185
  {
295
186
  name: "leftoverAmount",
296
187
  type: "uint256",
@@ -315,20 +206,10 @@ const iMidasGatewayAdapterV311Abi = [
315
206
  type: "function",
316
207
  name: "redeemRequest",
317
208
  inputs: [
318
- {
319
- name: "tokenOut",
320
- type: "address",
321
- internalType: "address"
322
- },
323
209
  {
324
210
  name: "amountMTokenIn",
325
211
  type: "uint256",
326
212
  internalType: "uint256"
327
- },
328
- {
329
- name: "extraData",
330
- type: "bytes",
331
- internalType: "bytes"
332
213
  }
333
214
  ],
334
215
  outputs: [
@@ -344,15 +225,15 @@ const iMidasGatewayAdapterV311Abi = [
344
225
  type: "function",
345
226
  name: "redeemRequest",
346
227
  inputs: [
347
- {
348
- name: "tokenOut",
349
- type: "address",
350
- internalType: "address"
351
- },
352
228
  {
353
229
  name: "amountMTokenIn",
354
230
  type: "uint256",
355
231
  internalType: "uint256"
232
+ },
233
+ {
234
+ name: "extraData",
235
+ type: "bytes",
236
+ internalType: "bytes"
356
237
  }
357
238
  ],
358
239
  outputs: [
@@ -368,11 +249,6 @@ const iMidasGatewayAdapterV311Abi = [
368
249
  type: "function",
369
250
  name: "redeemRequestDiff",
370
251
  inputs: [
371
- {
372
- name: "tokenOut",
373
- type: "address",
374
- internalType: "address"
375
- },
376
252
  {
377
253
  name: "leftoverAmount",
378
254
  type: "uint256",
@@ -392,11 +268,6 @@ const iMidasGatewayAdapterV311Abi = [
392
268
  type: "function",
393
269
  name: "redeemRequestDiff",
394
270
  inputs: [
395
- {
396
- name: "tokenOut",
397
- type: "address",
398
- internalType: "address"
399
- },
400
271
  {
401
272
  name: "leftoverAmount",
402
273
  type: "uint256",
@@ -443,54 +314,6 @@ const iMidasGatewayAdapterV311Abi = [
443
314
  ],
444
315
  stateMutability: "view"
445
316
  },
446
- {
447
- type: "function",
448
- name: "setInputTokenAllowedStatusBatch",
449
- inputs: [
450
- {
451
- name: "tokens",
452
- type: "address[]",
453
- internalType: "address[]"
454
- },
455
- {
456
- name: "allowed",
457
- type: "bool[]",
458
- internalType: "bool[]"
459
- }
460
- ],
461
- outputs: [],
462
- stateMutability: "nonpayable"
463
- },
464
- {
465
- type: "function",
466
- name: "setOutputTokenAllowedStatusBatch",
467
- inputs: [
468
- {
469
- name: "configs",
470
- type: "tuple[]",
471
- internalType: "struct IMidasGatewayAdapter.MidasAllowedTokenStatus[]",
472
- components: [
473
- {
474
- name: "token",
475
- type: "address",
476
- internalType: "address"
477
- },
478
- {
479
- name: "phantomToken",
480
- type: "address",
481
- internalType: "address"
482
- },
483
- {
484
- name: "allowed",
485
- type: "bool",
486
- internalType: "bool"
487
- }
488
- ]
489
- }
490
- ],
491
- outputs: [],
492
- stateMutability: "nonpayable"
493
- },
494
317
  {
495
318
  type: "function",
496
319
  name: "targetContract",
@@ -545,11 +368,6 @@ const iMidasGatewayAdapterV311Abi = [
545
368
  type: "function",
546
369
  name: "withdraw",
547
370
  inputs: [
548
- {
549
- name: "tokenOut",
550
- type: "address",
551
- internalType: "address"
552
- },
553
371
  {
554
372
  name: "amount",
555
373
  type: "uint256",
@@ -574,11 +392,6 @@ const iMidasGatewayAdapterV311Abi = [
574
392
  type: "address",
575
393
  internalType: "address"
576
394
  },
577
- {
578
- name: "tokenOut",
579
- type: "address",
580
- internalType: "address"
581
- },
582
395
  {
583
396
  name: "amount",
584
397
  type: "uint256",
@@ -618,55 +431,6 @@ const iMidasGatewayAdapterV311Abi = [
618
431
  ],
619
432
  stateMutability: "nonpayable"
620
433
  },
621
- {
622
- type: "event",
623
- name: "SetInputTokenAllowedStatus",
624
- inputs: [
625
- {
626
- name: "token",
627
- type: "address",
628
- indexed: true,
629
- internalType: "address"
630
- },
631
- {
632
- name: "allowed",
633
- type: "bool",
634
- indexed: false,
635
- internalType: "bool"
636
- }
637
- ],
638
- anonymous: false
639
- },
640
- {
641
- type: "event",
642
- name: "SetOutputTokenAllowedStatus",
643
- inputs: [
644
- {
645
- name: "token",
646
- type: "address",
647
- indexed: true,
648
- internalType: "address"
649
- },
650
- {
651
- name: "phantomToken",
652
- type: "address",
653
- indexed: true,
654
- internalType: "address"
655
- },
656
- {
657
- name: "allowed",
658
- type: "bool",
659
- indexed: false,
660
- internalType: "bool"
661
- }
662
- ],
663
- anonymous: false
664
- },
665
- {
666
- type: "error",
667
- name: "IncorrectArrayLengthException",
668
- inputs: []
669
- },
670
434
  {
671
435
  type: "error",
672
436
  name: "IncorrectStakedPhantomTokenException",
@@ -674,12 +438,7 @@ const iMidasGatewayAdapterV311Abi = [
674
438
  },
675
439
  {
676
440
  type: "error",
677
- name: "PhantomTokenTokenOutMismatchException",
678
- inputs: []
679
- },
680
- {
681
- type: "error",
682
- name: "TokenNotAllowedException",
441
+ name: "PhantomTokenNotSetException",
683
442
  inputs: []
684
443
  }
685
444
  ];
@@ -714,11 +473,6 @@ const iMidasGatewayV311Abi = [
714
473
  type: "function",
715
474
  name: "depositInstant",
716
475
  inputs: [
717
- {
718
- name: "tokenIn",
719
- type: "address",
720
- internalType: "address"
721
- },
722
476
  {
723
477
  name: "amountToken",
724
478
  type: "uint256",
@@ -759,11 +513,6 @@ const iMidasGatewayV311Abi = [
759
513
  name: "account",
760
514
  type: "address",
761
515
  internalType: "address"
762
- },
763
- {
764
- name: "tokenOut",
765
- type: "address",
766
- internalType: "address"
767
516
  }
768
517
  ],
769
518
  outputs: [
@@ -801,13 +550,34 @@ const iMidasGatewayV311Abi = [
801
550
  },
802
551
  {
803
552
  type: "function",
804
- name: "redeemInstant",
805
- inputs: [
553
+ name: "phantomToken",
554
+ inputs: [],
555
+ outputs: [
806
556
  {
807
- name: "tokenOut",
557
+ name: "",
808
558
  type: "address",
809
559
  internalType: "address"
810
- },
560
+ }
561
+ ],
562
+ stateMutability: "view"
563
+ },
564
+ {
565
+ type: "function",
566
+ name: "quoteToken",
567
+ inputs: [],
568
+ outputs: [
569
+ {
570
+ name: "",
571
+ type: "address",
572
+ internalType: "address"
573
+ }
574
+ ],
575
+ stateMutability: "view"
576
+ },
577
+ {
578
+ type: "function",
579
+ name: "redeemInstant",
580
+ inputs: [
811
581
  {
812
582
  name: "amountMTokenIn",
813
583
  type: "uint256",
@@ -839,11 +609,6 @@ const iMidasGatewayV311Abi = [
839
609
  type: "function",
840
610
  name: "requestRedeem",
841
611
  inputs: [
842
- {
843
- name: "tokenOut",
844
- type: "address",
845
- internalType: "address"
846
- },
847
612
  {
848
613
  name: "amountMTokenIn",
849
614
  type: "uint256",
@@ -906,11 +671,6 @@ const iMidasGatewayV311Abi = [
906
671
  type: "function",
907
672
  name: "withdraw",
908
673
  inputs: [
909
- {
910
- name: "tokenOut",
911
- type: "address",
912
- internalType: "address"
913
- },
914
674
  {
915
675
  name: "amount",
916
676
  type: "uint256",
@@ -929,11 +689,6 @@ const iMidasGatewayV311Abi = [
929
689
  type: "address",
930
690
  internalType: "address"
931
691
  },
932
- {
933
- name: "tokenOut",
934
- type: "address",
935
- internalType: "address"
936
- },
937
692
  {
938
693
  name: "amount",
939
694
  type: "uint256",
@@ -953,6 +708,11 @@ const iMidasGatewayV311Abi = [
953
708
  name: "CreditAccountNotEligibleException",
954
709
  inputs: []
955
710
  },
711
+ {
712
+ type: "error",
713
+ name: "IncompatibleAccessControlsException",
714
+ inputs: []
715
+ },
956
716
  {
957
717
  type: "error",
958
718
  name: "IncompatibleIssuanceAndRedemptionVaultsException",
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  decodeAbiParameters,
3
3
  decodeFunctionData,
4
- isAddressEqual
4
+ isAddressEqual,
5
+ zeroAddress
5
6
  } from "viem";
6
7
  import {
7
8
  MissingSerializedParamsError
@@ -16,9 +17,9 @@ const protocolAbi = iMidasGatewayV311Abi;
16
17
  class MidasGatewayAdapterContract extends AbstractAdapterContract {
17
18
  #gateway;
18
19
  #mToken;
20
+ #quoteToken;
21
+ #phantomToken;
19
22
  #referrerId;
20
- #allowedInputTokens;
21
- #allowedOutputTokens;
22
23
  constructor(sdk, args) {
23
24
  super(sdk, { ...args, abi, protocolAbi });
24
25
  if (args.baseParams.serializedParams) {
@@ -28,21 +29,17 @@ class MidasGatewayAdapterContract extends AbstractAdapterContract {
28
29
  { type: "address", name: "targetContract" },
29
30
  { type: "address", name: "gateway" },
30
31
  { type: "address", name: "mToken" },
31
- { type: "bytes32", name: "referrerId" },
32
- { type: "address[]", name: "allowedInputTokens" },
33
- { type: "address[]", name: "allowedOutputTokens" },
34
- { type: "address[]", name: "allowedPhantomTokens" }
32
+ { type: "address", name: "quoteToken" },
33
+ { type: "address", name: "phantomToken" },
34
+ { type: "bytes32", name: "referrerId" }
35
35
  ],
36
36
  args.baseParams.serializedParams
37
37
  );
38
38
  this.#gateway = decoded[2];
39
39
  this.#mToken = decoded[3];
40
- this.#referrerId = decoded[4];
41
- this.#allowedInputTokens = [...decoded[5]];
42
- this.#allowedOutputTokens = decoded[6].map((token, index) => ({
43
- token,
44
- phantomToken: decoded[7][index]
45
- }));
40
+ this.#quoteToken = decoded[4];
41
+ this.#phantomToken = decoded[5];
42
+ this.#referrerId = decoded[6];
46
43
  }
47
44
  }
48
45
  get gateway() {
@@ -53,67 +50,72 @@ class MidasGatewayAdapterContract extends AbstractAdapterContract {
53
50
  if (!this.#mToken) throw new MissingSerializedParamsError("mToken");
54
51
  return this.#mToken;
55
52
  }
53
+ get quoteToken() {
54
+ if (!this.#quoteToken) throw new MissingSerializedParamsError("quoteToken");
55
+ return this.#quoteToken;
56
+ }
57
+ /**
58
+ * Redemption phantom token; `zeroAddress` when the gateway was deployed
59
+ * without delayed withdrawals
60
+ */
61
+ get phantomToken() {
62
+ if (!this.#phantomToken)
63
+ throw new MissingSerializedParamsError("phantomToken");
64
+ return this.#phantomToken;
65
+ }
56
66
  get referrerId() {
57
67
  if (this.#referrerId === void 0)
58
68
  throw new MissingSerializedParamsError("referrerId");
59
69
  return this.#referrerId;
60
70
  }
61
- get allowedInputTokens() {
62
- if (!this.#allowedInputTokens)
63
- throw new MissingSerializedParamsError("allowedInputTokens");
64
- return this.#allowedInputTokens;
65
- }
66
- get allowedOutputTokens() {
67
- if (!this.#allowedOutputTokens)
68
- throw new MissingSerializedParamsError("allowedOutputTokens");
69
- return this.#allowedOutputTokens;
70
- }
71
71
  stateHuman(raw) {
72
72
  return {
73
73
  ...super.stateHuman(raw),
74
74
  gateway: this.#gateway ? this.labelAddress(this.#gateway) : void 0,
75
75
  mToken: this.#mToken ? this.labelAddress(this.#mToken) : void 0,
76
- referrerId: this.#referrerId,
77
- allowedInputTokens: this.#allowedInputTokens?.map(
78
- (t) => this.labelAddress(t)
79
- ),
80
- allowedOutputTokens: this.#allowedOutputTokens?.map((t) => ({
81
- token: this.labelAddress(t.token),
82
- phantomToken: this.labelAddress(t.phantomToken)
83
- }))
76
+ quoteToken: this.#quoteToken ? this.labelAddress(this.#quoteToken) : void 0,
77
+ phantomToken: this.#phantomToken ? this.labelAddress(this.#phantomToken) : void 0,
78
+ referrerId: this.#referrerId
84
79
  };
85
80
  }
86
81
  /**
87
82
  * `redeemRequest` (the only request call the withdrawal compressor emits)
88
- * spends the mToken and mints the phantom token of the requested
89
- * `tokenOut`, which is received when the redemption is claimed. The 3-arg
90
- * overload carries the intent `extraData`.
83
+ * spends the mToken and mints the redemption phantom token; the quote token
84
+ * is received when the redemption is claimed. The 2-arg overload carries
85
+ * the intent `extraData`.
91
86
  */
92
87
  parseDelayedWithdrawalRequest(calldata) {
93
88
  const decoded = decodeFunctionData({ abi: this.abi, data: calldata });
94
89
  if (decoded.functionName !== "redeemRequest") {
95
90
  return void 0;
96
91
  }
97
- const [tokenOut, , extraData] = decoded.args;
98
- const phantomToken = this.allowedOutputTokens.find(
99
- (t) => isAddressEqual(t.token, tokenOut)
100
- )?.phantomToken;
101
- if (!phantomToken) {
92
+ if (isAddressEqual(this.phantomToken, zeroAddress)) {
102
93
  return void 0;
103
94
  }
104
- return { phantomToken, claimToken: tokenOut, extraData };
95
+ const [, extraData] = decoded.args;
96
+ return {
97
+ phantomToken: this.phantomToken,
98
+ claimToken: this.quoteToken,
99
+ extraData
100
+ };
105
101
  }
106
102
  async applyBalanceChanges(balances, decoded) {
107
103
  switch (decoded.functionName) {
108
104
  case "depositInstantDiff": {
109
- const [tokenIn, leftoverAmount] = decoded.args;
110
- this.setLeftover(balances, tokenIn, leftoverAmount);
105
+ const [leftoverAmount] = decoded.args;
106
+ this.setLeftover(balances, this.quoteToken, leftoverAmount);
111
107
  break;
112
108
  }
113
- // instant redemption spends the mToken down to the leftover, tokenOut
114
- // arg is the received token
109
+ // instant redemption spends the mToken down to the leftover
115
110
  case "redeemInstantDiff": {
116
- const [, leftoverAmount] = decoded.args;
111
+ const [leftoverAmount] = decoded.args;
112
+ this.setLeftover(balances, this.mToken, leftoverAmount);
113
+ break;
114
+ }
115
+ // delayed redemption also spends the mToken down to the leftover (the
116
+ // minted phantom token is accounted for elsewhere)
117
+ case "redeemRequestDiff": {
118
+ const [leftoverAmount] = decoded.args;
117
119
  this.setLeftover(balances, this.mToken, leftoverAmount);
118
120
  break;
119
121
  }
@@ -1,9 +1,15 @@
1
+ import { isAddressEqual } from "viem";
1
2
  import {
2
- AssetsMap
3
+ AP_WETH_TOKEN,
4
+ AssetsMap,
5
+ NATIVE_ADDRESS,
6
+ NO_VERSION
3
7
  } from "../../sdk/index.js";
8
+ import { AllowancePrerequisite } from "./AllowancePrerequisite.js";
9
+ import { BalancePrerequisite } from "./BalancePrerequisite.js";
4
10
  import { allowanceAndBalance } from "./helpers.js";
5
11
  async function buildCollateralPrerequisites(spenderOptions, multicall, ctx) {
6
- const { sdk, wallet } = ctx;
12
+ const { sdk, wallet, value = 0n } = ctx;
7
13
  const required = new AssetsMap();
8
14
  for (const op of multicall) {
9
15
  if (op.operation !== "AddCollateral" || op.amount === 0n) {
@@ -11,12 +17,45 @@ async function buildCollateralPrerequisites(spenderOptions, multicall, ctx) {
11
17
  }
12
18
  required.inc(op.token, op.amount);
13
19
  }
14
- if (required.size === 0) {
20
+ if (required.size === 0 && value === 0n) {
15
21
  return [];
16
22
  }
17
- const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
18
23
  const prereqs = [];
24
+ if (value > 0n) {
25
+ prereqs.push(
26
+ new BalancePrerequisite({
27
+ token: NATIVE_ADDRESS,
28
+ owner: wallet,
29
+ required: value
30
+ })
31
+ );
32
+ }
33
+ if (required.size === 0) {
34
+ return prereqs;
35
+ }
36
+ const spender = await sdk.accounts.getApprovalAddress(spenderOptions);
37
+ const weth = sdk.addressProvider.getAddress(AP_WETH_TOKEN, NO_VERSION);
19
38
  for (const [token, amount] of required.entries()) {
39
+ if (value > 0n && isAddressEqual(token, weth)) {
40
+ prereqs.push(
41
+ new AllowancePrerequisite({
42
+ token,
43
+ owner: wallet,
44
+ spender,
45
+ required: amount
46
+ })
47
+ );
48
+ if (amount > value) {
49
+ prereqs.push(
50
+ new BalancePrerequisite({
51
+ token,
52
+ owner: wallet,
53
+ required: amount - value
54
+ })
55
+ );
56
+ }
57
+ continue;
58
+ }
20
59
  prereqs.push(
21
60
  ...allowanceAndBalance({
22
61
  token,
@@ -9,7 +9,8 @@ async function checkPrerequisites(input, options) {
9
9
  const ctx = {
10
10
  sdk,
11
11
  wallet,
12
- blockNumber: options?.blockNumber
12
+ blockNumber: options?.blockNumber,
13
+ value: input.value ?? 0n
13
14
  };
14
15
  const prereqs = await buildPrerequisites(tx, ctx);
15
16
  return Promise.all(prereqs.map((p) => p.verify(ctx)));