@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,690 +0,0 @@
1
- import { resolveVault, VaultNotFoundByNameError } from './chunk-Y5LBT2WT.mjs';
2
- import { getRateInQuoteWithAssetDecimals, getErc20Decimals, BoringVaultAbi, AccountantAbi } from './chunk-UY2WD7MF.mjs';
3
- import { calculateExpectedSharesMinted } from './chunk-6CU533DM.mjs';
4
- import { toChainId, APIError, readSupplyCapInBase, readFeeModuleFromDCD, getClient, readDepositFeeStructure, getRestV2BaseURL, DEFAULT_TIMEOUT, getRequestHeaders, isValidAddress, getCache, WithdrawQueueAbi, FeeModuleAbi } from './chunk-ODXJYXUH.mjs';
5
- import { parseUnits, zeroAddress, maxUint256, erc20Abi } from 'viem';
6
-
7
- async function getMinimumMint(params) {
8
- try {
9
- const normalizedChainId = toChainId(params.chainId);
10
- const config = await resolveVault({
11
- vaultName: params.vaultName,
12
- assetAddress: params.depositAssetAddress,
13
- chainId: normalizedChainId,
14
- callerEndpoint: "getMinimumMint"
15
- });
16
- if (!config.vault.accountantAddress) {
17
- throw new APIError(
18
- `Accountant contract address not configured for vault ${config.id}`,
19
- { endpoint: "getMinimumMint" }
20
- );
21
- }
22
- if (!config.vault.boringVaultAddress) {
23
- throw new APIError(
24
- `BoringVault contract address not configured for vault ${config.id}`,
25
- { endpoint: "getMinimumMint" }
26
- );
27
- }
28
- const rateResults = await getRateInQuoteWithAssetDecimals({
29
- assetAddress: params.depositAssetAddress,
30
- accountantAddress: config.vault.accountantAddress,
31
- chainId: normalizedChainId
32
- });
33
- const [assetDecimalsResult, exchangeRateResult] = rateResults;
34
- if (assetDecimalsResult.status === "failure" || exchangeRateResult.status === "failure") {
35
- throw new APIError(
36
- `Failed to get exchange rate or asset decimals: ${assetDecimalsResult.error?.message || exchangeRateResult.error?.message}`,
37
- { endpoint: "getMinimumMint" }
38
- );
39
- }
40
- const assetDecimals = assetDecimalsResult.result;
41
- const exchangeRate = exchangeRateResult.result;
42
- const shareDecimals = await getErc20Decimals({
43
- tokenAddress: config.vault.boringVaultAddress,
44
- chainId: normalizedChainId
45
- });
46
- const depositAmountBigInt = parseUnits(params.depositAmount, assetDecimals);
47
- const expectedShares = calculateExpectedSharesMinted(
48
- depositAmountBigInt,
49
- exchangeRate,
50
- shareDecimals
51
- );
52
- return {
53
- expectedShares,
54
- exchangeRate,
55
- shareDecimals,
56
- assetDecimals
57
- };
58
- } catch (error) {
59
- if (error instanceof APIError) {
60
- throw error;
61
- }
62
- throw new APIError(
63
- `Failed to calculate minimum mint: ${error instanceof Error ? error.message : String(error)}`,
64
- { endpoint: "getMinimumMint", cause: error }
65
- );
66
- }
67
- }
68
- async function getDepositCap(params) {
69
- try {
70
- const normalizedChainId = toChainId(params.chainId);
71
- const config = await resolveVault({
72
- vaultName: params.vaultName,
73
- assetAddress: params.assetAddress,
74
- chainId: normalizedChainId,
75
- callerEndpoint: "getDepositCap"
76
- });
77
- if (!config.vault.communityCodeDepositorAddress || !config.vault.depositFeeModuleAddress) {
78
- throw new APIError(
79
- `Deposit cap not available for vault ${config.id} \u2014 requires both CommunityCodeDepositor and deposit fee module`,
80
- { endpoint: "getDepositCap" }
81
- );
82
- }
83
- const [supplyCapInBase, depositFeeModuleAddress] = await Promise.all([
84
- readSupplyCapInBase(
85
- config.vault.communityCodeDepositorAddress,
86
- normalizedChainId
87
- ),
88
- readFeeModuleFromDCD(
89
- config.vault.communityCodeDepositorAddress,
90
- normalizedChainId
91
- )
92
- ]);
93
- return {
94
- supplyCapInBase,
95
- hasDepositCap: supplyCapInBase !== 0n && supplyCapInBase !== maxUint256,
96
- depositFeeModuleAddress,
97
- hasFees: depositFeeModuleAddress !== zeroAddress
98
- };
99
- } catch (error) {
100
- if (error instanceof APIError) {
101
- throw error;
102
- }
103
- throw new APIError(
104
- `Failed to get deposit cap: ${error instanceof Error ? error.message : String(error)}`,
105
- { endpoint: "getDepositCap", cause: error }
106
- );
107
- }
108
- }
109
- async function getCurrentSupply(params) {
110
- try {
111
- const normalizedChainId = toChainId(params.chainId);
112
- const config = await resolveVault({
113
- vaultName: params.vaultName,
114
- assetAddress: params.assetAddress,
115
- chainId: normalizedChainId,
116
- callerEndpoint: "getCurrentSupply"
117
- });
118
- if (!config.vault.boringVaultAddress) {
119
- throw new APIError(
120
- `BoringVault contract address not configured for vault ${config.id}`,
121
- { endpoint: "getCurrentSupply" }
122
- );
123
- }
124
- if (!config.vault.accountantAddress) {
125
- throw new APIError(
126
- `Accountant contract address not configured for vault ${config.id}`,
127
- { endpoint: "getCurrentSupply" }
128
- );
129
- }
130
- const client = await getClient(normalizedChainId);
131
- const results = await client.multicall({
132
- contracts: [
133
- {
134
- abi: BoringVaultAbi,
135
- address: config.vault.boringVaultAddress,
136
- functionName: "totalSupply"
137
- },
138
- {
139
- abi: AccountantAbi,
140
- address: config.vault.accountantAddress,
141
- functionName: "getRate"
142
- },
143
- {
144
- abi: AccountantAbi,
145
- address: config.vault.accountantAddress,
146
- functionName: "decimals"
147
- }
148
- ]
149
- });
150
- const [supplyResult, rateResult, decimalsResult] = results;
151
- if (supplyResult.status === "failure" || rateResult.status === "failure" || decimalsResult.status === "failure") {
152
- throw new APIError("Failed to read supply data from vault contracts", {
153
- endpoint: "getCurrentSupply"
154
- });
155
- }
156
- const totalShareSupply = supplyResult.result;
157
- const exchangeRate = rateResult.result;
158
- const accountantDecimals = decimalsResult.result;
159
- const totalValueInBase = totalShareSupply * exchangeRate / BigInt(10 ** accountantDecimals);
160
- return {
161
- totalShareSupply,
162
- exchangeRate,
163
- accountantDecimals,
164
- totalValueInBase
165
- };
166
- } catch (error) {
167
- if (error instanceof APIError) {
168
- throw error;
169
- }
170
- throw new APIError(
171
- `Failed to get current supply: ${error instanceof Error ? error.message : String(error)}`,
172
- { endpoint: "getCurrentSupply", cause: error }
173
- );
174
- }
175
- }
176
- async function calculateDepositFee(params) {
177
- try {
178
- const normalizedChainId = toChainId(params.chainId);
179
- const config = await resolveVault({
180
- vaultName: params.vaultName,
181
- assetAddress: params.assetAddress,
182
- chainId: normalizedChainId,
183
- callerEndpoint: "calculateDepositFee"
184
- });
185
- const depositFeeModuleAddress = config.vault.depositFeeModuleAddress ?? zeroAddress;
186
- const hasFees = depositFeeModuleAddress !== zeroAddress;
187
- if (!hasFees) {
188
- const assetDecimals2 = await getErc20Decimals({
189
- tokenAddress: params.assetAddress,
190
- chainId: normalizedChainId
191
- });
192
- const depositAmountBigInt2 = parseUnits(
193
- params.depositAmount,
194
- assetDecimals2
195
- );
196
- return {
197
- hasFees: false,
198
- depositFeeModuleAddress,
199
- feePercentage: 0n,
200
- oneHundredPercent: 0n,
201
- flatFee: 0n,
202
- variableFeeAmount: 0n,
203
- totalFeeAmount: 0n,
204
- depositAmountAfterFees: depositAmountBigInt2,
205
- assetDecimals: assetDecimals2
206
- };
207
- }
208
- const assetDecimals = await getErc20Decimals({
209
- tokenAddress: params.assetAddress,
210
- chainId: normalizedChainId
211
- });
212
- const { feePercentage, flatFee, oneHundredPercent } = await readDepositFeeStructure(
213
- depositFeeModuleAddress,
214
- params.assetAddress,
215
- normalizedChainId
216
- );
217
- const depositAmountBigInt = parseUnits(params.depositAmount, assetDecimals);
218
- const variableFeeAmount = oneHundredPercent > 0n ? depositAmountBigInt * feePercentage / oneHundredPercent : 0n;
219
- const totalFeeAmount = variableFeeAmount + flatFee;
220
- const depositAmountAfterFees = depositAmountBigInt > totalFeeAmount ? depositAmountBigInt - totalFeeAmount : 0n;
221
- return {
222
- hasFees: true,
223
- depositFeeModuleAddress,
224
- feePercentage,
225
- oneHundredPercent,
226
- flatFee,
227
- variableFeeAmount,
228
- totalFeeAmount,
229
- depositAmountAfterFees,
230
- assetDecimals
231
- };
232
- } catch (error) {
233
- if (error instanceof APIError) {
234
- throw error;
235
- }
236
- throw new APIError(
237
- `Failed to calculate deposit fee: ${error instanceof Error ? error.message : String(error)}`,
238
- { endpoint: "calculateDepositFee", cause: error }
239
- );
240
- }
241
- }
242
- async function getShareValue(params) {
243
- try {
244
- if (!params.userAddress && !params.shareAmount) {
245
- throw new APIError(
246
- "Either userAddress or shareAmount must be provided.",
247
- { endpoint: "getShareValue" }
248
- );
249
- }
250
- const normalizedChainId = toChainId(params.chainId);
251
- const config = await resolveVault({
252
- vaultName: params.vaultName,
253
- assetAddress: params.quoteAssetAddress,
254
- chainId: normalizedChainId,
255
- callerEndpoint: "getShareValue"
256
- });
257
- if (!config.vault.accountantAddress) {
258
- throw new APIError(
259
- `Accountant contract address not configured for vault ${config.id}`,
260
- { endpoint: "getShareValue" }
261
- );
262
- }
263
- if (!config.vault.boringVaultAddress) {
264
- throw new APIError(
265
- `BoringVault contract address not configured for vault ${config.id}`,
266
- { endpoint: "getShareValue" }
267
- );
268
- }
269
- const client = await getClient(normalizedChainId);
270
- const results = await client.multicall({
271
- contracts: [
272
- {
273
- abi: erc20Abi,
274
- address: params.quoteAssetAddress,
275
- functionName: "decimals"
276
- },
277
- {
278
- abi: BoringVaultAbi,
279
- address: config.vault.boringVaultAddress,
280
- functionName: "decimals"
281
- },
282
- {
283
- abi: AccountantAbi,
284
- address: config.vault.accountantAddress,
285
- functionName: "getRateInQuote",
286
- args: [params.quoteAssetAddress]
287
- }
288
- ]
289
- });
290
- const [quoteDecimalsResult, shareDecimalsResult, rateResult] = results;
291
- if (quoteDecimalsResult.status === "failure" || shareDecimalsResult.status === "failure" || rateResult.status === "failure") {
292
- throw new APIError(
293
- "Failed to read share value data from vault contracts",
294
- { endpoint: "getShareValue" }
295
- );
296
- }
297
- const quoteAssetDecimals = quoteDecimalsResult.result;
298
- const shareDecimals = shareDecimalsResult.result;
299
- const exchangeRate = rateResult.result;
300
- let shareBalance;
301
- if (params.shareAmount) {
302
- shareBalance = parseUnits(params.shareAmount, shareDecimals);
303
- } else {
304
- const [balanceResult] = await client.multicall({
305
- contracts: [
306
- {
307
- abi: erc20Abi,
308
- address: config.vault.boringVaultAddress,
309
- functionName: "balanceOf",
310
- args: [params.userAddress]
311
- }
312
- ]
313
- });
314
- if (balanceResult.status === "failure") {
315
- throw new APIError(
316
- `Failed to read balanceOf for ${params.userAddress}`,
317
- { endpoint: "getShareValue" }
318
- );
319
- }
320
- shareBalance = balanceResult.result;
321
- }
322
- const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals);
323
- const value = shareBalance * exchangeRate / ONE_SHARE;
324
- return {
325
- shareBalance,
326
- value,
327
- exchangeRate,
328
- shareDecimals,
329
- quoteAssetDecimals
330
- };
331
- } catch (error) {
332
- if (error instanceof APIError) {
333
- throw error;
334
- }
335
- throw new APIError(
336
- `Failed to get share value: ${error instanceof Error ? error.message : String(error)}`,
337
- { endpoint: "getShareValue", cause: error }
338
- );
339
- }
340
- }
341
-
342
- // src/display/vault-display.ts
343
- async function resolveVaultAddressForDisplay(params, callerEndpoint) {
344
- if (params.vaultAddress) {
345
- if (!isValidAddress(params.vaultAddress)) {
346
- throw new APIError(
347
- `Invalid vaultAddress: ${params.vaultAddress}. Must be a valid Ethereum address.`,
348
- { endpoint: callerEndpoint }
349
- );
350
- }
351
- return params.vaultAddress;
352
- }
353
- if (params.vaultName) {
354
- const cache = getCache();
355
- if (cache.isEmpty() || cache.isExpired()) {
356
- await cache.refresh();
357
- }
358
- const vault = cache.getVaultByName(params.vaultName);
359
- if (!vault) {
360
- throw new VaultNotFoundByNameError(
361
- `No vault found with name "${params.vaultName}". The vault may not exist or may not be available for your organization.`,
362
- { vaultName: params.vaultName, endpoint: callerEndpoint }
363
- );
364
- }
365
- return vault.vault.boringVaultAddress;
366
- }
367
- throw new APIError("Either vaultAddress or vaultName must be provided.", {
368
- endpoint: callerEndpoint
369
- });
370
- }
371
- async function getVaultAPY(params) {
372
- try {
373
- const resolvedAddress = await resolveVaultAddressForDisplay(
374
- params,
375
- "getVaultAPY"
376
- );
377
- const queryParams = new URLSearchParams({
378
- filter: `vaultAddress=${resolvedAddress}`,
379
- orderByTimestamp: "desc",
380
- pageSize: "1"
381
- });
382
- const url = `${getRestV2BaseURL()}/amplify/vaultApys?${queryParams.toString()}`;
383
- const controller = new AbortController();
384
- const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
385
- const response = await fetch(url, {
386
- method: "GET",
387
- headers: getRequestHeaders(),
388
- signal: controller.signal
389
- });
390
- clearTimeout(timeout);
391
- if (!response.ok) {
392
- throw new APIError(
393
- `Failed to fetch vault APY: ${response.status} ${response.statusText}`,
394
- { endpoint: "getVaultAPY", statusCode: response.status }
395
- );
396
- }
397
- const data = await response.json();
398
- if (!data.vaultApys || data.vaultApys.length === 0) {
399
- throw new APIError(`No APY data found for vault ${resolvedAddress}`, {
400
- endpoint: "getVaultAPY"
401
- });
402
- }
403
- const latest = data.vaultApys[0];
404
- const apyNumber = Number.parseFloat(latest.apy);
405
- return {
406
- apy: apyNumber,
407
- apyFormatted: `${apyNumber.toFixed(2)}%`,
408
- vaultAddress: latest.vaultAddress,
409
- timestamp: latest.timestamp
410
- };
411
- } catch (error) {
412
- if (error instanceof APIError) {
413
- throw error;
414
- }
415
- throw new APIError(
416
- `Failed to fetch vault APY: ${error instanceof Error ? error.message : String(error)}`,
417
- { endpoint: "getVaultAPY", cause: error }
418
- );
419
- }
420
- }
421
- async function getVaultTVL(params) {
422
- try {
423
- const resolvedAddress = await resolveVaultAddressForDisplay(
424
- params,
425
- "getVaultTVL"
426
- );
427
- const filterParts = [`vaultAddress=${resolvedAddress}`];
428
- if (params.chainId !== void 0) {
429
- filterParts.push(`chainId=${params.chainId}`);
430
- }
431
- const queryParams = new URLSearchParams({
432
- filter: filterParts.join(" AND "),
433
- includeCurrent: "true",
434
- orderByTimestamp: "desc",
435
- pageSize: "1"
436
- });
437
- const url = `${getRestV2BaseURL()}/amplify/vaultTvls?${queryParams.toString()}`;
438
- const controller = new AbortController();
439
- const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
440
- const response = await fetch(url, {
441
- method: "GET",
442
- headers: getRequestHeaders(),
443
- signal: controller.signal
444
- });
445
- clearTimeout(timeout);
446
- if (!response.ok) {
447
- throw new APIError(
448
- `Failed to fetch vault TVL: ${response.status} ${response.statusText}`,
449
- { endpoint: "getVaultTVL", statusCode: response.status }
450
- );
451
- }
452
- const data = await response.json();
453
- if (!data.vaultTvls || data.vaultTvls.length === 0) {
454
- throw new APIError(`No TVL data found for vault ${resolvedAddress}`, {
455
- endpoint: "getVaultTVL"
456
- });
457
- }
458
- const latest = data.vaultTvls[0];
459
- return {
460
- tvl: latest.tvl,
461
- tvlAsset: latest.tvlAsset,
462
- vaultAddress: latest.vaultAddress,
463
- chainId: latest.chainId,
464
- timestamp: latest.timestamp
465
- };
466
- } catch (error) {
467
- if (error instanceof APIError) {
468
- throw error;
469
- }
470
- throw new APIError(
471
- `Failed to fetch vault TVL: ${error instanceof Error ? error.message : String(error)}`,
472
- { endpoint: "getVaultTVL", cause: error }
473
- );
474
- }
475
- }
476
- function buildFilterString(params) {
477
- return Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => `${k}=${v}`).join(" AND ");
478
- }
479
- async function getWithdrawalRequests(params) {
480
- try {
481
- if (!isValidAddress(params.userAddress)) {
482
- throw new APIError(
483
- `Invalid userAddress: ${params.userAddress}. Must be a valid Ethereum address.`,
484
- { endpoint: "getWithdrawalRequests" }
485
- );
486
- }
487
- let resolvedVaultAddress = params.vaultAddress;
488
- if (!resolvedVaultAddress && params.vaultName) {
489
- const cache = getCache();
490
- if (cache.isEmpty() || cache.isExpired()) {
491
- await cache.refresh();
492
- }
493
- const vault = cache.getVaultByName(params.vaultName);
494
- if (!vault) {
495
- throw new VaultNotFoundByNameError(
496
- `No vault found with name "${params.vaultName}". The vault may not exist or may not be available for your organization.`,
497
- { vaultName: params.vaultName, endpoint: "getWithdrawalRequests" }
498
- );
499
- }
500
- resolvedVaultAddress = vault.vault.boringVaultAddress;
501
- }
502
- const filter = buildFilterString({
503
- userAddress: params.userAddress,
504
- chainId: params.chainId,
505
- vaultAddress: resolvedVaultAddress,
506
- status: params.status
507
- });
508
- const queryParams = new URLSearchParams();
509
- if (filter) queryParams.set("filter", filter);
510
- if (params.pageSize) queryParams.set("pageSize", String(params.pageSize));
511
- if (params.pageToken) queryParams.set("pageToken", params.pageToken);
512
- const url = `${getRestV2BaseURL()}/amplify/withdrawalRequests?${queryParams.toString()}`;
513
- const controller = new AbortController();
514
- const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
515
- const response = await fetch(url, {
516
- method: "GET",
517
- headers: getRequestHeaders(),
518
- signal: controller.signal
519
- });
520
- clearTimeout(timeout);
521
- if (!response.ok) {
522
- throw new APIError(
523
- `Failed to fetch withdrawal requests: ${response.status} ${response.statusText}`,
524
- {
525
- endpoint: "getWithdrawalRequests",
526
- statusCode: response.status
527
- }
528
- );
529
- }
530
- const data = await response.json();
531
- return {
532
- withdrawalRequests: data.withdrawalRequests ?? [],
533
- nextPageToken: data.nextPageToken ?? null
534
- };
535
- } catch (error) {
536
- if (error instanceof APIError) {
537
- throw error;
538
- }
539
- throw new APIError(
540
- `Failed to fetch withdrawal requests: ${error instanceof Error ? error.message : String(error)}`,
541
- { endpoint: "getWithdrawalRequests", cause: error }
542
- );
543
- }
544
- }
545
- async function getWithdrawalFee(params) {
546
- try {
547
- const normalizedChainId = toChainId(params.chainId);
548
- const config = await resolveVault({
549
- vaultName: params.vaultName,
550
- assetAddress: params.assetAddress,
551
- chainId: normalizedChainId,
552
- callerEndpoint: "getWithdrawalFee"
553
- });
554
- if (!config.vault.withdrawQueueAddress) {
555
- throw new APIError(
556
- `WithdrawQueue contract address not configured for vault ${config.id}`,
557
- { endpoint: "getWithdrawalFee" }
558
- );
559
- }
560
- if (!config.vault.boringVaultAddress) {
561
- throw new APIError(
562
- `BoringVault contract address not configured for vault ${config.id}`,
563
- { endpoint: "getWithdrawalFee" }
564
- );
565
- }
566
- const client = await getClient(normalizedChainId);
567
- const feeModuleAddress = await client.readContract({
568
- abi: WithdrawQueueAbi,
569
- address: config.vault.withdrawQueueAddress,
570
- functionName: "feeModule"
571
- });
572
- const shareDecimals = await getErc20Decimals({
573
- tokenAddress: config.vault.boringVaultAddress,
574
- chainId: normalizedChainId
575
- });
576
- const amountBigInt = parseUnits(params.amount, shareDecimals);
577
- const results = await client.multicall({
578
- contracts: [
579
- {
580
- abi: FeeModuleAbi,
581
- address: feeModuleAddress,
582
- functionName: "calculateOfferFees",
583
- args: [
584
- amountBigInt,
585
- params.offerAsset,
586
- params.wantAsset,
587
- params.receiver
588
- ]
589
- },
590
- {
591
- abi: FeeModuleAbi,
592
- address: feeModuleAddress,
593
- functionName: "offerFeePercentage"
594
- }
595
- ]
596
- });
597
- const [feeAmountResult, feePercentageResult] = results;
598
- if (feeAmountResult.status === "failure" || feePercentageResult.status === "failure") {
599
- throw new APIError("Failed to read fee data from FeeModule contract", {
600
- endpoint: "getWithdrawalFee"
601
- });
602
- }
603
- return {
604
- feeAmount: feeAmountResult.result,
605
- feePercentage: feePercentageResult.result
606
- };
607
- } catch (error) {
608
- if (error instanceof APIError) {
609
- throw error;
610
- }
611
- throw new APIError(
612
- `Failed to get withdrawal fee: ${error instanceof Error ? error.message : String(error)}`,
613
- { endpoint: "getWithdrawalFee", cause: error }
614
- );
615
- }
616
- }
617
- async function getMinimumWithdrawalOrderSize(params) {
618
- try {
619
- const normalizedChainId = toChainId(params.chainId);
620
- const config = await resolveVault({
621
- vaultName: params.vaultName,
622
- assetAddress: params.assetAddress,
623
- chainId: normalizedChainId,
624
- callerEndpoint: "getMinimumWithdrawalOrderSize"
625
- });
626
- if (!config.vault.withdrawQueueAddress) {
627
- throw new APIError(
628
- `WithdrawQueue contract address not configured for vault ${config.id}`,
629
- { endpoint: "getMinimumWithdrawalOrderSize" }
630
- );
631
- }
632
- if (!config.vault.boringVaultAddress) {
633
- throw new APIError(
634
- `BoringVault contract address not configured for vault ${config.id}`,
635
- { endpoint: "getMinimumWithdrawalOrderSize" }
636
- );
637
- }
638
- const client = await getClient(normalizedChainId);
639
- const [minOrderResult, shareDecimalsResult] = await client.multicall({
640
- contracts: [
641
- {
642
- abi: WithdrawQueueAbi,
643
- address: config.vault.withdrawQueueAddress,
644
- functionName: "minimumOrderSize"
645
- },
646
- {
647
- abi: [
648
- {
649
- inputs: [],
650
- name: "decimals",
651
- outputs: [
652
- {
653
- internalType: "uint8",
654
- name: "",
655
- type: "uint8"
656
- }
657
- ],
658
- stateMutability: "view",
659
- type: "function"
660
- }
661
- ],
662
- address: config.vault.boringVaultAddress,
663
- functionName: "decimals"
664
- }
665
- ]
666
- });
667
- if (minOrderResult.status === "failure" || shareDecimalsResult.status === "failure") {
668
- throw new APIError(
669
- "Failed to read minimum order size from WithdrawQueue contract",
670
- { endpoint: "getMinimumWithdrawalOrderSize" }
671
- );
672
- }
673
- return {
674
- minimumOrderSize: minOrderResult.result,
675
- shareDecimals: shareDecimalsResult.result
676
- };
677
- } catch (error) {
678
- if (error instanceof APIError) {
679
- throw error;
680
- }
681
- throw new APIError(
682
- `Failed to get minimum withdrawal order size: ${error instanceof Error ? error.message : String(error)}`,
683
- { endpoint: "getMinimumWithdrawalOrderSize", cause: error }
684
- );
685
- }
686
- }
687
-
688
- export { calculateDepositFee, getCurrentSupply, getDepositCap, getMinimumMint, getMinimumWithdrawalOrderSize, getShareValue, getVaultAPY, getVaultTVL, getWithdrawalFee, getWithdrawalRequests };
689
- //# sourceMappingURL=chunk-QMFYPHX5.mjs.map
690
- //# sourceMappingURL=chunk-QMFYPHX5.mjs.map