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