@paxoslabs/amplify-sdk 0.5.2 → 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/dist/{chain-utils-BdJecHBA.d.mts → chain-utils-5r2UnCDS.d.mts} +47 -1
- package/dist/{chain-utils-BdJecHBA.d.ts → chain-utils-5r2UnCDS.d.ts} +47 -1
- package/dist/{chunk-5OK753GA.js → chunk-4NQPS3JC.js} +470 -358
- package/dist/chunk-4NQPS3JC.js.map +1 -0
- package/dist/chunk-6JLKHV6O.js +128 -0
- package/dist/chunk-6JLKHV6O.js.map +1 -0
- package/dist/{chunk-NNDY5TID.js → chunk-FHE43NKY.js} +12 -12
- package/dist/{chunk-NNDY5TID.js.map → chunk-FHE43NKY.js.map} +1 -1
- package/dist/chunk-GOJQYEJQ.js +3212 -0
- package/dist/chunk-GOJQYEJQ.js.map +1 -0
- package/dist/{chunk-HU5CTL4C.mjs → chunk-LMNADWTH.mjs} +364 -253
- 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-QZHI2T7O.mjs → chunk-QMFYPHX5.mjs} +280 -47
- package/dist/chunk-QMFYPHX5.mjs.map +1 -0
- package/dist/{chunk-Q5FXJU5Y.mjs → chunk-UY2WD7MF.mjs} +3 -3
- package/dist/{chunk-Q5FXJU5Y.mjs.map → chunk-UY2WD7MF.mjs.map} +1 -1
- 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.mjs +4 -4
- package/dist/display.d.mts +211 -2
- package/dist/display.d.ts +211 -2
- package/dist/display.js +26 -10
- package/dist/display.mjs +4 -4
- package/dist/{index-DXXA8gEA.d.mts → index-D8RtV9cB.d.mts} +498 -410
- package/dist/{index-aE5lTOUH.d.ts → index-ev_V5sjt.d.ts} +498 -410
- package/dist/index.d.mts +40 -5
- package/dist/index.d.ts +40 -5
- package/dist/index.js +80 -60
- package/dist/index.mjs +5 -5
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +7 -7
- package/dist/utils.mjs +2 -2
- package/dist/vaults.d.mts +2 -2
- package/dist/vaults.d.ts +2 -2
- package/dist/vaults.js +25 -25
- package/dist/vaults.mjs +4 -4
- package/package.json +1 -1
- package/dist/chunk-5OK753GA.js.map +0 -1
- package/dist/chunk-7JQQ2TH4.mjs +0 -1231
- package/dist/chunk-7JQQ2TH4.mjs.map +0 -1
- package/dist/chunk-HU5CTL4C.mjs.map +0 -1
- package/dist/chunk-QZHI2T7O.mjs.map +0 -1
- package/dist/chunk-SWUG4PTB.js +0 -464
- package/dist/chunk-SWUG4PTB.js.map +0 -1
- package/dist/chunk-WK7EJRBB.mjs +0 -1482
- package/dist/chunk-WK7EJRBB.mjs.map +0 -1
- package/dist/chunk-WYBYBPX5.js +0 -1518
- package/dist/chunk-WYBYBPX5.js.map +0 -1
- package/dist/chunk-ZKDXRGI5.js +0 -1239
- package/dist/chunk-ZKDXRGI5.js.map +0 -1
|
@@ -1,9 +1,111 @@
|
|
|
1
|
-
import { resolveVault,
|
|
2
|
-
import { getTokenPermitInfoWithAllowance, getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals, erc2612Abi, getErc20Decimals, BoringVaultAbi } from './chunk-
|
|
1
|
+
import { resolveVault, InvalidChainIdError, TransactionDataError, WithdrawError } from './chunk-Y5LBT2WT.mjs';
|
|
2
|
+
import { getTokenPermitInfoWithAllowance, getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals, erc2612Abi, getErc20Decimals, BoringVaultAbi, AccountantAbi } from './chunk-UY2WD7MF.mjs';
|
|
3
3
|
import { WAD } from './chunk-6CU533DM.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { formatUnits, parseUnits, erc20Abi, stringToHex, zeroAddress, hexToSignature } from 'viem';
|
|
4
|
+
import { getLogger, APIError, getRestV2BaseURL, getRequestHeaders, createTimeoutSignal, DEFAULT_TIMEOUT, toChainId, getSupportedAssets, DEFAULT_APPROVAL_AMOUNT, DEFAULT_SLIPPAGE_BPS, DistributorCodeDepositorAbiV0, getClient, WithdrawQueueAbi, readDepositFeeStructure, readSupplyCapInBase } from './chunk-ODXJYXUH.mjs';
|
|
5
|
+
import { formatUnits, parseUnits, erc20Abi, stringToHex, zeroAddress, hexToSignature, maxUint256 } from 'viem';
|
|
6
6
|
|
|
7
|
+
// src/client/kyt-client.ts
|
|
8
|
+
var CHAIN_ID_TO_PREDICATE_CHAIN = {
|
|
9
|
+
1: "ethereum",
|
|
10
|
+
11155111: "sepolia",
|
|
11
|
+
8453: "base",
|
|
12
|
+
84532: "base-sepolia",
|
|
13
|
+
999: "hyperevm",
|
|
14
|
+
2201: "stable-testnet"
|
|
15
|
+
};
|
|
16
|
+
async function fetchKytAttestation(params) {
|
|
17
|
+
const { to, from, chainId } = params;
|
|
18
|
+
const logger = getLogger();
|
|
19
|
+
const chain = CHAIN_ID_TO_PREDICATE_CHAIN[chainId];
|
|
20
|
+
if (!chain) {
|
|
21
|
+
throw new APIError(
|
|
22
|
+
`KYT attestation not supported for chain ID ${chainId}. Supported chains: ${Object.keys(CHAIN_ID_TO_PREDICATE_CHAIN).join(", ")}`,
|
|
23
|
+
{ endpoint: "kytAttestation" }
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const url = `${getRestV2BaseURL()}/kytAttestation`;
|
|
27
|
+
const headers = getRequestHeaders();
|
|
28
|
+
logger.debug("Fetching KYT attestation", { to, from, chain });
|
|
29
|
+
let response;
|
|
30
|
+
try {
|
|
31
|
+
response = await fetch(url, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers,
|
|
34
|
+
body: JSON.stringify({ to, from, chain }),
|
|
35
|
+
signal: createTimeoutSignal(DEFAULT_TIMEOUT)
|
|
36
|
+
});
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
39
|
+
throw new APIError("KYT attestation request timed out", {
|
|
40
|
+
endpoint: "kytAttestation",
|
|
41
|
+
cause: error
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
throw new APIError(
|
|
45
|
+
`KYT attestation request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
46
|
+
{ endpoint: "kytAttestation", cause: error }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
let serverMessage;
|
|
51
|
+
try {
|
|
52
|
+
const errorBody = await response.json();
|
|
53
|
+
serverMessage = errorBody?.error?.message;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
if (response.status === 403) {
|
|
57
|
+
throw new APIError(
|
|
58
|
+
serverMessage ?? "Deposit blocked: transaction is not compliant with KYT policy",
|
|
59
|
+
{ endpoint: "kytAttestation", statusCode: 403 }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (response.status === 400) {
|
|
63
|
+
throw new APIError(
|
|
64
|
+
serverMessage ?? "KYT attestation request was rejected: invalid parameters",
|
|
65
|
+
{ endpoint: "kytAttestation", statusCode: 400 }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
throw new APIError(
|
|
69
|
+
serverMessage ?? `KYT attestation request failed (HTTP ${response.status})`,
|
|
70
|
+
{ endpoint: "kytAttestation", statusCode: response.status }
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
let body;
|
|
74
|
+
try {
|
|
75
|
+
body = await response.json();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw new APIError("KYT attestation response contained invalid JSON", {
|
|
78
|
+
endpoint: "kytAttestation",
|
|
79
|
+
cause: error
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (!body.attestation) {
|
|
83
|
+
throw new APIError("KYT attestation response missing attestation field", {
|
|
84
|
+
endpoint: "kytAttestation"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const { attestation } = body;
|
|
88
|
+
const missingFields = ["uuid", "attester", "signature", "expiration"].filter((f) => attestation[f] == null);
|
|
89
|
+
if (missingFields.length > 0) {
|
|
90
|
+
throw new APIError(
|
|
91
|
+
`KYT attestation response missing required fields: ${missingFields.join(", ")}`,
|
|
92
|
+
{ endpoint: "kytAttestation" }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (typeof attestation.expiration !== "number" && typeof attestation.expiration !== "string") {
|
|
96
|
+
throw new APIError(
|
|
97
|
+
"KYT attestation response has invalid expiration value",
|
|
98
|
+
{ endpoint: "kytAttestation" }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const sig = attestation.signature.startsWith("0x") ? attestation.signature : `0x${attestation.signature}`;
|
|
102
|
+
return {
|
|
103
|
+
uuid: attestation.uuid,
|
|
104
|
+
expiration: BigInt(attestation.expiration),
|
|
105
|
+
attester: attestation.attester,
|
|
106
|
+
signature: sig
|
|
107
|
+
};
|
|
108
|
+
}
|
|
7
109
|
var isDepositSpendApproved = async ({
|
|
8
110
|
vaultName,
|
|
9
111
|
chainId,
|
|
@@ -189,235 +291,6 @@ async function prepareApproveDepositTokenTxData({
|
|
|
189
291
|
}
|
|
190
292
|
}
|
|
191
293
|
|
|
192
|
-
// src/abi/distributor-code-depositor-abi-v0.ts
|
|
193
|
-
var DistributorCodeDepositorAbiV0 = [
|
|
194
|
-
{
|
|
195
|
-
inputs: [
|
|
196
|
-
{
|
|
197
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
198
|
-
name: "_teller",
|
|
199
|
-
type: "address"
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
internalType: "contract INativeWrapper",
|
|
203
|
-
name: "_nativeWrapper",
|
|
204
|
-
type: "address"
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
internalType: "contract Authority",
|
|
208
|
-
name: "_rolesAuthority",
|
|
209
|
-
type: "address"
|
|
210
|
-
},
|
|
211
|
-
{ internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
|
|
212
|
-
{ internalType: "address", name: "_owner", type: "address" }
|
|
213
|
-
],
|
|
214
|
-
stateMutability: "nonpayable",
|
|
215
|
-
type: "constructor"
|
|
216
|
-
},
|
|
217
|
-
{ inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
|
|
218
|
-
{ inputs: [], name: "NativeDepositNotSupported", type: "error" },
|
|
219
|
-
{
|
|
220
|
-
inputs: [],
|
|
221
|
-
name: "NativeWrapperAccountantDecimalsMismatch",
|
|
222
|
-
type: "error"
|
|
223
|
-
},
|
|
224
|
-
{ inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
|
|
225
|
-
{ inputs: [], name: "ZeroAddress", type: "error" },
|
|
226
|
-
{
|
|
227
|
-
anonymous: false,
|
|
228
|
-
inputs: [
|
|
229
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
230
|
-
{
|
|
231
|
-
indexed: true,
|
|
232
|
-
internalType: "contract Authority",
|
|
233
|
-
name: "newAuthority",
|
|
234
|
-
type: "address"
|
|
235
|
-
}
|
|
236
|
-
],
|
|
237
|
-
name: "AuthorityUpdated",
|
|
238
|
-
type: "event"
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
anonymous: false,
|
|
242
|
-
inputs: [
|
|
243
|
-
{
|
|
244
|
-
indexed: true,
|
|
245
|
-
internalType: "address",
|
|
246
|
-
name: "depositor",
|
|
247
|
-
type: "address"
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
indexed: true,
|
|
251
|
-
internalType: "contract ERC20",
|
|
252
|
-
name: "depositAsset",
|
|
253
|
-
type: "address"
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
indexed: false,
|
|
257
|
-
internalType: "uint256",
|
|
258
|
-
name: "depositAmount",
|
|
259
|
-
type: "uint256"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
indexed: false,
|
|
263
|
-
internalType: "uint256",
|
|
264
|
-
name: "minimumMint",
|
|
265
|
-
type: "uint256"
|
|
266
|
-
},
|
|
267
|
-
{ indexed: false, internalType: "address", name: "to", type: "address" },
|
|
268
|
-
{
|
|
269
|
-
indexed: false,
|
|
270
|
-
internalType: "bytes32",
|
|
271
|
-
name: "depositHash",
|
|
272
|
-
type: "bytes32"
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
indexed: true,
|
|
276
|
-
internalType: "bytes",
|
|
277
|
-
name: "distributorCode",
|
|
278
|
-
type: "bytes"
|
|
279
|
-
}
|
|
280
|
-
],
|
|
281
|
-
name: "DepositWithDistributorCode",
|
|
282
|
-
type: "event"
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
anonymous: false,
|
|
286
|
-
inputs: [
|
|
287
|
-
{ indexed: true, internalType: "address", name: "user", type: "address" },
|
|
288
|
-
{
|
|
289
|
-
indexed: true,
|
|
290
|
-
internalType: "address",
|
|
291
|
-
name: "newOwner",
|
|
292
|
-
type: "address"
|
|
293
|
-
}
|
|
294
|
-
],
|
|
295
|
-
name: "OwnershipTransferred",
|
|
296
|
-
type: "event"
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
inputs: [],
|
|
300
|
-
name: "authority",
|
|
301
|
-
outputs: [
|
|
302
|
-
{ internalType: "contract Authority", name: "", type: "address" }
|
|
303
|
-
],
|
|
304
|
-
stateMutability: "view",
|
|
305
|
-
type: "function"
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
inputs: [],
|
|
309
|
-
name: "boringVault",
|
|
310
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
311
|
-
stateMutability: "view",
|
|
312
|
-
type: "function"
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
inputs: [
|
|
316
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
317
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
318
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
319
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
320
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
321
|
-
],
|
|
322
|
-
name: "deposit",
|
|
323
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
324
|
-
stateMutability: "nonpayable",
|
|
325
|
-
type: "function"
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
inputs: [
|
|
329
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
330
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
331
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
332
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
333
|
-
],
|
|
334
|
-
name: "depositNative",
|
|
335
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
336
|
-
stateMutability: "payable",
|
|
337
|
-
type: "function"
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
inputs: [],
|
|
341
|
-
name: "depositNonce",
|
|
342
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
343
|
-
stateMutability: "view",
|
|
344
|
-
type: "function"
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
inputs: [
|
|
348
|
-
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
349
|
-
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
350
|
-
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
351
|
-
{ internalType: "address", name: "to", type: "address" },
|
|
352
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
353
|
-
{ internalType: "uint256", name: "deadline", type: "uint256" },
|
|
354
|
-
{ internalType: "uint8", name: "v", type: "uint8" },
|
|
355
|
-
{ internalType: "bytes32", name: "r", type: "bytes32" },
|
|
356
|
-
{ internalType: "bytes32", name: "s", type: "bytes32" }
|
|
357
|
-
],
|
|
358
|
-
name: "depositWithPermit",
|
|
359
|
-
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
360
|
-
stateMutability: "nonpayable",
|
|
361
|
-
type: "function"
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
inputs: [],
|
|
365
|
-
name: "isNativeDepositSupported",
|
|
366
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
367
|
-
stateMutability: "view",
|
|
368
|
-
type: "function"
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
inputs: [],
|
|
372
|
-
name: "nativeWrapper",
|
|
373
|
-
outputs: [
|
|
374
|
-
{ internalType: "contract INativeWrapper", name: "", type: "address" }
|
|
375
|
-
],
|
|
376
|
-
stateMutability: "view",
|
|
377
|
-
type: "function"
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
inputs: [],
|
|
381
|
-
name: "owner",
|
|
382
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
383
|
-
stateMutability: "view",
|
|
384
|
-
type: "function"
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
inputs: [
|
|
388
|
-
{
|
|
389
|
-
internalType: "contract Authority",
|
|
390
|
-
name: "newAuthority",
|
|
391
|
-
type: "address"
|
|
392
|
-
}
|
|
393
|
-
],
|
|
394
|
-
name: "setAuthority",
|
|
395
|
-
outputs: [],
|
|
396
|
-
stateMutability: "nonpayable",
|
|
397
|
-
type: "function"
|
|
398
|
-
},
|
|
399
|
-
{
|
|
400
|
-
inputs: [],
|
|
401
|
-
name: "teller",
|
|
402
|
-
outputs: [
|
|
403
|
-
{
|
|
404
|
-
internalType: "contract TellerWithMultiAssetSupport",
|
|
405
|
-
name: "",
|
|
406
|
-
type: "address"
|
|
407
|
-
}
|
|
408
|
-
],
|
|
409
|
-
stateMutability: "view",
|
|
410
|
-
type: "function"
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
|
|
414
|
-
name: "transferOwnership",
|
|
415
|
-
outputs: [],
|
|
416
|
-
stateMutability: "nonpayable",
|
|
417
|
-
type: "function"
|
|
418
|
-
}
|
|
419
|
-
];
|
|
420
|
-
|
|
421
294
|
// src/abi/distributor-code-depositor-abi-v1.ts
|
|
422
295
|
var DistributorCodeDepositorAbiV1 = [
|
|
423
296
|
{
|
|
@@ -910,8 +783,6 @@ var DistributorCodeDepositorAbiV1 = [
|
|
|
910
783
|
type: "function"
|
|
911
784
|
}
|
|
912
785
|
];
|
|
913
|
-
|
|
914
|
-
// src/vaults/deposit/utils.ts
|
|
915
786
|
var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) => {
|
|
916
787
|
const slippageValue = slippage ?? DEFAULT_SLIPPAGE_BPS;
|
|
917
788
|
const slippageAsBigInt = BigInt(slippageValue) * WAD.bigint / BigInt(1e4);
|
|
@@ -922,6 +793,75 @@ var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) =
|
|
|
922
793
|
}
|
|
923
794
|
return (minimumMint - slippageAmount) / BigInt(10) ** (BigInt(18) - BigInt(vaultTokenDecimals));
|
|
924
795
|
};
|
|
796
|
+
async function getDepositFeeForAmount(depositFeeModuleAddress, depositAsset, depositAmount, chainId) {
|
|
797
|
+
if (!depositFeeModuleAddress || depositFeeModuleAddress === zeroAddress) {
|
|
798
|
+
return 0n;
|
|
799
|
+
}
|
|
800
|
+
const { feePercentage, flatFee, oneHundredPercent } = await readDepositFeeStructure(
|
|
801
|
+
depositFeeModuleAddress,
|
|
802
|
+
depositAsset,
|
|
803
|
+
chainId
|
|
804
|
+
);
|
|
805
|
+
const variableFee = oneHundredPercent > 0n ? depositAmount * feePercentage / oneHundredPercent : 0n;
|
|
806
|
+
return variableFee + flatFee;
|
|
807
|
+
}
|
|
808
|
+
async function assertDepositWithinCap(vault, depositAmountRaw, depositAssetAddress, chainId, callerEndpoint) {
|
|
809
|
+
let supplyCapInBase = null;
|
|
810
|
+
let hasDepositCap = false;
|
|
811
|
+
if (vault.depositCap) {
|
|
812
|
+
supplyCapInBase = vault.depositCap.supplyCapInBase;
|
|
813
|
+
hasDepositCap = vault.depositCap.hasDepositCap;
|
|
814
|
+
} else if (vault.vault.communityCodeDepositorAddress && vault.vault.depositFeeModuleAddress) {
|
|
815
|
+
const onChainCap = await readSupplyCapInBase(
|
|
816
|
+
vault.vault.communityCodeDepositorAddress,
|
|
817
|
+
chainId
|
|
818
|
+
);
|
|
819
|
+
supplyCapInBase = onChainCap;
|
|
820
|
+
hasDepositCap = onChainCap !== 0n && onChainCap !== maxUint256;
|
|
821
|
+
}
|
|
822
|
+
if (!hasDepositCap || supplyCapInBase == null) return;
|
|
823
|
+
const client = await getClient(chainId);
|
|
824
|
+
const [supplyResult, baseRateResult, quoteRateResult, decResult] = await client.multicall({
|
|
825
|
+
contracts: [
|
|
826
|
+
{
|
|
827
|
+
abi: BoringVaultAbi,
|
|
828
|
+
address: vault.vault.boringVaultAddress,
|
|
829
|
+
functionName: "totalSupply"
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
abi: AccountantAbi,
|
|
833
|
+
address: vault.vault.accountantAddress,
|
|
834
|
+
functionName: "getRate"
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
abi: AccountantAbi,
|
|
838
|
+
address: vault.vault.accountantAddress,
|
|
839
|
+
functionName: "getRateInQuote",
|
|
840
|
+
args: [depositAssetAddress]
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
abi: AccountantAbi,
|
|
844
|
+
address: vault.vault.accountantAddress,
|
|
845
|
+
functionName: "decimals"
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
});
|
|
849
|
+
if (supplyResult.status !== "success" || baseRateResult.status !== "success" || quoteRateResult.status !== "success" || decResult.status !== "success") {
|
|
850
|
+
throw new APIError(
|
|
851
|
+
"Unable to verify deposit against supply cap: on-chain read failed",
|
|
852
|
+
{ endpoint: callerEndpoint }
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
const currentValueInBase = supplyResult.result * baseRateResult.result / 10n ** BigInt(decResult.result);
|
|
856
|
+
const depositAmountInBase = quoteRateResult.result > 0n ? depositAmountRaw * baseRateResult.result / quoteRateResult.result : depositAmountRaw;
|
|
857
|
+
const remaining = supplyCapInBase > currentValueInBase ? supplyCapInBase - currentValueInBase : 0n;
|
|
858
|
+
if (depositAmountInBase > remaining) {
|
|
859
|
+
throw new APIError(
|
|
860
|
+
`Deposit would exceed vault supply cap. Remaining capacity: ${remaining}, deposit amount (in base): ${depositAmountInBase}`,
|
|
861
|
+
{ endpoint: callerEndpoint }
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
925
865
|
|
|
926
866
|
// src/vaults/deposit/deposit.ts
|
|
927
867
|
var DepositType = {
|
|
@@ -1009,15 +949,52 @@ async function prepareDepositTxData(params) {
|
|
|
1009
949
|
depositAmount,
|
|
1010
950
|
depositAssetDecimalsResult.result
|
|
1011
951
|
);
|
|
1012
|
-
const
|
|
952
|
+
const totalFee = await getDepositFeeForAmount(
|
|
953
|
+
vault.vault.depositFeeModuleAddress,
|
|
954
|
+
depositAssetAddress,
|
|
1013
955
|
depositAmountAsBigInt,
|
|
956
|
+
normalizedChainId
|
|
957
|
+
);
|
|
958
|
+
if (totalFee >= depositAmountAsBigInt) {
|
|
959
|
+
throw new APIError(
|
|
960
|
+
"Deposit amount is entirely consumed by fees. Increase the deposit amount.",
|
|
961
|
+
{ endpoint: "prepareDepositTransactionData" }
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
const depositAmountAfterFees = depositAmountAsBigInt - totalFee;
|
|
965
|
+
await assertDepositWithinCap(
|
|
966
|
+
vault,
|
|
967
|
+
depositAmountAfterFees,
|
|
968
|
+
depositAssetAddress,
|
|
969
|
+
normalizedChainId,
|
|
970
|
+
"prepareDepositTransactionData"
|
|
971
|
+
);
|
|
972
|
+
const minimumMint = calculateMinimumMint(
|
|
973
|
+
depositAmountAfterFees,
|
|
1014
974
|
rateInQuoteResult.result,
|
|
1015
975
|
depositAssetDecimalsResult.result,
|
|
1016
976
|
slippage
|
|
1017
977
|
);
|
|
1018
978
|
const distributorCodeHex = stringToHex(distributorCode || "");
|
|
1019
|
-
|
|
1020
|
-
|
|
979
|
+
const policyId = vault.enterpriseConfig?.predicatePolicyId;
|
|
980
|
+
if (policyId === void 0) {
|
|
981
|
+
return {
|
|
982
|
+
depositType: DepositType.STANDARD,
|
|
983
|
+
abi: DistributorCodeDepositorAbiV0,
|
|
984
|
+
address: communityCodeDepositorAddress,
|
|
985
|
+
functionName: "deposit",
|
|
986
|
+
args: [
|
|
987
|
+
depositAssetAddress,
|
|
988
|
+
depositAmountAsBigInt,
|
|
989
|
+
minimumMint,
|
|
990
|
+
to,
|
|
991
|
+
distributorCodeHex
|
|
992
|
+
],
|
|
993
|
+
chainId: normalizedChainId
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
if (policyId === null) {
|
|
997
|
+
const emptyAttestation = {
|
|
1021
998
|
uuid: "",
|
|
1022
999
|
expiration: 0n,
|
|
1023
1000
|
attester: zeroAddress,
|
|
@@ -1034,22 +1011,28 @@ async function prepareDepositTxData(params) {
|
|
|
1034
1011
|
minimumMint,
|
|
1035
1012
|
to,
|
|
1036
1013
|
distributorCodeHex,
|
|
1037
|
-
|
|
1014
|
+
emptyAttestation
|
|
1038
1015
|
],
|
|
1039
1016
|
chainId: normalizedChainId
|
|
1040
1017
|
};
|
|
1041
1018
|
}
|
|
1019
|
+
const attestation = await fetchKytAttestation({
|
|
1020
|
+
to: communityCodeDepositorAddress,
|
|
1021
|
+
from: to,
|
|
1022
|
+
chainId: normalizedChainId
|
|
1023
|
+
});
|
|
1042
1024
|
return {
|
|
1043
|
-
depositType: DepositType.
|
|
1044
|
-
abi: DistributorCodeDepositorAbiV0,
|
|
1025
|
+
depositType: DepositType.KYT,
|
|
1045
1026
|
address: communityCodeDepositorAddress,
|
|
1027
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
1046
1028
|
functionName: "deposit",
|
|
1047
1029
|
args: [
|
|
1048
1030
|
depositAssetAddress,
|
|
1049
1031
|
depositAmountAsBigInt,
|
|
1050
1032
|
minimumMint,
|
|
1051
1033
|
to,
|
|
1052
|
-
distributorCodeHex
|
|
1034
|
+
distributorCodeHex,
|
|
1035
|
+
attestation
|
|
1053
1036
|
],
|
|
1054
1037
|
chainId: normalizedChainId
|
|
1055
1038
|
};
|
|
@@ -1369,15 +1352,56 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
1369
1352
|
}
|
|
1370
1353
|
const onChainDecimals = depositAssetDecimalsResult.result;
|
|
1371
1354
|
const depositAmountAsBigInt = parseUnits(depositAmount, onChainDecimals);
|
|
1372
|
-
const
|
|
1355
|
+
const totalFee = await getDepositFeeForAmount(
|
|
1356
|
+
vault.vault.depositFeeModuleAddress,
|
|
1357
|
+
depositAssetAddress,
|
|
1373
1358
|
depositAmountAsBigInt,
|
|
1359
|
+
normalizedChainId
|
|
1360
|
+
);
|
|
1361
|
+
if (totalFee >= depositAmountAsBigInt) {
|
|
1362
|
+
throw new APIError(
|
|
1363
|
+
"Deposit amount is entirely consumed by fees. Increase the deposit amount.",
|
|
1364
|
+
{ endpoint: "prepareDepositWithPermitTxData" }
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
const depositAmountAfterFees = depositAmountAsBigInt - totalFee;
|
|
1368
|
+
await assertDepositWithinCap(
|
|
1369
|
+
vault,
|
|
1370
|
+
depositAmountAfterFees,
|
|
1371
|
+
depositAssetAddress,
|
|
1372
|
+
normalizedChainId,
|
|
1373
|
+
"prepareDepositWithPermitTxData"
|
|
1374
|
+
);
|
|
1375
|
+
const minimumMint = calculateMinimumMint(
|
|
1376
|
+
depositAmountAfterFees,
|
|
1374
1377
|
rateInQuoteResult.result,
|
|
1375
1378
|
onChainDecimals,
|
|
1376
1379
|
slippage
|
|
1377
1380
|
);
|
|
1378
1381
|
const distributorCodeHex = stringToHex(distributorCode || "");
|
|
1379
|
-
|
|
1380
|
-
|
|
1382
|
+
const policyId = vault.enterpriseConfig?.predicatePolicyId;
|
|
1383
|
+
if (policyId === void 0) {
|
|
1384
|
+
return {
|
|
1385
|
+
depositType: DepositType.STANDARD,
|
|
1386
|
+
abi: DistributorCodeDepositorAbiV0,
|
|
1387
|
+
address: communityCodeDepositorAddress,
|
|
1388
|
+
functionName: "depositWithPermit",
|
|
1389
|
+
args: [
|
|
1390
|
+
depositAssetAddress,
|
|
1391
|
+
depositAmountAsBigInt,
|
|
1392
|
+
minimumMint,
|
|
1393
|
+
to,
|
|
1394
|
+
distributorCodeHex,
|
|
1395
|
+
deadline,
|
|
1396
|
+
v,
|
|
1397
|
+
r,
|
|
1398
|
+
s
|
|
1399
|
+
],
|
|
1400
|
+
chainId: normalizedChainId
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
if (policyId === null) {
|
|
1404
|
+
const emptyAttestation = {
|
|
1381
1405
|
uuid: "",
|
|
1382
1406
|
expiration: 0n,
|
|
1383
1407
|
attester: zeroAddress,
|
|
@@ -1394,7 +1418,7 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
1394
1418
|
minimumMint,
|
|
1395
1419
|
to,
|
|
1396
1420
|
distributorCodeHex,
|
|
1397
|
-
|
|
1421
|
+
emptyAttestation,
|
|
1398
1422
|
deadline,
|
|
1399
1423
|
v,
|
|
1400
1424
|
r,
|
|
@@ -1403,9 +1427,14 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
1403
1427
|
chainId: normalizedChainId
|
|
1404
1428
|
};
|
|
1405
1429
|
}
|
|
1430
|
+
const attestation = await fetchKytAttestation({
|
|
1431
|
+
to: communityCodeDepositorAddress,
|
|
1432
|
+
from: to,
|
|
1433
|
+
chainId: normalizedChainId
|
|
1434
|
+
});
|
|
1406
1435
|
return {
|
|
1407
|
-
depositType: DepositType.
|
|
1408
|
-
abi:
|
|
1436
|
+
depositType: DepositType.KYT,
|
|
1437
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
1409
1438
|
address: communityCodeDepositorAddress,
|
|
1410
1439
|
functionName: "depositWithPermit",
|
|
1411
1440
|
args: [
|
|
@@ -1414,6 +1443,7 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
1414
1443
|
minimumMint,
|
|
1415
1444
|
to,
|
|
1416
1445
|
distributorCodeHex,
|
|
1446
|
+
attestation,
|
|
1417
1447
|
deadline,
|
|
1418
1448
|
v,
|
|
1419
1449
|
r,
|
|
@@ -1830,6 +1860,79 @@ var prepareWithdrawOrderTxData = async ({
|
|
|
1830
1860
|
);
|
|
1831
1861
|
}
|
|
1832
1862
|
};
|
|
1863
|
+
var prepareAtomicWithdrawOrderTxData = async ({
|
|
1864
|
+
vaultName,
|
|
1865
|
+
wantAsset,
|
|
1866
|
+
userAddress,
|
|
1867
|
+
chainId,
|
|
1868
|
+
amountOffer
|
|
1869
|
+
}) => {
|
|
1870
|
+
try {
|
|
1871
|
+
const normalizedChainId = toChainId(chainId);
|
|
1872
|
+
const config = await resolveVault({
|
|
1873
|
+
vaultName,
|
|
1874
|
+
assetAddress: wantAsset,
|
|
1875
|
+
chainId: normalizedChainId,
|
|
1876
|
+
callerEndpoint: "prepareAtomicWithdrawOrderTxData"
|
|
1877
|
+
});
|
|
1878
|
+
if (config.chainId !== normalizedChainId) {
|
|
1879
|
+
throw new InvalidChainIdError(
|
|
1880
|
+
`Vault chain mismatch: vault is on chain ${config.chainId}, requested chain ${normalizedChainId}`,
|
|
1881
|
+
{
|
|
1882
|
+
vaultId: config.id,
|
|
1883
|
+
vaultChainId: config.chainId,
|
|
1884
|
+
requestedChainId: normalizedChainId
|
|
1885
|
+
}
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
if (!config.vault.withdrawQueueAddress) {
|
|
1889
|
+
throw new TransactionDataError(
|
|
1890
|
+
`WithdrawQueue contract address not configured for vault ${config.id}`,
|
|
1891
|
+
{ vaultId: config.id, field: "withdrawQueueAddress" }
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
if (!config.vault.boringVaultAddress) {
|
|
1895
|
+
throw new TransactionDataError(
|
|
1896
|
+
`BoringVault contract address not configured for vault ${config.id}`,
|
|
1897
|
+
{ vaultId: config.id, field: "boringVaultAddress" }
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
const sharesDecimals = await getErc20Decimals({
|
|
1901
|
+
tokenAddress: config.vault.boringVaultAddress,
|
|
1902
|
+
chainId: normalizedChainId
|
|
1903
|
+
});
|
|
1904
|
+
const formattedAmountOffer = parseUnits(amountOffer, sharesDecimals);
|
|
1905
|
+
return {
|
|
1906
|
+
abi: WithdrawQueueAbi,
|
|
1907
|
+
address: config.vault.withdrawQueueAddress,
|
|
1908
|
+
functionName: "submitOrderAndProcessAll",
|
|
1909
|
+
args: [
|
|
1910
|
+
{
|
|
1911
|
+
amountOffer: formattedAmountOffer,
|
|
1912
|
+
wantAsset,
|
|
1913
|
+
intendedDepositor: userAddress,
|
|
1914
|
+
receiver: userAddress,
|
|
1915
|
+
refundReceiver: userAddress,
|
|
1916
|
+
signatureParams: EMPTY_SIGNATURE_PARAMS
|
|
1917
|
+
}
|
|
1918
|
+
],
|
|
1919
|
+
chainId: normalizedChainId
|
|
1920
|
+
};
|
|
1921
|
+
} catch (error) {
|
|
1922
|
+
if (error instanceof WithdrawError) {
|
|
1923
|
+
throw error;
|
|
1924
|
+
}
|
|
1925
|
+
throw new TransactionDataError(
|
|
1926
|
+
`Failed to prepare atomic withdraw order transaction: ${error instanceof Error ? error.message : String(error)}`,
|
|
1927
|
+
{
|
|
1928
|
+
endpoint: "prepareAtomicWithdrawOrderTxData",
|
|
1929
|
+
cause: error
|
|
1930
|
+
}
|
|
1931
|
+
);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1935
|
+
// src/vaults/withdraw/index.ts
|
|
1833
1936
|
var WithdrawAuthMethod = {
|
|
1834
1937
|
APPROVAL: "approval",
|
|
1835
1938
|
ALREADY_APPROVED: "already_approved"
|
|
@@ -1843,13 +1946,21 @@ function isWithdrawAlreadyApprovedAuth(result) {
|
|
|
1843
1946
|
async function prepareWithdrawal(params) {
|
|
1844
1947
|
const { vaultName, wantAsset, withdrawAmount, userAddress, chainId } = params;
|
|
1845
1948
|
try {
|
|
1846
|
-
|
|
1949
|
+
const normalizedChainId = toChainId(chainId);
|
|
1950
|
+
const vault = await resolveVault({
|
|
1951
|
+
vaultName,
|
|
1952
|
+
assetAddress: wantAsset,
|
|
1953
|
+
chainId: normalizedChainId,
|
|
1954
|
+
callerEndpoint: "prepareWithdrawal"
|
|
1955
|
+
});
|
|
1956
|
+
const builderParams = {
|
|
1847
1957
|
vaultName,
|
|
1848
1958
|
wantAsset,
|
|
1849
1959
|
userAddress,
|
|
1850
1960
|
chainId,
|
|
1851
1961
|
amountOffer: withdrawAmount
|
|
1852
|
-
}
|
|
1962
|
+
};
|
|
1963
|
+
return vault.atomicWithdrawal ? await prepareAtomicWithdrawOrderTxData(builderParams) : await prepareWithdrawOrderTxData(builderParams);
|
|
1853
1964
|
} catch (error) {
|
|
1854
1965
|
if (error instanceof APIError) {
|
|
1855
1966
|
throw error;
|
|
@@ -1957,6 +2068,6 @@ async function prepareWithdrawalAuthorization(params) {
|
|
|
1957
2068
|
}
|
|
1958
2069
|
}
|
|
1959
2070
|
|
|
1960
|
-
export { DepositAuthMethod, DepositType, PERMIT_TYPES, WithdrawAuthMethod, isAlreadyApprovedAuth, isApprovalAuth, isDepositSpendApproved, isKytDeposit, isPermitAuth, isStandardDeposit, isWithdrawAlreadyApprovedAuth, isWithdrawApprovalAuth, isWithdrawalSpendApproved, parsePermitSignature, prepareApproveDepositTokenTxData, prepareApproveWithdrawOrderTxData, prepareCancelWithdrawOrderTxData, prepareDeposit, prepareDepositAuthorization, prepareDepositPermitSignature, prepareDepositTxData, prepareDepositWithPermitTxData, prepareWithdrawOrderTxData, prepareWithdrawal, prepareWithdrawalAuthorization, toEthSignTypedDataV4 };
|
|
1961
|
-
//# sourceMappingURL=chunk-
|
|
1962
|
-
//# sourceMappingURL=chunk-
|
|
2071
|
+
export { DepositAuthMethod, DepositType, PERMIT_TYPES, WithdrawAuthMethod, fetchKytAttestation, isAlreadyApprovedAuth, isApprovalAuth, isDepositSpendApproved, isKytDeposit, isPermitAuth, isStandardDeposit, isWithdrawAlreadyApprovedAuth, isWithdrawApprovalAuth, isWithdrawalSpendApproved, parsePermitSignature, prepareApproveDepositTokenTxData, prepareApproveWithdrawOrderTxData, prepareCancelWithdrawOrderTxData, prepareDeposit, prepareDepositAuthorization, prepareDepositPermitSignature, prepareDepositTxData, prepareDepositWithPermitTxData, prepareWithdrawOrderTxData, prepareWithdrawal, prepareWithdrawalAuthorization, toEthSignTypedDataV4 };
|
|
2072
|
+
//# sourceMappingURL=chunk-LMNADWTH.mjs.map
|
|
2073
|
+
//# sourceMappingURL=chunk-LMNADWTH.mjs.map
|