@vetro-protocol/gateway 1.3.0 → 1.3.1

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 (102) hide show
  1. package/_esm/actions/index.js +49 -21
  2. package/_esm/actions/index.js.map +7 -1
  3. package/_esm/chunk-ZE4YZMXK.js +1326 -0
  4. package/_esm/chunk-ZE4YZMXK.js.map +7 -0
  5. package/_esm/index.js +57 -31
  6. package/_esm/index.js.map +7 -1
  7. package/_types/actions/index.d.ts +18 -18
  8. package/_types/actions/public/getGateway.d.ts.map +1 -1
  9. package/_types/actions/public/getMaxMint.d.ts.map +1 -1
  10. package/_types/actions/public/getMaxWithdraw.d.ts.map +1 -1
  11. package/_types/actions/public/getMintFee.d.ts.map +1 -1
  12. package/_types/actions/public/getPeggedToken.d.ts.map +1 -1
  13. package/_types/actions/public/getRedeemFee.d.ts.map +1 -1
  14. package/_types/actions/public/getRedeemRequest.d.ts.map +1 -1
  15. package/_types/actions/public/getTreasury.d.ts.map +1 -1
  16. package/_types/actions/public/getWithdrawalDelay.d.ts.map +1 -1
  17. package/_types/actions/public/getWithdrawalDelayEnabled.d.ts.map +1 -1
  18. package/_types/actions/public/index.d.ts +14 -14
  19. package/_types/actions/public/isInstantRedeemWhitelisted.d.ts.map +1 -1
  20. package/_types/actions/public/previewDeposit.d.ts.map +1 -1
  21. package/_types/actions/public/previewRedeem.d.ts.map +1 -1
  22. package/_types/actions/public/previewWithdraw.d.ts.map +1 -1
  23. package/_types/actions/wallet/cancelRedeemRequest.d.ts +1 -1
  24. package/_types/actions/wallet/deposit.d.ts +1 -1
  25. package/_types/actions/wallet/redeem.d.ts +1 -1
  26. package/_types/actions/wallet/requestRedeem.d.ts +1 -1
  27. package/_types/gatewayAddresses.d.ts.map +1 -1
  28. package/_types/index.d.ts +12 -12
  29. package/package.json +7 -5
  30. package/src/actions/index.ts +18 -18
  31. package/src/actions/public/getGateway.ts +2 -2
  32. package/src/actions/public/getMaxMint.ts +2 -2
  33. package/src/actions/public/getMaxWithdraw.ts +2 -2
  34. package/src/actions/public/getMintFee.ts +2 -2
  35. package/src/actions/public/getPeggedToken.ts +2 -2
  36. package/src/actions/public/getRedeemFee.ts +2 -2
  37. package/src/actions/public/getRedeemRequest.ts +2 -2
  38. package/src/actions/public/getTreasury.ts +2 -2
  39. package/src/actions/public/getWithdrawalDelay.ts +2 -2
  40. package/src/actions/public/getWithdrawalDelayEnabled.ts +2 -2
  41. package/src/actions/public/index.ts +14 -14
  42. package/src/actions/public/isInstantRedeemWhitelisted.ts +2 -2
  43. package/src/actions/public/previewDeposit.ts +2 -2
  44. package/src/actions/public/previewRedeem.ts +2 -2
  45. package/src/actions/public/previewWithdraw.ts +2 -2
  46. package/src/actions/wallet/cancelRedeemRequest.ts +2 -2
  47. package/src/actions/wallet/deposit.ts +2 -2
  48. package/src/actions/wallet/redeem.ts +6 -6
  49. package/src/actions/wallet/requestRedeem.ts +3 -3
  50. package/src/gatewayAddresses.ts +6 -17
  51. package/src/index.ts +8 -8
  52. package/_esm/abi/gatewayAbi.js +0 -223
  53. package/_esm/abi/gatewayAbi.js.map +0 -1
  54. package/_esm/abi/peggedTokenAbi.js +0 -10
  55. package/_esm/abi/peggedTokenAbi.js.map +0 -1
  56. package/_esm/actions/public/getGateway.js +0 -30
  57. package/_esm/actions/public/getGateway.js.map +0 -1
  58. package/_esm/actions/public/getMaxMint.js +0 -23
  59. package/_esm/actions/public/getMaxMint.js.map +0 -1
  60. package/_esm/actions/public/getMaxWithdraw.js +0 -28
  61. package/_esm/actions/public/getMaxWithdraw.js.map +0 -1
  62. package/_esm/actions/public/getMintFee.js +0 -28
  63. package/_esm/actions/public/getMintFee.js.map +0 -1
  64. package/_esm/actions/public/getPeggedToken.js +0 -23
  65. package/_esm/actions/public/getPeggedToken.js.map +0 -1
  66. package/_esm/actions/public/getRedeemFee.js +0 -28
  67. package/_esm/actions/public/getRedeemFee.js.map +0 -1
  68. package/_esm/actions/public/getRedeemRequest.js +0 -28
  69. package/_esm/actions/public/getRedeemRequest.js.map +0 -1
  70. package/_esm/actions/public/getTreasury.js +0 -23
  71. package/_esm/actions/public/getTreasury.js.map +0 -1
  72. package/_esm/actions/public/getWithdrawalDelay.js +0 -23
  73. package/_esm/actions/public/getWithdrawalDelay.js.map +0 -1
  74. package/_esm/actions/public/getWithdrawalDelayEnabled.js +0 -23
  75. package/_esm/actions/public/getWithdrawalDelayEnabled.js.map +0 -1
  76. package/_esm/actions/public/index.js +0 -15
  77. package/_esm/actions/public/index.js.map +0 -1
  78. package/_esm/actions/public/isInstantRedeemWhitelisted.js +0 -28
  79. package/_esm/actions/public/isInstantRedeemWhitelisted.js.map +0 -1
  80. package/_esm/actions/public/previewDeposit.js +0 -35
  81. package/_esm/actions/public/previewDeposit.js.map +0 -1
  82. package/_esm/actions/public/previewRedeem.js +0 -35
  83. package/_esm/actions/public/previewRedeem.js.map +0 -1
  84. package/_esm/actions/public/previewWithdraw.js +0 -35
  85. package/_esm/actions/public/previewWithdraw.js.map +0 -1
  86. package/_esm/actions/wallet/cancelRedeemRequest.js +0 -89
  87. package/_esm/actions/wallet/cancelRedeemRequest.js.map +0 -1
  88. package/_esm/actions/wallet/deposit.js +0 -193
  89. package/_esm/actions/wallet/deposit.js.map +0 -1
  90. package/_esm/actions/wallet/redeem.js +0 -226
  91. package/_esm/actions/wallet/redeem.js.map +0 -1
  92. package/_esm/actions/wallet/requestRedeem.js +0 -153
  93. package/_esm/actions/wallet/requestRedeem.js.map +0 -1
  94. package/_esm/gatewayAddresses.js +0 -18
  95. package/_esm/gatewayAddresses.js.map +0 -1
  96. package/_esm/types.js +0 -2
  97. package/_esm/types.js.map +0 -1
  98. package/_esm/utils/isAddressValid.js +0 -3
  99. package/_esm/utils/isAddressValid.js.map +0 -1
  100. package/_types/utils/isAddressValid.d.ts +0 -3
  101. package/_types/utils/isAddressValid.d.ts.map +0 -1
  102. package/src/utils/isAddressValid.ts +0 -4
@@ -0,0 +1,1326 @@
1
+ // ../core/src/stakingVaultAddresses.ts
2
+ var sVusdAddress = "0x476310E34D2810f7d79C43A74E4D79405bd7a925";
3
+ var sVetBtcAddress = "0x0cB9D84d4bcEc8d3D5B2d99a6F07f4605325987e";
4
+
5
+ // ../core/src/protocolGraph.ts
6
+ var gateways = [
7
+ {
8
+ // VUSD gateway
9
+ address: "0xDaD503f8B9d42bb7af3AfC588358D30163e4416F",
10
+ pegBaseSymbol: "USD",
11
+ // VUSD
12
+ peggedToken: "0xCa83DDE9c22254f58e771bE5E157773212AcBAc3",
13
+ stakingVault: sVusdAddress,
14
+ treasury: "0xC8317A10385BE07901A4c9ee3d06E1D83AE378c9",
15
+ whitelistedTokens: [
16
+ // USDT
17
+ "0xdAC17F958D2ee523a2206206994597C13D831ec7",
18
+ // USDC
19
+ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
20
+ // frxUSD
21
+ "0xCAcd6fd266aF91b8AeD52aCCc382b4e165586E29"
22
+ ]
23
+ },
24
+ {
25
+ // vetBTC gateway
26
+ address: "0xCBA2Ffa0AC52d7871a4221a871793Eb788013faB",
27
+ pegBaseSymbol: "BTC",
28
+ // vetBTC
29
+ peggedToken: "0xf196C68233464A16CFDa319a47c21f4cECa62001",
30
+ stakingVault: sVetBtcAddress,
31
+ treasury: "0xd25a7b0b817fD816d0995eC67fb70e75EE65Bd7F",
32
+ whitelistedTokens: [
33
+ // WBTC
34
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
35
+ // cbBTC
36
+ "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
37
+ // hemiBTC
38
+ "0x06ea695B91700071B161A434fED42D1DcbAD9f00"
39
+ ]
40
+ }
41
+ ];
42
+ var gatewayAddresses = gateways.map(
43
+ (gateway) => gateway.address
44
+ );
45
+
46
+ // ../core/src/utils/isAddressValid.ts
47
+ import { isAddress, isAddressEqual, zeroAddress } from "viem";
48
+ var isAddressValid = (address) => !!address && isAddress(address) && !isAddressEqual(address, zeroAddress);
49
+
50
+ // src/actions/public/getGateway.ts
51
+ import { readContract } from "viem/actions";
52
+
53
+ // src/abi/peggedTokenAbi.ts
54
+ var peggedTokenAbi = [
55
+ {
56
+ inputs: [],
57
+ name: "gateway",
58
+ outputs: [{ type: "address" }],
59
+ stateMutability: "view",
60
+ type: "function"
61
+ }
62
+ ];
63
+
64
+ // src/actions/public/getGateway.ts
65
+ async function getGateway(client, parameters) {
66
+ if (!client) {
67
+ throw new Error("Client is not defined");
68
+ }
69
+ if (!parameters) {
70
+ throw new Error("Parameters are required");
71
+ }
72
+ if (!isAddressValid(parameters.address)) {
73
+ throw new Error("Pegged token is invalid");
74
+ }
75
+ return readContract(client, {
76
+ abi: peggedTokenAbi,
77
+ address: parameters.address,
78
+ functionName: "gateway"
79
+ });
80
+ }
81
+
82
+ // src/abi/gatewayAbi.ts
83
+ var gatewayAbi = [
84
+ {
85
+ inputs: [],
86
+ name: "PEGGED_TOKEN",
87
+ outputs: [{ type: "address" }],
88
+ stateMutability: "view",
89
+ type: "function"
90
+ },
91
+ {
92
+ inputs: [{ name: "token_", type: "address" }],
93
+ name: "mintFee",
94
+ outputs: [{ type: "uint256" }],
95
+ stateMutability: "view",
96
+ type: "function"
97
+ },
98
+ {
99
+ inputs: [],
100
+ name: "mintLimit",
101
+ outputs: [{ type: "uint256" }],
102
+ stateMutability: "view",
103
+ type: "function"
104
+ },
105
+ {
106
+ inputs: [],
107
+ name: "owner",
108
+ outputs: [{ type: "address" }],
109
+ stateMutability: "view",
110
+ type: "function"
111
+ },
112
+ {
113
+ inputs: [{ name: "token_", type: "address" }],
114
+ name: "redeemFee",
115
+ outputs: [{ type: "uint256" }],
116
+ stateMutability: "view",
117
+ type: "function"
118
+ },
119
+ {
120
+ inputs: [],
121
+ name: "treasury",
122
+ outputs: [{ type: "address" }],
123
+ stateMutability: "view",
124
+ type: "function"
125
+ },
126
+ {
127
+ inputs: [],
128
+ name: "withdrawalDelayEnabled",
129
+ outputs: [{ type: "bool" }],
130
+ stateMutability: "view",
131
+ type: "function"
132
+ },
133
+ {
134
+ inputs: [],
135
+ name: "withdrawalDelay",
136
+ outputs: [{ type: "uint256" }],
137
+ stateMutability: "view",
138
+ type: "function"
139
+ },
140
+ {
141
+ inputs: [{ name: "user_", type: "address" }],
142
+ name: "getRedeemRequest",
143
+ outputs: [
144
+ { name: "amountLocked", type: "uint256" },
145
+ { name: "claimableAt", type: "uint256" }
146
+ ],
147
+ stateMutability: "view",
148
+ type: "function"
149
+ },
150
+ {
151
+ inputs: [{ name: "account_", type: "address" }],
152
+ name: "isInstantRedeemWhitelisted",
153
+ outputs: [{ type: "bool" }],
154
+ stateMutability: "view",
155
+ type: "function"
156
+ },
157
+ {
158
+ inputs: [],
159
+ name: "maxMint",
160
+ outputs: [{ type: "uint256" }],
161
+ stateMutability: "view",
162
+ type: "function"
163
+ },
164
+ {
165
+ inputs: [{ name: "tokenOut_", type: "address" }],
166
+ name: "maxWithdraw",
167
+ outputs: [{ type: "uint256" }],
168
+ stateMutability: "view",
169
+ type: "function"
170
+ },
171
+ {
172
+ inputs: [{ name: "account_", type: "address" }],
173
+ name: "addToInstantRedeemWhitelist",
174
+ outputs: [],
175
+ stateMutability: "nonpayable",
176
+ type: "function"
177
+ },
178
+ {
179
+ inputs: [{ name: "account_", type: "address" }],
180
+ name: "removeFromInstantRedeemWhitelist",
181
+ outputs: [],
182
+ stateMutability: "nonpayable",
183
+ type: "function"
184
+ },
185
+ {
186
+ inputs: [
187
+ { name: "tokenIn_", type: "address" },
188
+ { name: "amountIn_", type: "uint256" }
189
+ ],
190
+ name: "previewDeposit",
191
+ outputs: [{ type: "uint256" }],
192
+ stateMutability: "view",
193
+ type: "function"
194
+ },
195
+ {
196
+ inputs: [
197
+ { name: "tokenOut_", type: "address" },
198
+ { name: "peggedTokenIn_", type: "uint256" }
199
+ ],
200
+ name: "previewRedeem",
201
+ outputs: [{ type: "uint256" }],
202
+ stateMutability: "view",
203
+ type: "function"
204
+ },
205
+ {
206
+ inputs: [
207
+ { name: "tokenOut_", type: "address" },
208
+ { name: "amountOut_", type: "uint256" }
209
+ ],
210
+ name: "previewWithdraw",
211
+ outputs: [{ type: "uint256" }],
212
+ stateMutability: "view",
213
+ type: "function"
214
+ },
215
+ {
216
+ inputs: [],
217
+ name: "cancelRedeemRequest",
218
+ outputs: [],
219
+ stateMutability: "nonpayable",
220
+ type: "function"
221
+ },
222
+ {
223
+ inputs: [
224
+ { name: "tokenIn_", type: "address" },
225
+ { name: "amountIn_", type: "uint256" },
226
+ { name: "minPeggedTokenOut_", type: "uint256" },
227
+ { name: "receiver_", type: "address" }
228
+ ],
229
+ name: "deposit",
230
+ outputs: [{ type: "uint256" }],
231
+ stateMutability: "nonpayable",
232
+ type: "function"
233
+ },
234
+ {
235
+ inputs: [
236
+ { name: "tokenOut_", type: "address" },
237
+ { name: "peggedTokenIn_", type: "uint256" },
238
+ { name: "minAmountOut_", type: "uint256" },
239
+ { name: "receiver_", type: "address" }
240
+ ],
241
+ name: "redeem",
242
+ outputs: [{ type: "uint256" }],
243
+ stateMutability: "nonpayable",
244
+ type: "function"
245
+ },
246
+ {
247
+ inputs: [{ name: "peggedTokenAmount_", type: "uint256" }],
248
+ name: "requestRedeem",
249
+ outputs: [],
250
+ stateMutability: "nonpayable",
251
+ type: "function"
252
+ },
253
+ {
254
+ inputs: [{ name: "enabled_", type: "bool" }],
255
+ name: "setWithdrawalDelayEnabled",
256
+ outputs: [],
257
+ stateMutability: "nonpayable",
258
+ type: "function"
259
+ },
260
+ {
261
+ inputs: [
262
+ { name: "token_", type: "address" },
263
+ { name: "newMintFee_", type: "uint256" }
264
+ ],
265
+ name: "updateMintFee",
266
+ outputs: [],
267
+ stateMutability: "nonpayable",
268
+ type: "function"
269
+ },
270
+ {
271
+ inputs: [{ name: "newMintLimit_", type: "uint256" }],
272
+ name: "updateMintLimit",
273
+ outputs: [],
274
+ stateMutability: "nonpayable",
275
+ type: "function"
276
+ },
277
+ {
278
+ inputs: [
279
+ { name: "token_", type: "address" },
280
+ { name: "newRedeemFee_", type: "uint256" }
281
+ ],
282
+ name: "updateRedeemFee",
283
+ outputs: [],
284
+ stateMutability: "nonpayable",
285
+ type: "function"
286
+ },
287
+ {
288
+ inputs: [{ name: "newDelay_", type: "uint256" }],
289
+ name: "updateWithdrawalDelay",
290
+ outputs: [],
291
+ stateMutability: "nonpayable",
292
+ type: "function"
293
+ },
294
+ {
295
+ anonymous: false,
296
+ inputs: [
297
+ { indexed: true, name: "user", type: "address" },
298
+ { indexed: false, name: "amount", type: "uint256" },
299
+ { indexed: false, name: "claimableAt", type: "uint256" }
300
+ ],
301
+ name: "RedeemRequested",
302
+ type: "event"
303
+ }
304
+ ];
305
+
306
+ // src/actions/public/getMaxMint.ts
307
+ import { readContract as readContract2 } from "viem/actions";
308
+ async function getMaxMint(client, parameters) {
309
+ if (!client) {
310
+ throw new Error("Client is not defined");
311
+ }
312
+ if (!parameters) {
313
+ throw new Error("Parameters are required");
314
+ }
315
+ if (!isAddressValid(parameters.address)) {
316
+ throw new Error("Gateway is invalid");
317
+ }
318
+ return readContract2(client, {
319
+ abi: gatewayAbi,
320
+ address: parameters.address,
321
+ functionName: "maxMint"
322
+ });
323
+ }
324
+
325
+ // src/actions/public/getMaxWithdraw.ts
326
+ import { readContract as readContract3 } from "viem/actions";
327
+ async function getMaxWithdraw(client, parameters) {
328
+ if (!client) {
329
+ throw new Error("Client is not defined");
330
+ }
331
+ if (!parameters) {
332
+ throw new Error("Parameters are required");
333
+ }
334
+ if (!isAddressValid(parameters.address)) {
335
+ throw new Error("Gateway is invalid");
336
+ }
337
+ if (!isAddressValid(parameters.tokenOut)) {
338
+ throw new Error("Token is invalid");
339
+ }
340
+ return readContract3(client, {
341
+ abi: gatewayAbi,
342
+ address: parameters.address,
343
+ args: [parameters.tokenOut],
344
+ functionName: "maxWithdraw"
345
+ });
346
+ }
347
+
348
+ // src/actions/public/getMintFee.ts
349
+ import { readContract as readContract4 } from "viem/actions";
350
+ async function getMintFee(client, parameters) {
351
+ if (!client) {
352
+ throw new Error("Client is not defined");
353
+ }
354
+ if (!parameters) {
355
+ throw new Error("Parameters are required");
356
+ }
357
+ if (!isAddressValid(parameters.address)) {
358
+ throw new Error("Gateway is invalid");
359
+ }
360
+ if (!isAddressValid(parameters.token)) {
361
+ throw new Error("Token is invalid");
362
+ }
363
+ return readContract4(client, {
364
+ abi: gatewayAbi,
365
+ address: parameters.address,
366
+ args: [parameters.token],
367
+ functionName: "mintFee"
368
+ });
369
+ }
370
+
371
+ // src/actions/public/getPeggedToken.ts
372
+ import { readContract as readContract5 } from "viem/actions";
373
+ async function getPeggedToken(client, parameters) {
374
+ if (!client) {
375
+ throw new Error("Client is not defined");
376
+ }
377
+ if (!parameters) {
378
+ throw new Error("Parameters are required");
379
+ }
380
+ if (!isAddressValid(parameters.address)) {
381
+ throw new Error("Gateway is invalid");
382
+ }
383
+ return readContract5(client, {
384
+ abi: gatewayAbi,
385
+ address: parameters.address,
386
+ functionName: "PEGGED_TOKEN"
387
+ });
388
+ }
389
+
390
+ // src/actions/public/getRedeemFee.ts
391
+ import { readContract as readContract6 } from "viem/actions";
392
+ async function getRedeemFee(client, parameters) {
393
+ if (!client) {
394
+ throw new Error("Client is not defined");
395
+ }
396
+ if (!parameters) {
397
+ throw new Error("Parameters are required");
398
+ }
399
+ if (!isAddressValid(parameters.address)) {
400
+ throw new Error("Gateway is invalid");
401
+ }
402
+ if (!isAddressValid(parameters.token)) {
403
+ throw new Error("Token is invalid");
404
+ }
405
+ return readContract6(client, {
406
+ abi: gatewayAbi,
407
+ address: parameters.address,
408
+ args: [parameters.token],
409
+ functionName: "redeemFee"
410
+ });
411
+ }
412
+
413
+ // src/actions/public/getRedeemRequest.ts
414
+ import { readContract as readContract7 } from "viem/actions";
415
+ async function getRedeemRequest(client, parameters) {
416
+ if (!client) {
417
+ throw new Error("Client is not defined");
418
+ }
419
+ if (!parameters) {
420
+ throw new Error("Parameters are required");
421
+ }
422
+ if (!isAddressValid(parameters.address)) {
423
+ throw new Error("Gateway is invalid");
424
+ }
425
+ if (!isAddressValid(parameters.user)) {
426
+ throw new Error("User is invalid");
427
+ }
428
+ return readContract7(client, {
429
+ abi: gatewayAbi,
430
+ address: parameters.address,
431
+ args: [parameters.user],
432
+ functionName: "getRedeemRequest"
433
+ });
434
+ }
435
+
436
+ // src/actions/public/getTreasury.ts
437
+ import { readContract as readContract8 } from "viem/actions";
438
+ async function getTreasury(client, parameters) {
439
+ if (!client) {
440
+ throw new Error("Client is not defined");
441
+ }
442
+ if (!parameters) {
443
+ throw new Error("Parameters are required");
444
+ }
445
+ if (!isAddressValid(parameters.address)) {
446
+ throw new Error("Gateway is invalid");
447
+ }
448
+ return readContract8(client, {
449
+ abi: gatewayAbi,
450
+ address: parameters.address,
451
+ functionName: "treasury"
452
+ });
453
+ }
454
+
455
+ // src/actions/public/getWithdrawalDelay.ts
456
+ import { readContract as readContract9 } from "viem/actions";
457
+ async function getWithdrawalDelay(client, parameters) {
458
+ if (!client) {
459
+ throw new Error("Client is not defined");
460
+ }
461
+ if (!parameters) {
462
+ throw new Error("Parameters are required");
463
+ }
464
+ if (!isAddressValid(parameters.address)) {
465
+ throw new Error("Gateway is invalid");
466
+ }
467
+ return readContract9(client, {
468
+ abi: gatewayAbi,
469
+ address: parameters.address,
470
+ functionName: "withdrawalDelay"
471
+ });
472
+ }
473
+
474
+ // src/actions/public/getWithdrawalDelayEnabled.ts
475
+ import { readContract as readContract10 } from "viem/actions";
476
+ async function getWithdrawalDelayEnabled(client, parameters) {
477
+ if (!client) {
478
+ throw new Error("Client is not defined");
479
+ }
480
+ if (!parameters) {
481
+ throw new Error("Parameters are required");
482
+ }
483
+ if (!isAddressValid(parameters.address)) {
484
+ throw new Error("Gateway is invalid");
485
+ }
486
+ return readContract10(client, {
487
+ abi: gatewayAbi,
488
+ address: parameters.address,
489
+ functionName: "withdrawalDelayEnabled"
490
+ });
491
+ }
492
+
493
+ // src/actions/public/isInstantRedeemWhitelisted.ts
494
+ import { readContract as readContract11 } from "viem/actions";
495
+ async function isInstantRedeemWhitelisted(client, parameters) {
496
+ if (!client) {
497
+ throw new Error("Client is not defined");
498
+ }
499
+ if (!parameters) {
500
+ throw new Error("Parameters are required");
501
+ }
502
+ if (!isAddressValid(parameters.address)) {
503
+ throw new Error("Gateway is invalid");
504
+ }
505
+ if (!isAddressValid(parameters.account)) {
506
+ throw new Error("Account is invalid");
507
+ }
508
+ return readContract11(client, {
509
+ abi: gatewayAbi,
510
+ address: parameters.address,
511
+ args: [parameters.account],
512
+ functionName: "isInstantRedeemWhitelisted"
513
+ });
514
+ }
515
+
516
+ // src/actions/public/previewDeposit.ts
517
+ import { readContract as readContract12 } from "viem/actions";
518
+ async function previewDeposit(client, parameters) {
519
+ if (!client) {
520
+ throw new Error("Client is not defined");
521
+ }
522
+ if (!parameters) {
523
+ throw new Error("Parameters are required");
524
+ }
525
+ if (!isAddressValid(parameters.address)) {
526
+ throw new Error("Gateway is invalid");
527
+ }
528
+ if (!isAddressValid(parameters.tokenIn)) {
529
+ throw new Error("Token is invalid");
530
+ }
531
+ if (typeof parameters.amountIn !== "bigint") {
532
+ throw new Error("Amount must be a bigint");
533
+ }
534
+ if (parameters.amountIn <= 0n) {
535
+ throw new Error("Amount must be greater than 0");
536
+ }
537
+ return readContract12(client, {
538
+ abi: gatewayAbi,
539
+ address: parameters.address,
540
+ args: [parameters.tokenIn, parameters.amountIn],
541
+ functionName: "previewDeposit"
542
+ });
543
+ }
544
+
545
+ // src/actions/public/previewRedeem.ts
546
+ import { readContract as readContract13 } from "viem/actions";
547
+ async function previewRedeem(client, parameters) {
548
+ if (!client) {
549
+ throw new Error("Client is not defined");
550
+ }
551
+ if (!parameters) {
552
+ throw new Error("Parameters are required");
553
+ }
554
+ if (!isAddressValid(parameters.address)) {
555
+ throw new Error("Gateway is invalid");
556
+ }
557
+ if (!isAddressValid(parameters.tokenOut)) {
558
+ throw new Error("Token is invalid");
559
+ }
560
+ if (typeof parameters.peggedTokenIn !== "bigint") {
561
+ throw new Error("Amount must be a bigint");
562
+ }
563
+ if (parameters.peggedTokenIn <= 0n) {
564
+ throw new Error("Amount must be greater than 0");
565
+ }
566
+ return readContract13(client, {
567
+ abi: gatewayAbi,
568
+ address: parameters.address,
569
+ args: [parameters.tokenOut, parameters.peggedTokenIn],
570
+ functionName: "previewRedeem"
571
+ });
572
+ }
573
+
574
+ // src/actions/public/previewWithdraw.ts
575
+ import { readContract as readContract14 } from "viem/actions";
576
+ async function previewWithdraw(client, parameters) {
577
+ if (!client) {
578
+ throw new Error("Client is not defined");
579
+ }
580
+ if (!parameters) {
581
+ throw new Error("Parameters are required");
582
+ }
583
+ if (!isAddressValid(parameters.address)) {
584
+ throw new Error("Gateway is invalid");
585
+ }
586
+ if (!isAddressValid(parameters.tokenOut)) {
587
+ throw new Error("Token is invalid");
588
+ }
589
+ if (typeof parameters.amountOut !== "bigint") {
590
+ throw new Error("Amount must be a bigint");
591
+ }
592
+ if (parameters.amountOut <= 0n) {
593
+ throw new Error("Amount must be greater than 0");
594
+ }
595
+ return readContract14(client, {
596
+ abi: gatewayAbi,
597
+ address: parameters.address,
598
+ args: [parameters.tokenOut, parameters.amountOut],
599
+ functionName: "previewWithdraw"
600
+ });
601
+ }
602
+
603
+ // src/actions/wallet/cancelRedeemRequest.ts
604
+ import { toPromiseEvent } from "to-promise-event";
605
+ import {
606
+ encodeFunctionData,
607
+ isAddress as isAddress2,
608
+ isAddressEqual as isAddressEqual2,
609
+ zeroAddress as zeroAddress2
610
+ } from "viem";
611
+ import { waitForTransactionReceipt, writeContract } from "viem/actions";
612
+ var canCancelRedeemRequest = function({
613
+ client,
614
+ gatewayAddress
615
+ }) {
616
+ if (!client) {
617
+ return {
618
+ canCancelRedeemRequest: false,
619
+ reason: "Client is not defined"
620
+ };
621
+ }
622
+ if (!client.chain) {
623
+ return {
624
+ canCancelRedeemRequest: false,
625
+ reason: "Chain is not defined on wallet client"
626
+ };
627
+ }
628
+ if (!client.account) {
629
+ return {
630
+ canCancelRedeemRequest: false,
631
+ reason: "Client must have an account"
632
+ };
633
+ }
634
+ if (!gatewayAddress || !isAddress2(gatewayAddress)) {
635
+ return {
636
+ canCancelRedeemRequest: false,
637
+ reason: "Invalid gateway address"
638
+ };
639
+ }
640
+ if (isAddressEqual2(gatewayAddress, zeroAddress2)) {
641
+ return {
642
+ canCancelRedeemRequest: false,
643
+ reason: "Gateway address cannot be zero address"
644
+ };
645
+ }
646
+ return { canCancelRedeemRequest: true };
647
+ };
648
+ var runCancelRedeemRequest = (walletClient, { gatewayAddress }) => async function(emitter) {
649
+ try {
650
+ const { canCancelRedeemRequest: canCancelRedeemRequestFlag, reason } = canCancelRedeemRequest({
651
+ client: walletClient,
652
+ gatewayAddress
653
+ });
654
+ if (!canCancelRedeemRequestFlag) {
655
+ emitter.emit("cancel-redeem-request-failed-validation", reason);
656
+ return;
657
+ }
658
+ emitter.emit("pre-cancel-redeem-request");
659
+ const cancelHash = await writeContract(walletClient, {
660
+ abi: gatewayAbi,
661
+ account: walletClient.account,
662
+ address: gatewayAddress,
663
+ chain: walletClient.chain,
664
+ functionName: "cancelRedeemRequest"
665
+ }).catch(function(error) {
666
+ emitter.emit("user-signing-cancel-redeem-request-error", error);
667
+ });
668
+ if (!cancelHash) {
669
+ return;
670
+ }
671
+ emitter.emit("user-signed-cancel-redeem-request", cancelHash);
672
+ const cancelReceipt = await waitForTransactionReceipt(walletClient, {
673
+ hash: cancelHash
674
+ }).catch(function(error) {
675
+ emitter.emit("cancel-redeem-request-failed", error);
676
+ });
677
+ if (!cancelReceipt) {
678
+ return;
679
+ }
680
+ const cancelEventMap = {
681
+ reverted: "cancel-redeem-request-transaction-reverted",
682
+ success: "cancel-redeem-request-transaction-succeeded"
683
+ };
684
+ emitter.emit(cancelEventMap[cancelReceipt.status], cancelReceipt);
685
+ } catch (error) {
686
+ emitter.emit("unexpected-error", error);
687
+ } finally {
688
+ emitter.emit("cancel-redeem-request-settled");
689
+ }
690
+ };
691
+ var cancelRedeemRequest = (...args) => toPromiseEvent(runCancelRedeemRequest(...args));
692
+ var encodeCancelRedeemRequest = () => encodeFunctionData({
693
+ abi: gatewayAbi,
694
+ functionName: "cancelRedeemRequest"
695
+ });
696
+
697
+ // src/actions/wallet/deposit.ts
698
+ import { toPromiseEvent as toPromiseEvent2 } from "to-promise-event";
699
+ import {
700
+ encodeFunctionData as encodeFunctionData2,
701
+ isAddress as isAddress3,
702
+ isAddressEqual as isAddressEqual3,
703
+ zeroAddress as zeroAddress3
704
+ } from "viem";
705
+ import { waitForTransactionReceipt as waitForTransactionReceipt2, writeContract as writeContract2 } from "viem/actions";
706
+ import { allowance, approve } from "viem-erc20/actions";
707
+ var canDeposit = function({
708
+ amountIn,
709
+ approveAmount,
710
+ client,
711
+ gatewayAddress,
712
+ minPeggedTokenOut,
713
+ receiver,
714
+ tokenIn
715
+ }) {
716
+ if (!client) {
717
+ return {
718
+ canDeposit: false,
719
+ reason: "Client is not defined"
720
+ };
721
+ }
722
+ if (!client.chain) {
723
+ return {
724
+ canDeposit: false,
725
+ reason: "Chain is not defined on wallet client"
726
+ };
727
+ }
728
+ if (!client.account) {
729
+ return {
730
+ canDeposit: false,
731
+ reason: "Client must have an account"
732
+ };
733
+ }
734
+ if (!gatewayAddress || !isAddress3(gatewayAddress)) {
735
+ return {
736
+ canDeposit: false,
737
+ reason: "Invalid gateway address"
738
+ };
739
+ }
740
+ if (isAddressEqual3(gatewayAddress, zeroAddress3)) {
741
+ return {
742
+ canDeposit: false,
743
+ reason: "Gateway address cannot be zero address"
744
+ };
745
+ }
746
+ if (!tokenIn || !isAddress3(tokenIn)) {
747
+ return {
748
+ canDeposit: false,
749
+ reason: "Invalid token address"
750
+ };
751
+ }
752
+ if (isAddressEqual3(tokenIn, zeroAddress3)) {
753
+ return {
754
+ canDeposit: false,
755
+ reason: "Token address cannot be zero address"
756
+ };
757
+ }
758
+ if (!receiver || !isAddress3(receiver)) {
759
+ return {
760
+ canDeposit: false,
761
+ reason: "Invalid receiver address"
762
+ };
763
+ }
764
+ if (isAddressEqual3(receiver, zeroAddress3)) {
765
+ return {
766
+ canDeposit: false,
767
+ reason: "Receiver address cannot be zero address"
768
+ };
769
+ }
770
+ if (typeof amountIn !== "bigint") {
771
+ return {
772
+ canDeposit: false,
773
+ reason: "Amount must be a bigint"
774
+ };
775
+ }
776
+ if (amountIn <= 0n) {
777
+ return {
778
+ canDeposit: false,
779
+ reason: "Amount must be greater than 0"
780
+ };
781
+ }
782
+ if (typeof minPeggedTokenOut !== "bigint") {
783
+ return {
784
+ canDeposit: false,
785
+ reason: "Minimum output must be a bigint"
786
+ };
787
+ }
788
+ if (minPeggedTokenOut < 0n) {
789
+ return {
790
+ canDeposit: false,
791
+ reason: "Minimum output cannot be negative"
792
+ };
793
+ }
794
+ if (approveAmount < amountIn) {
795
+ return {
796
+ canDeposit: false,
797
+ reason: "Approve amount must be greater than or equal to amount"
798
+ };
799
+ }
800
+ return { canDeposit: true };
801
+ };
802
+ var runDeposit = (walletClient, {
803
+ amountIn,
804
+ approveAmount = amountIn,
805
+ gatewayAddress,
806
+ minPeggedTokenOut,
807
+ receiver,
808
+ tokenIn
809
+ }) => async function(emitter) {
810
+ try {
811
+ const { canDeposit: canDepositFlag, reason } = canDeposit({
812
+ amountIn,
813
+ approveAmount,
814
+ client: walletClient,
815
+ gatewayAddress,
816
+ minPeggedTokenOut,
817
+ receiver,
818
+ tokenIn
819
+ });
820
+ if (!canDepositFlag) {
821
+ emitter.emit("deposit-failed-validation", reason);
822
+ return;
823
+ }
824
+ const currentAllowance = await allowance(walletClient, {
825
+ address: tokenIn,
826
+ // account is already validated
827
+ owner: walletClient.account.address,
828
+ spender: gatewayAddress
829
+ });
830
+ if (currentAllowance < amountIn) {
831
+ emitter.emit("pre-approve");
832
+ const approvalHash = await approve(walletClient, {
833
+ address: tokenIn,
834
+ amount: approveAmount,
835
+ spender: gatewayAddress
836
+ }).catch(function(error) {
837
+ emitter.emit("user-signing-approval-error", error);
838
+ });
839
+ if (!approvalHash) {
840
+ return;
841
+ }
842
+ emitter.emit("user-signed-approval", approvalHash);
843
+ const approvalReceipt = await waitForTransactionReceipt2(walletClient, {
844
+ hash: approvalHash
845
+ }).catch(function(error) {
846
+ emitter.emit("deposit-failed", error);
847
+ });
848
+ if (!approvalReceipt) {
849
+ return;
850
+ }
851
+ if (approvalReceipt.status === "reverted") {
852
+ emitter.emit("approve-transaction-reverted", approvalReceipt);
853
+ return;
854
+ }
855
+ emitter.emit("approve-transaction-succeeded", approvalReceipt);
856
+ }
857
+ emitter.emit("pre-deposit");
858
+ const depositHash = await writeContract2(walletClient, {
859
+ abi: gatewayAbi,
860
+ account: walletClient.account,
861
+ address: gatewayAddress,
862
+ args: [tokenIn, amountIn, minPeggedTokenOut, receiver],
863
+ chain: walletClient.chain,
864
+ functionName: "deposit"
865
+ }).catch(function(error) {
866
+ emitter.emit("user-signing-deposit-error", error);
867
+ });
868
+ if (!depositHash) {
869
+ return;
870
+ }
871
+ emitter.emit("user-signed-deposit", depositHash);
872
+ const depositReceipt = await waitForTransactionReceipt2(walletClient, {
873
+ hash: depositHash
874
+ }).catch(function(error) {
875
+ emitter.emit("deposit-failed", error);
876
+ });
877
+ if (!depositReceipt) {
878
+ return;
879
+ }
880
+ const depositEventMap = {
881
+ reverted: "deposit-transaction-reverted",
882
+ success: "deposit-transaction-succeeded"
883
+ };
884
+ emitter.emit(depositEventMap[depositReceipt.status], depositReceipt);
885
+ } catch (error) {
886
+ emitter.emit("unexpected-error", error);
887
+ } finally {
888
+ emitter.emit("deposit-settled");
889
+ }
890
+ };
891
+ var deposit = (...args) => toPromiseEvent2(runDeposit(...args));
892
+ var encodeDeposit = ({
893
+ amountIn,
894
+ minPeggedTokenOut,
895
+ receiver,
896
+ tokenIn
897
+ }) => encodeFunctionData2({
898
+ abi: gatewayAbi,
899
+ args: [tokenIn, amountIn, minPeggedTokenOut, receiver],
900
+ functionName: "deposit"
901
+ });
902
+
903
+ // src/actions/wallet/redeem.ts
904
+ import { toPromiseEvent as toPromiseEvent3 } from "to-promise-event";
905
+ import {
906
+ encodeFunctionData as encodeFunctionData3,
907
+ isAddress as isAddress4,
908
+ isAddressEqual as isAddressEqual4,
909
+ zeroAddress as zeroAddress4
910
+ } from "viem";
911
+ import { waitForTransactionReceipt as waitForTransactionReceipt3, writeContract as writeContract3 } from "viem/actions";
912
+ import { allowance as allowance2, approve as approve2 } from "viem-erc20/actions";
913
+ var canRedeem = async function({
914
+ approveAmount,
915
+ client,
916
+ gatewayAddress,
917
+ minAmountOut,
918
+ peggedTokenIn,
919
+ receiver,
920
+ tokenOut
921
+ }) {
922
+ if (!client) {
923
+ return {
924
+ canRedeem: false,
925
+ reason: "Client is not defined"
926
+ };
927
+ }
928
+ if (!client.chain) {
929
+ return {
930
+ canRedeem: false,
931
+ reason: "Chain is not defined on wallet client"
932
+ };
933
+ }
934
+ if (!client.account) {
935
+ return {
936
+ canRedeem: false,
937
+ reason: "Client must have an account"
938
+ };
939
+ }
940
+ if (!gatewayAddress || !isAddress4(gatewayAddress)) {
941
+ return {
942
+ canRedeem: false,
943
+ reason: "Invalid gateway address"
944
+ };
945
+ }
946
+ if (isAddressEqual4(gatewayAddress, zeroAddress4)) {
947
+ return {
948
+ canRedeem: false,
949
+ reason: "Gateway address cannot be zero address"
950
+ };
951
+ }
952
+ if (!tokenOut || !isAddress4(tokenOut)) {
953
+ return {
954
+ canRedeem: false,
955
+ reason: "Invalid token address"
956
+ };
957
+ }
958
+ if (isAddressEqual4(tokenOut, zeroAddress4)) {
959
+ return {
960
+ canRedeem: false,
961
+ reason: "Token address cannot be zero address"
962
+ };
963
+ }
964
+ if (!receiver || !isAddress4(receiver)) {
965
+ return {
966
+ canRedeem: false,
967
+ reason: "Invalid receiver address"
968
+ };
969
+ }
970
+ if (isAddressEqual4(receiver, zeroAddress4)) {
971
+ return {
972
+ canRedeem: false,
973
+ reason: "Receiver address cannot be zero address"
974
+ };
975
+ }
976
+ if (typeof peggedTokenIn !== "bigint") {
977
+ return {
978
+ canRedeem: false,
979
+ reason: "Amount must be a bigint"
980
+ };
981
+ }
982
+ if (peggedTokenIn <= 0n) {
983
+ return {
984
+ canRedeem: false,
985
+ reason: "Amount must be greater than 0"
986
+ };
987
+ }
988
+ if (typeof minAmountOut !== "bigint") {
989
+ return {
990
+ canRedeem: false,
991
+ reason: "Minimum output must be a bigint"
992
+ };
993
+ }
994
+ if (minAmountOut < 0n) {
995
+ return {
996
+ canRedeem: false,
997
+ reason: "Minimum output cannot be negative"
998
+ };
999
+ }
1000
+ if (approveAmount < peggedTokenIn) {
1001
+ return {
1002
+ canRedeem: false,
1003
+ reason: "Approve amount must be greater than or equal to amount"
1004
+ };
1005
+ }
1006
+ const maxWithdrawable = await getMaxWithdraw(client, {
1007
+ address: gatewayAddress,
1008
+ tokenOut
1009
+ });
1010
+ if (minAmountOut > maxWithdrawable) {
1011
+ return {
1012
+ canRedeem: false,
1013
+ reason: "Not enough balance in treasury"
1014
+ };
1015
+ }
1016
+ return { canRedeem: true };
1017
+ };
1018
+ var runRedeem = (walletClient, {
1019
+ approveAmount,
1020
+ gatewayAddress,
1021
+ minAmountOut,
1022
+ peggedTokenIn,
1023
+ receiver,
1024
+ tokenOut
1025
+ }) => async function(emitter) {
1026
+ const resolvedApproveAmount = approveAmount ?? peggedTokenIn;
1027
+ try {
1028
+ const { canRedeem: canRedeemFlag, reason } = await canRedeem({
1029
+ approveAmount: resolvedApproveAmount,
1030
+ client: walletClient,
1031
+ gatewayAddress,
1032
+ minAmountOut,
1033
+ peggedTokenIn,
1034
+ receiver,
1035
+ tokenOut
1036
+ });
1037
+ if (!canRedeemFlag) {
1038
+ emitter.emit("redeem-failed-validation", reason);
1039
+ return;
1040
+ }
1041
+ const [isWhitelisted, delayEnabled] = await Promise.all([
1042
+ isInstantRedeemWhitelisted(walletClient, {
1043
+ account: walletClient.account.address,
1044
+ address: gatewayAddress
1045
+ }),
1046
+ getWithdrawalDelayEnabled(walletClient, {
1047
+ address: gatewayAddress
1048
+ })
1049
+ ]);
1050
+ if (isWhitelisted || !delayEnabled) {
1051
+ const peggedTokenAddress = await getPeggedToken(walletClient, {
1052
+ address: gatewayAddress
1053
+ });
1054
+ const currentAllowance = await allowance2(walletClient, {
1055
+ address: peggedTokenAddress,
1056
+ owner: walletClient.account.address,
1057
+ spender: gatewayAddress
1058
+ });
1059
+ if (currentAllowance < peggedTokenIn) {
1060
+ emitter.emit("pre-approve");
1061
+ const approvalHash = await approve2(walletClient, {
1062
+ address: peggedTokenAddress,
1063
+ amount: resolvedApproveAmount,
1064
+ spender: gatewayAddress
1065
+ }).catch(function(error) {
1066
+ emitter.emit("user-signing-approval-error", error);
1067
+ });
1068
+ if (!approvalHash) {
1069
+ return;
1070
+ }
1071
+ emitter.emit("user-signed-approval", approvalHash);
1072
+ const approvalReceipt = await waitForTransactionReceipt3(
1073
+ walletClient,
1074
+ {
1075
+ hash: approvalHash
1076
+ }
1077
+ ).catch(function(error) {
1078
+ emitter.emit("redeem-failed", error);
1079
+ });
1080
+ if (!approvalReceipt) {
1081
+ return;
1082
+ }
1083
+ if (approvalReceipt.status === "reverted") {
1084
+ emitter.emit("approve-transaction-reverted", approvalReceipt);
1085
+ return;
1086
+ }
1087
+ emitter.emit("approve-transaction-succeeded", approvalReceipt);
1088
+ }
1089
+ }
1090
+ emitter.emit("pre-redeem");
1091
+ const redeemHash = await writeContract3(walletClient, {
1092
+ abi: gatewayAbi,
1093
+ account: walletClient.account,
1094
+ address: gatewayAddress,
1095
+ args: [tokenOut, peggedTokenIn, minAmountOut, receiver],
1096
+ chain: walletClient.chain,
1097
+ functionName: "redeem"
1098
+ }).catch(function(error) {
1099
+ emitter.emit("user-signing-redeem-error", error);
1100
+ });
1101
+ if (!redeemHash) {
1102
+ return;
1103
+ }
1104
+ emitter.emit("user-signed-redeem", redeemHash);
1105
+ const redeemReceipt = await waitForTransactionReceipt3(walletClient, {
1106
+ hash: redeemHash
1107
+ }).catch(function(error) {
1108
+ emitter.emit("redeem-failed", error);
1109
+ });
1110
+ if (!redeemReceipt) {
1111
+ return;
1112
+ }
1113
+ const redeemEventMap = {
1114
+ reverted: "redeem-transaction-reverted",
1115
+ success: "redeem-transaction-succeeded"
1116
+ };
1117
+ emitter.emit(redeemEventMap[redeemReceipt.status], redeemReceipt);
1118
+ } catch (error) {
1119
+ emitter.emit("unexpected-error", error);
1120
+ } finally {
1121
+ emitter.emit("redeem-settled");
1122
+ }
1123
+ };
1124
+ var redeem = (...args) => toPromiseEvent3(runRedeem(...args));
1125
+ var encodeRedeem = ({
1126
+ minAmountOut,
1127
+ peggedTokenIn,
1128
+ receiver,
1129
+ tokenOut
1130
+ }) => encodeFunctionData3({
1131
+ abi: gatewayAbi,
1132
+ args: [tokenOut, peggedTokenIn, minAmountOut, receiver],
1133
+ functionName: "redeem"
1134
+ });
1135
+
1136
+ // src/actions/wallet/requestRedeem.ts
1137
+ import { toPromiseEvent as toPromiseEvent4 } from "to-promise-event";
1138
+ import {
1139
+ encodeFunctionData as encodeFunctionData4,
1140
+ isAddress as isAddress5,
1141
+ isAddressEqual as isAddressEqual5,
1142
+ zeroAddress as zeroAddress5
1143
+ } from "viem";
1144
+ import { waitForTransactionReceipt as waitForTransactionReceipt4, writeContract as writeContract4 } from "viem/actions";
1145
+ import { allowance as allowance3, approve as approve3 } from "viem-erc20/actions";
1146
+ var canRequestRedeem = function({
1147
+ approveAmount,
1148
+ client,
1149
+ gatewayAddress,
1150
+ peggedTokenAmount
1151
+ }) {
1152
+ if (!client) {
1153
+ return {
1154
+ canRequestRedeem: false,
1155
+ reason: "Client is not defined"
1156
+ };
1157
+ }
1158
+ if (!client.chain) {
1159
+ return {
1160
+ canRequestRedeem: false,
1161
+ reason: "Chain is not defined on wallet client"
1162
+ };
1163
+ }
1164
+ if (!client.account) {
1165
+ return {
1166
+ canRequestRedeem: false,
1167
+ reason: "Client must have an account"
1168
+ };
1169
+ }
1170
+ if (!gatewayAddress || !isAddress5(gatewayAddress)) {
1171
+ return {
1172
+ canRequestRedeem: false,
1173
+ reason: "Invalid gateway address"
1174
+ };
1175
+ }
1176
+ if (isAddressEqual5(gatewayAddress, zeroAddress5)) {
1177
+ return {
1178
+ canRequestRedeem: false,
1179
+ reason: "Gateway address cannot be zero address"
1180
+ };
1181
+ }
1182
+ if (typeof peggedTokenAmount !== "bigint") {
1183
+ return {
1184
+ canRequestRedeem: false,
1185
+ reason: "Amount must be a bigint"
1186
+ };
1187
+ }
1188
+ if (peggedTokenAmount <= 0n) {
1189
+ return {
1190
+ canRequestRedeem: false,
1191
+ reason: "Amount must be greater than 0"
1192
+ };
1193
+ }
1194
+ if (approveAmount < peggedTokenAmount) {
1195
+ return {
1196
+ canRequestRedeem: false,
1197
+ reason: "Approve amount must be greater than or equal to amount"
1198
+ };
1199
+ }
1200
+ return { canRequestRedeem: true };
1201
+ };
1202
+ var runRequestRedeem = (walletClient, { approveAmount, gatewayAddress, peggedTokenAmount }) => async function(emitter) {
1203
+ const resolvedApproveAmount = approveAmount ?? peggedTokenAmount;
1204
+ try {
1205
+ const { canRequestRedeem: canRequestRedeemFlag, reason } = canRequestRedeem({
1206
+ approveAmount: resolvedApproveAmount,
1207
+ client: walletClient,
1208
+ gatewayAddress,
1209
+ peggedTokenAmount
1210
+ });
1211
+ if (!canRequestRedeemFlag) {
1212
+ emitter.emit("request-redeem-failed-validation", reason);
1213
+ return;
1214
+ }
1215
+ const peggedTokenAddress = await getPeggedToken(walletClient, {
1216
+ address: gatewayAddress
1217
+ });
1218
+ const currentAllowance = await allowance3(walletClient, {
1219
+ address: peggedTokenAddress,
1220
+ owner: walletClient.account.address,
1221
+ spender: gatewayAddress
1222
+ });
1223
+ if (currentAllowance < peggedTokenAmount) {
1224
+ emitter.emit("pre-approve");
1225
+ const approvalHash = await approve3(walletClient, {
1226
+ address: peggedTokenAddress,
1227
+ amount: resolvedApproveAmount,
1228
+ spender: gatewayAddress
1229
+ }).catch(function(error) {
1230
+ emitter.emit("user-signing-approval-error", error);
1231
+ });
1232
+ if (!approvalHash) {
1233
+ return;
1234
+ }
1235
+ emitter.emit("user-signed-approval", approvalHash);
1236
+ const approvalReceipt = await waitForTransactionReceipt4(walletClient, {
1237
+ hash: approvalHash
1238
+ }).catch(function(error) {
1239
+ emitter.emit("request-redeem-failed", error);
1240
+ });
1241
+ if (!approvalReceipt) {
1242
+ return;
1243
+ }
1244
+ if (approvalReceipt.status === "reverted") {
1245
+ emitter.emit("approve-transaction-reverted", approvalReceipt);
1246
+ return;
1247
+ }
1248
+ emitter.emit("approve-transaction-succeeded", approvalReceipt);
1249
+ }
1250
+ emitter.emit("pre-request-redeem");
1251
+ const requestRedeemHash = await writeContract4(walletClient, {
1252
+ abi: gatewayAbi,
1253
+ account: walletClient.account,
1254
+ address: gatewayAddress,
1255
+ args: [peggedTokenAmount],
1256
+ chain: walletClient.chain,
1257
+ functionName: "requestRedeem"
1258
+ }).catch(function(error) {
1259
+ emitter.emit("user-signing-request-redeem-error", error);
1260
+ });
1261
+ if (!requestRedeemHash) {
1262
+ return;
1263
+ }
1264
+ emitter.emit("user-signed-request-redeem", requestRedeemHash);
1265
+ const requestRedeemReceipt = await waitForTransactionReceipt4(
1266
+ walletClient,
1267
+ {
1268
+ hash: requestRedeemHash
1269
+ }
1270
+ ).catch(function(error) {
1271
+ emitter.emit("request-redeem-failed", error);
1272
+ });
1273
+ if (!requestRedeemReceipt) {
1274
+ return;
1275
+ }
1276
+ const requestRedeemEventMap = {
1277
+ reverted: "request-redeem-transaction-reverted",
1278
+ success: "request-redeem-transaction-succeeded"
1279
+ };
1280
+ emitter.emit(
1281
+ requestRedeemEventMap[requestRedeemReceipt.status],
1282
+ requestRedeemReceipt
1283
+ );
1284
+ } catch (error) {
1285
+ emitter.emit("unexpected-error", error);
1286
+ } finally {
1287
+ emitter.emit("request-redeem-settled");
1288
+ }
1289
+ };
1290
+ var requestRedeem = (...args) => toPromiseEvent4(runRequestRedeem(...args));
1291
+ var encodeRequestRedeem = ({
1292
+ peggedTokenAmount
1293
+ }) => encodeFunctionData4({
1294
+ abi: gatewayAbi,
1295
+ args: [peggedTokenAmount],
1296
+ functionName: "requestRedeem"
1297
+ });
1298
+
1299
+ export {
1300
+ gateways,
1301
+ gatewayAddresses,
1302
+ getGateway,
1303
+ gatewayAbi,
1304
+ getMaxMint,
1305
+ getMaxWithdraw,
1306
+ getMintFee,
1307
+ getPeggedToken,
1308
+ getRedeemFee,
1309
+ getRedeemRequest,
1310
+ getTreasury,
1311
+ getWithdrawalDelay,
1312
+ getWithdrawalDelayEnabled,
1313
+ isInstantRedeemWhitelisted,
1314
+ previewDeposit,
1315
+ previewRedeem,
1316
+ previewWithdraw,
1317
+ cancelRedeemRequest,
1318
+ encodeCancelRedeemRequest,
1319
+ deposit,
1320
+ encodeDeposit,
1321
+ redeem,
1322
+ encodeRedeem,
1323
+ requestRedeem,
1324
+ encodeRequestRedeem
1325
+ };
1326
+ //# sourceMappingURL=chunk-ZE4YZMXK.js.map