@augustdigital/sdk 8.11.0 → 8.13.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 +3 -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 +46 -4
- package/lib/core/constants/swap-router.js +50 -5
- 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/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/swap-router.d.ts +168 -5
- package/lib/core/helpers/swap-router.js +417 -4
- package/lib/core/helpers/vault-version.d.ts +19 -1
- package/lib/core/helpers/vault-version.js +15 -1
- package/lib/core/helpers/vaults.d.ts +1 -1
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +2 -0
- package/lib/main.d.ts +46 -0
- package/lib/main.js +46 -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 +75 -0
- package/lib/modules/vaults/main.js +127 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/sdk.d.ts +7227 -6544
- package/lib/types/subgraph.d.ts +9 -0
- package/lib/types/vaults.d.ts +34 -0
- package/package.json +3 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { IAddress, ITokenizedVault } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Per-vault on-chain reads resolved ahead of the positions fan-out, so
|
|
4
|
+
* `getVaultPositions` / `getVaultAvailableRedemptions` can skip their own
|
|
5
|
+
* `balanceOf` / `lagDuration` RPCs. A missing field means the read was not
|
|
6
|
+
* (or could not be) prefetched — the getter falls back to its own call.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface IPrefetchedVaultReads {
|
|
10
|
+
/** Raw share/receipt-token balance of the wallet (`balanceOf`). */
|
|
11
|
+
balance?: bigint;
|
|
12
|
+
/** Vault redemption lag in seconds (`lagDuration`). */
|
|
13
|
+
lagDuration?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Minimal shape of a backend tokenized-vault row the prefetch needs. The
|
|
17
|
+
* full backend response type is looser than this; only these fields are read.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
interface IPrefetchableVault {
|
|
21
|
+
address: string;
|
|
22
|
+
chain: number;
|
|
23
|
+
chain_type?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Backend vault kind. `getVaultVersionV2` reads this to classify evm-2
|
|
26
|
+
* (`multiAssetVault`) vaults whose address isn't in the hardcoded
|
|
27
|
+
* `MULTI_ASSET_VAULTS` list; without it such a vault would be misclassified
|
|
28
|
+
* as evm-1 and the batch would target the vault itself for `balanceOf`
|
|
29
|
+
* instead of its receipt token.
|
|
30
|
+
*/
|
|
31
|
+
internal_type?: ITokenizedVault['internal_type'];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Batch the two non-cacheable per-vault reads (`balanceOf`, `lagDuration`)
|
|
35
|
+
* for a vault list via Multicall3, grouped by chain, ahead of the per-vault
|
|
36
|
+
* positions fan-out.
|
|
37
|
+
*
|
|
38
|
+
* Scope and fallback rules (task 52):
|
|
39
|
+
* - Only EVM vaults on chains with a configured provider AND a verified
|
|
40
|
+
* Multicall3 deployment are batched. Solana/Stellar vaults, unverified
|
|
41
|
+
* chains (e.g. Citrea 4114), and provider-less chains are skipped — they
|
|
42
|
+
* keep today's exact per-vault read path.
|
|
43
|
+
* - `balanceOf` targets the receipt token for evm-2 vaults (resolved through
|
|
44
|
+
* the same cached `getReceiptTokenAddress` the getters use) and the vault
|
|
45
|
+
* itself for evm-1. Without an EVM wallet only `lagDuration` is batched.
|
|
46
|
+
* - Failures never propagate: a reverting vault call is simply absent from
|
|
47
|
+
* the result map, and a whole-chain error drops that chain's entries. The
|
|
48
|
+
* worst case is always "no prefetch → per-vault fallback", never wrong data.
|
|
49
|
+
*
|
|
50
|
+
* RPC cost: per batched chain, `ceil(reads / 10)` `eth_call`s (+1 cold
|
|
51
|
+
* `lpTokenAddress` per evm-2 vault) instead of ~2 `eth_call`s per vault.
|
|
52
|
+
*
|
|
53
|
+
* @param vaults Backend tokenized-vault rows about to be fanned out over.
|
|
54
|
+
* @param wallet Optional EVM wallet for `balanceOf` reads.
|
|
55
|
+
* @param providers Chain-id → RPC-url map (the module's `this.providers`).
|
|
56
|
+
* @returns Map keyed by lowercased vault address; vaults with no batched
|
|
57
|
+
* reads have no entry.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare function prefetchVaultPositionReads({ vaults, wallet, providers, }: {
|
|
61
|
+
vaults: IPrefetchableVault[];
|
|
62
|
+
wallet?: IAddress;
|
|
63
|
+
providers?: Partial<Record<number, string>>;
|
|
64
|
+
}): Promise<Map<string, IPrefetchedVaultReads>>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prefetchVaultPositionReads = prefetchVaultPositionReads;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const abis_1 = require("../../abis");
|
|
6
|
+
const TokenizedVaultV2Receipt_1 = require("../../abis/TokenizedVaultV2Receipt");
|
|
7
|
+
const core_1 = require("../../core");
|
|
8
|
+
/**
|
|
9
|
+
* Batch the two non-cacheable per-vault reads (`balanceOf`, `lagDuration`)
|
|
10
|
+
* for a vault list via Multicall3, grouped by chain, ahead of the per-vault
|
|
11
|
+
* positions fan-out.
|
|
12
|
+
*
|
|
13
|
+
* Scope and fallback rules (task 52):
|
|
14
|
+
* - Only EVM vaults on chains with a configured provider AND a verified
|
|
15
|
+
* Multicall3 deployment are batched. Solana/Stellar vaults, unverified
|
|
16
|
+
* chains (e.g. Citrea 4114), and provider-less chains are skipped — they
|
|
17
|
+
* keep today's exact per-vault read path.
|
|
18
|
+
* - `balanceOf` targets the receipt token for evm-2 vaults (resolved through
|
|
19
|
+
* the same cached `getReceiptTokenAddress` the getters use) and the vault
|
|
20
|
+
* itself for evm-1. Without an EVM wallet only `lagDuration` is batched.
|
|
21
|
+
* - Failures never propagate: a reverting vault call is simply absent from
|
|
22
|
+
* the result map, and a whole-chain error drops that chain's entries. The
|
|
23
|
+
* worst case is always "no prefetch → per-vault fallback", never wrong data.
|
|
24
|
+
*
|
|
25
|
+
* RPC cost: per batched chain, `ceil(reads / 10)` `eth_call`s (+1 cold
|
|
26
|
+
* `lpTokenAddress` per evm-2 vault) instead of ~2 `eth_call`s per vault.
|
|
27
|
+
*
|
|
28
|
+
* @param vaults Backend tokenized-vault rows about to be fanned out over.
|
|
29
|
+
* @param wallet Optional EVM wallet for `balanceOf` reads.
|
|
30
|
+
* @param providers Chain-id → RPC-url map (the module's `this.providers`).
|
|
31
|
+
* @returns Map keyed by lowercased vault address; vaults with no batched
|
|
32
|
+
* reads have no entry.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
async function prefetchVaultPositionReads({ vaults, wallet, providers, }) {
|
|
36
|
+
const reads = new Map();
|
|
37
|
+
const hasWallet = !!(wallet && (0, ethers_1.isAddress)(wallet));
|
|
38
|
+
const byChain = new Map();
|
|
39
|
+
for (const v of vaults) {
|
|
40
|
+
if (!v?.address || !(0, ethers_1.isAddress)(v.address))
|
|
41
|
+
continue;
|
|
42
|
+
if (!(0, core_1.isMulticall3Supported)(v.chain))
|
|
43
|
+
continue;
|
|
44
|
+
if (!providers?.[v.chain])
|
|
45
|
+
continue;
|
|
46
|
+
const group = byChain.get(v.chain) ?? [];
|
|
47
|
+
group.push(v);
|
|
48
|
+
byChain.set(v.chain, group);
|
|
49
|
+
}
|
|
50
|
+
await Promise.all(Array.from(byChain.entries()).map(async ([chain, chainVaults]) => {
|
|
51
|
+
try {
|
|
52
|
+
// Same cache key as the getters (`createProvider(rpcUrl)` without a
|
|
53
|
+
// chainId) so the receipt-token/decimals caches stay shared.
|
|
54
|
+
const provider = (0, core_1.createProvider)(providers[chain]);
|
|
55
|
+
// Resolve each vault's `balanceOf` target — the receipt token for
|
|
56
|
+
// evm-2 vaults (one `lpTokenAddress` read each on a cold cache),
|
|
57
|
+
// the vault itself otherwise. Bound the fan-out to
|
|
58
|
+
// `MULTICALL3_BATCH_SIZE` concurrent reads (CLAUDE.md §4.1): a wallet
|
|
59
|
+
// with many uncached evm-2 vaults on one chain would otherwise burst
|
|
60
|
+
// N simultaneous reads before the aggregate3 batch even fires.
|
|
61
|
+
const balanceTargets = [];
|
|
62
|
+
for (let i = 0; i < chainVaults.length; i += core_1.MULTICALL3_BATCH_SIZE) {
|
|
63
|
+
const slice = chainVaults.slice(i, i + core_1.MULTICALL3_BATCH_SIZE);
|
|
64
|
+
const resolved = await Promise.all(slice.map(async (v) => {
|
|
65
|
+
if (!hasWallet)
|
|
66
|
+
return undefined;
|
|
67
|
+
if ((0, core_1.getVaultVersionV2)(v) === 'evm-2') {
|
|
68
|
+
// Cached + in-flight-deduped; a cold miss costs the same
|
|
69
|
+
// `lpTokenAddress` read the getter itself would make.
|
|
70
|
+
return (0, core_1.getReceiptTokenAddress)(provider, v.address);
|
|
71
|
+
}
|
|
72
|
+
return v.address;
|
|
73
|
+
}));
|
|
74
|
+
balanceTargets.push(...resolved);
|
|
75
|
+
}
|
|
76
|
+
const calls = [];
|
|
77
|
+
const slots = [];
|
|
78
|
+
chainVaults.forEach((v, i) => {
|
|
79
|
+
calls.push({
|
|
80
|
+
target: v.address,
|
|
81
|
+
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
82
|
+
functionName: 'lagDuration',
|
|
83
|
+
});
|
|
84
|
+
slots.push({ address: v.address, field: 'lagDuration' });
|
|
85
|
+
const target = balanceTargets[i];
|
|
86
|
+
if (hasWallet && target && (0, ethers_1.isAddress)(target)) {
|
|
87
|
+
calls.push({
|
|
88
|
+
target: target,
|
|
89
|
+
abi: target === v.address
|
|
90
|
+
? abis_1.ABI_LENDING_POOL_V2
|
|
91
|
+
: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
|
|
92
|
+
functionName: 'balanceOf',
|
|
93
|
+
args: [wallet],
|
|
94
|
+
});
|
|
95
|
+
slots.push({ address: v.address, field: 'balance' });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const results = await (0, core_1.multicall3Aggregate)(provider, chain, calls);
|
|
99
|
+
results.forEach((r, i) => {
|
|
100
|
+
if (!r.success)
|
|
101
|
+
return;
|
|
102
|
+
const slot = slots[i];
|
|
103
|
+
const key = slot.address.toLowerCase();
|
|
104
|
+
const entry = reads.get(key) ?? {};
|
|
105
|
+
if (slot.field === 'lagDuration') {
|
|
106
|
+
entry.lagDuration = Number(r.value);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
entry.balance = BigInt(r.value);
|
|
110
|
+
}
|
|
111
|
+
reads.set(key, entry);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
core_1.Logger.log.warn('prefetchVaultPositionReads', `chain ${chain} prefetch failed — falling back to per-vault reads`, e);
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
return reads;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=prefetch.js.map
|