@augustdigital/sdk 8.11.0 → 8.12.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/index.d.ts +17 -1
- package/lib/adapters/evm/index.js +20 -0
- package/lib/core/analytics/method-taxonomy.js +1 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/constants/swap-router.d.ts +2 -0
- package/lib/core/constants/swap-router.js +1 -0
- package/lib/core/constants/web3.d.ts +19 -0
- package/lib/core/constants/web3.js +37 -1
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/swap-router.d.ts +36 -1
- package/lib/core/helpers/swap-router.js +80 -0
- package/lib/core/helpers/vault-version.d.ts +4 -1
- package/lib/core/helpers/vaults.d.ts +1 -1
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +1 -0
- package/lib/modules/vaults/getters.d.ts +25 -2
- package/lib/modules/vaults/getters.js +41 -11
- package/lib/modules/vaults/main.d.ts +22 -0
- package/lib/modules/vaults/main.js +54 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/sdk.d.ts +6689 -6550
- package/lib/types/subgraph.d.ts +9 -0
- package/lib/types/vaults.d.ts +34 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type IContractWriteOptions, type INativeDepositOptions, type ApproveResult } from '../../modules/vaults/write.actions';
|
|
2
|
-
import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions, ISwapRouterDepositOptions } from '../../types';
|
|
2
|
+
import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions, ISwapRouterDepositOptions, ISwapRouterDepositResultOptions } from '../../types';
|
|
3
3
|
import { type IPreviewDepositOptions, type IPreviewRedeemOptions, type IAllowanceOptions, type IBalanceOfOptions, type IMaxDepositOptions } from '../../modules/vaults/read.actions';
|
|
4
4
|
import { type CompatibleSigner } from '../../core/helpers/signer';
|
|
5
5
|
import type { IAddress } from '../../types';
|
|
@@ -214,6 +214,22 @@ declare class EVMAdapter {
|
|
|
214
214
|
* ```
|
|
215
215
|
*/
|
|
216
216
|
swapRouterDeposit(options: ISwapRouterDepositOptions): Promise<string>;
|
|
217
|
+
/**
|
|
218
|
+
* Resolves the real, post-execution outcome of a SwapRouter deposit from
|
|
219
|
+
* its mined receipt — the actual amount that reached the vault (and shares
|
|
220
|
+
* minted), decoded from the vault's own `Deposit` event, rather than the
|
|
221
|
+
* pre-trade quote shown before submission.
|
|
222
|
+
*
|
|
223
|
+
* @param options - {@link ISwapRouterDepositResultOptions}.
|
|
224
|
+
* @returns The decoded {@link ISwapRouterDepositResult}, or `null` if the
|
|
225
|
+
* receipt isn't found yet or carries no matching `Deposit` log.
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({ ... });
|
|
229
|
+
* const result = await augustSdk.evm.getSwapRouterDepositResult({ txHash: hash, vault });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
getSwapRouterDepositResult(options: ISwapRouterDepositResultOptions): Promise<import("../../types").ISwapRouterDepositResult>;
|
|
217
233
|
/**
|
|
218
234
|
* Claim assets from a matured redemption request on a dated-redemption
|
|
219
235
|
* (RWA-style) vault. The `year`, `month`, `day`, and `receiverIndex` tuple
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const write_actions_1 = require("../../modules/vaults/write.actions");
|
|
18
|
+
const swap_router_1 = require("../../core/helpers/swap-router");
|
|
18
19
|
const read_actions_1 = require("../../modules/vaults/read.actions");
|
|
19
20
|
const signer_1 = require("../../core/helpers/signer");
|
|
20
21
|
__exportStar(require("./getters"), exports);
|
|
@@ -277,6 +278,25 @@ class EVMAdapter {
|
|
|
277
278
|
const signer = await this.getSigner();
|
|
278
279
|
return (0, write_actions_1.swapRouterDeposit)(signer, options);
|
|
279
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Resolves the real, post-execution outcome of a SwapRouter deposit from
|
|
283
|
+
* its mined receipt — the actual amount that reached the vault (and shares
|
|
284
|
+
* minted), decoded from the vault's own `Deposit` event, rather than the
|
|
285
|
+
* pre-trade quote shown before submission.
|
|
286
|
+
*
|
|
287
|
+
* @param options - {@link ISwapRouterDepositResultOptions}.
|
|
288
|
+
* @returns The decoded {@link ISwapRouterDepositResult}, or `null` if the
|
|
289
|
+
* receipt isn't found yet or carries no matching `Deposit` log.
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({ ... });
|
|
293
|
+
* const result = await augustSdk.evm.getSwapRouterDepositResult({ txHash: hash, vault });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
async getSwapRouterDepositResult(options) {
|
|
297
|
+
const signer = await this.getSigner();
|
|
298
|
+
return (0, swap_router_1.getSwapRouterDepositResult)(signer, options);
|
|
299
|
+
}
|
|
280
300
|
/**
|
|
281
301
|
* Claim assets from a matured redemption request on a dated-redemption
|
|
282
302
|
* (RWA-style) vault. The `year`, `month`, `day`, and `receiverIndex` tuple
|
|
@@ -39,6 +39,7 @@ exports.METHOD_CATEGORIES = {
|
|
|
39
39
|
getVaultBorrowerHealthFactor: 'read.vault',
|
|
40
40
|
getYieldLastRealizedOn: 'read.vault',
|
|
41
41
|
getVaultActivity: 'read.vault',
|
|
42
|
+
getSwapRouterDepositResult: 'read.vault',
|
|
42
43
|
getVaultPositions: 'read.position',
|
|
43
44
|
getVaultUserHistory: 'read.position',
|
|
44
45
|
getUserHistory: 'read.position',
|
|
@@ -105,4 +105,6 @@ export declare const SWAP_ROUTER_DEX_AGGREGATOR: Readonly<Record<number, {
|
|
|
105
105
|
router: IAddress;
|
|
106
106
|
contractMethod: string;
|
|
107
107
|
selector: `0x${string}`;
|
|
108
|
+
/** Human-readable aggregator name — for display; never derive routing logic from it. */
|
|
109
|
+
name: string;
|
|
108
110
|
}>>;
|
|
@@ -47,6 +47,25 @@ export declare const ORACLE_CONTRACTS: {
|
|
|
47
47
|
};
|
|
48
48
|
export declare const NETWORKS: Record<IChainId, IChainObj>;
|
|
49
49
|
export declare const AVAILABLE_CHAINS: IChainId[];
|
|
50
|
+
/**
|
|
51
|
+
* Canonical [Multicall3](https://github.com/mds1/multicall) address, deployed
|
|
52
|
+
* via the deterministic deployer to the same address on most EVM chains.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export declare const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
56
|
+
/**
|
|
57
|
+
* Chains where the canonical Multicall3 deployment was **verified on-chain**
|
|
58
|
+
* (`eth_getCode` returned the 3808-byte runtime at {@link MULTICALL3_ADDRESS};
|
|
59
|
+
* checked per chain on 2026-07-14, Tempo checked separately on 2026-07-15) —
|
|
60
|
+
* deterministic-deployer presence is NOT assumed. Chains outside this set
|
|
61
|
+
* keep the per-call read path.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately excluded from `NETWORKS`:
|
|
64
|
+
* - 4114 (Citrea) — `eth_getCode` returned `0x` (not deployed).
|
|
65
|
+
* - -1 (Solana), -3 (Stellar) — non-EVM, no Multicall3.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export declare const MULTICALL3_VERIFIED_CHAINS: ReadonlySet<number>;
|
|
50
69
|
/**
|
|
51
70
|
* Fallbacks
|
|
52
71
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FALLBACK_RPC_URLS = exports.FALLBACK_CHAINID = exports.FALLBACK_DECIMALS = exports.AVAILABLE_CHAINS = exports.NETWORKS = exports.ORACLE_CONTRACTS = exports.MIN_ABIS = exports.EVM_NATIVE_DECIMALS = exports.NATIVE_ADDRESS = exports.SPECIAL_CHAINS = void 0;
|
|
3
|
+
exports.FALLBACK_RPC_URLS = exports.FALLBACK_CHAINID = exports.FALLBACK_DECIMALS = exports.MULTICALL3_VERIFIED_CHAINS = exports.MULTICALL3_ADDRESS = exports.AVAILABLE_CHAINS = exports.NETWORKS = exports.ORACLE_CONTRACTS = exports.MIN_ABIS = exports.EVM_NATIVE_DECIMALS = exports.NATIVE_ADDRESS = exports.SPECIAL_CHAINS = void 0;
|
|
4
4
|
// Special Chains
|
|
5
5
|
exports.SPECIAL_CHAINS = {
|
|
6
6
|
solana: {
|
|
@@ -141,6 +141,42 @@ exports.NETWORKS = {
|
|
|
141
141
|
},
|
|
142
142
|
};
|
|
143
143
|
exports.AVAILABLE_CHAINS = Object.keys(exports.NETWORKS).map((c) => Number(c));
|
|
144
|
+
/**
|
|
145
|
+
* Canonical [Multicall3](https://github.com/mds1/multicall) address, deployed
|
|
146
|
+
* via the deterministic deployer to the same address on most EVM chains.
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
exports.MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
150
|
+
/**
|
|
151
|
+
* Chains where the canonical Multicall3 deployment was **verified on-chain**
|
|
152
|
+
* (`eth_getCode` returned the 3808-byte runtime at {@link MULTICALL3_ADDRESS};
|
|
153
|
+
* checked per chain on 2026-07-14, Tempo checked separately on 2026-07-15) —
|
|
154
|
+
* deterministic-deployer presence is NOT assumed. Chains outside this set
|
|
155
|
+
* keep the per-call read path.
|
|
156
|
+
*
|
|
157
|
+
* Deliberately excluded from `NETWORKS`:
|
|
158
|
+
* - 4114 (Citrea) — `eth_getCode` returned `0x` (not deployed).
|
|
159
|
+
* - -1 (Solana), -3 (Stellar) — non-EVM, no Multicall3.
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
exports.MULTICALL3_VERIFIED_CHAINS = new Set([
|
|
163
|
+
1, // Ethereum
|
|
164
|
+
42161, // Arbitrum One
|
|
165
|
+
8453, // Base
|
|
166
|
+
43114, // Avalanche
|
|
167
|
+
137, // Polygon
|
|
168
|
+
56, // BNB Smart Chain
|
|
169
|
+
999, // HyperEVM
|
|
170
|
+
130, // Unichain
|
|
171
|
+
31612, // Mezo
|
|
172
|
+
143, // Monad
|
|
173
|
+
9745, // Plasma
|
|
174
|
+
57073, // Ink
|
|
175
|
+
14, // Flare
|
|
176
|
+
747474, // Katana
|
|
177
|
+
25363, // Fluent
|
|
178
|
+
4217, // Tempo
|
|
179
|
+
]);
|
|
144
180
|
/**
|
|
145
181
|
* Fallbacks
|
|
146
182
|
*/
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type InterfaceAbi } from 'ethers';
|
|
2
|
+
import type { IAddress, IContractRunner } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* One read to fold into a Multicall3 `aggregate3` batch.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface IMulticall3Request {
|
|
8
|
+
/** Contract to call. */
|
|
9
|
+
target: IAddress;
|
|
10
|
+
/** ABI containing `functionName` (full or minimal fragment). */
|
|
11
|
+
abi: InterfaceAbi;
|
|
12
|
+
/** View function to encode. */
|
|
13
|
+
functionName: string;
|
|
14
|
+
/** Positional arguments for the function. */
|
|
15
|
+
args?: unknown[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Per-call result of an `aggregate3` batch. `success: false` means that one
|
|
19
|
+
* call reverted (or its chunk failed at the transport level) — it never
|
|
20
|
+
* implies anything about the other calls in the batch.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface IMulticall3Result {
|
|
24
|
+
success: boolean;
|
|
25
|
+
/** First decoded return value; `undefined` when `success` is `false`. */
|
|
26
|
+
value?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Calls per `aggregate3` chunk. Mirrors the `batchMaxCount: 10` cap on
|
|
30
|
+
* `createProvider` — some RPC providers (e.g. rpc.hypurrscan.io) enforce
|
|
31
|
+
* their own batch/response-size limits, so an unbounded batch for a wallet
|
|
32
|
+
* with many vaults risks exceeding response-size or `eth_call` gas ceilings.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare const MULTICALL3_BATCH_SIZE = 10;
|
|
36
|
+
/**
|
|
37
|
+
* Whether Multicall3 read-aggregation is enabled for a chain. Only chains in
|
|
38
|
+
* {@link MULTICALL3_VERIFIED_CHAINS} (deployment verified via `eth_getCode`,
|
|
39
|
+
* never assumed) qualify — callers must fall back to individual reads for
|
|
40
|
+
* every other chain.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export declare function isMulticall3Supported(chainId: number | undefined): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Aggregate independent view calls into chunked Multicall3 `aggregate3`
|
|
46
|
+
* batches (`allowFailure: true` per call).
|
|
47
|
+
*
|
|
48
|
+
* Failure semantics — the load-bearing detail:
|
|
49
|
+
* - A reverting inner call (paused/deprecated vault) yields `success: false`
|
|
50
|
+
* for that call only; every other call in the batch decodes normally.
|
|
51
|
+
* - A transport-level failure of one chunk degrades that chunk's calls to
|
|
52
|
+
* `success: false` instead of throwing, so a caller can always fall back
|
|
53
|
+
* to its per-call path. This function never rejects for RPC reasons.
|
|
54
|
+
*
|
|
55
|
+
* RPC cost: `ceil(calls.length / batchSize)` `eth_call`s, versus
|
|
56
|
+
* `calls.length` without aggregation.
|
|
57
|
+
*
|
|
58
|
+
* @param provider Provider for the target chain.
|
|
59
|
+
* @param chainId Chain the provider is connected to — must be in the
|
|
60
|
+
* verified allowlist; gate with {@link isMulticall3Supported} first.
|
|
61
|
+
* @param calls Reads to aggregate, in order.
|
|
62
|
+
* @param batchSize Max calls per `aggregate3` chunk.
|
|
63
|
+
* @returns One {@link IMulticall3Result} per request, index-aligned.
|
|
64
|
+
* @throws AugustValidationError when `chainId` is not on the verified
|
|
65
|
+
* allowlist — programming error, not a runtime condition to swallow.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export declare function multicall3Aggregate(provider: IContractRunner, chainId: number, calls: IMulticall3Request[], batchSize?: number): Promise<IMulticall3Result[]>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MULTICALL3_BATCH_SIZE = void 0;
|
|
4
|
+
exports.isMulticall3Supported = isMulticall3Supported;
|
|
5
|
+
exports.multicall3Aggregate = multicall3Aggregate;
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const Multicall3_1 = require("../../abis/Multicall3");
|
|
8
|
+
const web3_1 = require("../constants/web3");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
/**
|
|
12
|
+
* Calls per `aggregate3` chunk. Mirrors the `batchMaxCount: 10` cap on
|
|
13
|
+
* `createProvider` — some RPC providers (e.g. rpc.hypurrscan.io) enforce
|
|
14
|
+
* their own batch/response-size limits, so an unbounded batch for a wallet
|
|
15
|
+
* with many vaults risks exceeding response-size or `eth_call` gas ceilings.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
exports.MULTICALL3_BATCH_SIZE = 10;
|
|
19
|
+
/**
|
|
20
|
+
* Whether Multicall3 read-aggregation is enabled for a chain. Only chains in
|
|
21
|
+
* {@link MULTICALL3_VERIFIED_CHAINS} (deployment verified via `eth_getCode`,
|
|
22
|
+
* never assumed) qualify — callers must fall back to individual reads for
|
|
23
|
+
* every other chain.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
function isMulticall3Supported(chainId) {
|
|
27
|
+
return typeof chainId === 'number' && web3_1.MULTICALL3_VERIFIED_CHAINS.has(chainId);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Aggregate independent view calls into chunked Multicall3 `aggregate3`
|
|
31
|
+
* batches (`allowFailure: true` per call).
|
|
32
|
+
*
|
|
33
|
+
* Failure semantics — the load-bearing detail:
|
|
34
|
+
* - A reverting inner call (paused/deprecated vault) yields `success: false`
|
|
35
|
+
* for that call only; every other call in the batch decodes normally.
|
|
36
|
+
* - A transport-level failure of one chunk degrades that chunk's calls to
|
|
37
|
+
* `success: false` instead of throwing, so a caller can always fall back
|
|
38
|
+
* to its per-call path. This function never rejects for RPC reasons.
|
|
39
|
+
*
|
|
40
|
+
* RPC cost: `ceil(calls.length / batchSize)` `eth_call`s, versus
|
|
41
|
+
* `calls.length` without aggregation.
|
|
42
|
+
*
|
|
43
|
+
* @param provider Provider for the target chain.
|
|
44
|
+
* @param chainId Chain the provider is connected to — must be in the
|
|
45
|
+
* verified allowlist; gate with {@link isMulticall3Supported} first.
|
|
46
|
+
* @param calls Reads to aggregate, in order.
|
|
47
|
+
* @param batchSize Max calls per `aggregate3` chunk.
|
|
48
|
+
* @returns One {@link IMulticall3Result} per request, index-aligned.
|
|
49
|
+
* @throws AugustValidationError when `chainId` is not on the verified
|
|
50
|
+
* allowlist — programming error, not a runtime condition to swallow.
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
async function multicall3Aggregate(provider, chainId, calls, batchSize = exports.MULTICALL3_BATCH_SIZE) {
|
|
54
|
+
if (!isMulticall3Supported(chainId)) {
|
|
55
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', `multicall3Aggregate: Multicall3 deployment is not verified on chain ${chainId} — use the per-call read path instead`);
|
|
56
|
+
}
|
|
57
|
+
if (calls.length === 0)
|
|
58
|
+
return [];
|
|
59
|
+
const encoded = calls.map((c) => {
|
|
60
|
+
const iface = new ethers_1.Interface(c.abi);
|
|
61
|
+
return {
|
|
62
|
+
target: c.target,
|
|
63
|
+
allowFailure: true,
|
|
64
|
+
callData: iface.encodeFunctionData(c.functionName, c.args ?? []),
|
|
65
|
+
iface,
|
|
66
|
+
functionName: c.functionName,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
const chunks = [];
|
|
70
|
+
for (let i = 0; i < encoded.length; i += batchSize) {
|
|
71
|
+
chunks.push(encoded.slice(i, i + batchSize));
|
|
72
|
+
}
|
|
73
|
+
const multicall = new ethers_1.Contract(web3_1.MULTICALL3_ADDRESS, Multicall3_1.ABI_MULTICALL3, provider);
|
|
74
|
+
const chunkResults = await Promise.all(chunks.map(async (chunk) => {
|
|
75
|
+
try {
|
|
76
|
+
const returned = (await multicall.aggregate3(chunk.map((c) => ({
|
|
77
|
+
target: c.target,
|
|
78
|
+
allowFailure: c.allowFailure,
|
|
79
|
+
callData: c.callData,
|
|
80
|
+
}))));
|
|
81
|
+
return chunk.map((c, i) => {
|
|
82
|
+
const r = returned[i];
|
|
83
|
+
if (!r?.success || !r.returnData || r.returnData === '0x') {
|
|
84
|
+
return { success: false, value: undefined };
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const decoded = c.iface.decodeFunctionResult(c.functionName, r.returnData);
|
|
88
|
+
return { success: true, value: decoded[0] };
|
|
89
|
+
}
|
|
90
|
+
catch (decodeError) {
|
|
91
|
+
logger_1.Logger.log.warn('multicall3Aggregate', `failed to decode ${c.functionName} result for ${c.target}`, decodeError);
|
|
92
|
+
return { success: false, value: undefined };
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (chunkError) {
|
|
97
|
+
logger_1.Logger.log.warn('multicall3Aggregate', `aggregate3 chunk failed on chain ${chainId} (${chunk.length} calls) — callers fall back to per-call reads`, chunkError);
|
|
98
|
+
return chunk.map(() => ({ success: false, value: undefined }));
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
return chunkResults.flat();
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=multicall.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Signer, type Wallet } from 'ethers';
|
|
2
|
+
import type { IAddress, ISwapRouterDepositResult, ISwapRouterDepositResultOptions } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* Resolve the `SwapRouter` address for a chain.
|
|
4
5
|
*
|
|
@@ -46,3 +47,37 @@ export declare const vaultUsesSwapRouter: typeof isSwapRouterEligible;
|
|
|
46
47
|
* @throws {@link AugustValidationError} when `provided` is not a 32-byte hex string.
|
|
47
48
|
*/
|
|
48
49
|
export declare function resolveOriginCode(provided?: `0x${string}`): `0x${string}`;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the real, post-execution outcome of a SwapRouter deposit from its
|
|
52
|
+
* mined transaction receipt. The SwapRouter contract itself emits no
|
|
53
|
+
* deposit/amount-out event — only the vault does, via its own `Deposit` event
|
|
54
|
+
* — so this decodes that log directly rather than trusting the pre-trade quote
|
|
55
|
+
* a UI shows before the user submits (the true post-swap amount depends on
|
|
56
|
+
* execution-time price and can differ from that estimate).
|
|
57
|
+
*
|
|
58
|
+
* Works for both vault generations without the caller resolving the version
|
|
59
|
+
* first: evm-1 (ERC-4626-style `Deposit(sender, owner, assets, shares)`) and
|
|
60
|
+
* evm-2 (`Deposit(assetIn, amountIn, shares, senderAddr, receiverAddr)`) have
|
|
61
|
+
* different event signatures (different topic0), so both are registered and
|
|
62
|
+
* whichever matches the vault's actual log is decoded.
|
|
63
|
+
*
|
|
64
|
+
* @param signer - ethers `Signer` or `Wallet` connected to a provider (used
|
|
65
|
+
* read-only here — no transaction is sent).
|
|
66
|
+
* @param options - {@link ISwapRouterDepositResultOptions}.
|
|
67
|
+
* @returns The decoded {@link ISwapRouterDepositResult}, or `null` if the
|
|
68
|
+
* receipt isn't found yet or carries no `Deposit` log from `vault` (e.g. the
|
|
69
|
+
* hash is wrong, or the tx hasn't mined).
|
|
70
|
+
* @throws {@link AugustValidationError} if `signer` has no connected provider.
|
|
71
|
+
* @worstCaseRpcCalls 1 — a single `getTransactionReceipt` call; decoding is
|
|
72
|
+
* local.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({ ... });
|
|
76
|
+
* const result = await augustSdk.evm.getSwapRouterDepositResult({
|
|
77
|
+
* txHash: hash,
|
|
78
|
+
* vault: '0x74ad2f789ed583dbd141bbdafc673fe1f033718b',
|
|
79
|
+
* });
|
|
80
|
+
* // result?.amountOut — actual reference-asset amount received after the swap
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function getSwapRouterDepositResult(signer: Signer | Wallet, { txHash, vault }: ISwapRouterDepositResultOptions): Promise<ISwapRouterDepositResult | null>;
|
|
@@ -4,6 +4,8 @@ exports.vaultUsesSwapRouter = void 0;
|
|
|
4
4
|
exports.getSwapRouterAddress = getSwapRouterAddress;
|
|
5
5
|
exports.isSwapRouterEligible = isSwapRouterEligible;
|
|
6
6
|
exports.resolveOriginCode = resolveOriginCode;
|
|
7
|
+
exports.getSwapRouterDepositResult = getSwapRouterDepositResult;
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
7
9
|
const swap_router_1 = require("../constants/swap-router");
|
|
8
10
|
const errors_1 = require("../errors");
|
|
9
11
|
/**
|
|
@@ -64,4 +66,82 @@ function resolveOriginCode(provided) {
|
|
|
64
66
|
}
|
|
65
67
|
return provided;
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the real, post-execution outcome of a SwapRouter deposit from its
|
|
71
|
+
* mined transaction receipt. The SwapRouter contract itself emits no
|
|
72
|
+
* deposit/amount-out event — only the vault does, via its own `Deposit` event
|
|
73
|
+
* — so this decodes that log directly rather than trusting the pre-trade quote
|
|
74
|
+
* a UI shows before the user submits (the true post-swap amount depends on
|
|
75
|
+
* execution-time price and can differ from that estimate).
|
|
76
|
+
*
|
|
77
|
+
* Works for both vault generations without the caller resolving the version
|
|
78
|
+
* first: evm-1 (ERC-4626-style `Deposit(sender, owner, assets, shares)`) and
|
|
79
|
+
* evm-2 (`Deposit(assetIn, amountIn, shares, senderAddr, receiverAddr)`) have
|
|
80
|
+
* different event signatures (different topic0), so both are registered and
|
|
81
|
+
* whichever matches the vault's actual log is decoded.
|
|
82
|
+
*
|
|
83
|
+
* @param signer - ethers `Signer` or `Wallet` connected to a provider (used
|
|
84
|
+
* read-only here — no transaction is sent).
|
|
85
|
+
* @param options - {@link ISwapRouterDepositResultOptions}.
|
|
86
|
+
* @returns The decoded {@link ISwapRouterDepositResult}, or `null` if the
|
|
87
|
+
* receipt isn't found yet or carries no `Deposit` log from `vault` (e.g. the
|
|
88
|
+
* hash is wrong, or the tx hasn't mined).
|
|
89
|
+
* @throws {@link AugustValidationError} if `signer` has no connected provider.
|
|
90
|
+
* @worstCaseRpcCalls 1 — a single `getTransactionReceipt` call; decoding is
|
|
91
|
+
* local.
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const hash = await augustSdk.evm.swapRouterDeposit({ ... });
|
|
95
|
+
* const result = await augustSdk.evm.getSwapRouterDepositResult({
|
|
96
|
+
* txHash: hash,
|
|
97
|
+
* vault: '0x74ad2f789ed583dbd141bbdafc673fe1f033718b',
|
|
98
|
+
* });
|
|
99
|
+
* // result?.amountOut — actual reference-asset amount received after the swap
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
async function getSwapRouterDepositResult(signer, { txHash, vault }) {
|
|
103
|
+
const provider = signer.provider;
|
|
104
|
+
if (!provider) {
|
|
105
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', 'getSwapRouterDepositResult: signer has no connected provider');
|
|
106
|
+
}
|
|
107
|
+
const receipt = await provider.getTransactionReceipt(txHash);
|
|
108
|
+
if (!receipt)
|
|
109
|
+
return null;
|
|
110
|
+
const iface = new ethers_1.ethers.Interface([
|
|
111
|
+
'event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares)',
|
|
112
|
+
'event Deposit(address assetIn, uint256 amountIn, uint256 shares, address indexed senderAddr, address indexed receiverAddr)',
|
|
113
|
+
]);
|
|
114
|
+
for (const log of receipt.logs) {
|
|
115
|
+
if (log.address.toLowerCase() !== vault.toLowerCase())
|
|
116
|
+
continue;
|
|
117
|
+
let parsed;
|
|
118
|
+
try {
|
|
119
|
+
parsed = iface.parseLog(log);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (parsed?.name !== 'Deposit')
|
|
125
|
+
continue;
|
|
126
|
+
// Discriminate on the matched event fragment, not on probing a
|
|
127
|
+
// possibly-absent named arg. Only the evm-2 signature declares `assetIn`,
|
|
128
|
+
// so its presence in the fragment inputs uniquely identifies the version.
|
|
129
|
+
// (Reading `parsed.args.assetIn` on the evm-1 log would couple correctness
|
|
130
|
+
// to ethers' `Result`-proxy behavior for unknown names.)
|
|
131
|
+
const isEvm2 = parsed.fragment.inputs.some((i) => i.name === 'assetIn');
|
|
132
|
+
if (isEvm2) {
|
|
133
|
+
// evm-2 TokenizedVault: Deposit(assetIn, amountIn, shares, sender, receiver)
|
|
134
|
+
return {
|
|
135
|
+
amountOut: BigInt(parsed.args.amountIn),
|
|
136
|
+
sharesOut: BigInt(parsed.args.shares),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// evm-1 ERC-4626-style: Deposit(sender, owner, assets, shares)
|
|
140
|
+
return {
|
|
141
|
+
amountOut: BigInt(parsed.args.assets),
|
|
142
|
+
sharesOut: BigInt(parsed.args.shares),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
67
147
|
//# sourceMappingURL=swap-router.js.map
|
|
@@ -2,4 +2,7 @@ import type { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
|
|
|
2
2
|
/** Classify an address by chain family (evm / solana / stellar / sui). */
|
|
3
3
|
export declare function getAddressChainType(address: string): ChainType;
|
|
4
4
|
export declare function getVaultVersion(vault: string): IVaultVersion | undefined;
|
|
5
|
-
export declare function getVaultVersionV2(vault: ITokenizedVault
|
|
5
|
+
export declare function getVaultVersionV2(vault: (Pick<ITokenizedVault, 'address'> & {
|
|
6
|
+
chain_type?: string;
|
|
7
|
+
internal_type?: string;
|
|
8
|
+
}) | undefined | null): IVaultVersion | undefined;
|
|
@@ -8,7 +8,7 @@ export declare const isBadVault: (address?: string) => boolean;
|
|
|
8
8
|
import { getAddressChainType, getVaultVersion, getVaultVersionV2 } from './vault-version';
|
|
9
9
|
export { getAddressChainType, getVaultVersion, getVaultVersionV2 };
|
|
10
10
|
export declare const REWARD_DISTRIBUTOR_ADDRESS: (chainId: number) => string[];
|
|
11
|
-
export declare const AVAX_PRICE_FEED_ADDRESS: (chainId: number) => "
|
|
11
|
+
export declare const AVAX_PRICE_FEED_ADDRESS: (chainId: number) => "0x" | "0xFF3EEb22B5E3dE6e705b44749C2559d704923FD7";
|
|
12
12
|
export declare function getVaultSymbol(vault: IAddress, provider: IContractRunner): Promise<string | undefined>;
|
|
13
13
|
/**
|
|
14
14
|
* @deprecated
|
package/lib/core/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './constants/web3';
|
|
|
11
11
|
export * from './constants/vaults';
|
|
12
12
|
export * from './constants/swap-router';
|
|
13
13
|
export * from './helpers/web3';
|
|
14
|
+
export * from './helpers/multicall';
|
|
14
15
|
export * from './helpers/vaults';
|
|
15
16
|
export * from './helpers/chain-error';
|
|
16
17
|
export * from './helpers/core';
|
package/lib/core/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __exportStar(require("./constants/web3"), exports);
|
|
|
27
27
|
__exportStar(require("./constants/vaults"), exports);
|
|
28
28
|
__exportStar(require("./constants/swap-router"), exports);
|
|
29
29
|
__exportStar(require("./helpers/web3"), exports);
|
|
30
|
+
__exportStar(require("./helpers/multicall"), exports);
|
|
30
31
|
__exportStar(require("./helpers/vaults"), exports);
|
|
31
32
|
__exportStar(require("./helpers/chain-error"), exports);
|
|
32
33
|
__exportStar(require("./helpers/core"), exports);
|
|
@@ -53,12 +53,22 @@ export declare function getVaultSubaccountLoans(vault: VaultAddress | IVault, op
|
|
|
53
53
|
* @returns Detailed allocation data with exposure categorization
|
|
54
54
|
*/
|
|
55
55
|
export declare function getVaultAllocations(vault: IAddress, options: IVaultBaseOptions): Promise<IVaultAllocations>;
|
|
56
|
-
export declare function getVaultAvailableRedemptions({ vault, wallet, options, }: {
|
|
56
|
+
export declare function getVaultAvailableRedemptions({ vault, wallet, options, prefetchedReads, }: {
|
|
57
57
|
vault: IAddress;
|
|
58
58
|
wallet?: IAddress;
|
|
59
59
|
options: IVaultBaseOptions & {
|
|
60
60
|
verbose?: boolean;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Values already read via a Multicall3 batch (see
|
|
64
|
+
* `modules/vaults/prefetch.ts`). When `lagDuration` is present the
|
|
65
|
+
* per-vault `lagDuration()` RPC is skipped; when omitted, behavior is
|
|
66
|
+
* exactly the pre-batching per-call path.
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
prefetchedReads?: {
|
|
70
|
+
lagDuration?: number;
|
|
71
|
+
};
|
|
62
72
|
}): Promise<{
|
|
63
73
|
processedWithdrawals: ISubgraphWithdrawProccessed[];
|
|
64
74
|
requestedWithdrawals: import("../../types").ISubgraphWithdrawRequest[];
|
|
@@ -71,15 +81,28 @@ export declare function getVaultRedemptionHistory({ vault, wallet, lookbackBlock
|
|
|
71
81
|
lookbackBlocks?: number;
|
|
72
82
|
options: IVaultBaseOptions;
|
|
73
83
|
}): Promise<IVaultRedemptionHistoryItem[]>;
|
|
84
|
+
export { getSwapRouterDepositResult } from '../../core/helpers/swap-router';
|
|
74
85
|
/**
|
|
75
86
|
* Vault Positions
|
|
76
87
|
*/
|
|
77
|
-
export declare function getVaultPositions({ vault, wallet, solanaWallet, stellarWallet, options, }: {
|
|
88
|
+
export declare function getVaultPositions({ vault, wallet, solanaWallet, stellarWallet, options, prefetchedReads, }: {
|
|
78
89
|
vault: IAddress;
|
|
79
90
|
wallet?: IAddress;
|
|
80
91
|
solanaWallet?: string;
|
|
81
92
|
stellarWallet?: string;
|
|
82
93
|
options: IVaultBaseOptions;
|
|
94
|
+
/**
|
|
95
|
+
* Per-vault values already read via a Multicall3 batch at the fan-out call
|
|
96
|
+
* sites (see `modules/vaults/prefetch.ts`). Supplied fields skip the
|
|
97
|
+
* corresponding `balanceOf` / `lagDuration` RPC for the vault matching the
|
|
98
|
+
* `vault` parameter; when omitted, behavior is exactly the pre-batching
|
|
99
|
+
* per-call path.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
prefetchedReads?: {
|
|
103
|
+
balance?: bigint;
|
|
104
|
+
lagDuration?: number;
|
|
105
|
+
};
|
|
83
106
|
}): Promise<IVaultPosition[]>;
|
|
84
107
|
/**
|
|
85
108
|
* @deprecated use getVaultHistoricalTimeseries instead
|