@paxoslabs/amplify-sdk 0.4.2 → 0.4.3-alpha.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.
- package/CHANGELOG.md +79 -64
- package/dist/{chain-utils-CRMbWzu7.d.mts → chain-utils-CbVFMjwR.d.mts} +13 -1
- package/dist/{chain-utils-CRMbWzu7.d.ts → chain-utils-CbVFMjwR.d.ts} +13 -1
- package/dist/{chunk-5CV25BTQ.js → chunk-4OEL42W2.mjs} +83 -4
- package/dist/chunk-4OEL42W2.mjs.map +1 -0
- package/dist/{chunk-RW7PZETN.mjs → chunk-7RAFG3NI.mjs} +167 -228
- package/dist/chunk-7RAFG3NI.mjs.map +1 -0
- package/dist/{chunk-CQZCGPZK.mjs → chunk-E2HBXOZY.js} +92 -3
- package/dist/chunk-E2HBXOZY.js.map +1 -0
- package/dist/{chunk-WZXCJAKM.js → chunk-EHRZFLWL.js} +12 -12
- package/dist/{chunk-WZXCJAKM.js.map → chunk-EHRZFLWL.js.map} +1 -1
- package/dist/{chunk-GMMBJB4B.mjs → chunk-GSYGURYO.mjs} +71 -46
- package/dist/chunk-GSYGURYO.mjs.map +1 -0
- package/dist/{chunk-VZED4E3L.mjs → chunk-HBFBGNRH.mjs} +3 -3
- package/dist/{chunk-VZED4E3L.mjs.map → chunk-HBFBGNRH.mjs.map} +1 -1
- package/dist/{chunk-TPU2HZAX.mjs → chunk-L3X5UBG6.mjs} +86 -169
- package/dist/chunk-L3X5UBG6.mjs.map +1 -0
- package/dist/{chunk-BQG3XKTU.js → chunk-R5G6F7RP.js} +168 -227
- package/dist/chunk-R5G6F7RP.js.map +1 -0
- package/dist/{chunk-OZJNKGW6.js → chunk-WHL5LQRP.js} +120 -95
- package/dist/chunk-WHL5LQRP.js.map +1 -0
- package/dist/{chunk-2YPKHXFJ.js → chunk-ZJBJFFBQ.js} +180 -263
- package/dist/chunk-ZJBJFFBQ.js.map +1 -0
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +16 -16
- package/dist/core.mjs +4 -4
- package/dist/display.d.mts +23 -11
- package/dist/display.d.ts +23 -11
- package/dist/display.js +10 -10
- package/dist/display.mjs +4 -4
- package/dist/index.d.mts +107 -7
- package/dist/index.d.ts +107 -7
- package/dist/index.js +75 -51
- package/dist/index.mjs +5 -5
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +7 -7
- package/dist/utils.mjs +2 -2
- package/dist/vaults.d.mts +107 -94
- package/dist/vaults.d.ts +107 -94
- package/dist/vaults.js +25 -25
- package/dist/vaults.mjs +4 -4
- package/package.json +18 -11
- package/dist/chunk-2YPKHXFJ.js.map +0 -1
- package/dist/chunk-5CV25BTQ.js.map +0 -1
- package/dist/chunk-BQG3XKTU.js.map +0 -1
- package/dist/chunk-CQZCGPZK.mjs.map +0 -1
- package/dist/chunk-GMMBJB4B.mjs.map +0 -1
- package/dist/chunk-OZJNKGW6.js.map +0 -1
- package/dist/chunk-RW7PZETN.mjs.map +0 -1
- package/dist/chunk-TPU2HZAX.mjs.map +0 -1
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkE2HBXOZY_js = require('./chunk-E2HBXOZY.js');
|
|
4
|
+
var chunkEHRZFLWL_js = require('./chunk-EHRZFLWL.js');
|
|
5
5
|
var chunk3I3PYX2F_js = require('./chunk-3I3PYX2F.js');
|
|
6
|
-
var
|
|
6
|
+
var chunkR5G6F7RP_js = require('./chunk-R5G6F7RP.js');
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
|
|
9
9
|
async function getMinimumMint(params) {
|
|
10
10
|
try {
|
|
11
|
-
const normalizedChainId =
|
|
12
|
-
const config = await
|
|
11
|
+
const normalizedChainId = chunkR5G6F7RP_js.toChainId(params.chainId);
|
|
12
|
+
const config = await chunkE2HBXOZY_js.resolveVault({
|
|
13
|
+
vaultName: params.vaultName,
|
|
13
14
|
assetAddress: params.depositAssetAddress,
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
chainId: normalizedChainId,
|
|
16
|
+
callerEndpoint: "getMinimumMint"
|
|
16
17
|
});
|
|
17
|
-
if (!config) {
|
|
18
|
-
throw new chunkBQG3XKTU_js.APIError(
|
|
19
|
-
`No vault found for asset ${params.depositAssetAddress} with yield type '${params.yieldType}' on chain ${normalizedChainId}`,
|
|
20
|
-
{ endpoint: "getMinimumMint" }
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
18
|
if (!config.vault.accountantAddress) {
|
|
24
|
-
throw new
|
|
19
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
25
20
|
`Accountant contract address not configured for vault ${config.id}`,
|
|
26
21
|
{ endpoint: "getMinimumMint" }
|
|
27
22
|
);
|
|
28
23
|
}
|
|
29
24
|
if (!config.vault.boringVaultAddress) {
|
|
30
|
-
throw new
|
|
25
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
31
26
|
`BoringVault contract address not configured for vault ${config.id}`,
|
|
32
27
|
{ endpoint: "getMinimumMint" }
|
|
33
28
|
);
|
|
34
29
|
}
|
|
35
|
-
const rateResults = await
|
|
30
|
+
const rateResults = await chunkEHRZFLWL_js.getRateInQuoteWithAssetDecimals({
|
|
36
31
|
assetAddress: params.depositAssetAddress,
|
|
37
32
|
accountantAddress: config.vault.accountantAddress,
|
|
38
33
|
chainId: normalizedChainId
|
|
39
34
|
});
|
|
40
35
|
const [assetDecimalsResult, exchangeRateResult] = rateResults;
|
|
41
36
|
if (assetDecimalsResult.status === "failure" || exchangeRateResult.status === "failure") {
|
|
42
|
-
throw new
|
|
37
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
43
38
|
`Failed to get exchange rate or asset decimals: ${assetDecimalsResult.error?.message || exchangeRateResult.error?.message}`,
|
|
44
39
|
{ endpoint: "getMinimumMint" }
|
|
45
40
|
);
|
|
46
41
|
}
|
|
47
42
|
const assetDecimals = assetDecimalsResult.result;
|
|
48
43
|
const exchangeRate = exchangeRateResult.result;
|
|
49
|
-
const shareDecimals = await
|
|
44
|
+
const shareDecimals = await chunkEHRZFLWL_js.getErc20Decimals({
|
|
50
45
|
tokenAddress: config.vault.boringVaultAddress,
|
|
51
46
|
chainId: normalizedChainId
|
|
52
47
|
});
|
|
@@ -66,10 +61,10 @@ async function getMinimumMint(params) {
|
|
|
66
61
|
assetDecimals
|
|
67
62
|
};
|
|
68
63
|
} catch (error) {
|
|
69
|
-
if (error instanceof
|
|
64
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
70
65
|
throw error;
|
|
71
66
|
}
|
|
72
|
-
throw new
|
|
67
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
73
68
|
`Failed to calculate minimum mint: ${error instanceof Error ? error.message : String(error)}`,
|
|
74
69
|
{ endpoint: "getMinimumMint", cause: error }
|
|
75
70
|
);
|
|
@@ -77,41 +72,68 @@ async function getMinimumMint(params) {
|
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
// src/display/vault-display.ts
|
|
80
|
-
async function
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
throw new
|
|
75
|
+
async function resolveVaultAddressForDisplay(params, callerEndpoint) {
|
|
76
|
+
if (params.vaultAddress) {
|
|
77
|
+
if (!chunkR5G6F7RP_js.isValidAddress(params.vaultAddress)) {
|
|
78
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
84
79
|
`Invalid vaultAddress: ${params.vaultAddress}. Must be a valid Ethereum address.`,
|
|
85
|
-
{ endpoint:
|
|
80
|
+
{ endpoint: callerEndpoint }
|
|
86
81
|
);
|
|
87
82
|
}
|
|
83
|
+
return params.vaultAddress;
|
|
84
|
+
}
|
|
85
|
+
if (params.vaultName) {
|
|
86
|
+
const cache = chunkR5G6F7RP_js.getCache();
|
|
87
|
+
if (cache.isEmpty() || cache.isExpired()) {
|
|
88
|
+
await cache.refresh();
|
|
89
|
+
}
|
|
90
|
+
const vault = cache.getVaultByName(params.vaultName);
|
|
91
|
+
if (!vault) {
|
|
92
|
+
throw new chunkE2HBXOZY_js.VaultNotFoundByNameError(
|
|
93
|
+
`No vault found with name "${params.vaultName}". The vault may not exist or may not be available for your organization.`,
|
|
94
|
+
{ vaultName: params.vaultName, endpoint: callerEndpoint }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return vault.vault.boringVaultAddress;
|
|
98
|
+
}
|
|
99
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
100
|
+
"Either vaultAddress or vaultName must be provided.",
|
|
101
|
+
{ endpoint: callerEndpoint }
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
async function getVaultAPY(params) {
|
|
105
|
+
try {
|
|
106
|
+
const resolvedAddress = await resolveVaultAddressForDisplay(
|
|
107
|
+
params,
|
|
108
|
+
"getVaultAPY"
|
|
109
|
+
);
|
|
88
110
|
const queryParams = new URLSearchParams({
|
|
89
|
-
filter: `vaultAddress=${
|
|
111
|
+
filter: `vaultAddress=${resolvedAddress}`,
|
|
90
112
|
orderByTimestamp: "desc",
|
|
91
113
|
pageSize: "1"
|
|
92
114
|
});
|
|
93
|
-
const url = `${
|
|
115
|
+
const url = `${chunkR5G6F7RP_js.getRestV2BaseURL()}/amplify/vaultApys?${queryParams.toString()}`;
|
|
94
116
|
const controller = new AbortController();
|
|
95
117
|
const timeout = setTimeout(
|
|
96
118
|
() => controller.abort(),
|
|
97
|
-
|
|
119
|
+
chunkR5G6F7RP_js.DEFAULT_TIMEOUT
|
|
98
120
|
);
|
|
99
121
|
const response = await fetch(url, {
|
|
100
122
|
method: "GET",
|
|
101
|
-
headers:
|
|
123
|
+
headers: chunkR5G6F7RP_js.getRequestHeaders(),
|
|
102
124
|
signal: controller.signal
|
|
103
125
|
});
|
|
104
126
|
clearTimeout(timeout);
|
|
105
127
|
if (!response.ok) {
|
|
106
|
-
throw new
|
|
128
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
107
129
|
`Failed to fetch vault APY: ${response.status} ${response.statusText}`,
|
|
108
130
|
{ endpoint: "getVaultAPY", statusCode: response.status }
|
|
109
131
|
);
|
|
110
132
|
}
|
|
111
133
|
const data = await response.json();
|
|
112
134
|
if (!data.vaultApys || data.vaultApys.length === 0) {
|
|
113
|
-
throw new
|
|
114
|
-
`No APY data found for vault ${
|
|
135
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
136
|
+
`No APY data found for vault ${resolvedAddress}`,
|
|
115
137
|
{ endpoint: "getVaultAPY" }
|
|
116
138
|
);
|
|
117
139
|
}
|
|
@@ -124,10 +146,10 @@ async function getVaultAPY(params) {
|
|
|
124
146
|
timestamp: latest.timestamp
|
|
125
147
|
};
|
|
126
148
|
} catch (error) {
|
|
127
|
-
if (error instanceof
|
|
149
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
128
150
|
throw error;
|
|
129
151
|
}
|
|
130
|
-
throw new
|
|
152
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
131
153
|
`Failed to fetch vault APY: ${error instanceof Error ? error.message : String(error)}`,
|
|
132
154
|
{ endpoint: "getVaultAPY", cause: error }
|
|
133
155
|
);
|
|
@@ -135,14 +157,12 @@ async function getVaultAPY(params) {
|
|
|
135
157
|
}
|
|
136
158
|
async function getVaultTVL(params) {
|
|
137
159
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
143
|
-
}
|
|
160
|
+
const resolvedAddress = await resolveVaultAddressForDisplay(
|
|
161
|
+
params,
|
|
162
|
+
"getVaultTVL"
|
|
163
|
+
);
|
|
144
164
|
const filterParts = [
|
|
145
|
-
`vaultAddress=${
|
|
165
|
+
`vaultAddress=${resolvedAddress}`
|
|
146
166
|
];
|
|
147
167
|
if (params.chainId !== void 0) {
|
|
148
168
|
filterParts.push(`chainId=${params.chainId}`);
|
|
@@ -153,28 +173,28 @@ async function getVaultTVL(params) {
|
|
|
153
173
|
orderByTimestamp: "desc",
|
|
154
174
|
pageSize: "1"
|
|
155
175
|
});
|
|
156
|
-
const url = `${
|
|
176
|
+
const url = `${chunkR5G6F7RP_js.getRestV2BaseURL()}/amplify/vaultTvls?${queryParams.toString()}`;
|
|
157
177
|
const controller = new AbortController();
|
|
158
178
|
const timeout = setTimeout(
|
|
159
179
|
() => controller.abort(),
|
|
160
|
-
|
|
180
|
+
chunkR5G6F7RP_js.DEFAULT_TIMEOUT
|
|
161
181
|
);
|
|
162
182
|
const response = await fetch(url, {
|
|
163
183
|
method: "GET",
|
|
164
|
-
headers:
|
|
184
|
+
headers: chunkR5G6F7RP_js.getRequestHeaders(),
|
|
165
185
|
signal: controller.signal
|
|
166
186
|
});
|
|
167
187
|
clearTimeout(timeout);
|
|
168
188
|
if (!response.ok) {
|
|
169
|
-
throw new
|
|
189
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
170
190
|
`Failed to fetch vault TVL: ${response.status} ${response.statusText}`,
|
|
171
191
|
{ endpoint: "getVaultTVL", statusCode: response.status }
|
|
172
192
|
);
|
|
173
193
|
}
|
|
174
194
|
const data = await response.json();
|
|
175
195
|
if (!data.vaultTvls || data.vaultTvls.length === 0) {
|
|
176
|
-
throw new
|
|
177
|
-
`No TVL data found for vault ${
|
|
196
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
197
|
+
`No TVL data found for vault ${resolvedAddress}`,
|
|
178
198
|
{ endpoint: "getVaultTVL" }
|
|
179
199
|
);
|
|
180
200
|
}
|
|
@@ -187,10 +207,10 @@ async function getVaultTVL(params) {
|
|
|
187
207
|
timestamp: latest.timestamp
|
|
188
208
|
};
|
|
189
209
|
} catch (error) {
|
|
190
|
-
if (error instanceof
|
|
210
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
191
211
|
throw error;
|
|
192
212
|
}
|
|
193
|
-
throw new
|
|
213
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
194
214
|
`Failed to fetch vault TVL: ${error instanceof Error ? error.message : String(error)}`,
|
|
195
215
|
{ endpoint: "getVaultTVL", cause: error }
|
|
196
216
|
);
|
|
@@ -241,16 +261,31 @@ function buildFilterString(params) {
|
|
|
241
261
|
}
|
|
242
262
|
async function getWithdrawalRequests(params) {
|
|
243
263
|
try {
|
|
244
|
-
if (!
|
|
245
|
-
throw new
|
|
264
|
+
if (!chunkR5G6F7RP_js.isValidAddress(params.userAddress)) {
|
|
265
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
246
266
|
`Invalid userAddress: ${params.userAddress}. Must be a valid Ethereum address.`,
|
|
247
267
|
{ endpoint: "getWithdrawalRequests" }
|
|
248
268
|
);
|
|
249
269
|
}
|
|
270
|
+
let resolvedVaultAddress = params.vaultAddress;
|
|
271
|
+
if (!resolvedVaultAddress && params.vaultName) {
|
|
272
|
+
const cache = chunkR5G6F7RP_js.getCache();
|
|
273
|
+
if (cache.isEmpty() || cache.isExpired()) {
|
|
274
|
+
await cache.refresh();
|
|
275
|
+
}
|
|
276
|
+
const vault = cache.getVaultByName(params.vaultName);
|
|
277
|
+
if (!vault) {
|
|
278
|
+
throw new chunkE2HBXOZY_js.VaultNotFoundByNameError(
|
|
279
|
+
`No vault found with name "${params.vaultName}". The vault may not exist or may not be available for your organization.`,
|
|
280
|
+
{ vaultName: params.vaultName, endpoint: "getWithdrawalRequests" }
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
resolvedVaultAddress = vault.vault.boringVaultAddress;
|
|
284
|
+
}
|
|
250
285
|
const filter = buildFilterString({
|
|
251
286
|
userAddress: params.userAddress,
|
|
252
287
|
chainId: params.chainId,
|
|
253
|
-
vaultAddress:
|
|
288
|
+
vaultAddress: resolvedVaultAddress,
|
|
254
289
|
status: params.status
|
|
255
290
|
});
|
|
256
291
|
const queryParams = new URLSearchParams();
|
|
@@ -259,20 +294,20 @@ async function getWithdrawalRequests(params) {
|
|
|
259
294
|
queryParams.set("pageSize", String(params.pageSize));
|
|
260
295
|
if (params.pageToken)
|
|
261
296
|
queryParams.set("pageToken", params.pageToken);
|
|
262
|
-
const url = `${
|
|
297
|
+
const url = `${chunkR5G6F7RP_js.getRestV2BaseURL()}/amplify/withdrawalRequests?${queryParams.toString()}`;
|
|
263
298
|
const controller = new AbortController();
|
|
264
299
|
const timeout = setTimeout(
|
|
265
300
|
() => controller.abort(),
|
|
266
|
-
|
|
301
|
+
chunkR5G6F7RP_js.DEFAULT_TIMEOUT
|
|
267
302
|
);
|
|
268
303
|
const response = await fetch(url, {
|
|
269
304
|
method: "GET",
|
|
270
|
-
headers:
|
|
305
|
+
headers: chunkR5G6F7RP_js.getRequestHeaders(),
|
|
271
306
|
signal: controller.signal
|
|
272
307
|
});
|
|
273
308
|
clearTimeout(timeout);
|
|
274
309
|
if (!response.ok) {
|
|
275
|
-
throw new
|
|
310
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
276
311
|
`Failed to fetch withdrawal requests: ${response.status} ${response.statusText}`,
|
|
277
312
|
{
|
|
278
313
|
endpoint: "getWithdrawalRequests",
|
|
@@ -286,10 +321,10 @@ async function getWithdrawalRequests(params) {
|
|
|
286
321
|
nextPageToken: data.nextPageToken ?? null
|
|
287
322
|
};
|
|
288
323
|
} catch (error) {
|
|
289
|
-
if (error instanceof
|
|
324
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
290
325
|
throw error;
|
|
291
326
|
}
|
|
292
|
-
throw new
|
|
327
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
293
328
|
`Failed to fetch withdrawal requests: ${error instanceof Error ? error.message : String(error)}`,
|
|
294
329
|
{ endpoint: "getWithdrawalRequests", cause: error }
|
|
295
330
|
);
|
|
@@ -297,37 +332,32 @@ async function getWithdrawalRequests(params) {
|
|
|
297
332
|
}
|
|
298
333
|
async function getWithdrawalFee(params) {
|
|
299
334
|
try {
|
|
300
|
-
const normalizedChainId =
|
|
301
|
-
const config = await
|
|
335
|
+
const normalizedChainId = chunkR5G6F7RP_js.toChainId(params.chainId);
|
|
336
|
+
const config = await chunkE2HBXOZY_js.resolveVault({
|
|
337
|
+
vaultName: params.vaultName,
|
|
302
338
|
assetAddress: params.assetAddress,
|
|
303
|
-
|
|
304
|
-
|
|
339
|
+
chainId: normalizedChainId,
|
|
340
|
+
callerEndpoint: "getWithdrawalFee"
|
|
305
341
|
});
|
|
306
|
-
if (!config) {
|
|
307
|
-
throw new chunkBQG3XKTU_js.APIError(
|
|
308
|
-
`No vault found for asset ${params.assetAddress} with yield type '${params.yieldType}' on chain ${normalizedChainId}`,
|
|
309
|
-
{ endpoint: "getWithdrawalFee" }
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
342
|
if (!config.vault.withdrawQueueAddress) {
|
|
313
|
-
throw new
|
|
343
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
314
344
|
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
315
345
|
{ endpoint: "getWithdrawalFee" }
|
|
316
346
|
);
|
|
317
347
|
}
|
|
318
348
|
if (!config.vault.boringVaultAddress) {
|
|
319
|
-
throw new
|
|
349
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
320
350
|
`BoringVault contract address not configured for vault ${config.id}`,
|
|
321
351
|
{ endpoint: "getWithdrawalFee" }
|
|
322
352
|
);
|
|
323
353
|
}
|
|
324
|
-
const client = await
|
|
354
|
+
const client = await chunkR5G6F7RP_js.getClient(normalizedChainId);
|
|
325
355
|
const feeModuleAddress = await client.readContract({
|
|
326
|
-
abi:
|
|
356
|
+
abi: chunkE2HBXOZY_js.WithdrawQueueAbi,
|
|
327
357
|
address: config.vault.withdrawQueueAddress,
|
|
328
358
|
functionName: "feeModule"
|
|
329
359
|
});
|
|
330
|
-
const shareDecimals = await
|
|
360
|
+
const shareDecimals = await chunkEHRZFLWL_js.getErc20Decimals({
|
|
331
361
|
tokenAddress: config.vault.boringVaultAddress,
|
|
332
362
|
chainId: normalizedChainId
|
|
333
363
|
});
|
|
@@ -354,7 +384,7 @@ async function getWithdrawalFee(params) {
|
|
|
354
384
|
});
|
|
355
385
|
const [feeAmountResult, feePercentageResult] = results;
|
|
356
386
|
if (feeAmountResult.status === "failure" || feePercentageResult.status === "failure") {
|
|
357
|
-
throw new
|
|
387
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
358
388
|
"Failed to read fee data from FeeModule contract",
|
|
359
389
|
{ endpoint: "getWithdrawalFee" }
|
|
360
390
|
);
|
|
@@ -364,10 +394,10 @@ async function getWithdrawalFee(params) {
|
|
|
364
394
|
feePercentage: feePercentageResult.result
|
|
365
395
|
};
|
|
366
396
|
} catch (error) {
|
|
367
|
-
if (error instanceof
|
|
397
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
368
398
|
throw error;
|
|
369
399
|
}
|
|
370
|
-
throw new
|
|
400
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
371
401
|
`Failed to get withdrawal fee: ${error instanceof Error ? error.message : String(error)}`,
|
|
372
402
|
{ endpoint: "getWithdrawalFee", cause: error }
|
|
373
403
|
);
|
|
@@ -375,35 +405,30 @@ async function getWithdrawalFee(params) {
|
|
|
375
405
|
}
|
|
376
406
|
async function getMinimumWithdrawalOrderSize(params) {
|
|
377
407
|
try {
|
|
378
|
-
const normalizedChainId =
|
|
379
|
-
const config = await
|
|
408
|
+
const normalizedChainId = chunkR5G6F7RP_js.toChainId(params.chainId);
|
|
409
|
+
const config = await chunkE2HBXOZY_js.resolveVault({
|
|
410
|
+
vaultName: params.vaultName,
|
|
380
411
|
assetAddress: params.assetAddress,
|
|
381
|
-
|
|
382
|
-
|
|
412
|
+
chainId: normalizedChainId,
|
|
413
|
+
callerEndpoint: "getMinimumWithdrawalOrderSize"
|
|
383
414
|
});
|
|
384
|
-
if (!config) {
|
|
385
|
-
throw new chunkBQG3XKTU_js.APIError(
|
|
386
|
-
`No vault found for asset ${params.assetAddress} with yield type '${params.yieldType}' on chain ${normalizedChainId}`,
|
|
387
|
-
{ endpoint: "getMinimumWithdrawalOrderSize" }
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
415
|
if (!config.vault.withdrawQueueAddress) {
|
|
391
|
-
throw new
|
|
416
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
392
417
|
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
393
418
|
{ endpoint: "getMinimumWithdrawalOrderSize" }
|
|
394
419
|
);
|
|
395
420
|
}
|
|
396
421
|
if (!config.vault.boringVaultAddress) {
|
|
397
|
-
throw new
|
|
422
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
398
423
|
`BoringVault contract address not configured for vault ${config.id}`,
|
|
399
424
|
{ endpoint: "getMinimumWithdrawalOrderSize" }
|
|
400
425
|
);
|
|
401
426
|
}
|
|
402
|
-
const client = await
|
|
427
|
+
const client = await chunkR5G6F7RP_js.getClient(normalizedChainId);
|
|
403
428
|
const [minOrderResult, shareDecimalsResult] = await client.multicall({
|
|
404
429
|
contracts: [
|
|
405
430
|
{
|
|
406
|
-
abi:
|
|
431
|
+
abi: chunkE2HBXOZY_js.WithdrawQueueAbi,
|
|
407
432
|
address: config.vault.withdrawQueueAddress,
|
|
408
433
|
functionName: "minimumOrderSize"
|
|
409
434
|
},
|
|
@@ -429,7 +454,7 @@ async function getMinimumWithdrawalOrderSize(params) {
|
|
|
429
454
|
]
|
|
430
455
|
});
|
|
431
456
|
if (minOrderResult.status === "failure" || shareDecimalsResult.status === "failure") {
|
|
432
|
-
throw new
|
|
457
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
433
458
|
"Failed to read minimum order size from WithdrawQueue contract",
|
|
434
459
|
{ endpoint: "getMinimumWithdrawalOrderSize" }
|
|
435
460
|
);
|
|
@@ -439,10 +464,10 @@ async function getMinimumWithdrawalOrderSize(params) {
|
|
|
439
464
|
shareDecimals: shareDecimalsResult.result
|
|
440
465
|
};
|
|
441
466
|
} catch (error) {
|
|
442
|
-
if (error instanceof
|
|
467
|
+
if (error instanceof chunkR5G6F7RP_js.APIError) {
|
|
443
468
|
throw error;
|
|
444
469
|
}
|
|
445
|
-
throw new
|
|
470
|
+
throw new chunkR5G6F7RP_js.APIError(
|
|
446
471
|
`Failed to get minimum withdrawal order size: ${error instanceof Error ? error.message : String(error)}`,
|
|
447
472
|
{ endpoint: "getMinimumWithdrawalOrderSize", cause: error }
|
|
448
473
|
);
|
|
@@ -455,5 +480,5 @@ exports.getVaultAPY = getVaultAPY;
|
|
|
455
480
|
exports.getVaultTVL = getVaultTVL;
|
|
456
481
|
exports.getWithdrawalFee = getWithdrawalFee;
|
|
457
482
|
exports.getWithdrawalRequests = getWithdrawalRequests;
|
|
458
|
-
//# sourceMappingURL=chunk-
|
|
459
|
-
//# sourceMappingURL=chunk-
|
|
483
|
+
//# sourceMappingURL=chunk-WHL5LQRP.js.map
|
|
484
|
+
//# sourceMappingURL=chunk-WHL5LQRP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/display/deposit-display.ts","../src/display/vault-display.ts","../src/abi/fee-module-abi.ts","../src/display/withdrawal-display.ts"],"names":["toChainId","resolveVault","APIError","getRateInQuoteWithAssetDecimals","getErc20Decimals","parseUnits","calculateExpectedSharesMinted","isValidAddress","getCache","VaultNotFoundByNameError","getRestV2BaseURL","DEFAULT_TIMEOUT","getRequestHeaders","getClient","WithdrawQueueAbi"],"mappings":";;;;;;;;AAmCA,eAAsB,eACpB,MAAA,EAC4B;AAC5B,EAAA,IAAI;AACF,IAAA,MAAM,iBAAA,GAAoBA,0BAAA,CAAU,MAAA,CAAO,OAAO,CAAA;AAElD,IAAA,MAAM,MAAA,GAAS,MAAMC,6BAAA,CAAa;AAAA,MAChC,WAAW,MAAA,CAAO,SAAA;AAAA,MAClB,cAAc,MAAA,CAAO,mBAAA;AAAA,MACrB,OAAA,EAAS,iBAAA;AAAA,MACT,cAAA,EAAgB;AAAA,KACjB,CAAA;AAED,IAAA,IAAI,CAAC,MAAA,CAAO,KAAA,CAAM,iBAAA,EAAmB;AACnC,MAAA,MAAM,IAAIC,yBAAA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AA,EAAM;AAAA;AACR,WACF;AAAA,UACA,OAAA,EAAS,OAAO,KAAA,CAAM,kBAAA;AAAA,UACtB,YAAA,EAAc;AAAA;AAChB;AACF,KACD,CAAA;AAEH,IAAA,IACE,cAAA,CAAe,MAAA,KAAW,SAAA,IAC1B,mBAAA,CAAoB,WAAW,SAAA,EAC/B;AACA,MAAA,MAAM,IAAIZ,yBAAA;AAAA,QACR,+DAAA;AAAA,QACA,EAAE,UAAU,+BAAA;AAAgC,OAC9C;AAAA,IACF;AAEA,IAAA,OAAO;AAAA,MACL,kBAAkB,cAAA,CAAe,MAAA;AAAA,MACjC,eAAe,mBAAA,CAAoB;AAAA,KACrC;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,iBAAiBA,yBAAA,EAAU;AAC7B,MAAA,MAAM,KAAA;AAAA,IACR;AACA,IAAA,MAAM,IAAIA,yBAAA;AAAA,MACR,gDACE,KAAA,YAAiB,KAAA,GAAQ,MAAM,OAAA,GAAU,MAAA,CAAO,KAAK,CACvD,CAAA,CAAA;AAAA,MACA,EAAE,QAAA,EAAU,+BAAA,EAAiC,KAAA,EAAO,KAAA;AAAM,KAC5D;AAAA,EACF;AACF","file":"chunk-WHL5LQRP.js","sourcesContent":["/**\n * @file Deposit display helpers\n * @module display/deposit-display\n */\n\nimport { parseUnits } from \"viem\";\nimport { getRateInQuoteWithAssetDecimals } from \"../api/accountant\";\nimport { getErc20Decimals } from \"../api/erc20\";\nimport { resolveVault } from \"../client/resolve-vault\";\nimport { APIError } from \"../types/amplify-sdk-api\";\nimport { calculateExpectedSharesMinted } from \"../utils/bigint\";\nimport { toChainId } from \"../utils/chain-utils\";\nimport type { GetMinimumMintParams, MinimumMintResult } from \"./types\";\n\n/**\n * Calculates the expected vault shares a user will receive for a deposit\n *\n * Uses the on-chain exchange rate from the Accountant contract to calculate\n * how many vault shares will be minted for a given deposit amount.\n *\n * @param params - Deposit parameters\n * @returns Expected shares, exchange rate, and decimal info\n * @throws {APIError} If vault not found or contract read fails\n *\n * @example\n * ```typescript\n * const result = await getMinimumMint({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * depositAssetAddress: \"0xA0b8...\", // USDC\n * depositAmount: \"1000.0\",\n * });\n * console.log(result.expectedShares);\n * ```\n */\nexport async function getMinimumMint(\n params: GetMinimumMintParams\n): Promise<MinimumMintResult> {\n try {\n const normalizedChainId = toChainId(params.chainId);\n\n const config = await resolveVault({\n vaultName: params.vaultName,\n assetAddress: params.depositAssetAddress,\n chainId: normalizedChainId,\n callerEndpoint: \"getMinimumMint\",\n });\n\n if (!config.vault.accountantAddress) {\n throw new APIError(\n `Accountant contract address not configured for vault ${config.id}`,\n { endpoint: \"getMinimumMint\" }\n );\n }\n\n if (!config.vault.boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n { endpoint: \"getMinimumMint\" }\n );\n }\n\n // Get exchange rate and asset decimals via multicall\n const rateResults = await getRateInQuoteWithAssetDecimals({\n assetAddress: params.depositAssetAddress,\n accountantAddress: config.vault.accountantAddress,\n chainId: normalizedChainId,\n });\n const [assetDecimalsResult, exchangeRateResult] = rateResults;\n if (assetDecimalsResult.status === \"failure\" || exchangeRateResult.status === \"failure\") {\n throw new APIError(\n `Failed to get exchange rate or asset decimals: ${assetDecimalsResult.error?.message || exchangeRateResult.error?.message\n }`,\n { endpoint: \"getMinimumMint\" }\n );\n }\n\n const assetDecimals = assetDecimalsResult.result;\n const exchangeRate = exchangeRateResult.result;\n\n // Get vault share decimals\n const shareDecimals = await getErc20Decimals({\n tokenAddress: config.vault.boringVaultAddress,\n chainId: normalizedChainId,\n });\n\n // Parse deposit amount using asset decimals\n const depositAmountBigInt = parseUnits(\n params.depositAmount,\n assetDecimals\n );\n\n // Calculate expected shares\n const expectedShares = calculateExpectedSharesMinted(\n depositAmountBigInt,\n exchangeRate,\n shareDecimals\n );\n\n return {\n expectedShares,\n exchangeRate,\n shareDecimals,\n assetDecimals,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to calculate minimum mint: ${error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getMinimumMint\", cause: error }\n );\n }\n}\n","/**\n * @file Vault display helpers\n * @module display/vault-display\n */\n\nimport type { Address } from \"viem\";\nimport { getCache } from \"../client/amplify-sdk-client\";\nimport { getRestV2BaseURL } from \"../constants/environment\";\nimport { getRequestHeaders } from \"../lib/sdk-config\";\nimport { APIError, isValidAddress } from \"../types/amplify-sdk-api\";\nimport { VaultNotFoundByNameError } from \"../types/withdraw-errors\";\nimport { DEFAULT_TIMEOUT } from \"../utils/fetch\";\nimport type {\n GetVaultAPYParams,\n GetVaultTVLParams,\n VaultAPYResult,\n VaultTVLResult,\n} from \"./types\";\n\n/**\n * Resolves a vault's on-chain BoringVault address for REST API display queries\n * (APY, TVL). Accepts either a direct `vaultAddress` or a `vaultName` lookup\n * via the local cache. No asset validation is performed since these are\n * informational queries, not transaction-prep.\n */\nasync function resolveVaultAddressForDisplay(\n params: { vaultAddress?: Address; vaultName?: string; chainId?: number },\n callerEndpoint: string\n): Promise<Address> {\n if (params.vaultAddress) {\n if (!isValidAddress(params.vaultAddress)) {\n throw new APIError(\n `Invalid vaultAddress: ${params.vaultAddress}. Must be a valid Ethereum address.`,\n { endpoint: callerEndpoint }\n );\n }\n return params.vaultAddress;\n }\n\n if (params.vaultName) {\n const cache = getCache();\n if (cache.isEmpty() || cache.isExpired()) {\n await cache.refresh();\n }\n const vault = cache.getVaultByName(params.vaultName);\n if (!vault) {\n throw new VaultNotFoundByNameError(\n `No vault found with name \"${params.vaultName}\". The vault may not exist or may not be available for your organization.`,\n { vaultName: params.vaultName, endpoint: callerEndpoint }\n );\n }\n return vault.vault.boringVaultAddress;\n }\n\n throw new APIError(\n \"Either vaultAddress or vaultName must be provided.\",\n { endpoint: callerEndpoint }\n );\n}\n\n/**\n * Fetches the latest APY for a vault from the backend API\n *\n * Requests the most recent APY data point by using\n * orderByTimestamp=desc with pageSize=1.\n *\n * @param params - Vault identifier parameters (vaultAddress, vaultName, or both)\n * @returns Latest APY value and metadata\n * @throws {APIError} If the API request fails or no data found\n *\n * @example\n * ```typescript\n * const result = await getVaultAPY({\n * vaultAddress: \"0x1234...\",\n * });\n * console.log(result.apyFormatted); // \"4.50%\"\n * ```\n */\nexport async function getVaultAPY(\n params: GetVaultAPYParams\n): Promise<VaultAPYResult> {\n try {\n const resolvedAddress = await resolveVaultAddressForDisplay(\n params,\n \"getVaultAPY\"\n );\n\n const queryParams = new URLSearchParams({\n filter: `vaultAddress=${resolvedAddress}`,\n orderByTimestamp: \"desc\",\n pageSize: \"1\",\n });\n\n const url = `${getRestV2BaseURL()}/amplify/vaultApys?${queryParams.toString()}`;\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n DEFAULT_TIMEOUT\n );\n\n const response = await fetch(url, {\n method: \"GET\",\n headers: getRequestHeaders(),\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n throw new APIError(\n `Failed to fetch vault APY: ${response.status} ${response.statusText}`,\n { endpoint: \"getVaultAPY\", statusCode: response.status }\n );\n }\n\n const data = (await response.json()) as {\n vaultApys: Array<{\n vaultAddress: string;\n timestamp: string;\n interval: string;\n apy: string;\n }>;\n nextPageToken: string | null;\n };\n\n if (!data.vaultApys || data.vaultApys.length === 0) {\n throw new APIError(\n `No APY data found for vault ${resolvedAddress}`,\n { endpoint: \"getVaultAPY\" }\n );\n }\n\n const latest = data.vaultApys[0];\n const apyNumber = Number.parseFloat(latest.apy);\n\n return {\n apy: apyNumber,\n apyFormatted: `${apyNumber.toFixed(2)}%`,\n vaultAddress: latest.vaultAddress as Address,\n timestamp: latest.timestamp,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to fetch vault APY: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getVaultAPY\", cause: error }\n );\n }\n}\n\n/**\n * Fetches the current TVL for a vault from the backend API\n *\n * Requests the most recent TVL data point by using\n * includeCurrent=true, orderByTimestamp=desc with pageSize=1.\n *\n * @param params - Vault identifier parameters (vaultAddress, vaultName, or both)\n * @returns Current TVL value and metadata\n * @throws {APIError} If the API request fails or no data found\n *\n * @example\n * ```typescript\n * const result = await getVaultTVL({\n * vaultAddress: \"0x1234...\",\n * });\n * console.log(result.tvl, result.tvlAsset);\n * ```\n */\nexport async function getVaultTVL(\n params: GetVaultTVLParams\n): Promise<VaultTVLResult> {\n try {\n const resolvedAddress = await resolveVaultAddressForDisplay(\n params,\n \"getVaultTVL\"\n );\n\n const filterParts = [\n `vaultAddress=${resolvedAddress}`,\n ];\n if (params.chainId !== undefined) {\n filterParts.push(`chainId=${params.chainId}`);\n }\n\n const queryParams = new URLSearchParams({\n filter: filterParts.join(\" AND \"),\n includeCurrent: \"true\",\n orderByTimestamp: \"desc\",\n pageSize: \"1\",\n });\n\n const url = `${getRestV2BaseURL()}/amplify/vaultTvls?${queryParams.toString()}`;\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n DEFAULT_TIMEOUT\n );\n\n const response = await fetch(url, {\n method: \"GET\",\n headers: getRequestHeaders(),\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n throw new APIError(\n `Failed to fetch vault TVL: ${response.status} ${response.statusText}`,\n { endpoint: \"getVaultTVL\", statusCode: response.status }\n );\n }\n\n const data = (await response.json()) as {\n vaultTvls: Array<{\n vaultAddress: string;\n chainId: number;\n timestamp: string;\n interval: string;\n tvl: string;\n tvlAsset: string;\n }>;\n nextPageToken: string | null;\n };\n\n if (!data.vaultTvls || data.vaultTvls.length === 0) {\n throw new APIError(\n `No TVL data found for vault ${resolvedAddress}`,\n { endpoint: \"getVaultTVL\" }\n );\n }\n\n const latest = data.vaultTvls[0];\n\n return {\n tvl: latest.tvl,\n tvlAsset: latest.tvlAsset,\n vaultAddress: latest.vaultAddress as Address,\n chainId: latest.chainId,\n timestamp: latest.timestamp,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to fetch vault TVL: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getVaultTVL\", cause: error }\n );\n }\n}\n","export const FeeModuleAbi = [\n {\n inputs: [\n { internalType: \"uint256\", name: \"_offerFeePercentage\", type: \"uint256\" },\n ],\n stateMutability: \"nonpayable\",\n type: \"constructor\",\n },\n {\n inputs: [\n { internalType: \"uint256\", name: \"feePercentage\", type: \"uint256\" },\n { internalType: \"uint256\", name: \"maxAllowed\", type: \"uint256\" },\n ],\n name: \"FeePercentageTooHigh\",\n type: \"error\",\n },\n {\n inputs: [\n { internalType: \"uint256\", name: \"amount\", type: \"uint256\" },\n { internalType: \"contract IERC20\", name: \"offerAsset\", type: \"address\" },\n { internalType: \"contract IERC20\", name: \"wantAsset\", type: \"address\" },\n { internalType: \"address\", name: \"receiver\", type: \"address\" },\n ],\n name: \"calculateOfferFees\",\n outputs: [{ internalType: \"uint256\", name: \"feeAmount\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"offerFeePercentage\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n] as const;\n","/**\n * @file Withdrawal display helpers\n * @module display/withdrawal-display\n */\n\nimport { type Address, parseUnits } from \"viem\";\nimport { FeeModuleAbi } from \"../abi/fee-module-abi\";\nimport { WithdrawQueueAbi } from \"../abi/withdraw-queue-abi\";\nimport { getErc20Decimals } from \"../api/erc20\";\nimport { getCache } from \"../client/amplify-sdk-client\";\nimport { resolveVault } from \"../client/resolve-vault\";\nimport { getRestV2BaseURL } from \"../constants/environment\";\nimport { getRequestHeaders } from \"../lib/sdk-config\";\nimport { getClient } from \"../lib/viem/client\";\nimport { APIError } from \"../types/amplify-sdk-api\";\nimport { isValidAddress } from \"../types/amplify-sdk-api\";\nimport { VaultNotFoundByNameError } from \"../types/withdraw-errors\";\nimport { DEFAULT_TIMEOUT } from \"../utils/fetch\";\nimport { toChainId } from \"../utils/chain-utils\";\nimport type {\n GetMinimumWithdrawalOrderSizeParams,\n GetWithdrawalFeeParams,\n GetWithdrawalRequestsParams,\n MinimumWithdrawalOrderSizeResult,\n WithdrawalFeeResult,\n WithdrawalRequest,\n WithdrawalRequestsResult,\n} from \"./types\";\n\n/**\n * Builds a filter string from typed params for the v2 API\n */\nfunction buildFilterString(\n params: Record<string, string | number | boolean | undefined>\n): string {\n return Object.entries(params)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => `${k}=${v}`)\n .join(\" AND \");\n}\n\n/**\n * Fetches a user's withdrawal requests from the backend API\n *\n * @param params - Filter parameters for withdrawal requests\n * @returns Paginated list of withdrawal requests\n * @throws {APIError} If the API request fails or parameters are invalid\n *\n * @example\n * ```typescript\n * const result = await getWithdrawalRequests({\n * userAddress: \"0x1234...\",\n * status: \"PENDING\",\n * chainId: 1,\n * });\n * console.log(result.withdrawalRequests);\n * ```\n */\nexport async function getWithdrawalRequests(\n params: GetWithdrawalRequestsParams\n): Promise<WithdrawalRequestsResult> {\n try {\n if (!isValidAddress(params.userAddress)) {\n throw new APIError(\n `Invalid userAddress: ${params.userAddress}. Must be a valid Ethereum address.`,\n { endpoint: \"getWithdrawalRequests\" }\n );\n }\n\n let resolvedVaultAddress = params.vaultAddress;\n if (!resolvedVaultAddress && params.vaultName) {\n const cache = getCache();\n if (cache.isEmpty() || cache.isExpired()) {\n await cache.refresh();\n }\n const vault = cache.getVaultByName(params.vaultName);\n if (!vault) {\n throw new VaultNotFoundByNameError(\n `No vault found with name \"${params.vaultName}\". The vault may not exist or may not be available for your organization.`,\n { vaultName: params.vaultName, endpoint: \"getWithdrawalRequests\" }\n );\n }\n resolvedVaultAddress = vault.vault.boringVaultAddress;\n }\n\n const filter = buildFilterString({\n userAddress: params.userAddress,\n chainId: params.chainId,\n vaultAddress: resolvedVaultAddress,\n status: params.status,\n });\n\n const queryParams = new URLSearchParams();\n if (filter) queryParams.set(\"filter\", filter);\n if (params.pageSize)\n queryParams.set(\"pageSize\", String(params.pageSize));\n if (params.pageToken)\n queryParams.set(\"pageToken\", params.pageToken);\n\n const url = `${getRestV2BaseURL()}/amplify/withdrawalRequests?${queryParams.toString()}`;\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n DEFAULT_TIMEOUT\n );\n\n const response = await fetch(url, {\n method: \"GET\",\n headers: getRequestHeaders(),\n signal: controller.signal,\n });\n\n clearTimeout(timeout);\n\n if (!response.ok) {\n throw new APIError(\n `Failed to fetch withdrawal requests: ${response.status} ${response.statusText}`,\n {\n endpoint: \"getWithdrawalRequests\",\n statusCode: response.status,\n }\n );\n }\n\n const data = (await response.json()) as {\n withdrawalRequests: WithdrawalRequest[];\n nextPageToken: string | null;\n };\n\n return {\n withdrawalRequests: data.withdrawalRequests ?? [],\n nextPageToken: data.nextPageToken ?? null,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to fetch withdrawal requests: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getWithdrawalRequests\", cause: error }\n );\n }\n}\n\n/**\n * Reads the withdrawal fee from the on-chain FeeModule contract\n *\n * Performs two sequential RPC calls:\n * 1. Reads the FeeModule address from WithdrawQueue.feeModule()\n * 2. Multicalls calculateOfferFees + offerFeePercentage on the FeeModule\n *\n * @param params - Parameters for fee calculation\n * @returns Fee amount and fee percentage\n * @throws {APIError} If vault not found or contract read fails\n *\n * @example\n * ```typescript\n * const fee = await getWithdrawalFee({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * assetAddress: \"0xA0b8...\", // USDC\n * amount: \"1.0\",\n * offerAsset: \"0x1234...\", // vault shares\n * wantAsset: \"0xA0b8...\", // USDC\n * receiver: \"0x5678...\",\n * });\n * console.log(fee.feeAmount, fee.feePercentage);\n * ```\n */\nexport async function getWithdrawalFee(\n params: GetWithdrawalFeeParams\n): Promise<WithdrawalFeeResult> {\n try {\n const normalizedChainId = toChainId(params.chainId);\n\n const config = await resolveVault({\n vaultName: params.vaultName,\n assetAddress: params.assetAddress,\n chainId: normalizedChainId,\n callerEndpoint: \"getWithdrawalFee\",\n });\n\n if (!config.vault.withdrawQueueAddress) {\n throw new APIError(\n `WithdrawQueue contract address not configured for vault ${config.id}`,\n { endpoint: \"getWithdrawalFee\" }\n );\n }\n\n if (!config.vault.boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n { endpoint: \"getWithdrawalFee\" }\n );\n }\n\n const client = await getClient(normalizedChainId);\n\n // Step 1: Read the FeeModule address from WithdrawQueue\n const feeModuleAddress = (await client.readContract({\n abi: WithdrawQueueAbi,\n address: config.vault.withdrawQueueAddress,\n functionName: \"feeModule\",\n })) as Address;\n\n // Get share decimals to parse the amount\n const shareDecimals = await getErc20Decimals({\n tokenAddress: config.vault.boringVaultAddress,\n chainId: normalizedChainId,\n });\n\n const amountBigInt = parseUnits(params.amount, shareDecimals);\n\n // Step 2: Multicall calculateOfferFees + offerFeePercentage\n const results = await client.multicall({\n contracts: [\n {\n abi: FeeModuleAbi,\n address: feeModuleAddress,\n functionName: \"calculateOfferFees\",\n args: [\n amountBigInt,\n params.offerAsset,\n params.wantAsset,\n params.receiver,\n ],\n },\n {\n abi: FeeModuleAbi,\n address: feeModuleAddress,\n functionName: \"offerFeePercentage\",\n },\n ],\n });\n\n const [feeAmountResult, feePercentageResult] = results;\n\n if (\n feeAmountResult.status === \"failure\" ||\n feePercentageResult.status === \"failure\"\n ) {\n throw new APIError(\n \"Failed to read fee data from FeeModule contract\",\n { endpoint: \"getWithdrawalFee\" }\n );\n }\n\n return {\n feeAmount: feeAmountResult.result,\n feePercentage: feePercentageResult.result,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to get withdrawal fee: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getWithdrawalFee\", cause: error }\n );\n }\n}\n\n/**\n * Reads the minimum withdrawal order size from the WithdrawQueue contract\n *\n * @param params - Parameters to identify the vault\n * @returns Minimum order size in vault shares and share decimals\n * @throws {APIError} If vault not found or contract read fails\n *\n * @example\n * ```typescript\n * const result = await getMinimumWithdrawalOrderSize({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * assetAddress: \"0xA0b8...\",\n * });\n * console.log(result.minimumOrderSize, result.shareDecimals);\n * ```\n */\nexport async function getMinimumWithdrawalOrderSize(\n params: GetMinimumWithdrawalOrderSizeParams\n): Promise<MinimumWithdrawalOrderSizeResult> {\n try {\n const normalizedChainId = toChainId(params.chainId);\n\n const config = await resolveVault({\n vaultName: params.vaultName,\n assetAddress: params.assetAddress,\n chainId: normalizedChainId,\n callerEndpoint: \"getMinimumWithdrawalOrderSize\",\n });\n\n if (!config.vault.withdrawQueueAddress) {\n throw new APIError(\n `WithdrawQueue contract address not configured for vault ${config.id}`,\n { endpoint: \"getMinimumWithdrawalOrderSize\" }\n );\n }\n\n if (!config.vault.boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n { endpoint: \"getMinimumWithdrawalOrderSize\" }\n );\n }\n\n const client = await getClient(normalizedChainId);\n\n const [minOrderResult, shareDecimalsResult] =\n await client.multicall({\n contracts: [\n {\n abi: WithdrawQueueAbi,\n address: config.vault.withdrawQueueAddress,\n functionName: \"minimumOrderSize\",\n },\n {\n abi: [\n {\n inputs: [],\n name: \"decimals\",\n outputs: [\n {\n internalType: \"uint8\",\n name: \"\",\n type: \"uint8\",\n },\n ],\n stateMutability: \"view\",\n type: \"function\",\n },\n ] as const,\n address: config.vault.boringVaultAddress,\n functionName: \"decimals\",\n },\n ],\n });\n\n if (\n minOrderResult.status === \"failure\" ||\n shareDecimalsResult.status === \"failure\"\n ) {\n throw new APIError(\n \"Failed to read minimum order size from WithdrawQueue contract\",\n { endpoint: \"getMinimumWithdrawalOrderSize\" }\n );\n }\n\n return {\n minimumOrderSize: minOrderResult.result,\n shareDecimals: shareDecimalsResult.result,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n throw new APIError(\n `Failed to get minimum withdrawal order size: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"getMinimumWithdrawalOrderSize\", cause: error }\n );\n }\n}\n"]}
|