@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,9 +1,111 @@
|
|
|
1
|
-
import { resolveVault,
|
|
2
|
-
import { getTokenPermitInfoWithAllowance, getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals, erc2612Abi, getErc20Decimals, BoringVaultAbi } from './chunk-
|
|
3
|
-
import { WAD } from './chunk-
|
|
4
|
-
import {
|
|
5
|
-
import { formatUnits, parseUnits, erc20Abi, stringToHex, hexToSignature } from 'viem';
|
|
1
|
+
import { resolveVault, InvalidChainIdError, TransactionDataError, WithdrawError } from './chunk-Y5LBT2WT.mjs';
|
|
2
|
+
import { getTokenPermitInfoWithAllowance, getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals, erc2612Abi, getErc20Decimals, BoringVaultAbi, AccountantAbi } from './chunk-UY2WD7MF.mjs';
|
|
3
|
+
import { WAD } from './chunk-6CU533DM.mjs';
|
|
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,8 +291,8 @@ async function prepareApproveDepositTokenTxData({
|
|
|
189
291
|
}
|
|
190
292
|
}
|
|
191
293
|
|
|
192
|
-
// src/abi/
|
|
193
|
-
var
|
|
294
|
+
// src/abi/distributor-code-depositor-abi-v1.ts
|
|
295
|
+
var DistributorCodeDepositorAbiV1 = [
|
|
194
296
|
{
|
|
195
297
|
inputs: [
|
|
196
298
|
{
|
|
@@ -209,19 +311,53 @@ var CommunityCodeDepositorAbi = [
|
|
|
209
311
|
type: "address"
|
|
210
312
|
},
|
|
211
313
|
{ internalType: "bool", name: "_isNativeDepositSupported", type: "bool" },
|
|
314
|
+
{ internalType: "uint256", name: "_supplyCap", type: "uint256" },
|
|
315
|
+
{
|
|
316
|
+
internalType: "contract IFeeModule",
|
|
317
|
+
name: "_feeModule",
|
|
318
|
+
type: "address"
|
|
319
|
+
},
|
|
320
|
+
{ internalType: "address", name: "_feeRecipient", type: "address" },
|
|
321
|
+
{ internalType: "address", name: "_registry", type: "address" },
|
|
322
|
+
{ internalType: "string", name: "_policyID", type: "string" },
|
|
212
323
|
{ internalType: "address", name: "_owner", type: "address" }
|
|
213
324
|
],
|
|
214
325
|
stateMutability: "nonpayable",
|
|
215
326
|
type: "constructor"
|
|
216
327
|
},
|
|
328
|
+
{ inputs: [], name: "FeesExceedOrEqualAmount", type: "error" },
|
|
217
329
|
{ inputs: [], name: "IncorrectNativeDepositAmount", type: "error" },
|
|
330
|
+
{
|
|
331
|
+
inputs: [
|
|
332
|
+
{ internalType: "uint256", name: "actual", type: "uint256" },
|
|
333
|
+
{ internalType: "uint256", name: "minimum", type: "uint256" }
|
|
334
|
+
],
|
|
335
|
+
name: "InsufficientSharesAfterFees",
|
|
336
|
+
type: "error"
|
|
337
|
+
},
|
|
218
338
|
{ inputs: [], name: "NativeDepositNotSupported", type: "error" },
|
|
219
339
|
{
|
|
220
340
|
inputs: [],
|
|
221
341
|
name: "NativeWrapperAccountantDecimalsMismatch",
|
|
222
342
|
type: "error"
|
|
223
343
|
},
|
|
344
|
+
{
|
|
345
|
+
inputs: [
|
|
346
|
+
{ internalType: "address", name: "addressEmptyCode", type: "address" }
|
|
347
|
+
],
|
|
348
|
+
name: "NoCode",
|
|
349
|
+
type: "error"
|
|
350
|
+
},
|
|
224
351
|
{ inputs: [], name: "PermitFailedAndAllowanceTooLow", type: "error" },
|
|
352
|
+
{
|
|
353
|
+
inputs: [
|
|
354
|
+
{ internalType: "uint256", name: "resultingValue", type: "uint256" },
|
|
355
|
+
{ internalType: "uint256", name: "supplyCapInBase", type: "uint256" }
|
|
356
|
+
],
|
|
357
|
+
name: "SupplyCapInBaseError",
|
|
358
|
+
type: "error"
|
|
359
|
+
},
|
|
360
|
+
{ inputs: [], name: "UnauthorizedTransaction", type: "error" },
|
|
225
361
|
{ inputs: [], name: "ZeroAddress", type: "error" },
|
|
226
362
|
{
|
|
227
363
|
anonymous: false,
|
|
@@ -281,6 +417,46 @@ var CommunityCodeDepositorAbi = [
|
|
|
281
417
|
name: "DepositWithDistributorCode",
|
|
282
418
|
type: "event"
|
|
283
419
|
},
|
|
420
|
+
{
|
|
421
|
+
anonymous: false,
|
|
422
|
+
inputs: [
|
|
423
|
+
{
|
|
424
|
+
indexed: true,
|
|
425
|
+
internalType: "contract IFeeModule",
|
|
426
|
+
name: "newFeeModule",
|
|
427
|
+
type: "address"
|
|
428
|
+
}
|
|
429
|
+
],
|
|
430
|
+
name: "FeeModuleUpdated",
|
|
431
|
+
type: "event"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
anonymous: false,
|
|
435
|
+
inputs: [
|
|
436
|
+
{
|
|
437
|
+
indexed: true,
|
|
438
|
+
internalType: "address",
|
|
439
|
+
name: "newFeeRecipient",
|
|
440
|
+
type: "address"
|
|
441
|
+
}
|
|
442
|
+
],
|
|
443
|
+
name: "FeeRecipientUpdated",
|
|
444
|
+
type: "event"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
anonymous: false,
|
|
448
|
+
inputs: [
|
|
449
|
+
{
|
|
450
|
+
indexed: true,
|
|
451
|
+
internalType: "contract ERC20",
|
|
452
|
+
name: "depositAsset",
|
|
453
|
+
type: "address"
|
|
454
|
+
},
|
|
455
|
+
{ indexed: true, internalType: "bool", name: "enabled", type: "bool" }
|
|
456
|
+
],
|
|
457
|
+
name: "KytStatusUpdated",
|
|
458
|
+
type: "event"
|
|
459
|
+
},
|
|
284
460
|
{
|
|
285
461
|
anonymous: false,
|
|
286
462
|
inputs: [
|
|
@@ -295,6 +471,64 @@ var CommunityCodeDepositorAbi = [
|
|
|
295
471
|
name: "OwnershipTransferred",
|
|
296
472
|
type: "event"
|
|
297
473
|
},
|
|
474
|
+
{
|
|
475
|
+
anonymous: false,
|
|
476
|
+
inputs: [
|
|
477
|
+
{
|
|
478
|
+
indexed: false,
|
|
479
|
+
internalType: "string",
|
|
480
|
+
name: "oldPolicyID",
|
|
481
|
+
type: "string"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
indexed: false,
|
|
485
|
+
internalType: "string",
|
|
486
|
+
name: "newPolicyID",
|
|
487
|
+
type: "string"
|
|
488
|
+
}
|
|
489
|
+
],
|
|
490
|
+
name: "PredicatePolicyIDUpdated",
|
|
491
|
+
type: "event"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
anonymous: false,
|
|
495
|
+
inputs: [
|
|
496
|
+
{
|
|
497
|
+
indexed: true,
|
|
498
|
+
internalType: "address",
|
|
499
|
+
name: "oldRegistry",
|
|
500
|
+
type: "address"
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
indexed: true,
|
|
504
|
+
internalType: "address",
|
|
505
|
+
name: "newRegistry",
|
|
506
|
+
type: "address"
|
|
507
|
+
}
|
|
508
|
+
],
|
|
509
|
+
name: "PredicateRegistryUpdated",
|
|
510
|
+
type: "event"
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
anonymous: false,
|
|
514
|
+
inputs: [
|
|
515
|
+
{
|
|
516
|
+
indexed: false,
|
|
517
|
+
internalType: "uint256",
|
|
518
|
+
name: "newSupplyCapInBase",
|
|
519
|
+
type: "uint256"
|
|
520
|
+
}
|
|
521
|
+
],
|
|
522
|
+
name: "SupplyCapInBaseUpdated",
|
|
523
|
+
type: "event"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
inputs: [],
|
|
527
|
+
name: "PREDICATE_DEPOSIT_SIGNATURE",
|
|
528
|
+
outputs: [{ internalType: "string", name: "", type: "string" }],
|
|
529
|
+
stateMutability: "view",
|
|
530
|
+
type: "function"
|
|
531
|
+
},
|
|
298
532
|
{
|
|
299
533
|
inputs: [],
|
|
300
534
|
name: "authority",
|
|
@@ -317,7 +551,18 @@ var CommunityCodeDepositorAbi = [
|
|
|
317
551
|
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
318
552
|
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
319
553
|
{ internalType: "address", name: "to", type: "address" },
|
|
320
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
554
|
+
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
555
|
+
{
|
|
556
|
+
components: [
|
|
557
|
+
{ internalType: "string", name: "uuid", type: "string" },
|
|
558
|
+
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
559
|
+
{ internalType: "address", name: "attester", type: "address" },
|
|
560
|
+
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
561
|
+
],
|
|
562
|
+
internalType: "struct Attestation",
|
|
563
|
+
name: "_attestation",
|
|
564
|
+
type: "tuple"
|
|
565
|
+
}
|
|
321
566
|
],
|
|
322
567
|
name: "deposit",
|
|
323
568
|
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
@@ -329,7 +574,18 @@ var CommunityCodeDepositorAbi = [
|
|
|
329
574
|
{ internalType: "uint256", name: "depositAmount", type: "uint256" },
|
|
330
575
|
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
331
576
|
{ internalType: "address", name: "to", type: "address" },
|
|
332
|
-
{ internalType: "bytes", name: "distributorCode", type: "bytes" }
|
|
577
|
+
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
578
|
+
{
|
|
579
|
+
components: [
|
|
580
|
+
{ internalType: "string", name: "uuid", type: "string" },
|
|
581
|
+
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
582
|
+
{ internalType: "address", name: "attester", type: "address" },
|
|
583
|
+
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
584
|
+
],
|
|
585
|
+
internalType: "struct Attestation",
|
|
586
|
+
name: "_attestation",
|
|
587
|
+
type: "tuple"
|
|
588
|
+
}
|
|
333
589
|
],
|
|
334
590
|
name: "depositNative",
|
|
335
591
|
outputs: [{ internalType: "uint256", name: "shares", type: "uint256" }],
|
|
@@ -350,6 +606,17 @@ var CommunityCodeDepositorAbi = [
|
|
|
350
606
|
{ internalType: "uint256", name: "minimumMint", type: "uint256" },
|
|
351
607
|
{ internalType: "address", name: "to", type: "address" },
|
|
352
608
|
{ internalType: "bytes", name: "distributorCode", type: "bytes" },
|
|
609
|
+
{
|
|
610
|
+
components: [
|
|
611
|
+
{ internalType: "string", name: "uuid", type: "string" },
|
|
612
|
+
{ internalType: "uint256", name: "expiration", type: "uint256" },
|
|
613
|
+
{ internalType: "address", name: "attester", type: "address" },
|
|
614
|
+
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
615
|
+
],
|
|
616
|
+
internalType: "struct Attestation",
|
|
617
|
+
name: "_attestation",
|
|
618
|
+
type: "tuple"
|
|
619
|
+
},
|
|
353
620
|
{ internalType: "uint256", name: "deadline", type: "uint256" },
|
|
354
621
|
{ internalType: "uint8", name: "v", type: "uint8" },
|
|
355
622
|
{ internalType: "bytes32", name: "r", type: "bytes32" },
|
|
@@ -360,6 +627,36 @@ var CommunityCodeDepositorAbi = [
|
|
|
360
627
|
stateMutability: "nonpayable",
|
|
361
628
|
type: "function"
|
|
362
629
|
},
|
|
630
|
+
{
|
|
631
|
+
inputs: [],
|
|
632
|
+
name: "feeModule",
|
|
633
|
+
outputs: [
|
|
634
|
+
{ internalType: "contract IFeeModule", name: "", type: "address" }
|
|
635
|
+
],
|
|
636
|
+
stateMutability: "view",
|
|
637
|
+
type: "function"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
inputs: [],
|
|
641
|
+
name: "feeRecipient",
|
|
642
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
643
|
+
stateMutability: "view",
|
|
644
|
+
type: "function"
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
inputs: [],
|
|
648
|
+
name: "getPolicyID",
|
|
649
|
+
outputs: [{ internalType: "string", name: "policyID", type: "string" }],
|
|
650
|
+
stateMutability: "view",
|
|
651
|
+
type: "function"
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
inputs: [],
|
|
655
|
+
name: "getRegistry",
|
|
656
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
657
|
+
stateMutability: "view",
|
|
658
|
+
type: "function"
|
|
659
|
+
},
|
|
363
660
|
{
|
|
364
661
|
inputs: [],
|
|
365
662
|
name: "isNativeDepositSupported",
|
|
@@ -367,6 +664,13 @@ var CommunityCodeDepositorAbi = [
|
|
|
367
664
|
stateMutability: "view",
|
|
368
665
|
type: "function"
|
|
369
666
|
},
|
|
667
|
+
{
|
|
668
|
+
inputs: [{ internalType: "contract ERC20", name: "", type: "address" }],
|
|
669
|
+
name: "kytEnabled",
|
|
670
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
671
|
+
stateMutability: "view",
|
|
672
|
+
type: "function"
|
|
673
|
+
},
|
|
370
674
|
{
|
|
371
675
|
inputs: [],
|
|
372
676
|
name: "nativeWrapper",
|
|
@@ -396,6 +700,27 @@ var CommunityCodeDepositorAbi = [
|
|
|
396
700
|
stateMutability: "nonpayable",
|
|
397
701
|
type: "function"
|
|
398
702
|
},
|
|
703
|
+
{
|
|
704
|
+
inputs: [{ internalType: "string", name: "_policyID", type: "string" }],
|
|
705
|
+
name: "setPolicyID",
|
|
706
|
+
outputs: [],
|
|
707
|
+
stateMutability: "nonpayable",
|
|
708
|
+
type: "function"
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
inputs: [{ internalType: "address", name: "_registry", type: "address" }],
|
|
712
|
+
name: "setRegistry",
|
|
713
|
+
outputs: [],
|
|
714
|
+
stateMutability: "nonpayable",
|
|
715
|
+
type: "function"
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
inputs: [],
|
|
719
|
+
name: "supplyCapInBase",
|
|
720
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
721
|
+
stateMutability: "view",
|
|
722
|
+
type: "function"
|
|
723
|
+
},
|
|
399
724
|
{
|
|
400
725
|
inputs: [],
|
|
401
726
|
name: "teller",
|
|
@@ -415,10 +740,49 @@ var CommunityCodeDepositorAbi = [
|
|
|
415
740
|
outputs: [],
|
|
416
741
|
stateMutability: "nonpayable",
|
|
417
742
|
type: "function"
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
inputs: [
|
|
746
|
+
{
|
|
747
|
+
internalType: "contract IFeeModule",
|
|
748
|
+
name: "newFeeModule",
|
|
749
|
+
type: "address"
|
|
750
|
+
}
|
|
751
|
+
],
|
|
752
|
+
name: "updateFeeModule",
|
|
753
|
+
outputs: [],
|
|
754
|
+
stateMutability: "nonpayable",
|
|
755
|
+
type: "function"
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
inputs: [
|
|
759
|
+
{ internalType: "address", name: "newFeeRecipient", type: "address" }
|
|
760
|
+
],
|
|
761
|
+
name: "updateFeeRecipient",
|
|
762
|
+
outputs: [],
|
|
763
|
+
stateMutability: "nonpayable",
|
|
764
|
+
type: "function"
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
inputs: [
|
|
768
|
+
{ internalType: "contract ERC20", name: "depositAsset", type: "address" },
|
|
769
|
+
{ internalType: "bool", name: "enabled", type: "bool" }
|
|
770
|
+
],
|
|
771
|
+
name: "updateKytStatus",
|
|
772
|
+
outputs: [],
|
|
773
|
+
stateMutability: "nonpayable",
|
|
774
|
+
type: "function"
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
inputs: [
|
|
778
|
+
{ internalType: "uint256", name: "newSupplyCapInBase", type: "uint256" }
|
|
779
|
+
],
|
|
780
|
+
name: "updateSupplyCapInBase",
|
|
781
|
+
outputs: [],
|
|
782
|
+
stateMutability: "nonpayable",
|
|
783
|
+
type: "function"
|
|
418
784
|
}
|
|
419
785
|
];
|
|
420
|
-
|
|
421
|
-
// src/vaults/deposit/utils.ts
|
|
422
786
|
var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) => {
|
|
423
787
|
const slippageValue = slippage ?? DEFAULT_SLIPPAGE_BPS;
|
|
424
788
|
const slippageAsBigInt = BigInt(slippageValue) * WAD.bigint / BigInt(1e4);
|
|
@@ -429,8 +793,87 @@ var calculateMinimumMint = (depositAmount, rate, vaultTokenDecimals, slippage) =
|
|
|
429
793
|
}
|
|
430
794
|
return (minimumMint - slippageAmount) / BigInt(10) ** (BigInt(18) - BigInt(vaultTokenDecimals));
|
|
431
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
|
+
}
|
|
432
865
|
|
|
433
866
|
// src/vaults/deposit/deposit.ts
|
|
867
|
+
var DepositType = {
|
|
868
|
+
STANDARD: "standard",
|
|
869
|
+
KYT: "kyt"
|
|
870
|
+
};
|
|
871
|
+
function isKytDeposit(data) {
|
|
872
|
+
return data.depositType === DepositType.KYT;
|
|
873
|
+
}
|
|
874
|
+
function isStandardDeposit(data) {
|
|
875
|
+
return data.depositType === DepositType.STANDARD;
|
|
876
|
+
}
|
|
434
877
|
async function prepareDepositTxData(params) {
|
|
435
878
|
const {
|
|
436
879
|
vaultName,
|
|
@@ -449,6 +892,11 @@ async function prepareDepositTxData(params) {
|
|
|
449
892
|
chainId: normalizedChainId,
|
|
450
893
|
callerEndpoint: "prepareDepositTransactionData"
|
|
451
894
|
});
|
|
895
|
+
if (vault.inDeprecation) {
|
|
896
|
+
getLogger().warn(
|
|
897
|
+
`Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
452
900
|
const assets = await getSupportedAssets({ address: depositAsset });
|
|
453
901
|
const asset = assets.find((a) => a.chains.includes(normalizedChainId)) || assets.find((a) => a.address.toLowerCase() === depositAsset.toLowerCase());
|
|
454
902
|
if (!asset) {
|
|
@@ -501,28 +949,90 @@ async function prepareDepositTxData(params) {
|
|
|
501
949
|
depositAmount,
|
|
502
950
|
depositAssetDecimalsResult.result
|
|
503
951
|
);
|
|
504
|
-
const
|
|
952
|
+
const totalFee = await getDepositFeeForAmount(
|
|
953
|
+
vault.vault.depositFeeModuleAddress,
|
|
954
|
+
depositAssetAddress,
|
|
505
955
|
depositAmountAsBigInt,
|
|
506
|
-
|
|
507
|
-
depositAssetDecimalsResult.result,
|
|
508
|
-
slippage
|
|
956
|
+
normalizedChainId
|
|
509
957
|
);
|
|
510
|
-
if (
|
|
958
|
+
if (totalFee >= depositAmountAsBigInt) {
|
|
511
959
|
throw new APIError(
|
|
512
|
-
|
|
960
|
+
"Deposit amount is entirely consumed by fees. Increase the deposit amount.",
|
|
513
961
|
{ endpoint: "prepareDepositTransactionData" }
|
|
514
962
|
);
|
|
515
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,
|
|
974
|
+
rateInQuoteResult.result,
|
|
975
|
+
depositAssetDecimalsResult.result,
|
|
976
|
+
slippage
|
|
977
|
+
);
|
|
978
|
+
const distributorCodeHex = stringToHex(distributorCode || "");
|
|
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 = {
|
|
998
|
+
uuid: "",
|
|
999
|
+
expiration: 0n,
|
|
1000
|
+
attester: zeroAddress,
|
|
1001
|
+
signature: "0x"
|
|
1002
|
+
};
|
|
1003
|
+
return {
|
|
1004
|
+
depositType: DepositType.KYT,
|
|
1005
|
+
address: communityCodeDepositorAddress,
|
|
1006
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
1007
|
+
functionName: "deposit",
|
|
1008
|
+
args: [
|
|
1009
|
+
depositAssetAddress,
|
|
1010
|
+
depositAmountAsBigInt,
|
|
1011
|
+
minimumMint,
|
|
1012
|
+
to,
|
|
1013
|
+
distributorCodeHex,
|
|
1014
|
+
emptyAttestation
|
|
1015
|
+
],
|
|
1016
|
+
chainId: normalizedChainId
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
const attestation = await fetchKytAttestation({
|
|
1020
|
+
to: communityCodeDepositorAddress,
|
|
1021
|
+
from: to,
|
|
1022
|
+
chainId: normalizedChainId
|
|
1023
|
+
});
|
|
516
1024
|
return {
|
|
517
|
-
|
|
1025
|
+
depositType: DepositType.KYT,
|
|
518
1026
|
address: communityCodeDepositorAddress,
|
|
1027
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
519
1028
|
functionName: "deposit",
|
|
520
1029
|
args: [
|
|
521
1030
|
depositAssetAddress,
|
|
522
1031
|
depositAmountAsBigInt,
|
|
523
1032
|
minimumMint,
|
|
524
1033
|
to,
|
|
525
|
-
|
|
1034
|
+
distributorCodeHex,
|
|
1035
|
+
attestation
|
|
526
1036
|
],
|
|
527
1037
|
chainId: normalizedChainId
|
|
528
1038
|
};
|
|
@@ -775,6 +1285,11 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
775
1285
|
chainId: normalizedChainId,
|
|
776
1286
|
callerEndpoint: "prepareDepositWithPermitTxData"
|
|
777
1287
|
});
|
|
1288
|
+
if (vault.inDeprecation) {
|
|
1289
|
+
getLogger().warn(
|
|
1290
|
+
`Vault "${vault.name}" is being deprecated. Please contact the Paxos Labs team for migration guidance.`
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
778
1293
|
let asset = null;
|
|
779
1294
|
const assets = await getSupportedAssets({ address: depositAsset });
|
|
780
1295
|
if (assets.length > 0) {
|
|
@@ -836,33 +1351,104 @@ async function prepareDepositWithPermitTxData(params) {
|
|
|
836
1351
|
);
|
|
837
1352
|
}
|
|
838
1353
|
const onChainDecimals = depositAssetDecimalsResult.result;
|
|
839
|
-
const depositAmountAsBigInt = parseUnits(
|
|
840
|
-
|
|
841
|
-
|
|
1354
|
+
const depositAmountAsBigInt = parseUnits(depositAmount, onChainDecimals);
|
|
1355
|
+
const totalFee = await getDepositFeeForAmount(
|
|
1356
|
+
vault.vault.depositFeeModuleAddress,
|
|
1357
|
+
depositAssetAddress,
|
|
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"
|
|
842
1374
|
);
|
|
843
1375
|
const minimumMint = calculateMinimumMint(
|
|
844
|
-
|
|
1376
|
+
depositAmountAfterFees,
|
|
845
1377
|
rateInQuoteResult.result,
|
|
846
1378
|
onChainDecimals,
|
|
847
1379
|
slippage
|
|
848
1380
|
);
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
1381
|
+
const distributorCodeHex = stringToHex(distributorCode || "");
|
|
1382
|
+
const policyId = vault.enterpriseConfig?.predicatePolicyId;
|
|
1383
|
+
if (policyId === void 0) {
|
|
1384
|
+
return {
|
|
1385
|
+
depositType: DepositType.STANDARD,
|
|
1386
|
+
abi: DistributorCodeDepositorAbiV0,
|
|
1387
|
+
address: communityCodeDepositorAddress,
|
|
852
1388
|
functionName: "depositWithPermit",
|
|
853
1389
|
args: [
|
|
854
1390
|
depositAssetAddress,
|
|
855
1391
|
depositAmountAsBigInt,
|
|
856
1392
|
minimumMint,
|
|
857
1393
|
to,
|
|
858
|
-
|
|
1394
|
+
distributorCodeHex,
|
|
859
1395
|
deadline,
|
|
860
1396
|
v,
|
|
861
1397
|
r,
|
|
862
1398
|
s
|
|
863
|
-
]
|
|
864
|
-
|
|
1399
|
+
],
|
|
1400
|
+
chainId: normalizedChainId
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
if (policyId === null) {
|
|
1404
|
+
const emptyAttestation = {
|
|
1405
|
+
uuid: "",
|
|
1406
|
+
expiration: 0n,
|
|
1407
|
+
attester: zeroAddress,
|
|
1408
|
+
signature: "0x"
|
|
1409
|
+
};
|
|
1410
|
+
return {
|
|
1411
|
+
depositType: DepositType.KYT,
|
|
1412
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
1413
|
+
address: communityCodeDepositorAddress,
|
|
1414
|
+
functionName: "depositWithPermit",
|
|
1415
|
+
args: [
|
|
1416
|
+
depositAssetAddress,
|
|
1417
|
+
depositAmountAsBigInt,
|
|
1418
|
+
minimumMint,
|
|
1419
|
+
to,
|
|
1420
|
+
distributorCodeHex,
|
|
1421
|
+
emptyAttestation,
|
|
1422
|
+
deadline,
|
|
1423
|
+
v,
|
|
1424
|
+
r,
|
|
1425
|
+
s
|
|
1426
|
+
],
|
|
1427
|
+
chainId: normalizedChainId
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
const attestation = await fetchKytAttestation({
|
|
1431
|
+
to: communityCodeDepositorAddress,
|
|
1432
|
+
from: to,
|
|
1433
|
+
chainId: normalizedChainId
|
|
1434
|
+
});
|
|
1435
|
+
return {
|
|
1436
|
+
depositType: DepositType.KYT,
|
|
1437
|
+
abi: DistributorCodeDepositorAbiV1,
|
|
865
1438
|
address: communityCodeDepositorAddress,
|
|
1439
|
+
functionName: "depositWithPermit",
|
|
1440
|
+
args: [
|
|
1441
|
+
depositAssetAddress,
|
|
1442
|
+
depositAmountAsBigInt,
|
|
1443
|
+
minimumMint,
|
|
1444
|
+
to,
|
|
1445
|
+
distributorCodeHex,
|
|
1446
|
+
attestation,
|
|
1447
|
+
deadline,
|
|
1448
|
+
v,
|
|
1449
|
+
r,
|
|
1450
|
+
s
|
|
1451
|
+
],
|
|
866
1452
|
chainId: normalizedChainId
|
|
867
1453
|
};
|
|
868
1454
|
} catch (error) {
|
|
@@ -955,10 +1541,7 @@ async function prepareDepositAuthorization(params) {
|
|
|
955
1541
|
permitData
|
|
956
1542
|
};
|
|
957
1543
|
}
|
|
958
|
-
const smartWallet = await isSmartContractWallet(
|
|
959
|
-
to,
|
|
960
|
-
normalizedChainId
|
|
961
|
-
);
|
|
1544
|
+
const smartWallet = await isSmartContractWallet(to, normalizedChainId);
|
|
962
1545
|
if (smartWallet) {
|
|
963
1546
|
const txData2 = await prepareApproveDepositTokenTxData({
|
|
964
1547
|
vaultName,
|
|
@@ -1277,6 +1860,79 @@ var prepareWithdrawOrderTxData = async ({
|
|
|
1277
1860
|
);
|
|
1278
1861
|
}
|
|
1279
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
|
|
1280
1936
|
var WithdrawAuthMethod = {
|
|
1281
1937
|
APPROVAL: "approval",
|
|
1282
1938
|
ALREADY_APPROVED: "already_approved"
|
|
@@ -1290,13 +1946,21 @@ function isWithdrawAlreadyApprovedAuth(result) {
|
|
|
1290
1946
|
async function prepareWithdrawal(params) {
|
|
1291
1947
|
const { vaultName, wantAsset, withdrawAmount, userAddress, chainId } = params;
|
|
1292
1948
|
try {
|
|
1293
|
-
|
|
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 = {
|
|
1294
1957
|
vaultName,
|
|
1295
1958
|
wantAsset,
|
|
1296
1959
|
userAddress,
|
|
1297
1960
|
chainId,
|
|
1298
1961
|
amountOffer: withdrawAmount
|
|
1299
|
-
}
|
|
1962
|
+
};
|
|
1963
|
+
return vault.atomicWithdrawal ? await prepareAtomicWithdrawOrderTxData(builderParams) : await prepareWithdrawOrderTxData(builderParams);
|
|
1300
1964
|
} catch (error) {
|
|
1301
1965
|
if (error instanceof APIError) {
|
|
1302
1966
|
throw error;
|
|
@@ -1371,9 +2035,7 @@ async function prepareWithdrawalAuthorization(params) {
|
|
|
1371
2035
|
}
|
|
1372
2036
|
const decimals = typeof approvalInfo.decimals === "string" ? Number(approvalInfo.decimals) : approvalInfo.decimals;
|
|
1373
2037
|
const withdrawAmountBigInt = parseUnits(withdrawAmount, decimals);
|
|
1374
|
-
const currentAllowanceBigInt = BigInt(
|
|
1375
|
-
approvalInfo.allowanceAsBigInt
|
|
1376
|
-
);
|
|
2038
|
+
const currentAllowanceBigInt = BigInt(approvalInfo.allowanceAsBigInt);
|
|
1377
2039
|
if (approvalInfo.isApproved && currentAllowanceBigInt >= withdrawAmountBigInt) {
|
|
1378
2040
|
return {
|
|
1379
2041
|
method: WithdrawAuthMethod.ALREADY_APPROVED,
|
|
@@ -1406,6 +2068,6 @@ async function prepareWithdrawalAuthorization(params) {
|
|
|
1406
2068
|
}
|
|
1407
2069
|
}
|
|
1408
2070
|
|
|
1409
|
-
export { DepositAuthMethod, PERMIT_TYPES, WithdrawAuthMethod, isAlreadyApprovedAuth, isApprovalAuth, isDepositSpendApproved, isPermitAuth, isWithdrawAlreadyApprovedAuth, isWithdrawApprovalAuth, isWithdrawalSpendApproved, parsePermitSignature, prepareApproveDepositTokenTxData, prepareApproveWithdrawOrderTxData, prepareCancelWithdrawOrderTxData, prepareDeposit, prepareDepositAuthorization, prepareDepositPermitSignature, prepareDepositTxData, prepareDepositWithPermitTxData, prepareWithdrawOrderTxData, prepareWithdrawal, prepareWithdrawalAuthorization, toEthSignTypedDataV4 };
|
|
1410
|
-
//# sourceMappingURL=chunk-
|
|
1411
|
-
//# 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
|