upshift-finance 1.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/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- 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/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -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 +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -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
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { type InterfaceAbi, type JsonRpcProvider } from 'ethers';
|
|
2
|
+
/** The revert shapes {@link decodeRevertData} distinguishes. */
|
|
3
|
+
export type IRevertKind = 'error-string' | 'panic' | 'custom' | 'unknown';
|
|
4
|
+
/** Result of decoding a raw revert blob with {@link decodeRevertData}. */
|
|
5
|
+
export interface IDecodedRevert {
|
|
6
|
+
/**
|
|
7
|
+
* `'error-string'` for `Error(string)` (a `require` message), `'panic'` for
|
|
8
|
+
* compiler-inserted `Panic(uint256)`, `'custom'` when the selector matched a
|
|
9
|
+
* corpus (or caller-supplied) custom error, `'unknown'` when nothing matched.
|
|
10
|
+
*/
|
|
11
|
+
kind: IRevertKind;
|
|
12
|
+
/** The 4-byte selector (`0x` + 8 hex chars), always present — even for `'unknown'` so callers can 4byte-lookup it. */
|
|
13
|
+
selector: string;
|
|
14
|
+
/** Error name (e.g. `'ERC20InsufficientBalance'`, `'Error'`, `'Panic'`). Absent for `'unknown'`. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Full error signature (e.g. `'ERC20InsufficientBalance(address,uint256,uint256)'`). Absent for `'unknown'`. */
|
|
17
|
+
signature?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Decoded arguments in declaration order (`bigint` for integers, checksummed
|
|
20
|
+
* strings for addresses). Absent when the selector matched but the argument
|
|
21
|
+
* bytes were truncated or malformed — see {@link IDecodedRevert.reason}.
|
|
22
|
+
*/
|
|
23
|
+
args?: unknown[];
|
|
24
|
+
/**
|
|
25
|
+
* Human-readable summary when one exists: the `Error(string)` message, the
|
|
26
|
+
* named `Panic` code, or a note that the argument data was truncated.
|
|
27
|
+
*/
|
|
28
|
+
reason?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Decode a raw EVM revert blob into a named error with arguments.
|
|
32
|
+
*
|
|
33
|
+
* Pure and offline — no RPC calls, no network. Handles the three revert
|
|
34
|
+
* shapes the EVM produces:
|
|
35
|
+
*
|
|
36
|
+
* 1. `Error(string)` (`0x08c379a0`) — a `require`/`revert` with a message.
|
|
37
|
+
* 2. `Panic(uint256)` (`0x4e487b71`) — compiler-inserted checks, with the
|
|
38
|
+
* numeric code translated to its documented meaning (overflow, division by
|
|
39
|
+
* zero, …).
|
|
40
|
+
* 3. Custom errors — matched against a built-in corpus of OpenZeppelin
|
|
41
|
+
* ERC-6093 / SafeERC20 / ERC4626 / Ownable / Pausable errors, LayerZero V2
|
|
42
|
+
* OApp/OFT errors, and every `error` fragment in the vault ABIs the SDK
|
|
43
|
+
* ships (tokenized vaults, SwapRouter, lending pools, …). Callers can
|
|
44
|
+
* extend the corpus per call via `opts.extraAbis`, which take precedence.
|
|
45
|
+
*
|
|
46
|
+
* Truncated input degrades gracefully: when the 4-byte selector matches a
|
|
47
|
+
* known error but the argument bytes are incomplete (e.g. an alert pipeline
|
|
48
|
+
* clipped the hex), the result still carries `kind: 'custom'`, `name`, and
|
|
49
|
+
* `signature`, with `args` omitted and `reason` explaining the truncation.
|
|
50
|
+
*
|
|
51
|
+
* @param data - The revert blob as a `0x`-prefixed hex string (the `data`
|
|
52
|
+
* field of an ethers v6 `CALL_EXCEPTION`). Anything shorter than a 4-byte
|
|
53
|
+
* selector, or not hex at all, yields `kind: 'unknown'`.
|
|
54
|
+
* @param opts - Optional settings.
|
|
55
|
+
* @param opts.extraAbis - Additional ABIs whose `error` fragments are checked
|
|
56
|
+
* before the built-in corpus.
|
|
57
|
+
* @returns The decoded revert. Never throws; unrecognized selectors return
|
|
58
|
+
* `kind: 'unknown'` with the selector preserved so callers can look it up
|
|
59
|
+
* via {@link lookupSelector}.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const decoded = decodeRevertData('0xe450d38c…');
|
|
64
|
+
* // {
|
|
65
|
+
* // kind: 'custom',
|
|
66
|
+
* // selector: '0xe450d38c',
|
|
67
|
+
* // name: 'ERC20InsufficientBalance',
|
|
68
|
+
* // signature: 'ERC20InsufficientBalance(address,uint256,uint256)',
|
|
69
|
+
* // args: ['0x9281…', 487711967n, 1261711967n],
|
|
70
|
+
* // }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function decodeRevertData(data: string, opts?: {
|
|
74
|
+
extraAbis?: InterfaceAbi[];
|
|
75
|
+
}): IDecodedRevert;
|
|
76
|
+
/** Fields recovered from an ethers v6 error string by {@link extractRevertFromErrorText}. */
|
|
77
|
+
export interface IExtractedRevertContext {
|
|
78
|
+
/** The revert blob from the top-level `data="0x…"` field, when present. */
|
|
79
|
+
revertData?: string;
|
|
80
|
+
/** The failed operation from `action="…"` (e.g. `'estimateGas'`, `'call'`). */
|
|
81
|
+
action?: string;
|
|
82
|
+
/** The ethers error code from `code=…` (e.g. `'CALL_EXCEPTION'`). */
|
|
83
|
+
code?: string;
|
|
84
|
+
/** The embedded `transaction={ … }` fields that survived, when any did. */
|
|
85
|
+
tx?: {
|
|
86
|
+
from?: string;
|
|
87
|
+
to?: string;
|
|
88
|
+
data?: string;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse an ethers v6 error *string* and recover the machine-readable fields
|
|
93
|
+
* embedded in it.
|
|
94
|
+
*
|
|
95
|
+
* ethers v6 serializes rich error objects into a single message of the shape
|
|
96
|
+
* `… (action="estimateGas", data="0x…", reason=…, transaction={ "data":
|
|
97
|
+
* "0x…", "from": "0x…", "to": "0x…" }, …, code=CALL_EXCEPTION, version=…)` —
|
|
98
|
+
* exactly what error-alert pipelines end up carrying once the original error
|
|
99
|
+
* object is stringified. This helper regex-extracts the revert `data`, the
|
|
100
|
+
* `action`, the `code`, and the embedded transaction fields.
|
|
101
|
+
*
|
|
102
|
+
* Pure and offline. Tolerant of truncation: alert transports often cap
|
|
103
|
+
* message length mid-hex, so every field is matched without requiring its
|
|
104
|
+
* closing quote and the result simply omits whatever did not survive.
|
|
105
|
+
*
|
|
106
|
+
* @param text - The error text to parse (an ethers v6 `error.message`, or a
|
|
107
|
+
* log/alert line that embeds one).
|
|
108
|
+
* @returns The recovered fields; an empty object when nothing matched. Never
|
|
109
|
+
* throws.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const ctx = extractRevertFromErrorText(alertErrorLine);
|
|
114
|
+
* if (ctx.revertData) console.log(decodeRevertData(ctx.revertData));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function extractRevertFromErrorText(text: string): IExtractedRevertContext;
|
|
118
|
+
/**
|
|
119
|
+
* Look up candidate signatures for an unknown 4-byte selector against public
|
|
120
|
+
* signature databases.
|
|
121
|
+
*
|
|
122
|
+
* Network helper — queries [openchain.xyz](https://openchain.xyz) first and
|
|
123
|
+
* falls back to [4byte.directory](https://www.4byte.directory). Kept separate
|
|
124
|
+
* from {@link decodeRevertData} so the core decode path stays offline.
|
|
125
|
+
* Worst case 2 HTTPS requests.
|
|
126
|
+
*
|
|
127
|
+
* @param selector - The selector to look up. Longer hex (a full revert blob)
|
|
128
|
+
* is accepted; only the first 4 bytes are used.
|
|
129
|
+
* @returns Candidate signatures (e.g. `['ERC20InsufficientBalance(address,uint256,uint256)']`),
|
|
130
|
+
* most-likely first. Empty when the input is not hex, no database knows the
|
|
131
|
+
* selector, or both databases were unreachable. Never throws.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const candidates = await lookupSelector('0xe450d38c');
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function lookupSelector(selector: string): Promise<string[]>;
|
|
139
|
+
/** Result of an {@link simulateCall} `eth_call` replay. */
|
|
140
|
+
export type ISimulateCallResult = {
|
|
141
|
+
/** The call succeeded. */
|
|
142
|
+
ok: true;
|
|
143
|
+
/** The raw return data of the call, `0x`-prefixed. */
|
|
144
|
+
returnData: string;
|
|
145
|
+
} | {
|
|
146
|
+
/** The call reverted or the node rejected it. */
|
|
147
|
+
ok: false;
|
|
148
|
+
/** Fresh, untruncated revert blob when the node returned one. */
|
|
149
|
+
revertData?: string;
|
|
150
|
+
/** {@link decodeRevertData} applied to `revertData`, when present. */
|
|
151
|
+
decoded?: IDecodedRevert;
|
|
152
|
+
/** The underlying error message, for failures without revert data. */
|
|
153
|
+
errorMessage: string;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Replay a call via `eth_call` and decode the revert when it fails.
|
|
157
|
+
*
|
|
158
|
+
* The primary use is re-executing a transaction that failed at `estimateGas`
|
|
159
|
+
* (so no transaction hash ever existed): the node returns the *full* revert
|
|
160
|
+
* blob, which both confirms the failure still reproduces and recovers
|
|
161
|
+
* untruncated revert data even when the original error text was clipped in
|
|
162
|
+
* transit. Passing a historical `blockTag` replays against archival state
|
|
163
|
+
* (requires an archive-capable RPC).
|
|
164
|
+
*
|
|
165
|
+
* Exactly 1 RPC call (`eth_call`).
|
|
166
|
+
*
|
|
167
|
+
* @param provider - A connected `JsonRpcProvider` for the target chain, e.g.
|
|
168
|
+
* from `createProvider(rpcUrl, chainId)`. Note that some listed public RPCs
|
|
169
|
+
* reject keyless `eth_call` — supply a working endpoint via the SDK's RPC
|
|
170
|
+
* precedence (constructor `providers` map / `AUGUST_RPC_<chainId>` env).
|
|
171
|
+
* @param tx - The call to replay: `to` and `data` are required, `from`
|
|
172
|
+
* matters whenever the target checks `msg.sender`.
|
|
173
|
+
* @param blockTag - Optional block to execute against (`'latest'` by
|
|
174
|
+
* default; a number or hex tag replays historical state).
|
|
175
|
+
* @param opts - Optional settings forwarded to {@link decodeRevertData}.
|
|
176
|
+
* @param opts.extraAbis - Additional ABIs checked before the built-in corpus
|
|
177
|
+
* when decoding a revert.
|
|
178
|
+
* @returns `{ ok: true, returnData }` on success; on failure `{ ok: false }`
|
|
179
|
+
* with the fresh `revertData` and its decode when the node supplied one.
|
|
180
|
+
* Never throws on revert — only on programmer error (e.g. no provider).
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* const result = await simulateCall(provider, {
|
|
185
|
+
* from: eoa,
|
|
186
|
+
* to: vault,
|
|
187
|
+
* data: calldata,
|
|
188
|
+
* });
|
|
189
|
+
* if (!result.ok && result.decoded) console.log(result.decoded.signature);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function simulateCall(provider: JsonRpcProvider, tx: {
|
|
193
|
+
from?: string;
|
|
194
|
+
to: string;
|
|
195
|
+
data: string;
|
|
196
|
+
}, blockTag?: string | number, opts?: {
|
|
197
|
+
extraAbis?: InterfaceAbi[];
|
|
198
|
+
}): Promise<ISimulateCallResult>;
|
|
199
|
+
/** Snapshot of a holder's token state returned by {@link readTokenState}. */
|
|
200
|
+
export interface ITokenState {
|
|
201
|
+
/** Token symbol, when the contract implements `symbol()`. */
|
|
202
|
+
symbol?: string;
|
|
203
|
+
/** Token decimals, when the contract implements `decimals()`. */
|
|
204
|
+
decimals?: number;
|
|
205
|
+
/** The holder's raw balance in base units, when `balanceOf` resolved. */
|
|
206
|
+
balance?: bigint;
|
|
207
|
+
/** Raw allowance from holder to `spender`, only probed when `spender` was given. */
|
|
208
|
+
allowance?: bigint;
|
|
209
|
+
/**
|
|
210
|
+
* Whether the holder is frozen/blacklisted by the token issuer, from the
|
|
211
|
+
* first compliance getter the token implements (`isAccountFrozen` — Agora
|
|
212
|
+
* AUSD, `isBlacklisted` — USDC-style, `isFrozen`). `undefined` when the
|
|
213
|
+
* token exposes none of them — which is NOT evidence the holder is clear,
|
|
214
|
+
* only that the token has no recognized compliance getter.
|
|
215
|
+
*/
|
|
216
|
+
frozen?: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Read a bounded, fixed set of token-state probes for a holder — the exact
|
|
220
|
+
* facts needed to explain a failed deposit/transfer: what the token is, what
|
|
221
|
+
* the holder has, what the spender may pull, and whether the issuer froze the
|
|
222
|
+
* holder.
|
|
223
|
+
*
|
|
224
|
+
* The probe set is deliberately fixed (no arbitrary calldata): `symbol()`,
|
|
225
|
+
* `decimals()`, `balanceOf(holder)`, `allowance(holder, spender)` when a
|
|
226
|
+
* spender is given, and the compliance getters tried in order —
|
|
227
|
+
* `isAccountFrozen(address)` (Agora AUSD, selector `0xe816d97f`),
|
|
228
|
+
* `isBlacklisted(address)` (USDC-style), `isFrozen(address)`. Probes the
|
|
229
|
+
* token does not implement resolve to `undefined`; this function never
|
|
230
|
+
* throws.
|
|
231
|
+
*
|
|
232
|
+
* Worst case 7 RPC calls (4 base probes + 3 compliance getters), batched by
|
|
233
|
+
* the provider where supported.
|
|
234
|
+
*
|
|
235
|
+
* @param provider - A connected `JsonRpcProvider` for the token's chain.
|
|
236
|
+
* @param token - The ERC-20 token contract address.
|
|
237
|
+
* @param holder - The account whose balance/compliance state to read.
|
|
238
|
+
* @param spender - Optional spender for the `allowance(holder, spender)`
|
|
239
|
+
* probe (e.g. the vault a deposit approves).
|
|
240
|
+
* @returns The token state with every unresolvable probe as `undefined`.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const state = await readTokenState(provider, ausd, eoa, vault);
|
|
245
|
+
* // { symbol: 'AUSD', decimals: 6, balance: 487711967n, allowance: 0n, frozen: false }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare function readTokenState(provider: JsonRpcProvider, token: string, holder: string, spender?: string): Promise<ITokenState>;
|