@augustdigital/sdk 8.3.2 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/abis/ERC20_Bytes32.d.ts +4 -0
- package/lib/abis/ERC20_Bytes32.js +4 -0
- package/lib/abis/ERC4626.d.ts +1 -0
- package/lib/abis/ERC4626.js +1 -0
- package/lib/abis/ERC721.d.ts +1 -0
- package/lib/abis/ERC721.js +1 -0
- package/lib/abis/FeeOracle.js +1 -0
- package/lib/abis/LendingPool.js +1 -0
- package/lib/abis/LendingPoolV2.js +1 -0
- package/lib/abis/Multicall3.js +3 -0
- package/lib/abis/OFT.d.ts +20 -0
- package/lib/abis/OFT.js +20 -0
- package/lib/abis/SmartAccount.d.ts +1 -0
- package/lib/abis/SmartAccount.js +3 -0
- package/lib/abis/SwapRouter.d.ts +1 -0
- package/lib/abis/SwapRouter.js +1 -0
- package/lib/abis/UniversalSignatureValidator.js +3 -0
- package/lib/abis/index.d.ts +5 -0
- package/lib/abis/index.js +5 -0
- package/lib/adapters/evm/getters.d.ts +17 -2
- package/lib/adapters/evm/getters.js +35 -3
- package/lib/adapters/evm/index.d.ts +262 -0
- package/lib/adapters/evm/index.js +268 -1
- package/lib/adapters/evm/utils.d.ts +6 -0
- package/lib/adapters/evm/utils.js +7 -0
- package/lib/adapters/solana/constants.js +4 -1
- package/lib/adapters/solana/getters.d.ts +8 -0
- package/lib/adapters/solana/getters.js +21 -0
- package/lib/adapters/solana/idl/vault-idl.js +9 -0
- package/lib/adapters/solana/index.d.ts +55 -0
- package/lib/adapters/solana/index.js +57 -0
- package/lib/adapters/solana/utils.d.ts +28 -0
- package/lib/adapters/solana/utils.js +79 -4
- package/lib/adapters/solana/vault.actions.d.ts +19 -0
- package/lib/adapters/solana/vault.actions.js +47 -3
- package/lib/adapters/stellar/actions.d.ts +25 -0
- package/lib/adapters/stellar/actions.js +33 -0
- package/lib/adapters/stellar/constants.d.ts +26 -0
- package/lib/adapters/stellar/constants.js +29 -0
- package/lib/adapters/stellar/getters.d.ts +56 -0
- package/lib/adapters/stellar/getters.js +81 -0
- package/lib/adapters/stellar/index.d.ts +48 -0
- package/lib/adapters/stellar/index.js +48 -0
- package/lib/adapters/stellar/soroban.d.ts +20 -0
- package/lib/adapters/stellar/soroban.js +46 -0
- package/lib/adapters/stellar/submit.d.ts +12 -0
- package/lib/adapters/stellar/submit.js +19 -0
- package/lib/adapters/stellar/types.d.ts +27 -0
- package/lib/adapters/stellar/types.js +3 -0
- package/lib/adapters/stellar/utils.d.ts +10 -0
- package/lib/adapters/stellar/utils.js +10 -0
- package/lib/adapters/sui/getters.d.ts +6 -0
- package/lib/adapters/sui/getters.js +6 -0
- package/lib/adapters/sui/index.d.ts +15 -0
- package/lib/adapters/sui/index.js +15 -0
- package/lib/adapters/sui/transformer.d.ts +6 -0
- package/lib/adapters/sui/transformer.js +6 -0
- package/lib/adapters/sui/utils.d.ts +6 -0
- package/lib/adapters/sui/utils.js +6 -0
- package/lib/core/analytics/chain-name.d.ts +8 -0
- package/lib/core/analytics/chain-name.js +8 -0
- package/lib/core/analytics/constants.d.ts +4 -0
- package/lib/core/analytics/constants.js +4 -0
- package/lib/core/analytics/env.d.ts +25 -0
- package/lib/core/analytics/env.js +26 -0
- package/lib/core/analytics/index.d.ts +26 -0
- package/lib/core/analytics/index.js +35 -0
- package/lib/core/analytics/instrumentation.d.ts +26 -0
- package/lib/core/analytics/instrumentation.js +66 -2
- package/lib/core/analytics/method-taxonomy.d.ts +16 -0
- package/lib/core/analytics/method-taxonomy.js +18 -0
- package/lib/core/analytics/metrics.d.ts +23 -0
- package/lib/core/analytics/metrics.js +40 -0
- package/lib/core/analytics/sanitize.d.ts +38 -0
- package/lib/core/analytics/sanitize.js +46 -0
- package/lib/core/analytics/sentry-runtime.d.ts +11 -0
- package/lib/core/analytics/sentry-runtime.js +19 -0
- package/lib/core/analytics/sentry.d.ts +45 -0
- package/lib/core/analytics/sentry.js +115 -2
- package/lib/core/analytics/types.d.ts +27 -0
- package/lib/core/analytics/user-identity.d.ts +34 -0
- package/lib/core/analytics/user-identity.js +42 -0
- package/lib/core/analytics/version.d.ts +6 -1
- package/lib/core/analytics/version.js +6 -1
- package/lib/core/auth/verify.js +5 -0
- package/lib/core/base.class.d.ts +75 -0
- package/lib/core/base.class.js +56 -0
- package/lib/core/cache.d.ts +5 -0
- package/lib/core/cache.js +6 -0
- package/lib/core/constants/adapters.d.ts +15 -0
- package/lib/core/constants/adapters.js +28 -8
- package/lib/core/constants/core.d.ts +12 -1
- package/lib/core/constants/core.js +12 -0
- package/lib/core/constants/swap-router.d.ts +46 -0
- package/lib/core/constants/swap-router.js +50 -0
- package/lib/core/constants/vaults.d.ts +56 -0
- package/lib/core/constants/vaults.js +66 -1
- package/lib/core/constants/web3.d.ts +3 -0
- package/lib/core/constants/web3.js +18 -5
- package/lib/core/errors/index.d.ts +36 -0
- package/lib/core/errors/index.js +29 -0
- package/lib/core/fetcher.d.ts +134 -0
- package/lib/core/fetcher.js +191 -5
- package/lib/core/helpers/adapters.d.ts +9 -0
- package/lib/core/helpers/adapters.js +11 -0
- package/lib/core/helpers/chain-address.d.ts +10 -0
- package/lib/core/helpers/chain-address.js +11 -0
- package/lib/core/helpers/core.d.ts +42 -0
- package/lib/core/helpers/core.js +66 -1
- package/lib/core/helpers/explorer-link.d.ts +14 -0
- package/lib/core/helpers/explorer-link.js +14 -0
- package/lib/core/helpers/signer.d.ts +26 -0
- package/lib/core/helpers/signer.js +39 -0
- package/lib/core/helpers/swap-router.d.ts +32 -0
- package/lib/core/helpers/swap-router.js +32 -0
- package/lib/core/helpers/vault-version.d.ts +1 -0
- package/lib/core/helpers/vault-version.js +2 -0
- package/lib/core/helpers/vaults.d.ts +8 -0
- package/lib/core/helpers/vaults.js +22 -8
- package/lib/core/helpers/web3.d.ts +152 -0
- package/lib/core/helpers/web3.js +183 -6
- package/lib/core/logger/index.d.ts +55 -0
- package/lib/core/logger/index.js +19 -0
- package/lib/core/logger/slack.d.ts +3 -0
- package/lib/core/logger/slack.js +3 -0
- package/lib/core/vault-metadata.d.ts +6 -0
- package/lib/core/vault-metadata.js +6 -0
- package/lib/core/version-check.d.ts +52 -0
- package/lib/core/version-check.js +81 -0
- package/lib/evm/methods/crossChainVault.d.ts +90 -0
- package/lib/evm/methods/crossChainVault.js +186 -1
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +1 -0
- package/lib/evm/methods/index.js +1 -0
- package/lib/evm/types/crossChain.d.ts +202 -0
- package/lib/evm/types/crossChain.js +11 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +19 -0
- package/lib/main.d.ts +288 -5
- package/lib/main.js +305 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +52 -0
- package/lib/modules/api/main.js +130 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +15 -0
- package/lib/modules/sub-accounts/fetcher.js +15 -0
- package/lib/modules/sub-accounts/main.d.ts +33 -0
- package/lib/modules/sub-accounts/main.js +38 -0
- package/lib/modules/sub-accounts/utils.d.ts +3 -0
- package/lib/modules/sub-accounts/utils.js +3 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +18 -0
- package/lib/modules/vaults/adapter.helpers.js +34 -0
- package/lib/modules/vaults/fetcher.d.ts +20 -0
- package/lib/modules/vaults/fetcher.js +40 -3
- package/lib/modules/vaults/getters.d.ts +295 -0
- package/lib/modules/vaults/getters.js +552 -12
- package/lib/modules/vaults/index.d.ts +12 -0
- package/lib/modules/vaults/index.js +12 -0
- package/lib/modules/vaults/main.d.ts +292 -4
- package/lib/modules/vaults/main.js +379 -7
- package/lib/modules/vaults/read.actions.d.ts +168 -0
- package/lib/modules/vaults/read.actions.js +143 -0
- package/lib/modules/vaults/types.d.ts +34 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +47 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
- package/lib/modules/vaults/utils/date-utils.js +47 -1
- package/lib/modules/vaults/utils.d.ts +69 -0
- package/lib/modules/vaults/utils.js +104 -5
- package/lib/modules/vaults/write.actions.d.ts +363 -3
- package/lib/modules/vaults/write.actions.js +364 -2
- package/lib/polyfills.js +2 -0
- package/lib/sdk.d.ts +23705 -0
- package/lib/services/coingecko/fetcher.d.ts +13 -0
- package/lib/services/coingecko/fetcher.js +17 -0
- package/lib/services/debank/fetcher.d.ts +14 -0
- package/lib/services/debank/fetcher.js +12 -0
- package/lib/services/debank/utils.js +17 -0
- package/lib/services/layerzero/deposits.d.ts +11 -0
- package/lib/services/layerzero/deposits.js +34 -11
- package/lib/services/layerzero/redeems.d.ts +10 -0
- package/lib/services/layerzero/redeems.js +13 -0
- package/lib/services/layerzero/utils.d.ts +8 -0
- package/lib/services/layerzero/utils.js +11 -0
- package/lib/services/octavfi/fetcher.d.ts +7 -0
- package/lib/services/octavfi/fetcher.js +25 -0
- package/lib/services/octavfi/utils.d.ts +12 -0
- package/lib/services/octavfi/utils.js +44 -10
- package/lib/services/subgraph/fetcher.js +4 -2
- package/lib/services/subgraph/vaults.d.ts +12 -0
- package/lib/services/subgraph/vaults.js +43 -2
- package/lib/services/swap-quotes/index.d.ts +71 -0
- package/lib/services/swap-quotes/index.js +25 -0
- package/lib/services/swap-quotes/paraswap.d.ts +17 -0
- package/lib/services/swap-quotes/paraswap.js +14 -0
- package/lib/types/pools.d.ts +3 -0
- package/lib/types/typed-contract.d.ts +64 -0
- package/lib/types/vaults.d.ts +137 -2
- package/lib/types/vaults.js +10 -0
- package/lib/types/web3.d.ts +8 -0
- package/lib/types/web3.js +1 -0
- package/lib/types/webserver.d.ts +45 -0
- package/package.json +6 -5
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Withdrawal Processing Transaction Decoder
|
|
4
|
+
*
|
|
5
|
+
* Decodes transaction calldata to extract which (year, month, day) cluster
|
|
6
|
+
* was processed when a WithdrawalProcessed event was emitted.
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.decodeWithdrawalProcessing = decodeWithdrawalProcessing;
|
|
4
10
|
exports.decodeFromReceiptLogs = decodeFromReceiptLogs;
|
|
5
11
|
exports.isMulticall = isMulticall;
|
|
6
12
|
exports.isWithdrawalProcessingFunction = isWithdrawalProcessingFunction;
|
|
13
|
+
/**
|
|
14
|
+
* Decode withdrawal processing transaction calldata.
|
|
15
|
+
* Handles both processAllClaimsByDate() and claim() functions.
|
|
16
|
+
*
|
|
17
|
+
* Both functions have the same first 3 parameters: (year, month, day)
|
|
18
|
+
*
|
|
19
|
+
* @param txData - Raw transaction data (tx.data from provider.getTransaction())
|
|
20
|
+
* @param iface - ethers Interface initialized with vault ABI
|
|
21
|
+
* @returns Decoded parameters or error
|
|
22
|
+
*/
|
|
7
23
|
function decodeWithdrawalProcessing(txData, iface) {
|
|
8
24
|
try {
|
|
9
25
|
const decoded = iface.parseTransaction({ data: txData });
|
|
26
|
+
// Validation
|
|
10
27
|
if (!decoded || !decoded.args || decoded.args.length < 3) {
|
|
11
28
|
return {
|
|
12
29
|
functionName: 'unknown',
|
|
@@ -16,9 +33,11 @@ function decodeWithdrawalProcessing(txData, iface) {
|
|
|
16
33
|
error: 'Invalid calldata: insufficient args',
|
|
17
34
|
};
|
|
18
35
|
}
|
|
36
|
+
// Extract first 3 parameters (shared by both functions)
|
|
19
37
|
const year = Number(decoded.args[0]);
|
|
20
38
|
const month = Number(decoded.args[1]);
|
|
21
39
|
const day = Number(decoded.args[2]);
|
|
40
|
+
// Validate date parameters are reasonable
|
|
22
41
|
if (year < 2000 || year > 2100 || month < 1 || month > 12 || day < 1) {
|
|
23
42
|
return {
|
|
24
43
|
functionName: 'unknown',
|
|
@@ -28,6 +47,7 @@ function decodeWithdrawalProcessing(txData, iface) {
|
|
|
28
47
|
error: 'Invalid date parameters',
|
|
29
48
|
};
|
|
30
49
|
}
|
|
50
|
+
// Validate day is valid for the month
|
|
31
51
|
const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
32
52
|
if (day > daysInMonth) {
|
|
33
53
|
return {
|
|
@@ -67,6 +87,7 @@ function decodeWithdrawalProcessing(txData, iface) {
|
|
|
67
87
|
receiverAddr: receiverAddr.toString(),
|
|
68
88
|
};
|
|
69
89
|
}
|
|
90
|
+
// Unknown function that decoded successfully
|
|
70
91
|
return {
|
|
71
92
|
functionName: 'unknown',
|
|
72
93
|
year,
|
|
@@ -85,6 +106,21 @@ function decodeWithdrawalProcessing(txData, iface) {
|
|
|
85
106
|
};
|
|
86
107
|
}
|
|
87
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Fallback: Parse receipt logs if calldata decoding fails.
|
|
111
|
+
*
|
|
112
|
+
* This handles the multicall wrapper case where the outer tx.data
|
|
113
|
+
* is the multicall wrapper, not the vault function. By parsing logs,
|
|
114
|
+
* we can infer what happened on-chain.
|
|
115
|
+
*
|
|
116
|
+
* Note: This is a best-effort fallback. Ideal solution is Option 2
|
|
117
|
+
* (subgraph indexing) to avoid RPC calls altogether.
|
|
118
|
+
*
|
|
119
|
+
* @param receipt - Transaction receipt from provider
|
|
120
|
+
* @param vaultAddress - Expected vault address
|
|
121
|
+
* @param iface - ethers Interface with vault ABI
|
|
122
|
+
* @returns Decoded parameters from logs, or error
|
|
123
|
+
*/
|
|
88
124
|
async function decodeFromReceiptLogs(receipt, vaultAddress, iface) {
|
|
89
125
|
if (!receipt) {
|
|
90
126
|
return {
|
|
@@ -95,6 +131,7 @@ async function decodeFromReceiptLogs(receipt, vaultAddress, iface) {
|
|
|
95
131
|
error: 'No receipt available',
|
|
96
132
|
};
|
|
97
133
|
}
|
|
134
|
+
// Look for WithdrawalProcessed events in the logs
|
|
98
135
|
for (const log of receipt.logs) {
|
|
99
136
|
if (log.address.toLowerCase() !== vaultAddress.toLowerCase()) {
|
|
100
137
|
continue;
|
|
@@ -102,6 +139,8 @@ async function decodeFromReceiptLogs(receipt, vaultAddress, iface) {
|
|
|
102
139
|
try {
|
|
103
140
|
const parsed = iface.parseLog(log);
|
|
104
141
|
if (parsed && parsed.name === 'WithdrawalProcessed') {
|
|
142
|
+
// Event found but date cannot be extracted from the current event schema.
|
|
143
|
+
// Return with year/month/day = 0 to signal caller should use fallback.
|
|
105
144
|
return {
|
|
106
145
|
functionName: 'processAllClaimsByDate',
|
|
107
146
|
year: 0,
|
|
@@ -112,6 +151,7 @@ async function decodeFromReceiptLogs(receipt, vaultAddress, iface) {
|
|
|
112
151
|
}
|
|
113
152
|
}
|
|
114
153
|
catch (e) {
|
|
154
|
+
// Not a matching event, continue
|
|
115
155
|
}
|
|
116
156
|
}
|
|
117
157
|
return {
|
|
@@ -122,6 +162,16 @@ async function decodeFromReceiptLogs(receipt, vaultAddress, iface) {
|
|
|
122
162
|
error: 'No WithdrawalProcessed logs found',
|
|
123
163
|
};
|
|
124
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Detect if this is a multicall/batch transaction.
|
|
167
|
+
* Common patterns:
|
|
168
|
+
* - Uniswap Multicall: 0x1f0464f6
|
|
169
|
+
* - Gnosis Safe: 0x6a761202
|
|
170
|
+
* - 1inch Aggregator: 0x7c025200
|
|
171
|
+
*
|
|
172
|
+
* @param functionName - Function name from parsed decoded tx
|
|
173
|
+
* @returns true if this appears to be a batch/multicall
|
|
174
|
+
*/
|
|
125
175
|
function isMulticall(functionName) {
|
|
126
176
|
const multicallNames = [
|
|
127
177
|
'multicall',
|
|
@@ -132,6 +182,12 @@ function isMulticall(functionName) {
|
|
|
132
182
|
];
|
|
133
183
|
return multicallNames.includes(functionName.toLowerCase());
|
|
134
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Detect if the decoded function is one we care about for withdrawal processing.
|
|
187
|
+
*
|
|
188
|
+
* @param functionName - Function name from decoding
|
|
189
|
+
* @returns true if this is a withdrawal processing function
|
|
190
|
+
*/
|
|
135
191
|
function isWithdrawalProcessingFunction(functionName) {
|
|
136
192
|
return functionName === 'processAllClaimsByDate' || functionName === 'claim';
|
|
137
193
|
}
|
|
@@ -1,11 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Withdrawal Date Utilities
|
|
3
|
+
*
|
|
4
|
+
* Mirrors TimelockedVault.sol's DateUtils logic for computing claimable dates.
|
|
5
|
+
* All operations are in UTC to match contract behavior.
|
|
6
|
+
*/
|
|
1
7
|
export interface ClaimableDate {
|
|
2
8
|
year: number;
|
|
3
9
|
month: number;
|
|
4
10
|
day: number;
|
|
5
11
|
epoch: number;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Compute the claimable date for a withdrawal request.
|
|
15
|
+
* Replicates TimelockedVault.requestRedeem() logic exactly.
|
|
16
|
+
*
|
|
17
|
+
* The contract does:
|
|
18
|
+
* (year, month, day) = DateUtils.timestampToDate(block.timestamp + 300 + lagDuration)
|
|
19
|
+
*
|
|
20
|
+
* @param requestTimestamp - Block timestamp of the request (in seconds, UTC)
|
|
21
|
+
* @param lagDuration - Lag duration in seconds (e.g., 86400 for 1 day)
|
|
22
|
+
* @returns The date when the withdrawal becomes claimable (UTC)
|
|
23
|
+
*/
|
|
7
24
|
export declare function computeClaimableDate(requestTimestamp: number, lagDuration: number): ClaimableDate;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a withdrawal request is ready to claim.
|
|
27
|
+
* The contract allows claiming when: block.timestamp + 300 >= claimableEpoch
|
|
28
|
+
*
|
|
29
|
+
* @param claimableEpoch - The epoch when this request became claimable
|
|
30
|
+
* @param currentEpoch - Current timestamp (usually block.timestamp or now)
|
|
31
|
+
* @returns true if claimable now
|
|
32
|
+
*/
|
|
8
33
|
export declare function isClaimableNow(claimableEpoch: number, currentEpoch: number): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Format date for use as a lookup key (e.g., "2024-03-16")
|
|
36
|
+
* Ensures consistent formatting across the codebase.
|
|
37
|
+
*/
|
|
9
38
|
export declare function formatDateKey(year: number, month: number, day: number): string;
|
|
39
|
+
/**
|
|
40
|
+
* Verify that computed date matches expected format.
|
|
41
|
+
* Used for debugging and validation.
|
|
42
|
+
*/
|
|
10
43
|
export declare function isValidClaimableDate(date: ClaimableDate): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get the number of days in a given month.
|
|
46
|
+
* @param year - Year (4-digit)
|
|
47
|
+
* @param month - Month (1-12)
|
|
48
|
+
* @returns Number of days in that month
|
|
49
|
+
*/
|
|
11
50
|
export declare function getDaysInMonth(year: number, month: number): number;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Withdrawal Date Utilities
|
|
4
|
+
*
|
|
5
|
+
* Mirrors TimelockedVault.sol's DateUtils logic for computing claimable dates.
|
|
6
|
+
* All operations are in UTC to match contract behavior.
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.computeClaimableDate = computeClaimableDate;
|
|
4
10
|
exports.isClaimableNow = isClaimableNow;
|
|
@@ -6,20 +12,53 @@ exports.formatDateKey = formatDateKey;
|
|
|
6
12
|
exports.isValidClaimableDate = isValidClaimableDate;
|
|
7
13
|
exports.getDaysInMonth = getDaysInMonth;
|
|
8
14
|
const TIMESTAMP_MANIPULATION_WINDOW = 300;
|
|
15
|
+
/**
|
|
16
|
+
* Compute the claimable date for a withdrawal request.
|
|
17
|
+
* Replicates TimelockedVault.requestRedeem() logic exactly.
|
|
18
|
+
*
|
|
19
|
+
* The contract does:
|
|
20
|
+
* (year, month, day) = DateUtils.timestampToDate(block.timestamp + 300 + lagDuration)
|
|
21
|
+
*
|
|
22
|
+
* @param requestTimestamp - Block timestamp of the request (in seconds, UTC)
|
|
23
|
+
* @param lagDuration - Lag duration in seconds (e.g., 86400 for 1 day)
|
|
24
|
+
* @returns The date when the withdrawal becomes claimable (UTC)
|
|
25
|
+
*/
|
|
9
26
|
function computeClaimableDate(requestTimestamp, lagDuration) {
|
|
27
|
+
// Add 300s + lagDuration to the request timestamp
|
|
28
|
+
// This must be done BEFORE converting to date, not after
|
|
10
29
|
const claimableEpoch = requestTimestamp + TIMESTAMP_MANIPULATION_WINDOW + lagDuration;
|
|
30
|
+
// Convert to UTC date
|
|
31
|
+
// CRITICAL: Use getUTC* methods, not local timezone methods
|
|
11
32
|
const date = new Date(claimableEpoch * 1000);
|
|
12
33
|
const year = date.getUTCFullYear();
|
|
13
|
-
const month = date.getUTCMonth() + 1;
|
|
34
|
+
const month = date.getUTCMonth() + 1; // getUTCMonth() returns 0-11
|
|
14
35
|
const day = date.getUTCDate();
|
|
15
36
|
return { year, month, day, epoch: claimableEpoch };
|
|
16
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a withdrawal request is ready to claim.
|
|
40
|
+
* The contract allows claiming when: block.timestamp + 300 >= claimableEpoch
|
|
41
|
+
*
|
|
42
|
+
* @param claimableEpoch - The epoch when this request became claimable
|
|
43
|
+
* @param currentEpoch - Current timestamp (usually block.timestamp or now)
|
|
44
|
+
* @returns true if claimable now
|
|
45
|
+
*/
|
|
17
46
|
function isClaimableNow(claimableEpoch, currentEpoch) {
|
|
47
|
+
// Ready to claim when: currentEpoch + 300 >= claimableEpoch
|
|
48
|
+
// Which means: currentEpoch >= claimableEpoch - 300
|
|
18
49
|
return currentEpoch >= claimableEpoch - TIMESTAMP_MANIPULATION_WINDOW;
|
|
19
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Format date for use as a lookup key (e.g., "2024-03-16")
|
|
53
|
+
* Ensures consistent formatting across the codebase.
|
|
54
|
+
*/
|
|
20
55
|
function formatDateKey(year, month, day) {
|
|
21
56
|
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
|
22
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Verify that computed date matches expected format.
|
|
60
|
+
* Used for debugging and validation.
|
|
61
|
+
*/
|
|
23
62
|
function isValidClaimableDate(date) {
|
|
24
63
|
if (date.year < 2000 ||
|
|
25
64
|
date.year > 2100 ||
|
|
@@ -29,9 +68,16 @@ function isValidClaimableDate(date) {
|
|
|
29
68
|
date.epoch <= 0) {
|
|
30
69
|
return false;
|
|
31
70
|
}
|
|
71
|
+
// Validate day is valid for the month (use Date.UTC to avoid local timezone issues)
|
|
32
72
|
const daysInMonth = new Date(Date.UTC(date.year, date.month, 0)).getUTCDate();
|
|
33
73
|
return date.day <= daysInMonth;
|
|
34
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the number of days in a given month.
|
|
77
|
+
* @param year - Year (4-digit)
|
|
78
|
+
* @param month - Month (1-12)
|
|
79
|
+
* @returns Number of days in that month
|
|
80
|
+
*/
|
|
35
81
|
function getDaysInMonth(year, month) {
|
|
36
82
|
return new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
37
83
|
}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import type { IAddress, IContractRunner, INormalizedNumber, IPoolFunctions, ITokenizedVault, IVault } from '../../types';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
import type { WalletClient } from 'viem';
|
|
4
|
+
/**
|
|
5
|
+
* @param walletClient a wagmi-derived client (from useWalletClient)
|
|
6
|
+
* @returns An ethers JsonRpcSigner object used in sdk.evm.setSigner
|
|
7
|
+
*/
|
|
4
8
|
export declare function walletClientToSigner(walletClient: WalletClient): Promise<ethers.JsonRpcSigner>;
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the reward multiplier based on the vault and optional timestamp.
|
|
11
|
+
* Returns the applicable multiplier for a given vault at a specific timestamp,
|
|
12
|
+
* or the latest multiplier if no timestamp is provided.
|
|
13
|
+
* @param foundPool The vault to get the multiplier for
|
|
14
|
+
* @param timestamp Optional timestamp to get historical multiplier
|
|
15
|
+
* @returns The reward multiplier value
|
|
16
|
+
*/
|
|
5
17
|
export declare const getRewardMultiplierByTimestamp: (foundPool: IVault, timestamp?: number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* Get the rewards for the vault
|
|
20
|
+
* @param tokenizedVault - The tokenized vault
|
|
21
|
+
* @returns The rewards
|
|
22
|
+
*/
|
|
6
23
|
export declare function getVaultRewards(tokenizedVault: ITokenizedVault): {
|
|
7
24
|
points: string;
|
|
8
25
|
multiplier: number;
|
|
@@ -12,9 +29,24 @@ export declare function getVaultRewards(tokenizedVault: ITokenizedVault): {
|
|
|
12
29
|
}[];
|
|
13
30
|
additionalPoints: string[];
|
|
14
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Get the idle assets for the vault
|
|
34
|
+
* @param provider - The provider
|
|
35
|
+
* @param vaultAddress - The vault address
|
|
36
|
+
* @param totalAssets - The total assets of the vault
|
|
37
|
+
* @returns The idle assets
|
|
38
|
+
*/
|
|
15
39
|
export declare function getIdleAssets(provider: IContractRunner, vaultAddress: IAddress, underlying: IAddress, totalAssets: INormalizedNumber): Promise<bigint>;
|
|
16
40
|
export declare function getYieldLastRealizedOn(provider: IContractRunner, vaultAddress: IAddress): Promise<number>;
|
|
41
|
+
/**
|
|
42
|
+
* Format APY data from backend tokenized vault into the unified IVaultApy shape.
|
|
43
|
+
* Shared across all chain adapters (EVM, Solana, Stellar).
|
|
44
|
+
*/
|
|
17
45
|
export declare function formatVaultApy(tokenizedVault: ITokenizedVault): IVault['apy'];
|
|
46
|
+
/**
|
|
47
|
+
* Map strategists from backend subaccounts or hardcoded list.
|
|
48
|
+
* Shared across all chain adapters.
|
|
49
|
+
*/
|
|
18
50
|
export declare function mapStrategists(tokenizedVault: ITokenizedVault): {
|
|
19
51
|
address: IAddress;
|
|
20
52
|
logo: string;
|
|
@@ -22,9 +54,30 @@ export declare function mapStrategists(tokenizedVault: ITokenizedVault): {
|
|
|
22
54
|
type: string;
|
|
23
55
|
website_url: string;
|
|
24
56
|
}[];
|
|
57
|
+
/**
|
|
58
|
+
* Map composability integrations from backend format to vault format.
|
|
59
|
+
* Shared across all chain adapters.
|
|
60
|
+
*/
|
|
25
61
|
export declare function mapComposabilityIntegrations(tokenizedVault: ITokenizedVault): IVault['composabilityIntegrations'];
|
|
62
|
+
/**
|
|
63
|
+
* Convert a backend-reported TVL (whole token units) to a NormalizedBn.
|
|
64
|
+
* Handles null, undefined, and non-finite values (NaN, Infinity) safely, defaulting to 0.
|
|
65
|
+
* Shared between non-EVM adapters (Solana, Stellar) and the module-level getVaultTvl handler.
|
|
66
|
+
*/
|
|
26
67
|
export declare function backendTvlToNormalizedBn(tvl: number | null | undefined, decimals: number): INormalizedNumber;
|
|
68
|
+
/**
|
|
69
|
+
* Build a base IVault from backend data, shared across non-EVM adapters (Solana, Stellar).
|
|
70
|
+
* Chain-specific fields (chainId, version, name, totalAssets, totalSupply, depositAssets, receipt)
|
|
71
|
+
* must be provided via the overrides parameter.
|
|
72
|
+
*/
|
|
27
73
|
export declare function buildBackendVault(tokenizedVault: ITokenizedVault, overrides: Pick<IVault, 'chainId' | 'version' | 'name' | 'totalAssets' | 'totalSupply' | 'depositAssets' | 'receipt'> & Pick<Partial<IVault>, 'programId' | 'enabled_historical_price_horizons' | 'defaultApyHorizon' | 'latest_reported_tvl' | 'isDepositPaused' | 'isWithdrawalPaused'>): IVault;
|
|
74
|
+
/**
|
|
75
|
+
* Build the formatted vault
|
|
76
|
+
* @param provider - The provider
|
|
77
|
+
* @param tokenizedVault - The tokenized vault
|
|
78
|
+
* @param contractCalls - The contract calls
|
|
79
|
+
* @returns The formatted vault
|
|
80
|
+
*/
|
|
28
81
|
export declare function buildFormattedVault(provider: IContractRunner, tokenizedVault: ITokenizedVault, contractCalls: Record<IPoolFunctions, string | number | INormalizedNumber | boolean | IAddress[]>): Promise<IVault>;
|
|
29
82
|
export declare const ERC_20_PERMIT_HASH = "0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9";
|
|
30
83
|
export interface PermitSignature {
|
|
@@ -33,5 +86,21 @@ export interface PermitSignature {
|
|
|
33
86
|
v: number;
|
|
34
87
|
deadline: number;
|
|
35
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Generate an ERC2612 permit signature
|
|
91
|
+
* @param token - The ERC20 token contract address
|
|
92
|
+
* @param owner - The token owner's address (signer)
|
|
93
|
+
* @param spender - The address that will be approved to spend (your pool contract)
|
|
94
|
+
* @param value - The amount to approve
|
|
95
|
+
* @param deadline - Unix timestamp for when the permit expires
|
|
96
|
+
* @param signer - The ethers.js Signer (wallet)
|
|
97
|
+
* @param provider - The ethers.js Provider
|
|
98
|
+
* @returns The signature components (v, r, s) and deadline
|
|
99
|
+
*/
|
|
36
100
|
export declare function generatePermitSignature(token: string, owner: string, spender: string, value: string | bigint, deadline: number, signer: ethers.Signer, chainId: number): Promise<PermitSignature>;
|
|
101
|
+
/**
|
|
102
|
+
* Helper to create a deadline (current time + offset in seconds)
|
|
103
|
+
* @param offsetSeconds - Number of seconds from now (default: 20 minutes)
|
|
104
|
+
* @returns Unix timestamp
|
|
105
|
+
*/
|
|
37
106
|
export declare function createDeadline(offsetSeconds?: number): number;
|