@paxoslabs/amplify-sdk 0.5.1 → 0.5.3
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 +7 -45
- package/README.md +22 -22
- package/dist/{chain-utils-D_b2LEEi.d.mts → chain-utils-5r2UnCDS.d.mts} +57 -1
- package/dist/{chain-utils-D_b2LEEi.d.ts → chain-utils-5r2UnCDS.d.ts} +57 -1
- package/dist/{chunk-L5XT67QZ.js → chunk-4NQPS3JC.js} +813 -147
- package/dist/chunk-4NQPS3JC.js.map +1 -0
- package/dist/{chunk-7RWWVUHP.mjs → chunk-6CU533DM.mjs} +2 -2
- package/dist/chunk-6CU533DM.mjs.map +1 -0
- package/dist/chunk-6JLKHV6O.js +128 -0
- package/dist/chunk-6JLKHV6O.js.map +1 -0
- package/dist/{chunk-YAYUSBC6.js → chunk-FHE43NKY.js} +12 -12
- package/dist/chunk-FHE43NKY.js.map +1 -0
- package/dist/chunk-GOJQYEJQ.js +3212 -0
- package/dist/chunk-GOJQYEJQ.js.map +1 -0
- package/dist/{chunk-3D6EDR3Z.mjs → chunk-LMNADWTH.mjs} +703 -41
- package/dist/chunk-LMNADWTH.mjs.map +1 -0
- package/dist/chunk-ODXJYXUH.mjs +3168 -0
- package/dist/chunk-ODXJYXUH.mjs.map +1 -0
- package/dist/{chunk-WJGSTAPB.mjs → chunk-QMFYPHX5.mjs} +300 -87
- package/dist/chunk-QMFYPHX5.mjs.map +1 -0
- package/dist/{chunk-3I3PYX2F.js → chunk-TNL23CO2.js} +2 -2
- package/dist/chunk-TNL23CO2.js.map +1 -0
- package/dist/{chunk-E6SBQNDA.mjs → chunk-UY2WD7MF.mjs} +3 -3
- package/dist/chunk-UY2WD7MF.mjs.map +1 -0
- package/dist/chunk-WD6QFSXZ.js +701 -0
- package/dist/chunk-WD6QFSXZ.js.map +1 -0
- package/dist/chunk-Y5LBT2WT.mjs +118 -0
- package/dist/chunk-Y5LBT2WT.mjs.map +1 -0
- package/dist/core.d.mts +50 -7
- package/dist/core.d.ts +50 -7
- package/dist/core.js +32 -16
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +4 -4
- package/dist/core.mjs.map +1 -1
- package/dist/display.d.mts +212 -3
- package/dist/display.d.ts +212 -3
- package/dist/display.js +27 -11
- package/dist/display.mjs +5 -5
- package/dist/index-D8RtV9cB.d.mts +5114 -0
- package/dist/index-ev_V5sjt.d.ts +5114 -0
- package/dist/index.d.mts +41 -6
- package/dist/index.d.ts +41 -6
- package/dist/index.js +90 -58
- package/dist/index.mjs +6 -6
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +13 -13
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/utils.mjs.map +1 -1
- package/dist/vaults.d.mts +3 -3817
- package/dist/vaults.d.ts +3 -3817
- package/dist/vaults.js +26 -26
- package/dist/vaults.mjs +5 -5
- package/package.json +30 -65
- package/dist/chunk-3D6EDR3Z.mjs.map +0 -1
- package/dist/chunk-3I3PYX2F.js.map +0 -1
- package/dist/chunk-7RWWVUHP.mjs.map +0 -1
- package/dist/chunk-AUDMOT6F.js +0 -1230
- package/dist/chunk-AUDMOT6F.js.map +0 -1
- package/dist/chunk-E5DH5YEE.js +0 -1485
- package/dist/chunk-E5DH5YEE.js.map +0 -1
- package/dist/chunk-E6SBQNDA.mjs.map +0 -1
- package/dist/chunk-JLZL25CY.mjs +0 -1450
- package/dist/chunk-JLZL25CY.mjs.map +0 -1
- package/dist/chunk-L5XT67QZ.js.map +0 -1
- package/dist/chunk-WJGSTAPB.mjs.map +0 -1
- package/dist/chunk-XVDK6J72.js +0 -484
- package/dist/chunk-XVDK6J72.js.map +0 -1
- package/dist/chunk-Y6RXVDQN.mjs +0 -1222
- package/dist/chunk-Y6RXVDQN.mjs.map +0 -1
- package/dist/chunk-YAYUSBC6.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolveVault, VaultNotFoundByNameError
|
|
2
|
-
import { getRateInQuoteWithAssetDecimals, getErc20Decimals } from './chunk-
|
|
3
|
-
import { calculateExpectedSharesMinted } from './chunk-
|
|
4
|
-
import { toChainId, APIError, getRestV2BaseURL, DEFAULT_TIMEOUT, getRequestHeaders, isValidAddress, getCache,
|
|
5
|
-
import { parseUnits } from 'viem';
|
|
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
6
|
|
|
7
7
|
async function getMinimumMint(params) {
|
|
8
8
|
try {
|
|
@@ -43,10 +43,7 @@ async function getMinimumMint(params) {
|
|
|
43
43
|
tokenAddress: config.vault.boringVaultAddress,
|
|
44
44
|
chainId: normalizedChainId
|
|
45
45
|
});
|
|
46
|
-
const depositAmountBigInt = parseUnits(
|
|
47
|
-
params.depositAmount,
|
|
48
|
-
assetDecimals
|
|
49
|
-
);
|
|
46
|
+
const depositAmountBigInt = parseUnits(params.depositAmount, assetDecimals);
|
|
50
47
|
const expectedShares = calculateExpectedSharesMinted(
|
|
51
48
|
depositAmountBigInt,
|
|
52
49
|
exchangeRate,
|
|
@@ -68,6 +65,279 @@ async function getMinimumMint(params) {
|
|
|
68
65
|
);
|
|
69
66
|
}
|
|
70
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
|
+
}
|
|
71
341
|
|
|
72
342
|
// src/display/vault-display.ts
|
|
73
343
|
async function resolveVaultAddressForDisplay(params, callerEndpoint) {
|
|
@@ -94,10 +364,9 @@ async function resolveVaultAddressForDisplay(params, callerEndpoint) {
|
|
|
94
364
|
}
|
|
95
365
|
return vault.vault.boringVaultAddress;
|
|
96
366
|
}
|
|
97
|
-
throw new APIError(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
367
|
+
throw new APIError("Either vaultAddress or vaultName must be provided.", {
|
|
368
|
+
endpoint: callerEndpoint
|
|
369
|
+
});
|
|
101
370
|
}
|
|
102
371
|
async function getVaultAPY(params) {
|
|
103
372
|
try {
|
|
@@ -112,10 +381,7 @@ async function getVaultAPY(params) {
|
|
|
112
381
|
});
|
|
113
382
|
const url = `${getRestV2BaseURL()}/amplify/vaultApys?${queryParams.toString()}`;
|
|
114
383
|
const controller = new AbortController();
|
|
115
|
-
const timeout = setTimeout(
|
|
116
|
-
() => controller.abort(),
|
|
117
|
-
DEFAULT_TIMEOUT
|
|
118
|
-
);
|
|
384
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
119
385
|
const response = await fetch(url, {
|
|
120
386
|
method: "GET",
|
|
121
387
|
headers: getRequestHeaders(),
|
|
@@ -130,10 +396,9 @@ async function getVaultAPY(params) {
|
|
|
130
396
|
}
|
|
131
397
|
const data = await response.json();
|
|
132
398
|
if (!data.vaultApys || data.vaultApys.length === 0) {
|
|
133
|
-
throw new APIError(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
399
|
+
throw new APIError(`No APY data found for vault ${resolvedAddress}`, {
|
|
400
|
+
endpoint: "getVaultAPY"
|
|
401
|
+
});
|
|
137
402
|
}
|
|
138
403
|
const latest = data.vaultApys[0];
|
|
139
404
|
const apyNumber = Number.parseFloat(latest.apy);
|
|
@@ -159,9 +424,7 @@ async function getVaultTVL(params) {
|
|
|
159
424
|
params,
|
|
160
425
|
"getVaultTVL"
|
|
161
426
|
);
|
|
162
|
-
const filterParts = [
|
|
163
|
-
`vaultAddress=${resolvedAddress}`
|
|
164
|
-
];
|
|
427
|
+
const filterParts = [`vaultAddress=${resolvedAddress}`];
|
|
165
428
|
if (params.chainId !== void 0) {
|
|
166
429
|
filterParts.push(`chainId=${params.chainId}`);
|
|
167
430
|
}
|
|
@@ -173,10 +436,7 @@ async function getVaultTVL(params) {
|
|
|
173
436
|
});
|
|
174
437
|
const url = `${getRestV2BaseURL()}/amplify/vaultTvls?${queryParams.toString()}`;
|
|
175
438
|
const controller = new AbortController();
|
|
176
|
-
const timeout = setTimeout(
|
|
177
|
-
() => controller.abort(),
|
|
178
|
-
DEFAULT_TIMEOUT
|
|
179
|
-
);
|
|
439
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
180
440
|
const response = await fetch(url, {
|
|
181
441
|
method: "GET",
|
|
182
442
|
headers: getRequestHeaders(),
|
|
@@ -191,10 +451,9 @@ async function getVaultTVL(params) {
|
|
|
191
451
|
}
|
|
192
452
|
const data = await response.json();
|
|
193
453
|
if (!data.vaultTvls || data.vaultTvls.length === 0) {
|
|
194
|
-
throw new APIError(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
454
|
+
throw new APIError(`No TVL data found for vault ${resolvedAddress}`, {
|
|
455
|
+
endpoint: "getVaultTVL"
|
|
456
|
+
});
|
|
198
457
|
}
|
|
199
458
|
const latest = data.vaultTvls[0];
|
|
200
459
|
return {
|
|
@@ -214,46 +473,6 @@ async function getVaultTVL(params) {
|
|
|
214
473
|
);
|
|
215
474
|
}
|
|
216
475
|
}
|
|
217
|
-
|
|
218
|
-
// src/abi/fee-module-abi.ts
|
|
219
|
-
var FeeModuleAbi = [
|
|
220
|
-
{
|
|
221
|
-
inputs: [
|
|
222
|
-
{ internalType: "uint256", name: "_offerFeePercentage", type: "uint256" }
|
|
223
|
-
],
|
|
224
|
-
stateMutability: "nonpayable",
|
|
225
|
-
type: "constructor"
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
inputs: [
|
|
229
|
-
{ internalType: "uint256", name: "feePercentage", type: "uint256" },
|
|
230
|
-
{ internalType: "uint256", name: "maxAllowed", type: "uint256" }
|
|
231
|
-
],
|
|
232
|
-
name: "FeePercentageTooHigh",
|
|
233
|
-
type: "error"
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
inputs: [
|
|
237
|
-
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
238
|
-
{ internalType: "contract IERC20", name: "offerAsset", type: "address" },
|
|
239
|
-
{ internalType: "contract IERC20", name: "wantAsset", type: "address" },
|
|
240
|
-
{ internalType: "address", name: "receiver", type: "address" }
|
|
241
|
-
],
|
|
242
|
-
name: "calculateOfferFees",
|
|
243
|
-
outputs: [{ internalType: "uint256", name: "feeAmount", type: "uint256" }],
|
|
244
|
-
stateMutability: "view",
|
|
245
|
-
type: "function"
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
inputs: [],
|
|
249
|
-
name: "offerFeePercentage",
|
|
250
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
251
|
-
stateMutability: "view",
|
|
252
|
-
type: "function"
|
|
253
|
-
}
|
|
254
|
-
];
|
|
255
|
-
|
|
256
|
-
// src/display/withdrawal-display.ts
|
|
257
476
|
function buildFilterString(params) {
|
|
258
477
|
return Object.entries(params).filter(([, v]) => v !== void 0).map(([k, v]) => `${k}=${v}`).join(" AND ");
|
|
259
478
|
}
|
|
@@ -288,16 +507,11 @@ async function getWithdrawalRequests(params) {
|
|
|
288
507
|
});
|
|
289
508
|
const queryParams = new URLSearchParams();
|
|
290
509
|
if (filter) queryParams.set("filter", filter);
|
|
291
|
-
if (params.pageSize)
|
|
292
|
-
|
|
293
|
-
if (params.pageToken)
|
|
294
|
-
queryParams.set("pageToken", params.pageToken);
|
|
510
|
+
if (params.pageSize) queryParams.set("pageSize", String(params.pageSize));
|
|
511
|
+
if (params.pageToken) queryParams.set("pageToken", params.pageToken);
|
|
295
512
|
const url = `${getRestV2BaseURL()}/amplify/withdrawalRequests?${queryParams.toString()}`;
|
|
296
513
|
const controller = new AbortController();
|
|
297
|
-
const timeout = setTimeout(
|
|
298
|
-
() => controller.abort(),
|
|
299
|
-
DEFAULT_TIMEOUT
|
|
300
|
-
);
|
|
514
|
+
const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
301
515
|
const response = await fetch(url, {
|
|
302
516
|
method: "GET",
|
|
303
517
|
headers: getRequestHeaders(),
|
|
@@ -382,10 +596,9 @@ async function getWithdrawalFee(params) {
|
|
|
382
596
|
});
|
|
383
597
|
const [feeAmountResult, feePercentageResult] = results;
|
|
384
598
|
if (feeAmountResult.status === "failure" || feePercentageResult.status === "failure") {
|
|
385
|
-
throw new APIError(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
599
|
+
throw new APIError("Failed to read fee data from FeeModule contract", {
|
|
600
|
+
endpoint: "getWithdrawalFee"
|
|
601
|
+
});
|
|
389
602
|
}
|
|
390
603
|
return {
|
|
391
604
|
feeAmount: feeAmountResult.result,
|
|
@@ -472,6 +685,6 @@ async function getMinimumWithdrawalOrderSize(params) {
|
|
|
472
685
|
}
|
|
473
686
|
}
|
|
474
687
|
|
|
475
|
-
export { getMinimumMint, getMinimumWithdrawalOrderSize, getVaultAPY, getVaultTVL, getWithdrawalFee, getWithdrawalRequests };
|
|
476
|
-
//# sourceMappingURL=chunk-
|
|
477
|
-
//# sourceMappingURL=chunk-
|
|
688
|
+
export { calculateDepositFee, getCurrentSupply, getDepositCap, getMinimumMint, getMinimumWithdrawalOrderSize, getShareValue, getVaultAPY, getVaultTVL, getWithdrawalFee, getWithdrawalRequests };
|
|
689
|
+
//# sourceMappingURL=chunk-QMFYPHX5.mjs.map
|
|
690
|
+
//# sourceMappingURL=chunk-QMFYPHX5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/display/deposit-display.ts","../src/display/vault-display.ts","../src/display/withdrawal-display.ts"],"names":["assetDecimals","depositAmountBigInt","parseUnits"],"mappings":";;;;;;AA4DA,eAAsB,eACpB,MAAA,EAC4B;AAC5B,EAAA,IAAI;AACF,IAAA,MAAM,iBAAA,GAAoB,SAAA,CAAU,MAAA,CAAO,OAAO,CAAA;AAElD,IAAA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ACN,IAAA,EAAM;AAAA;AACR,eACF;AAAA,cACA,eAAA,EAAiB,MAAA;AAAA,cACjB,IAAA,EAAM;AAAA;AACR,WACF;AAAA,UACA,OAAA,EAAS,OAAO,KAAA,CAAM,kBAAA;AAAA,UACtB,YAAA,EAAc;AAAA;AAChB;AACF,KACD,CAAA;AAED,IAAA,IACE,cAAA,CAAe,MAAA,KAAW,SAAA,IAC1B,mBAAA,CAAoB,WAAW,SAAA,EAC/B;AACA,MAAA,MAAM,IAAI,QAAA;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,iBAAiB,QAAA,EAAU;AAC7B,MAAA,MAAM,KAAA;AAAA,IACR;AACA,IAAA,MAAM,IAAI,QAAA;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-QMFYPHX5.mjs","sourcesContent":["/**\n * @file Deposit display helpers\n * @module display/deposit-display\n */\n\nimport {\n type Address,\n erc20Abi,\n maxUint256,\n parseUnits,\n zeroAddress,\n} from 'viem'\nimport { AccountantAbi } from '../abi/accountant-abi'\nimport { BoringVaultAbi } from '../abi/boring-vault-abi'\nimport { getRateInQuoteWithAssetDecimals } from '../api/accountant'\nimport { getErc20Decimals } from '../api/erc20'\nimport {\n readDepositFeeStructure,\n readFeeModuleFromDCD,\n readSupplyCapInBase,\n} from '../api/fees-and-supply-cap'\nimport { resolveVault } from '../client/resolve-vault'\nimport { getClient } from '../lib/viem/client'\nimport { APIError } from '../types/amplify-sdk-api'\nimport { calculateExpectedSharesMinted } from '../utils/bigint'\nimport { toChainId } from '../utils/chain-utils'\nimport type {\n CalculateDepositFeeParams,\n CurrentSupplyResult,\n DepositCapResult,\n DepositFeeResult,\n GetCurrentSupplyParams,\n GetDepositCapParams,\n GetMinimumMintParams,\n GetShareValueParams,\n MinimumMintResult,\n ShareValueResult,\n} 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 (\n assetDecimalsResult.status === 'failure' ||\n exchangeRateResult.status === 'failure'\n ) {\n throw new APIError(\n `Failed to get exchange rate or asset decimals: ${\n assetDecimalsResult.error?.message ||\n 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(params.depositAmount, assetDecimals)\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: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: 'getMinimumMint', cause: error }\n )\n }\n}\n\n/**\n * Reads the deposit cap and fee module info from the DCD contract on-chain\n *\n * Uses the customer's configured RPC to call `supplyCapInBase()` and\n * `feeModule()` on the DistributorCodeDepositor contract.\n *\n * @param params - Vault identification parameters\n * @returns Supply cap, fee module address, and derived boolean flags\n * @throws {APIError} If vault not found or contract read fails\n *\n * @example\n * ```typescript\n * const cap = await getDepositCap({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * assetAddress: \"0xA0b8...\",\n * });\n * console.log(cap.hasDepositCap); // true if supplyCapInBase != 0 and != maxUint256\n * console.log(cap.hasFees); // true if depositFeeModuleAddress from vault config != zeroAddress\n * ```\n */\nexport async function getDepositCap(\n params: GetDepositCapParams\n): Promise<DepositCapResult> {\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: 'getDepositCap',\n })\n\n if (\n !config.vault.communityCodeDepositorAddress ||\n !config.vault.depositFeeModuleAddress\n ) {\n throw new APIError(\n `Deposit cap not available for vault ${config.id} — requires both CommunityCodeDepositor and deposit fee module`,\n { endpoint: 'getDepositCap' }\n )\n }\n\n const [supplyCapInBase, depositFeeModuleAddress] = await Promise.all([\n readSupplyCapInBase(\n config.vault.communityCodeDepositorAddress,\n normalizedChainId\n ),\n readFeeModuleFromDCD(\n config.vault.communityCodeDepositorAddress,\n normalizedChainId\n ),\n ])\n\n return {\n supplyCapInBase,\n hasDepositCap: supplyCapInBase !== 0n && supplyCapInBase !== maxUint256,\n depositFeeModuleAddress,\n hasFees: depositFeeModuleAddress !== zeroAddress,\n }\n } catch (error) {\n if (error instanceof APIError) {\n throw error\n }\n throw new APIError(\n `Failed to get deposit cap: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: 'getDepositCap', cause: error }\n )\n }\n}\n\n/**\n * Reads the current total supply value from the boring vault and accountant\n *\n * Computes `totalValueInBase = totalSupply * accountant.getRate() / 10^accountant.decimals()`,\n * matching the on-chain supply cap enforcement logic in the DCD contract.\n *\n * @param params - Vault identification parameters\n * @returns Total share supply, exchange rate, and computed value in base-asset units\n * @throws {APIError} If vault not found or contract read fails\n *\n * @example\n * ```typescript\n * const supply = await getCurrentSupply({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * assetAddress: \"0xA0b8...\",\n * });\n * console.log(supply.totalValueInBase); // current TVL in base-asset raw units\n * ```\n */\nexport async function getCurrentSupply(\n params: GetCurrentSupplyParams\n): Promise<CurrentSupplyResult> {\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: 'getCurrentSupply',\n })\n\n if (!config.vault.boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n { endpoint: 'getCurrentSupply' }\n )\n }\n\n if (!config.vault.accountantAddress) {\n throw new APIError(\n `Accountant contract address not configured for vault ${config.id}`,\n { endpoint: 'getCurrentSupply' }\n )\n }\n\n const client = await getClient(normalizedChainId)\n\n const results = await client.multicall({\n contracts: [\n {\n abi: BoringVaultAbi,\n address: config.vault.boringVaultAddress,\n functionName: 'totalSupply',\n },\n {\n abi: AccountantAbi,\n address: config.vault.accountantAddress,\n functionName: 'getRate',\n },\n {\n abi: AccountantAbi,\n address: config.vault.accountantAddress,\n functionName: 'decimals',\n },\n ],\n })\n\n const [supplyResult, rateResult, decimalsResult] = results\n\n if (\n supplyResult.status === 'failure' ||\n rateResult.status === 'failure' ||\n decimalsResult.status === 'failure'\n ) {\n throw new APIError('Failed to read supply data from vault contracts', {\n endpoint: 'getCurrentSupply',\n })\n }\n\n const totalShareSupply = supplyResult.result as bigint\n const exchangeRate = rateResult.result as bigint\n const accountantDecimals = decimalsResult.result as number\n\n const totalValueInBase =\n (totalShareSupply * exchangeRate) / BigInt(10 ** accountantDecimals)\n\n return {\n totalShareSupply,\n exchangeRate,\n accountantDecimals,\n totalValueInBase,\n }\n } catch (error) {\n if (error instanceof APIError) {\n throw error\n }\n throw new APIError(\n `Failed to get current supply: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: 'getCurrentSupply', cause: error }\n )\n }\n}\n\n/**\n * Calculates the deposit fee for a given deposit amount by reading the\n * fee module's `depositTokenFeeData` and `ONE_HUNDRED_PERCENT` on-chain.\n *\n * Returns both the fixed (flat) and variable fee components, along with\n * the total fee and the net deposit amount after fees.\n *\n * @param params - Deposit parameters including vault name, chain, asset, and amount\n * @returns Fee breakdown with fixed, variable, total, and net amounts\n * @throws {APIError} If vault not found, no fee module, or contract read fails\n *\n * @example\n * ```typescript\n * const fee = await calculateDepositFee({\n * vaultName: \"Amplify USDC Core\",\n * chainId: 1,\n * assetAddress: \"0xA0b8...\",\n * depositAmount: \"1000.0\",\n * });\n * console.log(fee.variableFeeAmount); // variable portion\n * console.log(fee.flatFee); // fixed portion\n * console.log(fee.totalFeeAmount); // variable + fixed\n * ```\n */\nexport async function calculateDepositFee(\n params: CalculateDepositFeeParams\n): Promise<DepositFeeResult> {\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: 'calculateDepositFee',\n })\n\n const depositFeeModuleAddress = (config.vault.depositFeeModuleAddress ??\n zeroAddress) as Address\n const hasFees = depositFeeModuleAddress !== zeroAddress\n\n if (!hasFees) {\n const assetDecimals = await getErc20Decimals({\n tokenAddress: params.assetAddress,\n chainId: normalizedChainId,\n })\n const depositAmountBigInt = parseUnits(\n params.depositAmount,\n assetDecimals\n )\n\n return {\n hasFees: false,\n depositFeeModuleAddress,\n feePercentage: 0n,\n oneHundredPercent: 0n,\n flatFee: 0n,\n variableFeeAmount: 0n,\n totalFeeAmount: 0n,\n depositAmountAfterFees: depositAmountBigInt,\n assetDecimals,\n }\n }\n\n const assetDecimals = await getErc20Decimals({\n tokenAddress: params.assetAddress,\n chainId: normalizedChainId,\n })\n\n const { feePercentage, flatFee, oneHundredPercent } =\n await readDepositFeeStructure(\n depositFeeModuleAddress,\n params.assetAddress,\n normalizedChainId\n )\n\n const depositAmountBigInt = parseUnits(params.depositAmount, assetDecimals)\n\n const variableFeeAmount =\n oneHundredPercent > 0n\n ? (depositAmountBigInt * feePercentage) / oneHundredPercent\n : 0n\n\n const totalFeeAmount = variableFeeAmount + flatFee\n\n const depositAmountAfterFees =\n depositAmountBigInt > totalFeeAmount\n ? depositAmountBigInt - totalFeeAmount\n : 0n\n\n return {\n hasFees: true,\n depositFeeModuleAddress,\n feePercentage,\n oneHundredPercent,\n flatFee,\n variableFeeAmount,\n totalFeeAmount,\n depositAmountAfterFees,\n assetDecimals,\n }\n } catch (error) {\n if (error instanceof APIError) {\n throw error\n }\n throw new APIError(\n `Failed to calculate deposit fee: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: 'calculateDepositFee', cause: error }\n )\n }\n}\n\n/**\n * Calculates the value of vault shares in a quote asset\n *\n * Reads the on-chain exchange rate from the Accountant contract via\n * `getRateInQuote(quoteAsset)` and computes:\n * value = shareBalance * rateInQuote / 10^shareDecimals\n *\n * The share balance can come from two sources:\n * - `userAddress`: reads `balanceOf(userAddress)` on the BoringVault on-chain\n * - `shareAmount`: uses the provided amount directly (skips balanceOf)\n *\n * When both are provided, `shareAmount` takes precedence. At least one\n * must be specified.\n *\n * @param params - Share value parameters\n * @returns Share balance, value in quote-asset units, exchange rate, and decimal info\n * @throws {APIError} If neither userAddress nor shareAmount provided, vault not found, or contract read fails\n *\n * @example\n * ```typescript\n * // Look up a user's position value by wallet address\n * const result = await getShareValue({\n * vaultName: \"pxlUSDCc\",\n * chainId: 1,\n * quoteAssetAddress: \"0xA0b8...\", // USDC\n * userAddress: \"0x1234...\",\n * });\n * console.log(result.shareBalance); // shares held\n * console.log(result.value); // worth in USDC units\n *\n * // Or value a known share amount directly\n * const preview = await getShareValue({\n * vaultName: \"pxlUSDCc\",\n * chainId: 1,\n * quoteAssetAddress: \"0xA0b8...\",\n * shareAmount: \"100.0\",\n * });\n * ```\n */\nexport async function getShareValue(\n params: GetShareValueParams\n): Promise<ShareValueResult> {\n try {\n if (!params.userAddress && !params.shareAmount) {\n throw new APIError(\n 'Either userAddress or shareAmount must be provided.',\n { endpoint: 'getShareValue' }\n )\n }\n\n const normalizedChainId = toChainId(params.chainId)\n\n const config = await resolveVault({\n vaultName: params.vaultName,\n assetAddress: params.quoteAssetAddress,\n chainId: normalizedChainId,\n callerEndpoint: 'getShareValue',\n })\n\n if (!config.vault.accountantAddress) {\n throw new APIError(\n `Accountant contract address not configured for vault ${config.id}`,\n { endpoint: 'getShareValue' }\n )\n }\n\n if (!config.vault.boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n { endpoint: 'getShareValue' }\n )\n }\n\n const client = await getClient(normalizedChainId)\n\n const results = await client.multicall({\n contracts: [\n {\n abi: erc20Abi,\n address: params.quoteAssetAddress,\n functionName: 'decimals',\n },\n {\n abi: BoringVaultAbi,\n address: config.vault.boringVaultAddress,\n functionName: 'decimals',\n },\n {\n abi: AccountantAbi,\n address: config.vault.accountantAddress,\n functionName: 'getRateInQuote',\n args: [params.quoteAssetAddress],\n },\n ],\n })\n\n const [quoteDecimalsResult, shareDecimalsResult, rateResult] = results\n\n if (\n quoteDecimalsResult.status === 'failure' ||\n shareDecimalsResult.status === 'failure' ||\n rateResult.status === 'failure'\n ) {\n throw new APIError(\n 'Failed to read share value data from vault contracts',\n { endpoint: 'getShareValue' }\n )\n }\n\n const quoteAssetDecimals = quoteDecimalsResult.result as number\n const shareDecimals = shareDecimalsResult.result as number\n const exchangeRate = rateResult.result as bigint\n\n let shareBalance: bigint\n if (params.shareAmount) {\n shareBalance = parseUnits(params.shareAmount, shareDecimals)\n } else {\n const [balanceResult] = await client.multicall({\n contracts: [\n {\n abi: erc20Abi,\n address: config.vault.boringVaultAddress,\n functionName: 'balanceOf',\n args: [params.userAddress!],\n },\n ],\n })\n\n if (balanceResult.status === 'failure') {\n throw new APIError(\n `Failed to read balanceOf for ${params.userAddress}`,\n { endpoint: 'getShareValue' }\n )\n }\n shareBalance = balanceResult.result\n }\n\n const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals)\n const value = (shareBalance * exchangeRate) / ONE_SHARE\n\n return {\n shareBalance,\n value,\n exchangeRate,\n shareDecimals,\n quoteAssetDecimals,\n }\n } catch (error) {\n if (error instanceof APIError) {\n throw error\n }\n throw new APIError(\n `Failed to get share value: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: 'getShareValue', 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('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(() => controller.abort(), DEFAULT_TIMEOUT)\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(`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 = [`vaultAddress=${resolvedAddress}`]\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(() => controller.abort(), DEFAULT_TIMEOUT)\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(`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","/**\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) queryParams.set('pageSize', String(params.pageSize))\n if (params.pageToken) queryParams.set('pageToken', params.pageToken)\n\n const url = `${getRestV2BaseURL()}/amplify/withdrawalRequests?${queryParams.toString()}`\n const controller = new AbortController()\n const timeout = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT)\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('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] = 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"]}
|
|
@@ -41,5 +41,5 @@ exports.WAD = WAD;
|
|
|
41
41
|
exports.bigIntToNumberAsString = bigIntToNumberAsString;
|
|
42
42
|
exports.calculateAtomicPrice = calculateAtomicPrice;
|
|
43
43
|
exports.calculateExpectedSharesMinted = calculateExpectedSharesMinted;
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-TNL23CO2.js.map
|
|
45
|
+
//# sourceMappingURL=chunk-TNL23CO2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/bigint.ts"],"names":["formatUnits"],"mappings":";;;;;AAUO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAOO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAgBO,SAAS,sBAAA,CACd,KAAA,EACA,IAAA,GAII,EAAC,EACG;AACR,EAAA,MAAM;AAAA,IACJ,QAAA,GAAW,EAAA;AAAA,IACX,qBAAA,GAAwB,CAAA;AAAA,IACxB,qBAAA,GAAwB;AAAA,GAC1B,GAAI,IAAA;AACJ,EAAA,MAAM,cAAc,MAAA,CAAO,UAAA,CAAWA,gBAAA,CAAY,KAAA,EAAO,QAAQ,CAAC,CAAA;AAClE,EAAA,OAAO,IAAI,IAAA,CAAK,YAAA,CAAa,OAAA,EAAS;AAAA,IACpC,qBAAA;AAAA,IACA;AAAA,GACD,CAAA,CAAE,MAAA,CAAO,WAAW,CAAA;AACvB;AAaO,SAAS,6BAAA,CACd,aAAA,EACA,WAAA,EACA,aAAA,EACQ;AAER,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,EAAE,CAAA,IAAK,OAAO,aAAa,CAAA;AAIpD,EAAA,MAAM,YAAA,GAAgB,gBAAgB,SAAA,GAAa,WAAA;AAEnD,EAAA,OAAO,YAAA;AACT;AAYO,SAAS,oBAAA,CACd,aACA,QAAA,EACQ;AAGR,EAAA,MAAM,WAAA,GAAc,GAAA;AACpB,EAAA,MAAM,qBAAA,GAAwB,IAAA,CAAK,KAAA,CAAM,QAAA,GAAW,WAAW,CAAA;AAC/D,EAAA,MAAM,mBAAmB,WAAA,GAAc,qBAAA;AAIvC,EAAA,MAAM,cACH,WAAA,GAAc,MAAA,CAAO,gBAAgB,CAAA,GAAK,OAAO,WAAW,CAAA;AAE/D,EAAA,OAAO,WAAA;AACT","file":"chunk-TNL23CO2.js","sourcesContent":["/**\n * @fileoverview Utilities for working with bigint values and fixed-point math\n */\nimport { formatUnits } from 'viem'\n\n/**\n * RAY precision unit (10^27)\n * Used for high precision fixed-point calculations\n * @type {{bigint: bigint, number: number}}\n */\nexport const RAY = {\n bigint: BigInt(1e27),\n number: 1e27,\n}\n\n/**\n * WAD precision unit (10^18)\n * Common precision unit for Ethereum tokens (matches ETH's 18 decimals)\n * @type {{bigint: bigint, number: number}}\n */\nexport const WAD = {\n bigint: BigInt(1e18),\n number: 1e18,\n}\n\n/**\n * Converts a bigint value to a formatted number string with specified decimal precision\n *\n * @param {bigint} value - The bigint value to convert\n * @param {Object} opts - Formatting options\n * @param {number} [opts.decimals=18] - Number of decimals to use when converting from bigint\n * @param {number} [opts.minimumFractionDigits=0] - Minimum number of fraction digits to display\n * @param {number} [opts.maximumFractionDigits=3] - Maximum number of fraction digits to display\n * @returns {string} The formatted number as a string\n *\n * @example\n * // Returns \"123.456\"\n * bigIntToNumberAsString(BigInt(\"123456000000000000000\"), { decimals: 18 })\n */\nexport function bigIntToNumberAsString(\n value: bigint,\n opts: {\n decimals?: number\n minimumFractionDigits?: number\n maximumFractionDigits?: number\n } = {}\n): string {\n const {\n decimals = 18,\n minimumFractionDigits = 0,\n maximumFractionDigits = 3,\n } = opts\n const numberValue = Number.parseFloat(formatUnits(value, decimals))\n return new Intl.NumberFormat('en-US', {\n minimumFractionDigits: minimumFractionDigits,\n maximumFractionDigits: maximumFractionDigits,\n }).format(numberValue)\n}\n\n/**\n * Calculates the expected amount of shares to be minted based on deposit amount and rate\n *\n * The calculation follows the formula:\n * sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n *\n * @param {bigint} depositAmount - The amount to deposit in quote asset decimals\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} shareDecimals - The decimal precision of the BoringVault shares (ONE_SHARE)\n * @returns {bigint} The expected amount of shares to be minted\n */\nexport function calculateExpectedSharesMinted(\n depositAmount: bigint,\n rateInQuote: bigint,\n shareDecimals: number\n): bigint {\n // Calculate ONE_SHARE based on the vault's share decimals\n const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals)\n\n // Calculate shares minted using the formula:\n // sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n const sharesMinted = (depositAmount * ONE_SHARE) / rateInQuote\n\n return sharesMinted\n}\n\n/**\n * Calculates the atomic price with slippage applied\n * The calculation follows the formula:\n * atomicPrice = rateInQuote * (1 - slippage)\n *\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} slippage - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%)\n * @param {number} quoteDecimals - The decimal precision of the quote asset\n * @returns {bigint} The atomic price with slippage applied\n */\nexport function calculateAtomicPrice(\n rateInQuote: bigint,\n slippage: number\n): bigint {\n // Convert slippage to basis points (1% = 100 basis points = 0.01)\n // Multiply by 10000 to get precision and subtract from 10000 to get the percentage to keep\n const basisPoints = 10000\n const slippageInBasisPoints = Math.floor(slippage * basisPoints)\n const percentageToKeep = basisPoints - slippageInBasisPoints\n\n // Calculate atomic price using fixed point arithmetic:\n // atomicPrice = rateInQuote * percentageToKeep / basisPoints\n const atomicPrice =\n (rateInQuote * BigInt(percentageToKeep)) / BigInt(basisPoints)\n\n return atomicPrice\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getClient, APIError } from './chunk-
|
|
1
|
+
import { getClient, APIError } from './chunk-ODXJYXUH.mjs';
|
|
2
2
|
import { erc20Abi } from 'viem';
|
|
3
3
|
|
|
4
4
|
// src/abi/accountant-abi.ts
|
|
@@ -1129,5 +1129,5 @@ var getTokenPermitInfoWithAllowance = async ({
|
|
|
1129
1129
|
};
|
|
1130
1130
|
|
|
1131
1131
|
export { AccountantAbi, BoringVaultAbi, erc2612Abi, getErc20Allowance, getErc20AllowanceWithDecimals, getErc20Balance, getErc20Decimals, getRateInQuoteWithAssetDecimals, getTokenPermitInfoWithAllowance };
|
|
1132
|
-
//# sourceMappingURL=chunk-
|
|
1133
|
-
//# sourceMappingURL=chunk-
|
|
1132
|
+
//# sourceMappingURL=chunk-UY2WD7MF.mjs.map
|
|
1133
|
+
//# sourceMappingURL=chunk-UY2WD7MF.mjs.map
|