@augustdigital/sdk 6.0.1 → 7.0.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/adapters/evm/getters.d.ts +1 -1
- package/lib/adapters/evm/getters.js +14 -19
- package/lib/adapters/evm/index.d.ts +8 -1
- package/lib/adapters/evm/index.js +24 -0
- package/lib/adapters/solana/index.d.ts +4 -4
- package/lib/adapters/solana/utils.d.ts +5 -4
- package/lib/adapters/solana/utils.js +82 -45
- package/lib/adapters/solana/vault.actions.d.ts +2 -2
- package/lib/adapters/solana/vault.actions.js +112 -74
- package/lib/adapters/stellar/actions.js +3 -2
- package/lib/adapters/stellar/constants.d.ts +2 -0
- package/lib/adapters/stellar/constants.js +3 -1
- package/lib/adapters/stellar/getters.js +2 -2
- package/lib/adapters/stellar/soroban.js +19 -8
- package/lib/adapters/stellar/submit.js +16 -6
- package/lib/adapters/stellar/utils.d.ts +2 -1
- package/lib/adapters/stellar/utils.js +7 -15
- package/lib/adapters/sui/utils.d.ts +1 -1
- package/lib/adapters/sui/utils.js +3 -7
- package/lib/core/analytics/chain-name.d.ts +1 -0
- package/lib/core/analytics/chain-name.js +26 -0
- package/lib/core/analytics/env.d.ts +4 -0
- package/lib/core/analytics/env.js +33 -0
- package/lib/core/analytics/index.d.ts +6 -2
- package/lib/core/analytics/index.js +16 -1
- package/lib/core/analytics/instrumentation.js +56 -48
- package/lib/core/analytics/method-taxonomy.d.ts +3 -0
- package/lib/core/analytics/method-taxonomy.js +82 -0
- package/lib/core/analytics/metrics.js +18 -42
- package/lib/core/analytics/sanitize.d.ts +1 -0
- package/lib/core/analytics/sanitize.js +34 -0
- package/lib/core/analytics/sentry-runtime.d.ts +4 -0
- package/lib/core/analytics/sentry-runtime.js +78 -0
- package/lib/core/analytics/sentry.d.ts +7 -1
- package/lib/core/analytics/sentry.js +107 -51
- package/lib/core/analytics/types.d.ts +2 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/base.class.d.ts +2 -1
- package/lib/core/base.class.js +5 -1
- package/lib/core/cache.d.ts +4 -0
- package/lib/core/cache.js +25 -0
- package/lib/core/fetcher.d.ts +4 -4
- package/lib/core/fetcher.js +49 -60
- package/lib/core/helpers/chain-address.d.ts +3 -0
- package/lib/core/helpers/chain-address.js +36 -0
- package/lib/core/helpers/explorer-link.d.ts +2 -0
- package/lib/core/helpers/explorer-link.js +11 -0
- package/lib/core/helpers/vault-version.d.ts +4 -0
- package/lib/core/helpers/vault-version.js +59 -0
- package/lib/core/helpers/vaults.d.ts +3 -4
- package/lib/core/helpers/vaults.js +12 -62
- package/lib/core/helpers/web3.d.ts +6 -6
- package/lib/core/helpers/web3.js +142 -79
- package/lib/core/logger/slack.js +2 -2
- package/lib/core/vault-metadata.d.ts +6 -0
- package/lib/core/vault-metadata.js +36 -0
- package/lib/evm/methods/crossChainVault.js +72 -16
- package/lib/evm/types/crossChain.d.ts +4 -0
- package/lib/evm/types/crossChain.js +6 -0
- package/lib/modules/vaults/fetcher.d.ts +1 -6
- package/lib/modules/vaults/fetcher.js +27 -36
- package/lib/modules/vaults/getters.d.ts +1 -1
- package/lib/modules/vaults/getters.js +3 -2
- package/lib/modules/vaults/read.actions.d.ts +27 -0
- package/lib/modules/vaults/read.actions.js +220 -0
- package/lib/modules/vaults/utils/date-utils.js +1 -2
- package/lib/modules/vaults/utils.js +57 -36
- package/lib/modules/vaults/write.actions.d.ts +35 -2
- package/lib/modules/vaults/write.actions.js +254 -94
- package/package.json +3 -1
|
@@ -50,6 +50,7 @@ exports.getAvailableChains = getAvailableChains;
|
|
|
50
50
|
exports.formatCrossChainError = formatCrossChainError;
|
|
51
51
|
exports.getLayerZeroScanUrl = getLayerZeroScanUrl;
|
|
52
52
|
const core_1 = require("../../core");
|
|
53
|
+
const crossChain_1 = require("../types/crossChain");
|
|
53
54
|
const OFT_1 = require("../../abis/OFT");
|
|
54
55
|
const LZ_RECEIVE_OPTION_HEX = '010011010000000000000000000000000007a120';
|
|
55
56
|
const DEFAULT_FEE_BUFFER_PERCENT = 50;
|
|
@@ -99,10 +100,23 @@ async function generateOVaultInputsWithOverride(input, config, hubPublicClient,
|
|
|
99
100
|
patchLock = new Promise((r) => {
|
|
100
101
|
unlock = r;
|
|
101
102
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
let timeoutHandle;
|
|
104
|
+
try {
|
|
105
|
+
await Promise.race([
|
|
106
|
+
prev,
|
|
107
|
+
new Promise((_resolve, reject) => {
|
|
108
|
+
timeoutHandle = setTimeout(() => reject(new Error(`crossChainVault patch lock timed out after ${PATCH_LOCK_TIMEOUT_MS}ms — a prior call may be hung`)), PATCH_LOCK_TIMEOUT_MS);
|
|
109
|
+
}),
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
unlock();
|
|
114
|
+
if (timeoutHandle)
|
|
115
|
+
clearTimeout(timeoutHandle);
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
if (timeoutHandle)
|
|
119
|
+
clearTimeout(timeoutHandle);
|
|
106
120
|
const Builder = OVaultSyncMessageBuilder;
|
|
107
121
|
const origGetOutputAmount = Builder.getOutputAmount;
|
|
108
122
|
const origQuoteOVaultOutput = Builder.quoteOVaultOutput;
|
|
@@ -188,19 +202,45 @@ async function buildCrossChainVaultTx(props) {
|
|
|
188
202
|
error: 'Hub chain and source chain are required',
|
|
189
203
|
};
|
|
190
204
|
}
|
|
205
|
+
const supportedChains = [
|
|
206
|
+
config.hubChainId,
|
|
207
|
+
...Object.keys(config.layerZeroEids.spokes).map((k) => Number(k)),
|
|
208
|
+
];
|
|
209
|
+
const supportedChainsList = supportedChains.join(', ');
|
|
210
|
+
if (props.destinationChainId !== undefined &&
|
|
211
|
+
props.destinationChainId !== config.hubChainId &&
|
|
212
|
+
!config.layerZeroEids.spokes[props.destinationChainId]) {
|
|
213
|
+
return {
|
|
214
|
+
success: false,
|
|
215
|
+
error: `Destination chain ${props.destinationChainId} is not configured for this vault. Supported chains: ${supportedChainsList}.`,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (props.operation === 'DEPOSIT' &&
|
|
219
|
+
props.userChainId !== config.hubChainId &&
|
|
220
|
+
!config.layerZeroEids.spokes[props.userChainId]) {
|
|
221
|
+
return {
|
|
222
|
+
success: false,
|
|
223
|
+
error: `Source chain ${props.userChainId} is not configured for this vault. Supported chains: ${supportedChainsList}.`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const resolveDstEid = (chainId) => {
|
|
227
|
+
if (chainId === undefined)
|
|
228
|
+
return undefined;
|
|
229
|
+
if (chainId === config.hubChainId)
|
|
230
|
+
return config.layerZeroEids.hub;
|
|
231
|
+
return config.layerZeroEids.spokes[chainId];
|
|
232
|
+
};
|
|
191
233
|
let srcEid;
|
|
192
234
|
let dstEid;
|
|
193
235
|
let tokenAddress;
|
|
194
236
|
let oftAddress;
|
|
195
237
|
switch (props.operation) {
|
|
196
238
|
case 'DEPOSIT': {
|
|
239
|
+
const resolvedSrc = resolveDstEid(props.userChainId);
|
|
197
240
|
srcEid =
|
|
198
|
-
config.layerZeroEids.
|
|
199
|
-
|
|
200
|
-
dstEid =
|
|
201
|
-
? config.layerZeroEids.spokes[props.destinationChainId] ||
|
|
202
|
-
config.layerZeroEids.hub
|
|
203
|
-
: srcEid;
|
|
241
|
+
resolvedSrc !== undefined ? resolvedSrc : config.layerZeroEids.hub;
|
|
242
|
+
const resolved = resolveDstEid(props.destinationChainId);
|
|
243
|
+
dstEid = resolved !== undefined ? resolved : srcEid;
|
|
204
244
|
tokenAddress = config.contracts.assetToken[props.userChainId];
|
|
205
245
|
oftAddress = config.contracts.assetOFT[props.userChainId];
|
|
206
246
|
if (!tokenAddress || !oftAddress) {
|
|
@@ -213,11 +253,9 @@ async function buildCrossChainVaultTx(props) {
|
|
|
213
253
|
}
|
|
214
254
|
case 'REDEEM': {
|
|
215
255
|
srcEid = config.layerZeroEids.hub;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
: config.layerZeroEids.spokes[props.userChainId] ||
|
|
220
|
-
config.layerZeroEids.hub;
|
|
256
|
+
const resolved = resolveDstEid(props.destinationChainId) ??
|
|
257
|
+
resolveDstEid(props.userChainId);
|
|
258
|
+
dstEid = resolved !== undefined ? resolved : config.layerZeroEids.hub;
|
|
221
259
|
tokenAddress = config.vaultAddress;
|
|
222
260
|
oftAddress = config.contracts.shareOFTAdapter;
|
|
223
261
|
break;
|
|
@@ -276,6 +314,9 @@ async function buildCrossChainVaultTx(props) {
|
|
|
276
314
|
const sendFee = inputs.txArgs[1];
|
|
277
315
|
sendFee.nativeFee = inputs.messageFee.nativeFee;
|
|
278
316
|
}
|
|
317
|
+
else {
|
|
318
|
+
core_1.Logger.log.warn('crossChainVault:fee-patch', `Unexpected contractFunctionName "${inputs.contractFunctionName}" from LayerZero SDK — fee buffer not applied to txArgs in-place`, { contractFunctionName: inputs.contractFunctionName });
|
|
319
|
+
}
|
|
279
320
|
return {
|
|
280
321
|
success: true,
|
|
281
322
|
data: {
|
|
@@ -324,10 +365,13 @@ async function quoteCrossChainDeposit(props) {
|
|
|
324
365
|
});
|
|
325
366
|
if (!result.success || !result.data)
|
|
326
367
|
return null;
|
|
368
|
+
const quotedAt = Date.now();
|
|
327
369
|
return {
|
|
328
370
|
nativeFee: result.data.messageFee.nativeFee,
|
|
329
371
|
dstAmount: result.data.dstAmount,
|
|
330
372
|
minDstAmount: result.data.minDstAmount,
|
|
373
|
+
quotedAt,
|
|
374
|
+
expiresAt: quotedAt + crossChain_1.CROSS_CHAIN_QUOTE_TTL_MS,
|
|
331
375
|
};
|
|
332
376
|
}
|
|
333
377
|
async function quoteCrossChainRedeem(props) {
|
|
@@ -347,10 +391,13 @@ async function quoteCrossChainRedeem(props) {
|
|
|
347
391
|
});
|
|
348
392
|
if (!result.success || !result.data)
|
|
349
393
|
return null;
|
|
394
|
+
const quotedAt = Date.now();
|
|
350
395
|
return {
|
|
351
396
|
nativeFee: result.data.messageFee.nativeFee,
|
|
352
397
|
dstAmount: result.data.dstAmount,
|
|
353
398
|
minDstAmount: result.data.minDstAmount,
|
|
399
|
+
quotedAt,
|
|
400
|
+
expiresAt: quotedAt + crossChain_1.CROSS_CHAIN_QUOTE_TTL_MS,
|
|
354
401
|
};
|
|
355
402
|
}
|
|
356
403
|
async function needsCrossChainApproval(tokenAddress, spenderAddress, walletAddress, amount, publicClient) {
|
|
@@ -378,10 +425,19 @@ async function approveCrossChain(tokenAddress, spenderAddress, amount, walletCli
|
|
|
378
425
|
functionName: 'approve',
|
|
379
426
|
args: [spenderAddress, amount],
|
|
380
427
|
});
|
|
381
|
-
await publicClient.waitForTransactionReceipt({
|
|
428
|
+
const receipt = await publicClient.waitForTransactionReceipt({
|
|
429
|
+
hash: hash,
|
|
430
|
+
});
|
|
431
|
+
if (receipt.status === 'reverted') {
|
|
432
|
+
throw new Error(`Approval transaction reverted on-chain (tx ${hash}). Check token allowance limits or that the token contract supports approve().`);
|
|
433
|
+
}
|
|
382
434
|
return hash;
|
|
383
435
|
}
|
|
384
436
|
async function crossChainVaultDeposit(props) {
|
|
437
|
+
if (props.userChainId !== props.config.hubChainId &&
|
|
438
|
+
!props.config.spokeChainIds.includes(props.userChainId)) {
|
|
439
|
+
throw new Error(`Chain ${props.userChainId} is not supported for deposits to this vault — switch to the hub (${props.config.hubChainId}) or a configured spoke (${props.config.spokeChainIds.join(', ')}).`);
|
|
440
|
+
}
|
|
385
441
|
const walletClient = props.walletClient;
|
|
386
442
|
const publicClient = props.publicClient;
|
|
387
443
|
const result = await buildCrossChainVaultTx({
|
|
@@ -141,7 +141,11 @@ export interface IQuoteCrossChainResult {
|
|
|
141
141
|
nativeFee: bigint;
|
|
142
142
|
dstAmount: bigint;
|
|
143
143
|
minDstAmount: bigint;
|
|
144
|
+
quotedAt: number;
|
|
145
|
+
expiresAt: number;
|
|
144
146
|
}
|
|
147
|
+
export declare const CROSS_CHAIN_QUOTE_TTL_MS = 30000;
|
|
148
|
+
export declare function isQuoteStale(quote: Pick<IQuoteCrossChainResult, 'expiresAt'>, now?: number): boolean;
|
|
145
149
|
export interface ICrossChainOperationStatus {
|
|
146
150
|
srcTxHash: string;
|
|
147
151
|
status: 'PENDING' | 'INFLIGHT' | 'DELIVERED' | 'FAILED';
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CROSS_CHAIN_QUOTE_TTL_MS = void 0;
|
|
4
|
+
exports.isQuoteStale = isQuoteStale;
|
|
5
|
+
exports.CROSS_CHAIN_QUOTE_TTL_MS = 30000;
|
|
6
|
+
function isQuoteStale(quote, now = Date.now()) {
|
|
7
|
+
return now >= quote.expiresAt;
|
|
8
|
+
}
|
|
3
9
|
//# sourceMappingURL=crossChain.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IVaultMetadata } from '../../types';
|
|
2
1
|
export declare function fetchVaultWithFallback<T>(vaultAddress: string, fetchFn: () => Promise<T>, options?: {
|
|
3
2
|
maxRetries?: number;
|
|
4
3
|
baseDelay?: number;
|
|
@@ -100,8 +99,4 @@ export declare function filterVaultsIntelligently<T extends {
|
|
|
100
99
|
successRate: number;
|
|
101
100
|
};
|
|
102
101
|
};
|
|
103
|
-
export
|
|
104
|
-
options?: {
|
|
105
|
-
headers?: Record<string, string>;
|
|
106
|
-
};
|
|
107
|
-
}): Promise<IVaultMetadata>;
|
|
102
|
+
export { fetchVaultMetadata } from '../../core/vault-metadata';
|
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVaultMetadata = void 0;
|
|
3
4
|
exports.fetchVaultWithFallback = fetchVaultWithFallback;
|
|
4
5
|
exports.fetchVaultsBatch = fetchVaultsBatch;
|
|
5
6
|
exports.fetchVaultsComprehensive = fetchVaultsComprehensive;
|
|
6
7
|
exports.filterVaultsIntelligently = filterVaultsIntelligently;
|
|
7
|
-
exports.fetchVaultMetadata = fetchVaultMetadata;
|
|
8
8
|
const core_1 = require("../../core");
|
|
9
|
+
async function runWithConcurrency(tasks, limit) {
|
|
10
|
+
if (!Number.isFinite(limit) || limit <= 0) {
|
|
11
|
+
throw new Error(`runWithConcurrency: limit must be a positive finite number, got ${limit}`);
|
|
12
|
+
}
|
|
13
|
+
const results = new Array(tasks.length);
|
|
14
|
+
let nextIndex = 0;
|
|
15
|
+
const workerCount = Math.min(Math.floor(limit), tasks.length);
|
|
16
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
17
|
+
while (true) {
|
|
18
|
+
const i = nextIndex++;
|
|
19
|
+
if (i >= tasks.length)
|
|
20
|
+
return;
|
|
21
|
+
results[i] = await tasks[i]();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
await Promise.all(workers);
|
|
25
|
+
return results;
|
|
26
|
+
}
|
|
9
27
|
async function fetchVaultWithFallback(vaultAddress, fetchFn, options = {}) {
|
|
10
28
|
const { maxRetries = 3, baseDelay = 1000 } = options;
|
|
11
29
|
try {
|
|
@@ -22,13 +40,13 @@ async function fetchVaultWithFallback(vaultAddress, fetchFn, options = {}) {
|
|
|
22
40
|
};
|
|
23
41
|
}
|
|
24
42
|
async function fetchVaultsBatch(vaults, options = {}) {
|
|
25
|
-
const { maxRetries = 3, baseDelay = 1000, batchSize = 10, parallelLimit
|
|
43
|
+
const { maxRetries = 3, baseDelay = 1000, batchSize = 10, parallelLimit = batchSize, } = options;
|
|
26
44
|
const successful = [];
|
|
27
45
|
const failed = [];
|
|
28
46
|
let totalAttempted = 0;
|
|
29
47
|
for (let i = 0; i < vaults.length; i += batchSize) {
|
|
30
48
|
const batch = vaults.slice(i, i + batchSize);
|
|
31
|
-
const
|
|
49
|
+
const batchTasks = batch.map((vault, batchIndex) => async () => {
|
|
32
50
|
const globalIndex = i + batchIndex;
|
|
33
51
|
totalAttempted++;
|
|
34
52
|
try {
|
|
@@ -59,7 +77,7 @@ async function fetchVaultsBatch(vaults, options = {}) {
|
|
|
59
77
|
});
|
|
60
78
|
}
|
|
61
79
|
});
|
|
62
|
-
await
|
|
80
|
+
await runWithConcurrency(batchTasks, parallelLimit);
|
|
63
81
|
if (i + batchSize < vaults.length) {
|
|
64
82
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
65
83
|
}
|
|
@@ -73,14 +91,14 @@ async function fetchVaultsBatch(vaults, options = {}) {
|
|
|
73
91
|
};
|
|
74
92
|
}
|
|
75
93
|
async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
|
|
76
|
-
const { maxRetries = 5, baseDelay = 2000, batchSize = 10, parallelLimit
|
|
94
|
+
const { maxRetries = 5, baseDelay = 2000, batchSize = 10, parallelLimit = batchSize, includeClosed: _includeClosed = false, includeInvisible: _includeInvisible = false, fallbackRpcUrls = {}, timeout = 60000, } = options;
|
|
77
95
|
const successful = [];
|
|
78
96
|
const failed = [];
|
|
79
97
|
const rpcFailures = {};
|
|
80
98
|
let totalAttempted = 0;
|
|
81
99
|
for (let i = 0; i < vaults.length; i += batchSize) {
|
|
82
100
|
const batch = vaults.slice(i, i + batchSize);
|
|
83
|
-
const
|
|
101
|
+
const batchTasks = batch.map((vault, batchIndex) => async () => {
|
|
84
102
|
const globalIndex = i + batchIndex;
|
|
85
103
|
totalAttempted++;
|
|
86
104
|
let attempts = 0;
|
|
@@ -182,7 +200,7 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
|
|
|
182
200
|
});
|
|
183
201
|
rpcFailures[vault.chain] = (rpcFailures[vault.chain] || 0) + 1;
|
|
184
202
|
});
|
|
185
|
-
await
|
|
203
|
+
await runWithConcurrency(batchTasks, parallelLimit);
|
|
186
204
|
if (i + batchSize < vaults.length) {
|
|
187
205
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
188
206
|
}
|
|
@@ -255,33 +273,6 @@ function filterVaultsIntelligently(vaults, options = {}) {
|
|
|
255
273
|
},
|
|
256
274
|
};
|
|
257
275
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
const cacheKey = 'vaults_metadata';
|
|
262
|
-
if (core_1.CACHE.has(cacheKey)) {
|
|
263
|
-
return core_1.CACHE.get(cacheKey);
|
|
264
|
-
}
|
|
265
|
-
const response = await fetch(`${core_1.WEBSERVER_URL['upshift']}${core_1.WEBSERVER_ENDPOINTS.upshift.vaults.metadata}`, {
|
|
266
|
-
method: 'GET',
|
|
267
|
-
headers: {
|
|
268
|
-
'content-type': 'application/json',
|
|
269
|
-
accept: 'application/json',
|
|
270
|
-
'x-request-client': 'august-sdk',
|
|
271
|
-
...options?.headers,
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
if (!response.ok) {
|
|
275
|
-
throw new Error(`Failed to fetch vault metadata: ${response.statusText}`);
|
|
276
|
-
}
|
|
277
|
-
const metadata = await response.json();
|
|
278
|
-
core_1.CACHE.set(cacheKey, metadata, { ttl: 10 * 60 * 1000 });
|
|
279
|
-
return metadata;
|
|
280
|
-
}
|
|
281
|
-
catch (e) {
|
|
282
|
-
core_1.Logger.log.error('getVaultMetadata', e);
|
|
283
|
-
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
284
|
-
throw new Error(`#getVaultMetadata::${errorMessage}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
276
|
+
var vault_metadata_1 = require("../../core/vault-metadata");
|
|
277
|
+
Object.defineProperty(exports, "fetchVaultMetadata", { enumerable: true, get: function () { return vault_metadata_1.fetchVaultMetadata; } });
|
|
287
278
|
//# sourceMappingURL=fetcher.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAddress, IHistoricalTimeseriesResponse, INormalizedNumber, ISubgraphWithdrawProccessed, IVault, IVaultAllocations, IVaultAnnualizedApy, IVaultAvailableRedemption, IVaultLoan, IVaultPosition, IVaultRedemptionHistoryItem, IVaultSummary, IVaultWithdrawals, IVaultPendingRedemptions, IActiveStakingPosition, IVaultHistoricalParams, IVaultUserLifetimePnl, IVaultPnl, VaultAddress } from '../../types';
|
|
2
|
-
import { IVaultBaseOptions } from '
|
|
2
|
+
import { IVaultBaseOptions } from './types';
|
|
3
3
|
export declare function getVault({ vault, loans, allocations, options, loadSubaccounts, loadSnapshots, }: {
|
|
4
4
|
vault: IAddress;
|
|
5
5
|
loans?: boolean;
|
|
@@ -938,12 +938,13 @@ async function getVaultPositions({ vault, wallet, solanaWallet, stellarWallet, o
|
|
|
938
938
|
});
|
|
939
939
|
let bal = BigInt(0);
|
|
940
940
|
if (version === 'evm-2') {
|
|
941
|
-
|
|
941
|
+
const receiptAddress = await (0, core_1.getReceiptTokenAddress)(provider, vault);
|
|
942
|
+
decimals = await (0, core_1.getDecimals)(provider, receiptAddress, false);
|
|
942
943
|
if (wallet && (0, ethers_1.isAddress)(wallet)) {
|
|
943
944
|
const receiptContract = (0, core_1.createContract)({
|
|
944
945
|
provider,
|
|
945
946
|
abi: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
|
|
946
|
-
address:
|
|
947
|
+
address: receiptAddress,
|
|
947
948
|
});
|
|
948
949
|
bal = await receiptContract.balanceOf(wallet);
|
|
949
950
|
}
|
|
@@ -28,3 +28,30 @@ export type IPreviewRwaRedemptionOptions = {
|
|
|
28
28
|
outputDecimals: number;
|
|
29
29
|
};
|
|
30
30
|
export declare function previewRwaRedemption(signer: IContractRunner, options: IPreviewRwaRedemptionOptions): Promise<INormalizedNumber | undefined>;
|
|
31
|
+
export type IPreviewDepositOptions = {
|
|
32
|
+
vault: IAddress;
|
|
33
|
+
amount: string | bigint | number;
|
|
34
|
+
asset?: IAddress;
|
|
35
|
+
};
|
|
36
|
+
export type IPreviewRedeemOptions = {
|
|
37
|
+
vault: IAddress;
|
|
38
|
+
shares: string | bigint | number;
|
|
39
|
+
};
|
|
40
|
+
export type IAllowanceOptions = {
|
|
41
|
+
vault: IAddress;
|
|
42
|
+
owner: IAddress;
|
|
43
|
+
asset?: IAddress;
|
|
44
|
+
};
|
|
45
|
+
export type IBalanceOfOptions = {
|
|
46
|
+
asset: IAddress;
|
|
47
|
+
owner: IAddress;
|
|
48
|
+
};
|
|
49
|
+
export type IMaxDepositOptions = {
|
|
50
|
+
vault: IAddress;
|
|
51
|
+
receiver?: IAddress;
|
|
52
|
+
};
|
|
53
|
+
export declare function previewDeposit(signer: IContractRunner, options: IPreviewDepositOptions): Promise<bigint>;
|
|
54
|
+
export declare function previewRedeem(signer: IContractRunner, options: IPreviewRedeemOptions): Promise<bigint>;
|
|
55
|
+
export declare function allowance(signer: IContractRunner, options: IAllowanceOptions): Promise<bigint>;
|
|
56
|
+
export declare function balanceOf(signer: IContractRunner, options: IBalanceOfOptions): Promise<bigint>;
|
|
57
|
+
export declare function maxDeposit(signer: IContractRunner, options: IMaxDepositOptions): Promise<bigint>;
|
|
@@ -7,6 +7,11 @@ exports.isWhitelisted = isWhitelisted;
|
|
|
7
7
|
exports.getDeposited = getDeposited;
|
|
8
8
|
exports.getRemainingAllocations = getRemainingAllocations;
|
|
9
9
|
exports.previewRwaRedemption = previewRwaRedemption;
|
|
10
|
+
exports.previewDeposit = previewDeposit;
|
|
11
|
+
exports.previewRedeem = previewRedeem;
|
|
12
|
+
exports.allowance = allowance;
|
|
13
|
+
exports.balanceOf = balanceOf;
|
|
14
|
+
exports.maxDeposit = maxDeposit;
|
|
10
15
|
const abis_1 = require("../../abis");
|
|
11
16
|
const core_1 = require("../../core");
|
|
12
17
|
async function fetchInstantRedemptionFee(signer, options) {
|
|
@@ -216,4 +221,219 @@ async function previewRwaRedemption(signer, options) {
|
|
|
216
221
|
throw new Error(`Preview RWA redemption failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
|
|
217
222
|
}
|
|
218
223
|
}
|
|
224
|
+
function toRawBigInt(value, label) {
|
|
225
|
+
if (typeof value === 'bigint')
|
|
226
|
+
return value;
|
|
227
|
+
if (typeof value === 'number') {
|
|
228
|
+
if (!Number.isFinite(value)) {
|
|
229
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be finite, got ${value}`);
|
|
230
|
+
}
|
|
231
|
+
if (value < 0) {
|
|
232
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be non-negative, got ${value}`);
|
|
233
|
+
}
|
|
234
|
+
if (!Number.isSafeInteger(value)) {
|
|
235
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount ${value} exceeds Number.MAX_SAFE_INTEGER; pass a string or bigint to preserve precision`);
|
|
236
|
+
}
|
|
237
|
+
return BigInt(value);
|
|
238
|
+
}
|
|
239
|
+
if (typeof value === 'string') {
|
|
240
|
+
if (value.trim() === '') {
|
|
241
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount string must not be empty`);
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const parsed = BigInt(value);
|
|
245
|
+
if (parsed < 0n) {
|
|
246
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be non-negative, got ${value}`);
|
|
247
|
+
}
|
|
248
|
+
return parsed;
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
if (e instanceof core_1.AugustValidationError)
|
|
252
|
+
throw e;
|
|
253
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount "${value}" is not a valid integer`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `${label}: amount must be a string, bigint, or number`);
|
|
257
|
+
}
|
|
258
|
+
async function previewDeposit(signer, options) {
|
|
259
|
+
const { vault, amount, asset } = options;
|
|
260
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
261
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `previewDeposit: invalid vault address ${vault}`);
|
|
262
|
+
}
|
|
263
|
+
const amountRaw = toRawBigInt(amount, 'previewDeposit');
|
|
264
|
+
try {
|
|
265
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
266
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
267
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
268
|
+
if (isMultiAsset) {
|
|
269
|
+
if (!asset || !(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
270
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', 'previewDeposit: multi-asset vaults require an explicit `asset` parameter');
|
|
271
|
+
}
|
|
272
|
+
const contract = (0, core_1.createContract)({
|
|
273
|
+
address: vault,
|
|
274
|
+
provider: signer,
|
|
275
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
276
|
+
});
|
|
277
|
+
const result = await contract.previewDeposit(asset, amountRaw);
|
|
278
|
+
const shares = Array.isArray(result) ? result[0] : result;
|
|
279
|
+
return BigInt(shares);
|
|
280
|
+
}
|
|
281
|
+
const contract = (0, core_1.createContract)({
|
|
282
|
+
address: vault,
|
|
283
|
+
provider: signer,
|
|
284
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
285
|
+
});
|
|
286
|
+
const result = await contract.previewDeposit(amountRaw);
|
|
287
|
+
return BigInt(result);
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
291
|
+
throw e;
|
|
292
|
+
}
|
|
293
|
+
core_1.Logger.log.error('previewDeposit', e, { vault, amount: amount.toString() });
|
|
294
|
+
throw new core_1.AugustSDKError('UNKNOWN', `previewDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, amount: amount.toString() } });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async function previewRedeem(signer, options) {
|
|
298
|
+
const { vault, shares } = options;
|
|
299
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
300
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `previewRedeem: invalid vault address ${vault}`);
|
|
301
|
+
}
|
|
302
|
+
const sharesRaw = toRawBigInt(shares, 'previewRedeem');
|
|
303
|
+
try {
|
|
304
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
305
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
306
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
307
|
+
if (isMultiAsset) {
|
|
308
|
+
const contract = (0, core_1.createContract)({
|
|
309
|
+
address: vault,
|
|
310
|
+
provider: signer,
|
|
311
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
312
|
+
});
|
|
313
|
+
const result = await contract.previewRedemption(sharesRaw, false);
|
|
314
|
+
const assets = Array.isArray(result) ? result[0] : result;
|
|
315
|
+
return BigInt(assets);
|
|
316
|
+
}
|
|
317
|
+
const contract = (0, core_1.createContract)({
|
|
318
|
+
address: vault,
|
|
319
|
+
provider: signer,
|
|
320
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
321
|
+
});
|
|
322
|
+
const result = await contract.previewRedeem(sharesRaw);
|
|
323
|
+
return BigInt(result);
|
|
324
|
+
}
|
|
325
|
+
catch (e) {
|
|
326
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
327
|
+
throw e;
|
|
328
|
+
}
|
|
329
|
+
core_1.Logger.log.error('previewRedeem', e, {
|
|
330
|
+
vault,
|
|
331
|
+
shares: shares.toString(),
|
|
332
|
+
});
|
|
333
|
+
throw new core_1.AugustSDKError('UNKNOWN', `previewRedeem failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, shares: shares.toString() } });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
async function allowance(signer, options) {
|
|
337
|
+
const { vault, owner, asset } = options;
|
|
338
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
339
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid vault address ${vault}`);
|
|
340
|
+
}
|
|
341
|
+
if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
|
|
342
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid owner address ${owner}`);
|
|
343
|
+
}
|
|
344
|
+
if (asset && !(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
345
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `allowance: invalid asset address ${asset}`);
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
let tokenAddress;
|
|
349
|
+
if (asset) {
|
|
350
|
+
tokenAddress = asset;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const vaultContract = (0, core_1.createContract)({
|
|
354
|
+
address: vault,
|
|
355
|
+
provider: signer,
|
|
356
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
357
|
+
});
|
|
358
|
+
tokenAddress = (await vaultContract.asset());
|
|
359
|
+
}
|
|
360
|
+
const tokenContract = (0, core_1.createContract)({
|
|
361
|
+
address: tokenAddress,
|
|
362
|
+
provider: signer,
|
|
363
|
+
abi: abis_1.ABI_ERC20,
|
|
364
|
+
});
|
|
365
|
+
const raw = (await tokenContract.allowance(owner, vault));
|
|
366
|
+
return BigInt(raw);
|
|
367
|
+
}
|
|
368
|
+
catch (e) {
|
|
369
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
370
|
+
throw e;
|
|
371
|
+
}
|
|
372
|
+
core_1.Logger.log.error('allowance', e, { vault, owner, asset });
|
|
373
|
+
throw new core_1.AugustSDKError('UNKNOWN', `allowance failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, owner, asset } });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async function balanceOf(signer, options) {
|
|
377
|
+
const { asset, owner } = options;
|
|
378
|
+
if (!(0, core_1.checkAddress)(asset, console, 'contract')) {
|
|
379
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `balanceOf: invalid asset address ${asset}`);
|
|
380
|
+
}
|
|
381
|
+
if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
|
|
382
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `balanceOf: invalid owner address ${owner}`);
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
const tokenContract = (0, core_1.createContract)({
|
|
386
|
+
address: asset,
|
|
387
|
+
provider: signer,
|
|
388
|
+
abi: abis_1.ABI_ERC20,
|
|
389
|
+
});
|
|
390
|
+
const raw = (await tokenContract.balanceOf(owner));
|
|
391
|
+
return BigInt(raw);
|
|
392
|
+
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
395
|
+
throw e;
|
|
396
|
+
}
|
|
397
|
+
core_1.Logger.log.error('balanceOf', e, { asset, owner });
|
|
398
|
+
throw new core_1.AugustSDKError('UNKNOWN', `balanceOf failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { asset, owner } });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function maxDeposit(signer, options) {
|
|
402
|
+
const { vault, receiver } = options;
|
|
403
|
+
if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
|
|
404
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `maxDeposit: invalid vault address ${vault}`);
|
|
405
|
+
}
|
|
406
|
+
if (receiver && !(0, core_1.checkAddress)(receiver, console, 'wallet')) {
|
|
407
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `maxDeposit: invalid receiver address ${receiver}`);
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault))?.[0];
|
|
411
|
+
const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
|
|
412
|
+
const isMultiAsset = vaultVersion === 'evm-2';
|
|
413
|
+
if (isMultiAsset) {
|
|
414
|
+
const contract = (0, core_1.createContract)({
|
|
415
|
+
address: vault,
|
|
416
|
+
provider: signer,
|
|
417
|
+
abi: abis_1.ABI_TOKENIZED_VAULT_V2,
|
|
418
|
+
});
|
|
419
|
+
const raw = (await contract.maxDepositAmount());
|
|
420
|
+
return BigInt(raw);
|
|
421
|
+
}
|
|
422
|
+
const contract = (0, core_1.createContract)({
|
|
423
|
+
address: vault,
|
|
424
|
+
provider: signer,
|
|
425
|
+
abi: abis_1.ABI_LENDING_POOLS,
|
|
426
|
+
});
|
|
427
|
+
const target = receiver ?? '0x0000000000000000000000000000000000000000';
|
|
428
|
+
const raw = (await contract.maxDeposit(target));
|
|
429
|
+
return BigInt(raw);
|
|
430
|
+
}
|
|
431
|
+
catch (e) {
|
|
432
|
+
if (e instanceof core_1.AugustValidationError || e instanceof core_1.AugustSDKError) {
|
|
433
|
+
throw e;
|
|
434
|
+
}
|
|
435
|
+
core_1.Logger.log.error('maxDeposit', e, { vault, receiver });
|
|
436
|
+
throw new core_1.AugustSDKError('UNKNOWN', `maxDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, receiver } });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
219
439
|
//# sourceMappingURL=read.actions.js.map
|
|
@@ -5,8 +5,8 @@ exports.isClaimableNow = isClaimableNow;
|
|
|
5
5
|
exports.formatDateKey = formatDateKey;
|
|
6
6
|
exports.isValidClaimableDate = isValidClaimableDate;
|
|
7
7
|
exports.getDaysInMonth = getDaysInMonth;
|
|
8
|
+
const TIMESTAMP_MANIPULATION_WINDOW = 300;
|
|
8
9
|
function computeClaimableDate(requestTimestamp, lagDuration) {
|
|
9
|
-
const TIMESTAMP_MANIPULATION_WINDOW = 300;
|
|
10
10
|
const claimableEpoch = requestTimestamp + TIMESTAMP_MANIPULATION_WINDOW + lagDuration;
|
|
11
11
|
const date = new Date(claimableEpoch * 1000);
|
|
12
12
|
const year = date.getUTCFullYear();
|
|
@@ -15,7 +15,6 @@ function computeClaimableDate(requestTimestamp, lagDuration) {
|
|
|
15
15
|
return { year, month, day, epoch: claimableEpoch };
|
|
16
16
|
}
|
|
17
17
|
function isClaimableNow(claimableEpoch, currentEpoch) {
|
|
18
|
-
const TIMESTAMP_MANIPULATION_WINDOW = 300;
|
|
19
18
|
return currentEpoch >= claimableEpoch - TIMESTAMP_MANIPULATION_WINDOW;
|
|
20
19
|
}
|
|
21
20
|
function formatDateKey(year, month, day) {
|