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