@paxoslabs/amplify-sdk 0.5.2 → 1.0.0

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 (62) hide show
  1. package/dist/index.d.mts +3158 -725
  2. package/dist/index.d.ts +3158 -725
  3. package/dist/index.js +15013 -171
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +15067 -6
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +25 -86
  8. package/CHANGELOG.md +0 -320
  9. package/LICENSE +0 -28
  10. package/README.md +0 -119
  11. package/dist/chain-utils-BdJecHBA.d.mts +0 -334
  12. package/dist/chain-utils-BdJecHBA.d.ts +0 -334
  13. package/dist/chunk-5OK753GA.js +0 -1989
  14. package/dist/chunk-5OK753GA.js.map +0 -1
  15. package/dist/chunk-6CU533DM.mjs +0 -39
  16. package/dist/chunk-6CU533DM.mjs.map +0 -1
  17. package/dist/chunk-7JQQ2TH4.mjs +0 -1231
  18. package/dist/chunk-7JQQ2TH4.mjs.map +0 -1
  19. package/dist/chunk-HU5CTL4C.mjs +0 -1962
  20. package/dist/chunk-HU5CTL4C.mjs.map +0 -1
  21. package/dist/chunk-NNDY5TID.js +0 -1143
  22. package/dist/chunk-NNDY5TID.js.map +0 -1
  23. package/dist/chunk-Q5FXJU5Y.mjs +0 -1133
  24. package/dist/chunk-Q5FXJU5Y.mjs.map +0 -1
  25. package/dist/chunk-QZHI2T7O.mjs +0 -457
  26. package/dist/chunk-QZHI2T7O.mjs.map +0 -1
  27. package/dist/chunk-SWUG4PTB.js +0 -464
  28. package/dist/chunk-SWUG4PTB.js.map +0 -1
  29. package/dist/chunk-TNL23CO2.js +0 -45
  30. package/dist/chunk-TNL23CO2.js.map +0 -1
  31. package/dist/chunk-WK7EJRBB.mjs +0 -1482
  32. package/dist/chunk-WK7EJRBB.mjs.map +0 -1
  33. package/dist/chunk-WYBYBPX5.js +0 -1518
  34. package/dist/chunk-WYBYBPX5.js.map +0 -1
  35. package/dist/chunk-ZKDXRGI5.js +0 -1239
  36. package/dist/chunk-ZKDXRGI5.js.map +0 -1
  37. package/dist/core.d.mts +0 -152
  38. package/dist/core.d.ts +0 -152
  39. package/dist/core.js +0 -1220
  40. package/dist/core.js.map +0 -1
  41. package/dist/core.mjs +0 -1194
  42. package/dist/core.mjs.map +0 -1
  43. package/dist/display.d.mts +0 -263
  44. package/dist/display.d.ts +0 -263
  45. package/dist/display.js +0 -36
  46. package/dist/display.js.map +0 -1
  47. package/dist/display.mjs +0 -7
  48. package/dist/display.mjs.map +0 -1
  49. package/dist/index-DXXA8gEA.d.mts +0 -5026
  50. package/dist/index-aE5lTOUH.d.ts +0 -5026
  51. package/dist/utils.d.mts +0 -112
  52. package/dist/utils.d.ts +0 -112
  53. package/dist/utils.js +0 -67
  54. package/dist/utils.js.map +0 -1
  55. package/dist/utils.mjs +0 -25
  56. package/dist/utils.mjs.map +0 -1
  57. package/dist/vaults.d.mts +0 -4
  58. package/dist/vaults.d.ts +0 -4
  59. package/dist/vaults.js +0 -96
  60. package/dist/vaults.js.map +0 -1
  61. package/dist/vaults.mjs +0 -7
  62. package/dist/vaults.mjs.map +0 -1
@@ -1,1962 +0,0 @@
1
- import { resolveVault, WithdrawQueueAbi } from './chunk-7JQQ2TH4.mjs';
2
- import { getTokenPermitInfoWithAllowance, getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals, erc2612Abi, getErc20Decimals, BoringVaultAbi } from './chunk-Q5FXJU5Y.mjs';
3
- import { WAD } from './chunk-6CU533DM.mjs';
4
- import { toChainId, APIError, getSupportedAssets, DEFAULT_APPROVAL_AMOUNT, DEFAULT_SLIPPAGE_BPS, getLogger, getClient } from './chunk-WK7EJRBB.mjs';
5
- import { formatUnits, parseUnits, erc20Abi, stringToHex, zeroAddress, hexToSignature } from 'viem';
6
-
7
- var isDepositSpendApproved = async ({
8
- vaultName,
9
- chainId,
10
- depositAssetAddress,
11
- recipientAddress
12
- }) => {
13
- try {
14
- const normalizedChainId = toChainId(chainId);
15
- const config = await resolveVault({
16
- vaultName,
17
- chainId: normalizedChainId,
18
- assetAddress: depositAssetAddress,
19
- callerEndpoint: "isDepositSpendApproved"
20
- });
21
- const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
22
- if (!communityCodeDepositorAddress) {
23
- throw new APIError(
24
- `Community code depositor contract address not configured for vault ${config.id}`,
25
- {
26
- endpoint: "isDepositSpendApproved"
27
- }
28
- );
29
- }
30
- const {
31
- decimals,
32
- allowance,
33
- supportsPermit,
34
- nonce,
35
- domainSeparator,
36
- tokenName,
37
- tokenVersion
38
- } = await getTokenPermitInfoWithAllowance({
39
- chainId: normalizedChainId,
40
- tokenAddress: depositAssetAddress,
41
- owner: recipientAddress,
42
- spender: communityCodeDepositorAddress
43
- });
44
- return {
45
- isApproved: allowance > 0n,
46
- allowance: formatUnits(allowance, decimals),
47
- allowanceAsBigInt: allowance.toString(),
48
- decimals,
49
- supportsPermit,
50
- nonce,
51
- domainSeparator,
52
- tokenName,
53
- tokenVersion,
54
- error: null
55
- };
56
- } catch (error) {
57
- if (error instanceof APIError) {
58
- throw error;
59
- }
60
- throw new APIError(
61
- `Failed to check deposit approval: ${error instanceof Error ? error.message : String(error)}`,
62
- {
63
- endpoint: "isDepositSpendApproved",
64
- cause: error
65
- }
66
- );
67
- }
68
- };
69
- var isWithdrawalSpendApproved = async ({
70
- vaultName,
71
- chainId,
72
- wantAssetAddress,
73
- recipientAddress
74
- }) => {
75
- try {
76
- const normalizedChainId = toChainId(chainId);
77
- const config = await resolveVault({
78
- vaultName,
79
- chainId: normalizedChainId,
80
- assetAddress: wantAssetAddress,
81
- callerEndpoint: "isWithdrawalSpendApproved"
82
- });
83
- const boringVaultAddress = config.vault.boringVaultAddress;
84
- if (!boringVaultAddress) {
85
- throw new APIError(
86
- `BoringVault contract address not configured for vault ${config.id}`,
87
- {
88
- endpoint: "isWithdrawalSpendApproved"
89
- }
90
- );
91
- }
92
- const withdrawQueueAddress = config.vault.withdrawQueueAddress;
93
- if (!withdrawQueueAddress) {
94
- throw new APIError(
95
- `WithdrawQueue contract address not configured for vault ${config.id}`,
96
- {
97
- endpoint: "isWithdrawalSpendApproved"
98
- }
99
- );
100
- }
101
- const [allowance, decimals] = await getErc20AllowanceWithDecimals({
102
- chainId: normalizedChainId,
103
- tokenAddress: boringVaultAddress,
104
- recipientAddress,
105
- spenderAddress: withdrawQueueAddress
106
- });
107
- if (allowance.status === "failure" || decimals.status === "failure") {
108
- return {
109
- isApproved: false,
110
- allowance: "0",
111
- allowanceAsBigInt: "0",
112
- decimals: "0",
113
- error: allowance.error || decimals.error
114
- };
115
- }
116
- return {
117
- isApproved: allowance.result > 0n,
118
- allowance: formatUnits(allowance.result, decimals.result),
119
- allowanceAsBigInt: allowance.result.toString(),
120
- decimals: decimals.result,
121
- error: null
122
- };
123
- } catch (error) {
124
- if (error instanceof APIError) {
125
- throw error;
126
- }
127
- throw new APIError(
128
- `Failed to check withdrawal approval: ${error instanceof Error ? error.message : String(error)}`,
129
- { endpoint: "isWithdrawalSpendApproved", cause: error }
130
- );
131
- }
132
- };
133
- async function prepareApproveDepositTokenTxData({
134
- vaultName,
135
- depositAsset,
136
- approvalAmount,
137
- chainId
138
- }) {
139
- const normalizedChainId = toChainId(chainId);
140
- try {
141
- const config = await resolveVault({
142
- vaultName,
143
- assetAddress: depositAsset,
144
- chainId: normalizedChainId,
145
- callerEndpoint: "prepareApproveDepositToken"
146
- });
147
- const communityCodeDepositorAddress = config.vault.communityCodeDepositorAddress;
148
- if (!communityCodeDepositorAddress) {
149
- throw new APIError(
150
- `Community Code Depositor contract address not configured for vault ${config.id}`,
151
- { endpoint: "prepareApproveDepositToken" }
152
- );
153
- }
154
- const assets = await getSupportedAssets({ address: depositAsset });
155
- if (assets.length === 0) {
156
- throw new APIError(
157
- `Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
158
- { endpoint: "prepareApproveDepositToken" }
159
- );
160
- }
161
- const verifiedAsset = assets.find(
162
- (asset) => asset.address.toLowerCase() === depositAsset.toLowerCase() && asset.chains.includes(normalizedChainId)
163
- );
164
- if (!verifiedAsset) {
165
- throw new APIError(
166
- `Asset ${depositAsset} not verified on chain ${normalizedChainId}`,
167
- { endpoint: "prepareApproveDepositToken" }
168
- );
169
- }
170
- const decimals = verifiedAsset.decimals;
171
- const amount = approvalAmount ? parseUnits(approvalAmount, decimals) : DEFAULT_APPROVAL_AMOUNT;
172
- return {
173
- abi: erc20Abi,
174
- address: depositAsset,
175
- functionName: "approve",
176
- args: [communityCodeDepositorAddress, amount]
177
- };
178
- } catch (error) {
179
- if (error instanceof APIError) {
180
- throw error;
181
- }
182
- throw new APIError(
183
- `Failed to prepare approval transaction: ${error instanceof Error ? error.message : String(error)}`,
184
- {
185
- endpoint: "prepareApproveDepositToken",
186
- cause: error
187
- }
188
- );
189
- }
190
- }
191
-
192
- // src/abi/distributor-code-depositor-abi-v0.ts
193
- var DistributorCodeDepositorAbiV0 = [
194
- {
195
- inputs: [
196
- {
197
- internalType: "contract TellerWithMultiAssetSupport",
198
- name: "_teller",
199
- type: "address"
200
- },
201
- {
202
- internalType: "contract INativeWrapper",
203
- name: "_nativeWrapper",
204
- type: "address"
205
- },
206
- {
207
- internalType: "contract Authority",
208
- name: "_rolesAuthority",
209
- type: "address"
210
- },
211
- { internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
212
- { internalType: "address", name: "_owner", type: "address" }
213
- ],
214
- stateMutability: "nonpayable",
215
- type: "constructor"
216
- },
217
- { inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
218
- { inputs: [], name: "NativeDepositNotSupported", type: "error" },
219
- {
220
- inputs: [],
221
- name: "NativeWrapperAccountantDecimalsMismatch",
222
- type: "error"
223
- },
224
- { inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
225
- { inputs: [], name: "ZeroAddress", type: "error" },
226
- {
227
- anonymous: false,
228
- inputs: [
229
- { indexed: true, internalType: "address", name: "user", type: "address" },
230
- {
231
- indexed: true,
232
- internalType: "contract Authority",
233
- name: "newAuthority",
234
- type: "address"
235
- }
236
- ],
237
- name: "AuthorityUpdated",
238
- type: "event"
239
- },
240
- {
241
- anonymous: false,
242
- inputs: [
243
- {
244
- indexed: true,
245
- internalType: "address",
246
- name: "depositor",
247
- type: "address"
248
- },
249
- {
250
- indexed: true,
251
- internalType: "contract ERC20",
252
- name: "depositAsset",
253
- type: "address"
254
- },
255
- {
256
- indexed: false,
257
- internalType: "uint256",
258
- name: "depositAmount",
259
- type: "uint256"
260
- },
261
- {
262
- indexed: false,
263
- internalType: "uint256",
264
- name: "minimumMint",
265
- type: "uint256"
266
- },
267
- { indexed: false, internalType: "address", name: "to", type: "address" },
268
- {
269
- indexed: false,
270
- internalType: "bytes32",
271
- name: "depositHash",
272
- type: "bytes32"
273
- },
274
- {
275
- indexed: true,
276
- internalType: "bytes",
277
- name: "distributorCode",
278
- type: "bytes"
279
- }
280
- ],
281
- name: "DepositWithDistributorCode",
282
- type: "event"
283
- },
284
- {
285
- anonymous: false,
286
- inputs: [
287
- { indexed: true, internalType: "address", name: "user", type: "address" },
288
- {
289
- indexed: true,
290
- internalType: "address",
291
- name: "newOwner",
292
- type: "address"
293
- }
294
- ],
295
- name: "OwnershipTransferred",
296
- type: "event"
297
- },
298
- {
299
- inputs: [],
300
- name: "authority",
301
- outputs: [
302
- { internalType: "contract Authority", name: "", type: "address" }
303
- ],
304
- stateMutability: "view",
305
- type: "function"
306
- },
307
- {
308
- inputs: [],
309
- name: "boringVault",
310
- outputs: [{ internalType: "address", name: "", type: "address" }],
311
- stateMutability: "view",
312
- type: "function"
313
- },
314
- {
315
- inputs: [
316
- { internalType: "contract ERC20", name: "depositAsset", type: "address" },
317
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
318
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
319
- { internalType: "address", name: "to", type: "address" },
320
- { internalType: "bytes", name: "distributorCode", type: "bytes" }
321
- ],
322
- name: "deposit",
323
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
324
- stateMutability: "nonpayable",
325
- type: "function"
326
- },
327
- {
328
- inputs: [
329
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
330
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
331
- { internalType: "address", name: "to", type: "address" },
332
- { internalType: "bytes", name: "distributorCode", type: "bytes" }
333
- ],
334
- name: "depositNative",
335
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
336
- stateMutability: "payable",
337
- type: "function"
338
- },
339
- {
340
- inputs: [],
341
- name: "depositNonce",
342
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
343
- stateMutability: "view",
344
- type: "function"
345
- },
346
- {
347
- inputs: [
348
- { internalType: "contract ERC20", name: "depositAsset", type: "address" },
349
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
350
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
351
- { internalType: "address", name: "to", type: "address" },
352
- { internalType: "bytes", name: "distributorCode", type: "bytes" },
353
- { internalType: "uint256", name: "deadline", type: "uint256" },
354
- { internalType: "uint8", name: "v", type: "uint8" },
355
- { internalType: "bytes32", name: "r", type: "bytes32" },
356
- { internalType: "bytes32", name: "s", type: "bytes32" }
357
- ],
358
- name: "depositWithPermit",
359
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
360
- stateMutability: "nonpayable",
361
- type: "function"
362
- },
363
- {
364
- inputs: [],
365
- name: "isNativeDepositSupported",
366
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
367
- stateMutability: "view",
368
- type: "function"
369
- },
370
- {
371
- inputs: [],
372
- name: "nativeWrapper",
373
- outputs: [
374
- { internalType: "contract INativeWrapper", name: "", type: "address" }
375
- ],
376
- stateMutability: "view",
377
- type: "function"
378
- },
379
- {
380
- inputs: [],
381
- name: "owner",
382
- outputs: [{ internalType: "address", name: "", type: "address" }],
383
- stateMutability: "view",
384
- type: "function"
385
- },
386
- {
387
- inputs: [
388
- {
389
- internalType: "contract Authority",
390
- name: "newAuthority",
391
- type: "address"
392
- }
393
- ],
394
- name: "setAuthority",
395
- outputs: [],
396
- stateMutability: "nonpayable",
397
- type: "function"
398
- },
399
- {
400
- inputs: [],
401
- name: "teller",
402
- outputs: [
403
- {
404
- internalType: "contract TellerWithMultiAssetSupport",
405
- name: "",
406
- type: "address"
407
- }
408
- ],
409
- stateMutability: "view",
410
- type: "function"
411
- },
412
- {
413
- inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
414
- name: "transferOwnership",
415
- outputs: [],
416
- stateMutability: "nonpayable",
417
- type: "function"
418
- }
419
- ];
420
-
421
- // src/abi/distributor-code-depositor-abi-v1.ts
422
- var DistributorCodeDepositorAbiV1 = [
423
- {
424
- inputs: [
425
- {
426
- internalType: "contract TellerWithMultiAssetSupport",
427
- name: "_teller",
428
- type: "address"
429
- },
430
- {
431
- internalType: "contract INativeWrapper",
432
- name: "_nativeWrapper",
433
- type: "address"
434
- },
435
- {
436
- internalType: "contract Authority",
437
- name: "_rolesAuthority",
438
- type: "address"
439
- },
440
- { internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
441
- { internalType: "uint256", name: "_supplyCap", type: "uint256" },
442
- {
443
- internalType: "contract IFeeModule",
444
- name: "_feeModule",
445
- type: "address"
446
- },
447
- { internalType: "address", name: "_feeRecipient", type: "address" },
448
- { internalType: "address", name: "_registry", type: "address" },
449
- { internalType: "string", name: "_policyID", type: "string" },
450
- { internalType: "address", name: "_owner", type: "address" }
451
- ],
452
- stateMutability: "nonpayable",
453
- type: "constructor"
454
- },
455
- { inputs: [], name: "FeesExceedOrEqualAmount", type: "error" },
456
- { inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
457
- {
458
- inputs: [
459
- { internalType: "uint256", name: "actual", type: "uint256" },
460
- { internalType: "uint256", name: "minimum", type: "uint256" }
461
- ],
462
- name: "InsufficientSharesAfterFees",
463
- type: "error"
464
- },
465
- { inputs: [], name: "NativeDepositNotSupported", type: "error" },
466
- {
467
- inputs: [],
468
- name: "NativeWrapperAccountantDecimalsMismatch",
469
- type: "error"
470
- },
471
- {
472
- inputs: [
473
- { internalType: "address", name: "addressEmptyCode", type: "address" }
474
- ],
475
- name: "NoCode",
476
- type: "error"
477
- },
478
- { inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
479
- {
480
- inputs: [
481
- { internalType: "uint256", name: "resultingValue", type: "uint256" },
482
- { internalType: "uint256", name: "supplyCapInBase", type: "uint256" }
483
- ],
484
- name: "SupplyCapInBaseError",
485
- type: "error"
486
- },
487
- { inputs: [], name: "UnauthorizedTransaction", type: "error" },
488
- { inputs: [], name: "ZeroAddress", type: "error" },
489
- {
490
- anonymous: false,
491
- inputs: [
492
- { indexed: true, internalType: "address", name: "user", type: "address" },
493
- {
494
- indexed: true,
495
- internalType: "contract Authority",
496
- name: "newAuthority",
497
- type: "address"
498
- }
499
- ],
500
- name: "AuthorityUpdated",
501
- type: "event"
502
- },
503
- {
504
- anonymous: false,
505
- inputs: [
506
- {
507
- indexed: true,
508
- internalType: "address",
509
- name: "depositor",
510
- type: "address"
511
- },
512
- {
513
- indexed: true,
514
- internalType: "contract ERC20",
515
- name: "depositAsset",
516
- type: "address"
517
- },
518
- {
519
- indexed: false,
520
- internalType: "uint256",
521
- name: "depositAmount",
522
- type: "uint256"
523
- },
524
- {
525
- indexed: false,
526
- internalType: "uint256",
527
- name: "minimumMint",
528
- type: "uint256"
529
- },
530
- { indexed: false, internalType: "address", name: "to", type: "address" },
531
- {
532
- indexed: false,
533
- internalType: "bytes32",
534
- name: "depositHash",
535
- type: "bytes32"
536
- },
537
- {
538
- indexed: true,
539
- internalType: "bytes",
540
- name: "distributorCode",
541
- type: "bytes"
542
- }
543
- ],
544
- name: "DepositWithDistributorCode",
545
- type: "event"
546
- },
547
- {
548
- anonymous: false,
549
- inputs: [
550
- {
551
- indexed: true,
552
- internalType: "contract IFeeModule",
553
- name: "newFeeModule",
554
- type: "address"
555
- }
556
- ],
557
- name: "FeeModuleUpdated",
558
- type: "event"
559
- },
560
- {
561
- anonymous: false,
562
- inputs: [
563
- {
564
- indexed: true,
565
- internalType: "address",
566
- name: "newFeeRecipient",
567
- type: "address"
568
- }
569
- ],
570
- name: "FeeRecipientUpdated",
571
- type: "event"
572
- },
573
- {
574
- anonymous: false,
575
- inputs: [
576
- {
577
- indexed: true,
578
- internalType: "contract ERC20",
579
- name: "depositAsset",
580
- type: "address"
581
- },
582
- { indexed: true, internalType: "bool", name: "enabled", type: "bool" }
583
- ],
584
- name: "KytStatusUpdated",
585
- type: "event"
586
- },
587
- {
588
- anonymous: false,
589
- inputs: [
590
- { indexed: true, internalType: "address", name: "user", type: "address" },
591
- {
592
- indexed: true,
593
- internalType: "address",
594
- name: "newOwner",
595
- type: "address"
596
- }
597
- ],
598
- name: "OwnershipTransferred",
599
- type: "event"
600
- },
601
- {
602
- anonymous: false,
603
- inputs: [
604
- {
605
- indexed: false,
606
- internalType: "string",
607
- name: "oldPolicyID",
608
- type: "string"
609
- },
610
- {
611
- indexed: false,
612
- internalType: "string",
613
- name: "newPolicyID",
614
- type: "string"
615
- }
616
- ],
617
- name: "PredicatePolicyIDUpdated",
618
- type: "event"
619
- },
620
- {
621
- anonymous: false,
622
- inputs: [
623
- {
624
- indexed: true,
625
- internalType: "address",
626
- name: "oldRegistry",
627
- type: "address"
628
- },
629
- {
630
- indexed: true,
631
- internalType: "address",
632
- name: "newRegistry",
633
- type: "address"
634
- }
635
- ],
636
- name: "PredicateRegistryUpdated",
637
- type: "event"
638
- },
639
- {
640
- anonymous: false,
641
- inputs: [
642
- {
643
- indexed: false,
644
- internalType: "uint256",
645
- name: "newSupplyCapInBase",
646
- type: "uint256"
647
- }
648
- ],
649
- name: "SupplyCapInBaseUpdated",
650
- type: "event"
651
- },
652
- {
653
- inputs: [],
654
- name: "PREDICATE_DEPOSIT_SIGNATURE",
655
- outputs: [{ internalType: "string", name: "", type: "string" }],
656
- stateMutability: "view",
657
- type: "function"
658
- },
659
- {
660
- inputs: [],
661
- name: "authority",
662
- outputs: [
663
- { internalType: "contract Authority", name: "", type: "address" }
664
- ],
665
- stateMutability: "view",
666
- type: "function"
667
- },
668
- {
669
- inputs: [],
670
- name: "boringVault",
671
- outputs: [{ internalType: "address", name: "", type: "address" }],
672
- stateMutability: "view",
673
- type: "function"
674
- },
675
- {
676
- inputs: [
677
- { internalType: "contract ERC20", name: "depositAsset", type: "address" },
678
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
679
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
680
- { internalType: "address", name: "to", type: "address" },
681
- { internalType: "bytes", name: "distributorCode", type: "bytes" },
682
- {
683
- components: [
684
- { internalType: "string", name: "uuid", type: "string" },
685
- { internalType: "uint256", name: "expiration", type: "uint256" },
686
- { internalType: "address", name: "attester", type: "address" },
687
- { internalType: "bytes", name: "signature", type: "bytes" }
688
- ],
689
- internalType: "struct Attestation",
690
- name: "_attestation",
691
- type: "tuple"
692
- }
693
- ],
694
- name: "deposit",
695
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
696
- stateMutability: "nonpayable",
697
- type: "function"
698
- },
699
- {
700
- inputs: [
701
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
702
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
703
- { internalType: "address", name: "to", type: "address" },
704
- { internalType: "bytes", name: "distributorCode", type: "bytes" },
705
- {
706
- components: [
707
- { internalType: "string", name: "uuid", type: "string" },
708
- { internalType: "uint256", name: "expiration", type: "uint256" },
709
- { internalType: "address", name: "attester", type: "address" },
710
- { internalType: "bytes", name: "signature", type: "bytes" }
711
- ],
712
- internalType: "struct Attestation",
713
- name: "_attestation",
714
- type: "tuple"
715
- }
716
- ],
717
- name: "depositNative",
718
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
719
- stateMutability: "payable",
720
- type: "function"
721
- },
722
- {
723
- inputs: [],
724
- name: "depositNonce",
725
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
726
- stateMutability: "view",
727
- type: "function"
728
- },
729
- {
730
- inputs: [
731
- { internalType: "contract ERC20", name: "depositAsset", type: "address" },
732
- { internalType: "uint256", name: "depositAmount", type: "uint256" },
733
- { internalType: "uint256", name: "minimumMint", type: "uint256" },
734
- { internalType: "address", name: "to", type: "address" },
735
- { internalType: "bytes", name: "distributorCode", type: "bytes" },
736
- {
737
- components: [
738
- { internalType: "string", name: "uuid", type: "string" },
739
- { internalType: "uint256", name: "expiration", type: "uint256" },
740
- { internalType: "address", name: "attester", type: "address" },
741
- { internalType: "bytes", name: "signature", type: "bytes" }
742
- ],
743
- internalType: "struct Attestation",
744
- name: "_attestation",
745
- type: "tuple"
746
- },
747
- { internalType: "uint256", name: "deadline", type: "uint256" },
748
- { internalType: "uint8", name: "v", type: "uint8" },
749
- { internalType: "bytes32", name: "r", type: "bytes32" },
750
- { internalType: "bytes32", name: "s", type: "bytes32" }
751
- ],
752
- name: "depositWithPermit",
753
- outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
754
- stateMutability: "nonpayable",
755
- type: "function"
756
- },
757
- {
758
- inputs: [],
759
- name: "feeModule",
760
- outputs: [
761
- { internalType: "contract IFeeModule", name: "", type: "address" }
762
- ],
763
- stateMutability: "view",
764
- type: "function"
765
- },
766
- {
767
- inputs: [],
768
- name: "feeRecipient",
769
- outputs: [{ internalType: "address", name: "", type: "address" }],
770
- stateMutability: "view",
771
- type: "function"
772
- },
773
- {
774
- inputs: [],
775
- name: "getPolicyID",
776
- outputs: [{ internalType: "string", name: "policyID", type: "string" }],
777
- stateMutability: "view",
778
- type: "function"
779
- },
780
- {
781
- inputs: [],
782
- name: "getRegistry",
783
- outputs: [{ internalType: "address", name: "", type: "address" }],
784
- stateMutability: "view",
785
- type: "function"
786
- },
787
- {
788
- inputs: [],
789
- name: "isNativeDepositSupported",
790
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
791
- stateMutability: "view",
792
- type: "function"
793
- },
794
- {
795
- inputs: [{ internalType: "contract ERC20", name: "", type: "address" }],
796
- name: "kytEnabled",
797
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
798
- stateMutability: "view",
799
- type: "function"
800
- },
801
- {
802
- inputs: [],
803
- name: "nativeWrapper",
804
- outputs: [
805
- { internalType: "contract INativeWrapper", name: "", type: "address" }
806
- ],
807
- stateMutability: "view",
808
- type: "function"
809
- },
810
- {
811
- inputs: [],
812
- name: "owner",
813
- outputs: [{ internalType: "address", name: "", type: "address" }],
814
- stateMutability: "view",
815
- type: "function"
816
- },
817
- {
818
- inputs: [
819
- {
820
- internalType: "contract Authority",
821
- name: "newAuthority",
822
- type: "address"
823
- }
824
- ],
825
- name: "setAuthority",
826
- outputs: [],
827
- stateMutability: "nonpayable",
828
- type: "function"
829
- },
830
- {
831
- inputs: [{ internalType: "string", name: "_policyID", type: "string" }],
832
- name: "setPolicyID",
833
- outputs: [],
834
- stateMutability: "nonpayable",
835
- type: "function"
836
- },
837
- {
838
- inputs: [{ internalType: "address", name: "_registry", type: "address" }],
839
- name: "setRegistry",
840
- outputs: [],
841
- stateMutability: "nonpayable",
842
- type: "function"
843
- },
844
- {
845
- inputs: [],
846
- name: "supplyCapInBase",
847
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
848
- stateMutability: "view",
849
- type: "function"
850
- },
851
- {
852
- inputs: [],
853
- name: "teller",
854
- outputs: [
855
- {
856
- internalType: "contract TellerWithMultiAssetSupport",
857
- name: "",
858
- type: "address"
859
- }
860
- ],
861
- stateMutability: "view",
862
- type: "function"
863
- },
864
- {
865
- inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
866
- name: "transferOwnership",
867
- outputs: [],
868
- stateMutability: "nonpayable",
869
- type: "function"
870
- },
871
- {
872
- inputs: [
873
- {
874
- internalType: "contract IFeeModule",
875
- name: "newFeeModule",
876
- type: "address"
877
- }
878
- ],
879
- name: "updateFeeModule",
880
- outputs: [],
881
- stateMutability: "nonpayable",
882
- type: "function"
883
- },
884
- {
885
- inputs: [
886
- { internalType: "address", name: "newFeeRecipient", type: "address" }
887
- ],
888
- name: "updateFeeRecipient",
889
- outputs: [],
890
- stateMutability: "nonpayable",
891
- type: "function"
892
- },
893
- {
894
- inputs: [
895
- { internalType: "contract ERC20", name: "depositAsset", type: "address" },
896
- { internalType: "bool", name: "enabled", type: "bool" }
897
- ],
898
- name: "updateKytStatus",
899
- outputs: [],
900
- stateMutability: "nonpayable",
901
- type: "function"
902
- },
903
- {
904
- inputs: [
905
- { internalType: "uint256", name: "newSupplyCapInBase", type: "uint256" }
906
- ],
907
- name: "updateSupplyCapInBase",
908
- outputs: [],
909
- stateMutability: "nonpayable",
910
- type: "function"
911
- }
912
- ];
913
-
914
- // src/vaults/deposit/utils.ts
915
- var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) => {
916
- const slippageValue = slippage ?? DEFAULT_SLIPPAGE_BPS;
917
- const slippageAsBigInt = BigInt(slippageValue) * WAD.bigint / BigInt(1e4);
918
- const minimumMint = depositAmount * WAD.bigint / rate;
919
- const slippageAmount = minimumMint * slippageAsBigInt / WAD.bigint;
920
- if (vaultTokenDecimals > 18) {
921
- return (minimumMint - slippageAmount) * BigInt(10) ** (BigInt(vaultTokenDecimals) - BigInt(18));
922
- }
923
- return (minimumMint - slippageAmount) / BigInt(10) ** (BigInt(18) - BigInt(vaultTokenDecimals));
924
- };
925
-
926
- // src/vaults/deposit/deposit.ts
927
- var DepositType = {
928
- STANDARD: "standard",
929
- KYT: "kyt"
930
- };
931
- function isKytDeposit(data) {
932
- return data.depositType === DepositType.KYT;
933
- }
934
- function isStandardDeposit(data) {
935
- return data.depositType === DepositType.STANDARD;
936
- }
937
- async function prepareDepositTxData(params) {
938
- const {
939
- vaultName,
940
- depositAsset,
941
- depositAmount,
942
- chainId,
943
- slippage = DEFAULT_SLIPPAGE_BPS,
944
- to,
945
- distributorCode
946
- } = params;
947
- try {
948
- const normalizedChainId = toChainId(chainId);
949
- const vault = await resolveVault({
950
- vaultName,
951
- assetAddress: depositAsset,
952
- chainId: normalizedChainId,
953
- callerEndpoint: "prepareDepositTransactionData"
954
- });
955
- if (vault.inDeprecation) {
956
- getLogger().warn(
957
- `Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
958
- );
959
- }
960
- const assets = await getSupportedAssets({ address: depositAsset });
961
- const asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets.find((a) => a.address.toLowerCase() === depositAsset.toLowerCase());
962
- if (!asset) {
963
- throw new APIError(
964
- `Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
965
- {
966
- endpoint: "prepareDepositTransactionData"
967
- }
968
- );
969
- }
970
- const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
971
- if (!communityCodeDepositorAddress) {
972
- throw new APIError(
973
- `Community Code Depositor contract address not found for vault ${vault.id}`,
974
- { endpoint: "prepareDepositTransactionData" }
975
- );
976
- }
977
- const accountantAddress = vault.vault.accountantAddress;
978
- if (!accountantAddress) {
979
- throw new APIError(
980
- `Accountant contract address not found for vault ${vault.id}`,
981
- { endpoint: "prepareDepositTransactionData" }
982
- );
983
- }
984
- const depositAssetAddress = asset.address;
985
- const [depositAssetDecimalsResult, rateInQuoteResult] = await getRateInQuoteWithAssetDecimals({
986
- assetAddress: depositAssetAddress,
987
- accountantAddress,
988
- chainId: normalizedChainId
989
- });
990
- if (depositAssetDecimalsResult.status === "failure") {
991
- throw new APIError(
992
- `Failed to get asset decimals: ${depositAssetDecimalsResult.error?.message || "Unknown error"}`,
993
- {
994
- endpoint: "prepareDepositTransactionData",
995
- cause: depositAssetDecimalsResult.error
996
- }
997
- );
998
- }
999
- if (rateInQuoteResult.status === "failure") {
1000
- throw new APIError(
1001
- `Failed to get exchange rate: ${rateInQuoteResult.error?.message || "Unknown error"}`,
1002
- {
1003
- endpoint: "prepareDepositTransactionData",
1004
- cause: rateInQuoteResult.error
1005
- }
1006
- );
1007
- }
1008
- const depositAmountAsBigInt = parseUnits(
1009
- depositAmount,
1010
- depositAssetDecimalsResult.result
1011
- );
1012
- const minimumMint = calculateMinimumMint(
1013
- depositAmountAsBigInt,
1014
- rateInQuoteResult.result,
1015
- depositAssetDecimalsResult.result,
1016
- slippage
1017
- );
1018
- const distributorCodeHex = stringToHex(distributorCode || "");
1019
- if (vault.enterpriseConfig?.predicatePolicyId != null) {
1020
- const attestation = {
1021
- uuid: "",
1022
- expiration: 0n,
1023
- attester: zeroAddress,
1024
- signature: "0x"
1025
- };
1026
- return {
1027
- depositType: DepositType.KYT,
1028
- address: communityCodeDepositorAddress,
1029
- abi: DistributorCodeDepositorAbiV1,
1030
- functionName: "deposit",
1031
- args: [
1032
- depositAssetAddress,
1033
- depositAmountAsBigInt,
1034
- minimumMint,
1035
- to,
1036
- distributorCodeHex,
1037
- attestation
1038
- ],
1039
- chainId: normalizedChainId
1040
- };
1041
- }
1042
- return {
1043
- depositType: DepositType.STANDARD,
1044
- abi: DistributorCodeDepositorAbiV0,
1045
- address: communityCodeDepositorAddress,
1046
- functionName: "deposit",
1047
- args: [
1048
- depositAssetAddress,
1049
- depositAmountAsBigInt,
1050
- minimumMint,
1051
- to,
1052
- distributorCodeHex
1053
- ],
1054
- chainId: normalizedChainId
1055
- };
1056
- } catch (error) {
1057
- if (error instanceof APIError) {
1058
- throw error;
1059
- }
1060
- throw new APIError(
1061
- `Failed to prepare deposit transaction: ${error instanceof Error ? error.message : String(error)}`,
1062
- {
1063
- endpoint: "prepareDepositTransactionData",
1064
- cause: error
1065
- }
1066
- );
1067
- }
1068
- }
1069
- var PERMIT_TYPES = {
1070
- Permit: [
1071
- { name: "owner", type: "address" },
1072
- { name: "spender", type: "address" },
1073
- { name: "value", type: "uint256" },
1074
- { name: "nonce", type: "uint256" },
1075
- { name: "deadline", type: "uint256" }
1076
- ]
1077
- };
1078
- var EIP712_DOMAIN_TYPE = [
1079
- { name: "name", type: "string" },
1080
- { name: "version", type: "string" },
1081
- { name: "chainId", type: "uint256" },
1082
- { name: "verifyingContract", type: "address" }
1083
- ];
1084
- function toEthSignTypedDataV4(permitData) {
1085
- return JSON.stringify({
1086
- domain: permitData.domain,
1087
- types: {
1088
- EIP712Domain: EIP712_DOMAIN_TYPE,
1089
- ...permitData.types
1090
- },
1091
- primaryType: permitData.primaryType,
1092
- message: {
1093
- owner: permitData.message.owner,
1094
- spender: permitData.message.spender,
1095
- value: permitData.message.value.toString(),
1096
- nonce: permitData.message.nonce.toString(),
1097
- deadline: permitData.message.deadline.toString()
1098
- }
1099
- });
1100
- }
1101
- async function prepareDepositPermitSignature(params) {
1102
- const {
1103
- vaultName,
1104
- depositAsset,
1105
- depositAmount,
1106
- to,
1107
- chainId,
1108
- deadline,
1109
- // Optional pre-fetched data to skip RPC calls
1110
- nonce: prefetchedNonce,
1111
- decimals: prefetchedDecimals,
1112
- tokenName: prefetchedTokenName,
1113
- tokenVersion: prefetchedTokenVersion
1114
- } = params;
1115
- try {
1116
- const normalizedChainId = toChainId(chainId);
1117
- const vault = await resolveVault({
1118
- vaultName,
1119
- assetAddress: depositAsset,
1120
- chainId: normalizedChainId,
1121
- callerEndpoint: "prepareDepositPermitSignature"
1122
- });
1123
- const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
1124
- if (!communityCodeDepositorAddress) {
1125
- throw new APIError(
1126
- `CommunityCodeDepositor contract address not found for vault ${vault.id}`,
1127
- { endpoint: "prepareDepositPermitSignature" }
1128
- );
1129
- }
1130
- let resolvedTokenName;
1131
- let resolvedTokenVersion;
1132
- let resolvedNonce;
1133
- const hasAllPrefetchedData = prefetchedTokenName !== void 0 && prefetchedTokenVersion !== void 0 && prefetchedNonce !== void 0;
1134
- if (hasAllPrefetchedData) {
1135
- resolvedTokenName = prefetchedTokenName;
1136
- resolvedTokenVersion = prefetchedTokenVersion;
1137
- resolvedNonce = prefetchedNonce;
1138
- } else {
1139
- const client = await getClient(normalizedChainId);
1140
- try {
1141
- const [nameResult, versionResult, nonceResult] = await client.multicall(
1142
- {
1143
- contracts: [
1144
- {
1145
- address: depositAsset,
1146
- abi: erc2612Abi,
1147
- functionName: "name"
1148
- },
1149
- {
1150
- address: depositAsset,
1151
- abi: erc2612Abi,
1152
- functionName: "version"
1153
- },
1154
- {
1155
- address: depositAsset,
1156
- abi: erc2612Abi,
1157
- functionName: "nonces",
1158
- args: [to]
1159
- }
1160
- ]
1161
- }
1162
- );
1163
- if (prefetchedTokenName !== void 0) {
1164
- resolvedTokenName = prefetchedTokenName;
1165
- } else if (nameResult.status === "success") {
1166
- resolvedTokenName = nameResult.result;
1167
- } else {
1168
- throw new APIError(`Failed to read token name from ${depositAsset}`, {
1169
- endpoint: "prepareDepositPermitSignature",
1170
- cause: nameResult.error
1171
- });
1172
- }
1173
- if (prefetchedTokenVersion !== void 0) {
1174
- resolvedTokenVersion = prefetchedTokenVersion;
1175
- } else if (versionResult.status === "success") {
1176
- resolvedTokenVersion = versionResult.result;
1177
- } else {
1178
- resolvedTokenVersion = "1";
1179
- }
1180
- if (prefetchedNonce !== void 0) {
1181
- resolvedNonce = prefetchedNonce;
1182
- } else if (nonceResult.status === "success") {
1183
- resolvedNonce = nonceResult.result;
1184
- } else {
1185
- throw new APIError(
1186
- `Token ${depositAsset} does not support EIP-2612 permit. Missing required function: nonces()`,
1187
- {
1188
- endpoint: "prepareDepositPermitSignature",
1189
- cause: nonceResult.error
1190
- }
1191
- );
1192
- }
1193
- } catch (error) {
1194
- if (error instanceof APIError) {
1195
- throw error;
1196
- }
1197
- throw new APIError(
1198
- `Failed to read token metadata: ${error instanceof Error ? error.message : "Unknown error"}`,
1199
- {
1200
- endpoint: "prepareDepositPermitSignature",
1201
- cause: error
1202
- }
1203
- );
1204
- }
1205
- }
1206
- const permitDeadline = deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 3600);
1207
- let resolvedDecimals;
1208
- if (prefetchedDecimals !== void 0) {
1209
- resolvedDecimals = prefetchedDecimals;
1210
- } else {
1211
- resolvedDecimals = await getErc20Decimals({
1212
- tokenAddress: depositAsset,
1213
- chainId: normalizedChainId
1214
- });
1215
- }
1216
- const value = parseUnits(depositAmount, resolvedDecimals);
1217
- const domain = {
1218
- name: resolvedTokenName,
1219
- version: resolvedTokenVersion,
1220
- chainId: normalizedChainId,
1221
- verifyingContract: depositAsset
1222
- };
1223
- const message = {
1224
- owner: to,
1225
- spender: communityCodeDepositorAddress,
1226
- value,
1227
- nonce: resolvedNonce,
1228
- deadline: permitDeadline
1229
- };
1230
- return {
1231
- account: to,
1232
- domain,
1233
- types: PERMIT_TYPES,
1234
- primaryType: "Permit",
1235
- message
1236
- };
1237
- } catch (error) {
1238
- if (error instanceof APIError) {
1239
- throw error;
1240
- }
1241
- throw new APIError(
1242
- `Failed to prepare permit signature: ${error instanceof Error ? error.message : String(error)}`,
1243
- {
1244
- endpoint: "prepareDepositPermitSignature",
1245
- cause: error
1246
- }
1247
- );
1248
- }
1249
- }
1250
- function parsePermitSignature(signature) {
1251
- try {
1252
- const parsed = hexToSignature(signature);
1253
- let v;
1254
- if (parsed.v !== void 0) {
1255
- v = Number(parsed.v);
1256
- } else if (parsed.yParity !== void 0) {
1257
- v = parsed.yParity + 27;
1258
- } else {
1259
- v = 27;
1260
- }
1261
- return {
1262
- v,
1263
- r: parsed.r,
1264
- s: parsed.s
1265
- };
1266
- } catch (error) {
1267
- throw new APIError(
1268
- `Invalid permit signature format. Expected hex string but received: ${signature}. ${error instanceof Error ? error.message : "Unknown error"}`,
1269
- {
1270
- endpoint: "parsePermitSignature",
1271
- cause: error
1272
- }
1273
- );
1274
- }
1275
- }
1276
- async function prepareDepositWithPermitTxData(params) {
1277
- const {
1278
- vaultName,
1279
- depositAsset,
1280
- depositAmount,
1281
- chainId,
1282
- signature,
1283
- deadline,
1284
- slippage = DEFAULT_SLIPPAGE_BPS,
1285
- to,
1286
- distributorCode
1287
- } = params;
1288
- try {
1289
- const { v, r, s } = parsePermitSignature(signature);
1290
- if (slippage < 0 || slippage > 1e4) {
1291
- throw new APIError(
1292
- `Invalid slippage value: ${slippage}. Slippage must be between 0 and 10000 basis points.`,
1293
- {
1294
- endpoint: "prepareDepositWithPermitTxData"
1295
- }
1296
- );
1297
- }
1298
- const normalizedChainId = toChainId(chainId);
1299
- const vault = await resolveVault({
1300
- vaultName,
1301
- assetAddress: depositAsset,
1302
- chainId: normalizedChainId,
1303
- callerEndpoint: "prepareDepositWithPermitTxData"
1304
- });
1305
- if (vault.inDeprecation) {
1306
- getLogger().warn(
1307
- `Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
1308
- );
1309
- }
1310
- let asset = null;
1311
- const assets = await getSupportedAssets({ address: depositAsset });
1312
- if (assets.length > 0) {
1313
- asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets[0] || null;
1314
- }
1315
- if (!asset) {
1316
- throw new APIError(
1317
- `Asset metadata not found for token ${depositAsset} on chain ${normalizedChainId}`,
1318
- {
1319
- endpoint: "prepareDepositWithPermitTxData"
1320
- }
1321
- );
1322
- }
1323
- if (!asset.chains || !asset.chains.includes(normalizedChainId)) {
1324
- throw new APIError(
1325
- `Token ${asset.symbol || depositAsset} not supported on chain ${normalizedChainId}`,
1326
- {
1327
- endpoint: "prepareDepositWithPermitTxData"
1328
- }
1329
- );
1330
- }
1331
- const communityCodeDepositorAddress = vault.vault.communityCodeDepositorAddress;
1332
- const accountantAddress = vault.vault.accountantAddress;
1333
- const depositAssetAddress = depositAsset;
1334
- if (!communityCodeDepositorAddress) {
1335
- throw new APIError(
1336
- `CommunityCodeDepositor contract address not found for vault ${vault.id}`,
1337
- { endpoint: "prepareDepositWithPermitTxData" }
1338
- );
1339
- }
1340
- if (!accountantAddress) {
1341
- throw new APIError(
1342
- `Accountant contract address not found for vault ${vault.id}`,
1343
- { endpoint: "prepareDepositWithPermitTxData" }
1344
- );
1345
- }
1346
- const rateAndDecimalResults = await getRateInQuoteWithAssetDecimals({
1347
- assetAddress: depositAssetAddress,
1348
- accountantAddress,
1349
- chainId: normalizedChainId
1350
- });
1351
- const [depositAssetDecimalsResult, rateInQuoteResult] = rateAndDecimalResults;
1352
- if (depositAssetDecimalsResult.status === "failure") {
1353
- throw new APIError(
1354
- `Failed to get asset decimals: ${depositAssetDecimalsResult.error?.message || "Unknown error"}`,
1355
- {
1356
- endpoint: "prepareDepositWithPermitTxData",
1357
- cause: depositAssetDecimalsResult.error
1358
- }
1359
- );
1360
- }
1361
- if (rateInQuoteResult.status === "failure") {
1362
- throw new APIError(
1363
- `Failed to get exchange rate: ${rateInQuoteResult.error?.message || "Unknown error"}`,
1364
- {
1365
- endpoint: "prepareDepositWithPermitTxData",
1366
- cause: rateInQuoteResult.error
1367
- }
1368
- );
1369
- }
1370
- const onChainDecimals = depositAssetDecimalsResult.result;
1371
- const depositAmountAsBigInt = parseUnits(depositAmount, onChainDecimals);
1372
- const minimumMint = calculateMinimumMint(
1373
- depositAmountAsBigInt,
1374
- rateInQuoteResult.result,
1375
- onChainDecimals,
1376
- slippage
1377
- );
1378
- const distributorCodeHex = stringToHex(distributorCode || "");
1379
- if (vault.enterpriseConfig?.predicatePolicyId != null) {
1380
- const attestation = {
1381
- uuid: "",
1382
- expiration: 0n,
1383
- attester: zeroAddress,
1384
- signature: "0x"
1385
- };
1386
- return {
1387
- depositType: DepositType.KYT,
1388
- abi: DistributorCodeDepositorAbiV1,
1389
- address: communityCodeDepositorAddress,
1390
- functionName: "depositWithPermit",
1391
- args: [
1392
- depositAssetAddress,
1393
- depositAmountAsBigInt,
1394
- minimumMint,
1395
- to,
1396
- distributorCodeHex,
1397
- attestation,
1398
- deadline,
1399
- v,
1400
- r,
1401
- s
1402
- ],
1403
- chainId: normalizedChainId
1404
- };
1405
- }
1406
- return {
1407
- depositType: DepositType.STANDARD,
1408
- abi: DistributorCodeDepositorAbiV0,
1409
- address: communityCodeDepositorAddress,
1410
- functionName: "depositWithPermit",
1411
- args: [
1412
- depositAssetAddress,
1413
- depositAmountAsBigInt,
1414
- minimumMint,
1415
- to,
1416
- distributorCodeHex,
1417
- deadline,
1418
- v,
1419
- r,
1420
- s
1421
- ],
1422
- chainId: normalizedChainId
1423
- };
1424
- } catch (error) {
1425
- if (error instanceof APIError) {
1426
- throw error;
1427
- }
1428
- throw new APIError(
1429
- `Failed to prepare deposit with permit transaction: ${error instanceof Error ? error.message : String(error)}`,
1430
- {
1431
- endpoint: "prepareDepositWithPermitTxData",
1432
- cause: error
1433
- }
1434
- );
1435
- }
1436
- }
1437
-
1438
- // src/utils/wallet.ts
1439
- async function isSmartContractWallet(address, chainId) {
1440
- const client = await getClient(chainId);
1441
- const code = await client.getCode({ address });
1442
- return !!code && code !== "0x";
1443
- }
1444
-
1445
- // src/vaults/deposit/index.ts
1446
- var DepositAuthMethod = {
1447
- PERMIT: "permit",
1448
- APPROVAL: "approval",
1449
- ALREADY_APPROVED: "already_approved"
1450
- };
1451
- function isPermitAuth(result) {
1452
- return result.method === DepositAuthMethod.PERMIT;
1453
- }
1454
- function isApprovalAuth(result) {
1455
- return result.method === DepositAuthMethod.APPROVAL;
1456
- }
1457
- function isAlreadyApprovedAuth(result) {
1458
- return result.method === DepositAuthMethod.ALREADY_APPROVED;
1459
- }
1460
- async function prepareDepositAuthorization(params) {
1461
- const {
1462
- vaultName,
1463
- depositAsset,
1464
- depositAmount,
1465
- to,
1466
- chainId,
1467
- deadline,
1468
- forceMethod
1469
- } = params;
1470
- try {
1471
- const normalizedChainId = toChainId(chainId);
1472
- const vault = await resolveVault({
1473
- vaultName,
1474
- assetAddress: depositAsset,
1475
- chainId: normalizedChainId,
1476
- callerEndpoint: "prepareDepositAuthorization"
1477
- });
1478
- if (forceMethod === "approval") {
1479
- const txData2 = await prepareApproveDepositTokenTxData({
1480
- vaultName,
1481
- depositAsset,
1482
- approvalAmount: depositAmount,
1483
- chainId: normalizedChainId
1484
- });
1485
- return {
1486
- method: DepositAuthMethod.APPROVAL,
1487
- txData: txData2
1488
- };
1489
- }
1490
- if (forceMethod === "permit") {
1491
- const tokenInfo2 = await isDepositSpendApproved({
1492
- vaultName: vault.name,
1493
- chainId: normalizedChainId,
1494
- depositAssetAddress: depositAsset,
1495
- recipientAddress: to
1496
- });
1497
- const permitData = await prepareDepositPermitSignature({
1498
- vaultName,
1499
- depositAsset,
1500
- depositAmount,
1501
- to,
1502
- chainId: normalizedChainId,
1503
- deadline,
1504
- nonce: tokenInfo2.nonce ?? void 0,
1505
- decimals: tokenInfo2.decimals,
1506
- tokenName: tokenInfo2.tokenName,
1507
- tokenVersion: tokenInfo2.tokenVersion
1508
- });
1509
- return {
1510
- method: DepositAuthMethod.PERMIT,
1511
- permitData
1512
- };
1513
- }
1514
- const smartWallet = await isSmartContractWallet(to, normalizedChainId);
1515
- if (smartWallet) {
1516
- const txData2 = await prepareApproveDepositTokenTxData({
1517
- vaultName,
1518
- depositAsset,
1519
- approvalAmount: depositAmount,
1520
- chainId: normalizedChainId
1521
- });
1522
- return {
1523
- method: DepositAuthMethod.APPROVAL,
1524
- txData: txData2
1525
- };
1526
- }
1527
- const tokenInfo = await isDepositSpendApproved({
1528
- vaultName: vault.name,
1529
- chainId: normalizedChainId,
1530
- depositAssetAddress: depositAsset,
1531
- recipientAddress: to
1532
- });
1533
- if (tokenInfo.supportsPermit) {
1534
- const permitData = await prepareDepositPermitSignature({
1535
- vaultName,
1536
- depositAsset,
1537
- depositAmount,
1538
- to,
1539
- chainId: normalizedChainId,
1540
- deadline,
1541
- nonce: tokenInfo.nonce ?? void 0,
1542
- decimals: tokenInfo.decimals,
1543
- tokenName: tokenInfo.tokenName,
1544
- tokenVersion: tokenInfo.tokenVersion
1545
- });
1546
- return {
1547
- method: DepositAuthMethod.PERMIT,
1548
- permitData
1549
- };
1550
- }
1551
- const depositAmountBigInt = parseUnits(depositAmount, tokenInfo.decimals);
1552
- const currentAllowanceBigInt = BigInt(tokenInfo.allowanceAsBigInt);
1553
- if (tokenInfo.isApproved && currentAllowanceBigInt >= depositAmountBigInt) {
1554
- return {
1555
- method: DepositAuthMethod.ALREADY_APPROVED,
1556
- allowance: tokenInfo.allowance,
1557
- allowanceAsBigInt: tokenInfo.allowanceAsBigInt
1558
- };
1559
- }
1560
- const txData = await prepareApproveDepositTokenTxData({
1561
- vaultName,
1562
- depositAsset,
1563
- approvalAmount: depositAmount,
1564
- chainId: normalizedChainId
1565
- });
1566
- return {
1567
- method: DepositAuthMethod.APPROVAL,
1568
- txData
1569
- };
1570
- } catch (error) {
1571
- if (error instanceof APIError) {
1572
- throw error;
1573
- }
1574
- throw new APIError(
1575
- `Failed to prepare deposit authorization: ${error instanceof Error ? error.message : String(error)}`,
1576
- {
1577
- endpoint: "prepareDepositAuthorization",
1578
- cause: error
1579
- }
1580
- );
1581
- }
1582
- }
1583
- async function prepareDeposit(params) {
1584
- const {
1585
- vaultName,
1586
- depositAsset,
1587
- depositAmount,
1588
- to,
1589
- chainId,
1590
- slippage,
1591
- distributorCode,
1592
- signature,
1593
- deadline,
1594
- forceMethod
1595
- } = params;
1596
- try {
1597
- if (forceMethod === "permit" && (!signature || deadline === void 0)) {
1598
- throw new APIError(
1599
- "Permit deposit requires both signature and deadline parameters when forceMethod is 'permit'",
1600
- { endpoint: "prepareDeposit" }
1601
- );
1602
- }
1603
- const usePermit = forceMethod === "permit" || forceMethod !== "approval" && signature !== void 0 && deadline !== void 0;
1604
- if (usePermit) {
1605
- if (!signature || deadline === void 0) {
1606
- throw new APIError(
1607
- "Permit deposit requires both signature and deadline parameters",
1608
- { endpoint: "prepareDeposit" }
1609
- );
1610
- }
1611
- const txData2 = await prepareDepositWithPermitTxData({
1612
- vaultName,
1613
- depositAsset,
1614
- depositAmount,
1615
- to,
1616
- chainId,
1617
- signature,
1618
- deadline,
1619
- slippage,
1620
- distributorCode
1621
- });
1622
- return {
1623
- method: DepositAuthMethod.PERMIT,
1624
- txData: txData2
1625
- };
1626
- }
1627
- const txData = await prepareDepositTxData({
1628
- vaultName,
1629
- depositAsset,
1630
- depositAmount,
1631
- to,
1632
- chainId,
1633
- slippage,
1634
- distributorCode
1635
- });
1636
- return {
1637
- method: DepositAuthMethod.APPROVAL,
1638
- txData
1639
- };
1640
- } catch (error) {
1641
- if (error instanceof APIError) {
1642
- throw error;
1643
- }
1644
- throw new APIError(
1645
- `Failed to prepare deposit: ${error instanceof Error ? error.message : String(error)}`,
1646
- {
1647
- endpoint: "prepareDeposit",
1648
- cause: error
1649
- }
1650
- );
1651
- }
1652
- }
1653
- async function prepareApproveWithdrawOrderTxData({
1654
- vaultName,
1655
- wantAssetAddress,
1656
- withdrawAmount,
1657
- chainId,
1658
- shareDecimals
1659
- }) {
1660
- try {
1661
- const normalizedChainId = toChainId(chainId);
1662
- const config = await resolveVault({
1663
- vaultName,
1664
- assetAddress: wantAssetAddress,
1665
- chainId: normalizedChainId,
1666
- callerEndpoint: "prepareApproveWithdrawOrderTxData"
1667
- });
1668
- if (!config.vault.boringVaultAddress) {
1669
- throw new APIError(
1670
- `BoringVault contract address not configured for vault ${config.id}`,
1671
- { endpoint: "prepareApproveWithdrawOrderTxData" }
1672
- );
1673
- }
1674
- if (!config.vault.withdrawQueueAddress) {
1675
- throw new APIError(
1676
- `WithdrawQueue contract address not configured for vault ${config.id}`,
1677
- { endpoint: "prepareApproveWithdrawOrderTxData" }
1678
- );
1679
- }
1680
- const boringVaultAddress = config.vault.boringVaultAddress;
1681
- const withdrawQueueAddress = config.vault.withdrawQueueAddress;
1682
- const decimals = shareDecimals ?? await getErc20Decimals({
1683
- tokenAddress: boringVaultAddress,
1684
- chainId: normalizedChainId
1685
- });
1686
- const withdrawAmountAsBigInt = withdrawAmount ? parseUnits(withdrawAmount, decimals) : DEFAULT_APPROVAL_AMOUNT;
1687
- return {
1688
- abi: BoringVaultAbi,
1689
- address: boringVaultAddress,
1690
- functionName: "approve",
1691
- args: [withdrawQueueAddress, withdrawAmountAsBigInt]
1692
- };
1693
- } catch (error) {
1694
- if (error instanceof APIError) {
1695
- throw error;
1696
- }
1697
- throw new APIError(
1698
- `Failed to prepare approval transaction: ${error instanceof Error ? error.message : String(error)}`,
1699
- {
1700
- endpoint: "prepareApproveWithdrawOrderTxData",
1701
- cause: error
1702
- }
1703
- );
1704
- }
1705
- }
1706
-
1707
- // src/vaults/withdraw/cancel-withdraw.ts
1708
- var prepareCancelWithdrawOrderTxData = async ({
1709
- vaultName,
1710
- wantAsset,
1711
- chainId,
1712
- orderIndex
1713
- }) => {
1714
- try {
1715
- const normalizedChainId = toChainId(chainId);
1716
- const config = await resolveVault({
1717
- vaultName,
1718
- assetAddress: wantAsset,
1719
- chainId: normalizedChainId,
1720
- callerEndpoint: "prepareCancelWithdrawOrderTxData"
1721
- });
1722
- if (config.chainId !== normalizedChainId) {
1723
- throw new APIError(
1724
- `Vault chain mismatch: vault is on chain ${config.chainId}, requested chain ${normalizedChainId}`,
1725
- { endpoint: "prepareCancelWithdrawOrderTxData" }
1726
- );
1727
- }
1728
- if (!config.vault.withdrawQueueAddress) {
1729
- throw new APIError(
1730
- `WithdrawQueue contract address not configured for vault ${config.id}`,
1731
- { endpoint: "prepareCancelWithdrawOrderTxData" }
1732
- );
1733
- }
1734
- return {
1735
- abi: WithdrawQueueAbi,
1736
- address: config.vault.withdrawQueueAddress,
1737
- functionName: "cancelOrder",
1738
- args: [orderIndex],
1739
- chainId: normalizedChainId
1740
- };
1741
- } catch (error) {
1742
- if (error instanceof APIError) {
1743
- throw error;
1744
- }
1745
- throw new APIError(
1746
- `Failed to prepare cancel order transaction: ${error instanceof Error ? error.message : String(error)}`,
1747
- {
1748
- endpoint: "prepareCancelWithdrawOrderTxData",
1749
- cause: error
1750
- }
1751
- );
1752
- }
1753
- };
1754
- var ApprovalMethod = {
1755
- /** Standard ERC20 approve (user has pre-approved via approve()) */
1756
- EIP20_APPROVE: 0};
1757
- var EMPTY_SIGNATURE_PARAMS = {
1758
- approvalMethod: ApprovalMethod.EIP20_APPROVE,
1759
- approvalV: 0,
1760
- approvalR: "0x0000000000000000000000000000000000000000000000000000000000000000",
1761
- approvalS: "0x0000000000000000000000000000000000000000000000000000000000000000",
1762
- submitWithSignature: false,
1763
- deadline: 0n,
1764
- eip2612Signature: "0x"
1765
- };
1766
- var prepareWithdrawOrderTxData = async ({
1767
- vaultName,
1768
- wantAsset,
1769
- userAddress,
1770
- chainId,
1771
- amountOffer
1772
- }) => {
1773
- try {
1774
- const normalizedChainId = toChainId(chainId);
1775
- const config = await resolveVault({
1776
- vaultName,
1777
- assetAddress: wantAsset,
1778
- chainId: normalizedChainId,
1779
- callerEndpoint: "prepareWithdrawOrderTxData"
1780
- });
1781
- if (config.chainId !== normalizedChainId) {
1782
- throw new APIError(
1783
- `Vault chain mismatch: vault is on chain ${config.chainId}, requested chain ${normalizedChainId}`,
1784
- { endpoint: "prepareWithdrawOrderTxData" }
1785
- );
1786
- }
1787
- if (!config.vault.withdrawQueueAddress) {
1788
- throw new APIError(
1789
- `WithdrawQueue contract address not configured for vault ${config.id}`,
1790
- { endpoint: "prepareWithdrawOrderTxData" }
1791
- );
1792
- }
1793
- if (!config.vault.boringVaultAddress) {
1794
- throw new APIError(
1795
- `BoringVault contract address not configured for vault ${config.id}`,
1796
- { endpoint: "prepareWithdrawOrderTxData" }
1797
- );
1798
- }
1799
- const sharesDecimals = await getErc20Decimals({
1800
- tokenAddress: config.vault.boringVaultAddress,
1801
- chainId: normalizedChainId
1802
- });
1803
- const formattedAmountOffer = parseUnits(amountOffer, sharesDecimals);
1804
- return {
1805
- abi: WithdrawQueueAbi,
1806
- address: config.vault.withdrawQueueAddress,
1807
- functionName: "submitOrder",
1808
- args: [
1809
- {
1810
- amountOffer: formattedAmountOffer,
1811
- wantAsset,
1812
- intendedDepositor: userAddress,
1813
- receiver: userAddress,
1814
- refundReceiver: userAddress,
1815
- signatureParams: EMPTY_SIGNATURE_PARAMS
1816
- }
1817
- ],
1818
- chainId: normalizedChainId
1819
- };
1820
- } catch (error) {
1821
- if (error instanceof APIError) {
1822
- throw error;
1823
- }
1824
- throw new APIError(
1825
- `Failed to prepare withdraw order transaction: ${error instanceof Error ? error.message : String(error)}`,
1826
- {
1827
- endpoint: "prepareWithdrawOrderTxData",
1828
- cause: error
1829
- }
1830
- );
1831
- }
1832
- };
1833
- var WithdrawAuthMethod = {
1834
- APPROVAL: "approval",
1835
- ALREADY_APPROVED: "already_approved"
1836
- };
1837
- function isWithdrawApprovalAuth(result) {
1838
- return result.method === WithdrawAuthMethod.APPROVAL;
1839
- }
1840
- function isWithdrawAlreadyApprovedAuth(result) {
1841
- return result.method === WithdrawAuthMethod.ALREADY_APPROVED;
1842
- }
1843
- async function prepareWithdrawal(params) {
1844
- const { vaultName, wantAsset, withdrawAmount, userAddress, chainId } = params;
1845
- try {
1846
- return await prepareWithdrawOrderTxData({
1847
- vaultName,
1848
- wantAsset,
1849
- userAddress,
1850
- chainId,
1851
- amountOffer: withdrawAmount
1852
- });
1853
- } catch (error) {
1854
- if (error instanceof APIError) {
1855
- throw error;
1856
- }
1857
- throw new APIError(
1858
- `Failed to prepare withdrawal: ${error instanceof Error ? error.message : String(error)}`,
1859
- {
1860
- endpoint: "prepareWithdrawal",
1861
- cause: error
1862
- }
1863
- );
1864
- }
1865
- }
1866
- async function prepareWithdrawalAuthorization(params) {
1867
- const {
1868
- vaultName,
1869
- wantAsset,
1870
- withdrawAmount,
1871
- userAddress,
1872
- chainId,
1873
- forceMethod
1874
- } = params;
1875
- try {
1876
- const normalizedChainId = toChainId(chainId);
1877
- const vault = await resolveVault({
1878
- vaultName,
1879
- assetAddress: wantAsset,
1880
- chainId: normalizedChainId,
1881
- callerEndpoint: "prepareWithdrawalAuthorization"
1882
- });
1883
- if (forceMethod === "approval") {
1884
- const txData2 = await prepareApproveWithdrawOrderTxData({
1885
- vaultName,
1886
- wantAssetAddress: wantAsset,
1887
- withdrawAmount,
1888
- chainId: normalizedChainId
1889
- });
1890
- return {
1891
- method: WithdrawAuthMethod.APPROVAL,
1892
- txData: txData2
1893
- };
1894
- }
1895
- if (forceMethod !== "allowance_check") {
1896
- const smartWallet = await isSmartContractWallet(
1897
- userAddress,
1898
- normalizedChainId
1899
- );
1900
- if (smartWallet) {
1901
- const txData2 = await prepareApproveWithdrawOrderTxData({
1902
- vaultName,
1903
- wantAssetAddress: wantAsset,
1904
- withdrawAmount,
1905
- chainId: normalizedChainId
1906
- });
1907
- return {
1908
- method: WithdrawAuthMethod.APPROVAL,
1909
- txData: txData2
1910
- };
1911
- }
1912
- }
1913
- const approvalInfo = await isWithdrawalSpendApproved({
1914
- vaultName: vault.name,
1915
- chainId: normalizedChainId,
1916
- wantAssetAddress: wantAsset,
1917
- recipientAddress: userAddress
1918
- });
1919
- if (approvalInfo.error) {
1920
- throw new APIError(
1921
- `Failed to check withdrawal approval: ${approvalInfo.error}`,
1922
- { endpoint: "prepareWithdrawalAuthorization" }
1923
- );
1924
- }
1925
- const decimals = typeof approvalInfo.decimals === "string" ? Number(approvalInfo.decimals) : approvalInfo.decimals;
1926
- const withdrawAmountBigInt = parseUnits(withdrawAmount, decimals);
1927
- const currentAllowanceBigInt = BigInt(approvalInfo.allowanceAsBigInt);
1928
- if (approvalInfo.isApproved && currentAllowanceBigInt >= withdrawAmountBigInt) {
1929
- return {
1930
- method: WithdrawAuthMethod.ALREADY_APPROVED,
1931
- allowance: approvalInfo.allowance,
1932
- allowanceAsBigInt: approvalInfo.allowanceAsBigInt
1933
- };
1934
- }
1935
- const txData = await prepareApproveWithdrawOrderTxData({
1936
- vaultName,
1937
- wantAssetAddress: wantAsset,
1938
- withdrawAmount,
1939
- chainId: normalizedChainId,
1940
- shareDecimals: decimals
1941
- });
1942
- return {
1943
- method: WithdrawAuthMethod.APPROVAL,
1944
- txData
1945
- };
1946
- } catch (error) {
1947
- if (error instanceof APIError) {
1948
- throw error;
1949
- }
1950
- throw new APIError(
1951
- `Failed to prepare withdrawal authorization: ${error instanceof Error ? error.message : String(error)}`,
1952
- {
1953
- endpoint: "prepareWithdrawalAuthorization",
1954
- cause: error
1955
- }
1956
- );
1957
- }
1958
- }
1959
-
1960
- export { DepositAuthMethod, DepositType, PERMIT_TYPES, WithdrawAuthMethod, isAlreadyApprovedAuth, isApprovalAuth, isDepositSpendApproved, isKytDeposit, isPermitAuth, isStandardDeposit, isWithdrawAlreadyApprovedAuth, isWithdrawApprovalAuth, isWithdrawalSpendApproved, parsePermitSignature, prepareApproveDepositTokenTxData, prepareApproveWithdrawOrderTxData, prepareCancelWithdrawOrderTxData, prepareDeposit, prepareDepositAuthorization, prepareDepositPermitSignature, prepareDepositTxData, prepareDepositWithPermitTxData, prepareWithdrawOrderTxData, prepareWithdrawal, prepareWithdrawalAuthorization, toEthSignTypedDataV4 };
1961
- //# sourceMappingURL=chunk-HU5CTL4C.mjs.map
1962
- //# sourceMappingURL=chunk-HU5CTL4C.mjs.map