@upshiftfinance/sdk 0.0.0-stage → 0.1.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 +408 -2
- 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 +953 -0
- package/lib/abis/SwapRouter.js +1228 -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 +249 -0
- package/lib/adapters/evm/index.d.ts +539 -0
- package/lib/adapters/evm/index.js +656 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/confirm.d.ts +88 -0
- package/lib/adapters/solana/confirm.js +291 -0
- package/lib/adapters/solana/constants.d.ts +42 -0
- package/lib/adapters/solana/constants.js +59 -0
- package/lib/adapters/solana/getters.d.ts +42 -0
- package/lib/adapters/solana/getters.js +275 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +700 -0
- package/lib/adapters/solana/idl/vault-idl.js +2101 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.d.ts +795 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.js +1864 -0
- package/lib/adapters/solana/index.d.ts +372 -0
- package/lib/adapters/solana/index.js +459 -0
- package/lib/adapters/solana/pricing.d.ts +184 -0
- package/lib/adapters/solana/pricing.js +239 -0
- package/lib/adapters/solana/queue-hints.d.ts +29 -0
- package/lib/adapters/solana/queue-hints.js +59 -0
- package/lib/adapters/solana/queue.actions.d.ts +97 -0
- package/lib/adapters/solana/queue.actions.js +468 -0
- package/lib/adapters/solana/token-reads.d.ts +108 -0
- package/lib/adapters/solana/token-reads.js +145 -0
- package/lib/adapters/solana/types.d.ts +325 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +229 -0
- package/lib/adapters/solana/utils.js +773 -0
- package/lib/adapters/solana/vault.actions.d.ts +140 -0
- package/lib/adapters/solana/vault.actions.js +657 -0
- package/lib/adapters/solana/withdrawal-queue.d.ts +125 -0
- package/lib/adapters/solana/withdrawal-queue.js +301 -0
- package/lib/adapters/stellar/actions.d.ts +41 -0
- package/lib/adapters/stellar/actions.js +126 -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 +126 -0
- package/lib/adapters/stellar/index.js +187 -0
- package/lib/adapters/stellar/invocation.d.ts +55 -0
- package/lib/adapters/stellar/invocation.js +92 -0
- package/lib/adapters/stellar/soroban.d.ts +131 -0
- package/lib/adapters/stellar/soroban.js +617 -0
- package/lib/adapters/stellar/submit.d.ts +42 -0
- package/lib/adapters/stellar/submit.js +195 -0
- package/lib/adapters/stellar/types.d.ts +57 -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 +1 -0
- package/lib/adapters/sui/constants.js +9 -0
- package/lib/adapters/sui/getters.d.ts +24 -0
- package/lib/adapters/sui/getters.js +134 -0
- package/lib/adapters/sui/index.d.ts +53 -0
- package/lib/adapters/sui/index.js +96 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +115 -0
- package/lib/adapters/sui/types.d.ts +70 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +8 -0
- package/lib/adapters/sui/utils.js +17 -0
- package/lib/core/analytics/app-name.d.ts +27 -0
- package/lib/core/analytics/app-name.js +48 -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 +15 -0
- package/lib/core/analytics/constants.js +28 -0
- package/lib/core/analytics/env.d.ts +46 -0
- package/lib/core/analytics/env.js +147 -0
- package/lib/core/analytics/index.d.ts +39 -0
- package/lib/core/analytics/index.js +83 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +292 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +156 -0
- package/lib/core/analytics/metrics.d.ts +48 -0
- package/lib/core/analytics/metrics.js +142 -0
- package/lib/core/analytics/sanitize.d.ts +57 -0
- package/lib/core/analytics/sanitize.js +272 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +131 -0
- package/lib/core/analytics/sentry.d.ts +100 -0
- package/lib/core/analytics/sentry.js +696 -0
- package/lib/core/analytics/types.d.ts +55 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +55 -0
- package/lib/core/analytics/user-identity.js +218 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +159 -0
- package/lib/core/attribution.js +194 -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 +35 -0
- package/lib/core/base.class.d.ts +193 -0
- package/lib/core/base.class.js +163 -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 +162 -0
- package/lib/core/constants/core.js +281 -0
- package/lib/core/constants/swap-router.d.ts +180 -0
- package/lib/core/constants/swap-router.js +203 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +277 -0
- package/lib/core/constants/web3.d.ts +106 -0
- package/lib/core/constants/web3.js +251 -0
- package/lib/core/errors/index.d.ts +177 -0
- package/lib/core/errors/index.js +257 -0
- package/lib/core/fetcher.d.ts +237 -0
- package/lib/core/fetcher.js +1103 -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 +697 -0
- package/lib/core/helpers/chain-support.d.ts +98 -0
- package/lib/core/helpers/chain-support.js +139 -0
- package/lib/core/helpers/concurrency.d.ts +51 -0
- package/lib/core/helpers/concurrency.js +79 -0
- package/lib/core/helpers/core.d.ts +92 -0
- package/lib/core/helpers/core.js +368 -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 +61 -0
- package/lib/core/helpers/signer.js +184 -0
- package/lib/core/helpers/swap-router.d.ts +269 -0
- package/lib/core/helpers/swap-router.js +542 -0
- package/lib/core/helpers/vault-version.d.ts +24 -0
- package/lib/core/helpers/vault-version.js +83 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +241 -0
- package/lib/core/helpers/web3.d.ts +366 -0
- package/lib/core/helpers/web3.js +1034 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/curator-alert.d.ts +217 -0
- package/lib/core/logger/curator-alert.js +276 -0
- package/lib/core/logger/index.d.ts +99 -0
- package/lib/core/logger/index.js +163 -0
- package/lib/core/logger/slack.d.ts +49 -0
- package/lib/core/logger/slack.js +111 -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 +132 -0
- package/lib/evm/methods/crossChainVault.js +857 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +239 -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 +596 -0
- package/lib/main.js +681 -0
- package/lib/modules/api/fetcher.d.ts +108 -0
- package/lib/modules/api/fetcher.js +187 -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 +587 -0
- package/lib/modules/api/main.js +911 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +96 -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 +249 -0
- package/lib/modules/sub-accounts/main.js +211 -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 +84 -0
- package/lib/modules/vaults/adapter.helpers.js +202 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +357 -0
- package/lib/modules/vaults/getters.d.ts +1060 -0
- package/lib/modules/vaults/getters.js +4079 -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 +607 -0
- package/lib/modules/vaults/main.js +1687 -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 +406 -0
- package/lib/modules/vaults/read.actions.js +891 -0
- package/lib/modules/vaults/types.d.ts +149 -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 +153 -0
- package/lib/modules/vaults/utils.js +818 -0
- package/lib/modules/vaults/write.actions.d.ts +812 -0
- package/lib/modules/vaults/write.actions.js +2377 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +30154 -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 +50 -0
- package/lib/services/debank/utils.js +325 -0
- package/lib/services/layerzero/deposits.d.ts +55 -0
- package/lib/services/layerzero/deposits.js +174 -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 +33 -0
- package/lib/services/octavfi/fetcher.js +39 -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 +244 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +66 -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 +48 -0
- package/lib/services/subgraph/schema.js +87 -0
- package/lib/services/subgraph/vaults.d.ts +83 -0
- package/lib/services/subgraph/vaults.js +1282 -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/services/untangled/fetcher.d.ts +40 -0
- package/lib/services/untangled/fetcher.js +110 -0
- package/lib/services/untangled/index.d.ts +3 -0
- package/lib/services/untangled/index.js +20 -0
- package/lib/services/untangled/types.d.ts +83 -0
- package/lib/services/untangled/types.js +10 -0
- package/lib/services/untangled/utils.d.ts +91 -0
- package/lib/services/untangled/utils.js +339 -0
- package/lib/types/api.d.ts +498 -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 +150 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +84 -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 +886 -0
- package/lib/types/vaults.js +30 -0
- package/lib/types/web3.d.ts +81 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +730 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -3
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { ethers, Interface, type InterfaceAbi, JsonRpcProvider } from 'ethers';
|
|
2
|
+
import type { Abi } from 'abitype';
|
|
3
|
+
import type { TypedContract } from '../../types/typed-contract';
|
|
4
|
+
import type { IAddress, IContractRunner, IInfuraOptions } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* Web3 Helper Utilities
|
|
7
|
+
*
|
|
8
|
+
* Core utilities for blockchain interaction:
|
|
9
|
+
* - Provider Management: createProvider, getInfuraProvider, getChainId
|
|
10
|
+
* - Contract Helpers: createContract, getDecimals, getSymbol, getTokenMetadata
|
|
11
|
+
* - Transaction Utilities: simulateTransaction, checkAddress
|
|
12
|
+
* - Historical Queries: getHistoricalContractData, getHistoricalContractDataByDate
|
|
13
|
+
* - Oracle Integration: getLoanOracleFeeRate
|
|
14
|
+
* - Block Utilities: determineBlockCutoff, determineBlockSkipInternal
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Get maximum block range for historical queries per chain.
|
|
18
|
+
* Prevents RPC timeouts by limiting lookback window.
|
|
19
|
+
* @param chain Chain ID
|
|
20
|
+
* @returns Maximum number of blocks to query
|
|
21
|
+
*/
|
|
22
|
+
export declare const determineBlockCutoff: (chain: number) => 120000 | 3456000 | 150000;
|
|
23
|
+
/**
|
|
24
|
+
* Approximate block time in seconds per chain.
|
|
25
|
+
* Used to estimate time ranges from block counts.
|
|
26
|
+
* @param chain - Chain ID
|
|
27
|
+
* @returns Seconds per block
|
|
28
|
+
*/
|
|
29
|
+
export declare const determineSecondsPerBlock: (chain: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Get block interval for paginated historical queries per chain.
|
|
32
|
+
* Respects RPC eth_getLogs range limits.
|
|
33
|
+
* @param chain Chain ID
|
|
34
|
+
* @returns Block interval for pagination
|
|
35
|
+
*/
|
|
36
|
+
export declare const determineBlockSkipInternal: (chain: number) => 999 | 1000 | 8000 | 10000;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum JSON-RPC calls ethers may coalesce into a single batched HTTP
|
|
39
|
+
* request for a given endpoint.
|
|
40
|
+
*
|
|
41
|
+
* Providers advertise wildly different batch limits and reject the whole batch
|
|
42
|
+
* — not the excess — when exceeded, so one oversized batch fails every call
|
|
43
|
+
* inside it. dRPC's free tier caps batches at 3, which made every Mezo read
|
|
44
|
+
* fail with `server response 500 … "Batch of more than 3 requests are not
|
|
45
|
+
* allowed"` (the single highest-volume SDK error in production).
|
|
46
|
+
*
|
|
47
|
+
* Detection is host-based rather than chain-based because the limit is a
|
|
48
|
+
* property of the endpoint, not the chain: the same chain served by a
|
|
49
|
+
* self-hosted node has no such cap.
|
|
50
|
+
*
|
|
51
|
+
* @param rpcUrl - The RPC endpoint URL. Unparseable values fall back to the
|
|
52
|
+
* conservative default rather than throwing.
|
|
53
|
+
* @returns Batch size cap to pass to ethers as `batchMaxCount`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const determineRpcBatchMaxCount: (rpcUrl: string) => number;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieve chain ID from web3 provider.
|
|
58
|
+
* Handles both initialized and uninitialized provider states.
|
|
59
|
+
* @param provider Web3 provider instance
|
|
60
|
+
* @returns Numeric chain ID
|
|
61
|
+
*/
|
|
62
|
+
export declare const getChainId: (provider: IContractRunner) => Promise<number>;
|
|
63
|
+
/**
|
|
64
|
+
* Create ethers contract instance with address validation.
|
|
65
|
+
* @param provider Web3 provider for contract calls
|
|
66
|
+
* @param address Contract address (must be checksummed)
|
|
67
|
+
* @param abi Contract ABI (must be declared with `as const`)
|
|
68
|
+
* @returns Strongly-typed contract instance or undefined if address invalid
|
|
69
|
+
*/
|
|
70
|
+
export declare function createContract<const TAbi extends Abi>({ provider, address, abi, }: {
|
|
71
|
+
address: string;
|
|
72
|
+
provider: IContractRunner;
|
|
73
|
+
abi: TAbi;
|
|
74
|
+
}): TypedContract<TAbi> | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Create or reuse a cached JSON-RPC provider.
|
|
77
|
+
* Passing `chainId` enables ethers' `staticNetwork` to skip the `eth_chainId`
|
|
78
|
+
* round-trip on first use.
|
|
79
|
+
*
|
|
80
|
+
* @param rpcUrl RPC endpoint URL — must be a non-empty string.
|
|
81
|
+
* @param chainId Optional chain ID — enables staticNetwork
|
|
82
|
+
* @throws Error with a clear, remediable message when `rpcUrl` is missing or
|
|
83
|
+
* empty. Without this guard, ethers v6 silently defaults to
|
|
84
|
+
* `http://localhost:8545` and surfaces a cryptic
|
|
85
|
+
* `network is not available yet (NETWORK_ERROR)` on the first RPC call.
|
|
86
|
+
*/
|
|
87
|
+
export declare const createProvider: (rpcUrl: string, chainId?: number) => JsonRpcProvider;
|
|
88
|
+
/**
|
|
89
|
+
* Create or reuse a cached Infura provider for the specified chain.
|
|
90
|
+
* @param infura Configuration with chain ID and API key
|
|
91
|
+
*/
|
|
92
|
+
export declare const getInfuraProvider: (infura: IInfuraOptions) => JsonRpcProvider;
|
|
93
|
+
export { explorerLink } from './explorer-link';
|
|
94
|
+
/**
|
|
95
|
+
* Fetch token decimals from contract or Solana mint.
|
|
96
|
+
* Results are cached to minimize RPC calls.
|
|
97
|
+
*
|
|
98
|
+
* **Never throws** — a failed read resolves `undefined`. Callers that must not
|
|
99
|
+
* silently proceed on an unknown scale (any path that encodes an amount) should
|
|
100
|
+
* use {@link getDecimalsOrThrow} instead: feeding `undefined` into
|
|
101
|
+
* `toNormalizedBn` silently defaults to 18 decimals.
|
|
102
|
+
*
|
|
103
|
+
* Transient transport faults (provider rate limits, socket resets, an empty
|
|
104
|
+
* response to `decimals()`) are logged at `warn` — a breadcrumb, not a
|
|
105
|
+
* standalone Sentry issue — since the caller sees the same `undefined` either
|
|
106
|
+
* way. Everything else is logged at `error`. The read itself is **not**
|
|
107
|
+
* retried here; that is opt-in via {@link getDecimalsOrThrow}.
|
|
108
|
+
*
|
|
109
|
+
* @param provider Web3 provider
|
|
110
|
+
* @param address Token contract address or Solana mint
|
|
111
|
+
* @param isVault Resolve `address` as a vault (evm-2 vaults redirect to the
|
|
112
|
+
* receipt token) rather than reading it as a plain ERC-20. Defaults to `true`.
|
|
113
|
+
* @returns Number of decimals for the token, or `undefined` when the read failed.
|
|
114
|
+
*/
|
|
115
|
+
export declare const getDecimals: (provider: IContractRunner, address: IAddress, isVault?: boolean) => Promise<number>;
|
|
116
|
+
/**
|
|
117
|
+
* Read a token's `decimals()` with the **same cache and stampede protection as
|
|
118
|
+
* {@link getDecimals}**, but surfacing failures instead of swallowing them, and
|
|
119
|
+
* retrying the transient ones.
|
|
120
|
+
*
|
|
121
|
+
* Two reasons this exists rather than a flag on `getDecimals`:
|
|
122
|
+
*
|
|
123
|
+
* 1. **`getDecimals` must keep returning `undefined` on failure** — a dozen
|
|
124
|
+
* read paths depend on that. Amount-encoding paths need the opposite: an
|
|
125
|
+
* `undefined` reaching `toNormalizedBn` silently means 18 decimals, which
|
|
126
|
+
* misencodes the transaction. Here the original error propagates, so the
|
|
127
|
+
* caller's `UpshiftSDKError` keeps its cause and its Sentry grouping.
|
|
128
|
+
* 2. **Retry.** Providers intermittently return an empty response to
|
|
129
|
+
* `decimals()`, which ethers reports as
|
|
130
|
+
* `missing revert data (action="call", data="0x313ce567", …)` — a shape a
|
|
131
|
+
* deployed ERC-20 cannot legitimately produce, since `decimals()` takes no
|
|
132
|
+
* arguments. That is retried here via {@link isEmptyViewResponse} scoped to
|
|
133
|
+
* this exact selector, alongside ordinary transport faults
|
|
134
|
+
* ({@link isRetryableRpcError}). The empty-view widening applies **only**
|
|
135
|
+
* here; everywhere else the strict transport definition stands. A genuine
|
|
136
|
+
* revert (`CALL_EXCEPTION` carrying revert data) is never retried.
|
|
137
|
+
*
|
|
138
|
+
* Cache is shared with `getDecimals`, so a read-then-write flow against the
|
|
139
|
+
* same token costs one `decimals()` RPC in total, and N concurrent callers for
|
|
140
|
+
* an uncached token collapse to one.
|
|
141
|
+
*
|
|
142
|
+
* **Exception — an unresolvable chain scope bypasses the cache entirely.** When
|
|
143
|
+
* {@link resolveProviderScope} cannot determine the chain (a runner with no
|
|
144
|
+
* resolved network and no connection URL, e.g. a browser provider before its
|
|
145
|
+
* first request), the only available key is the shared `unknown` bucket. Read
|
|
146
|
+
* paths happily use that bucket, and this function deliberately does not: the
|
|
147
|
+
* two paths have different blast radii. A wrong cached `decimals` on a read
|
|
148
|
+
* renders a wrong number on screen; on a write it misencodes an amount the user
|
|
149
|
+
* then *signs*. The collision needed — the same address being a different token
|
|
150
|
+
* with different decimals on two chains, within one process, across a
|
|
151
|
+
* mid-session chain switch — is narrow, but "no worse than the read path" is
|
|
152
|
+
* not the bar for a value that ends up in a transaction. In that case the read
|
|
153
|
+
* is neither served from nor written to the cache, and it also skips the
|
|
154
|
+
* in-flight dedup map, since joining another caller under an untrusted key
|
|
155
|
+
* would reintroduce exactly the collision being avoided. Retries still apply;
|
|
156
|
+
* the only thing forgone is the RPC saving.
|
|
157
|
+
*
|
|
158
|
+
* RPC cost: 1 on a cache miss, 0 on a hit, up to 3 on a miss that keeps
|
|
159
|
+
* faulting (~750ms of added latency in the worst case before it gives up).
|
|
160
|
+
* Always ≥1 when the chain scope is unresolvable.
|
|
161
|
+
*
|
|
162
|
+
* @param runner - Provider or signer to read through. A signer is unwrapped to
|
|
163
|
+
* its provider for cache scoping, so it shares entries with reads on the
|
|
164
|
+
* same chain.
|
|
165
|
+
* @param address - Token address. Read directly as an ERC-20 — pass the
|
|
166
|
+
* receipt-token address yourself for an `evm-2` vault's share scale.
|
|
167
|
+
* @param tag - Low-cardinality label for retry breadcrumbs (e.g.
|
|
168
|
+
* `'vaultDeposit:poolDecimals'`).
|
|
169
|
+
* @returns The token's decimals.
|
|
170
|
+
* @throws The underlying read error once retries are exhausted, or immediately
|
|
171
|
+
* when the failure is neither a transport fault nor an empty view response.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* // Amount encoding must not proceed on a guessed scale.
|
|
176
|
+
* const decimals = await getDecimalsOrThrow(signer, token, 'deposit:decimals');
|
|
177
|
+
* const amount = toNormalizedBn(userInput, decimals);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare const getDecimalsOrThrow: (runner: IContractRunner, address: IAddress, tag: string) => Promise<number>;
|
|
181
|
+
/**
|
|
182
|
+
* Fetch the whitelisted deposit-asset addresses from a vault's whitelist
|
|
183
|
+
* contract. Cached with a 5-minute TTL; a fresh fetch fans out into N
|
|
184
|
+
* decimals/symbol reads downstream.
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
export declare const getWhitelistedAssets: (provider: IContractRunner, whitelistAddress: IAddress) => Promise<IAddress[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Read an `evm-2` vault's receipt (LP) token address via `lpTokenAddress()`,
|
|
190
|
+
* retrying only the transient transport faults and surfacing everything else
|
|
191
|
+
* unchanged.
|
|
192
|
+
*
|
|
193
|
+
* Why this exists: `lpTokenAddress()` sits immediately before the receipt-token
|
|
194
|
+
* `decimals()` read on every `evm-2` write path (approve / deposit / request
|
|
195
|
+
* redeem / swap-router deposit). Those `decimals()` reads were hardened against
|
|
196
|
+
* provider blips ({@link getDecimalsOrThrow}); the `lpTokenAddress()` read one
|
|
197
|
+
* line above them was not, so a single truncated `eth_call` response still
|
|
198
|
+
* failed the whole write with
|
|
199
|
+
* `missing revert data (action="call", data="0xf5ae497a", …)` — observed in
|
|
200
|
+
* production against a mainnet vault whose `lpTokenAddress()` demonstrably
|
|
201
|
+
* returns a real address when the provider is healthy.
|
|
202
|
+
*
|
|
203
|
+
* **This must never hide a misrouted vault, and does not.** `lpTokenAddress()`
|
|
204
|
+
* exists *only* on `evm-2` vaults. A vault wrongly classified as `evm-2` returns
|
|
205
|
+
* empty returndata for it, deterministically and forever, and that empty
|
|
206
|
+
* response is byte-identical to the transient one — it is the *only* signal the
|
|
207
|
+
* SDK gets that its version routing was wrong. So the retry here is deliberately
|
|
208
|
+
* shaped to preserve that signal:
|
|
209
|
+
*
|
|
210
|
+
* - it is **bounded** (3 attempts, ~750ms of backoff in total — see
|
|
211
|
+
* `retryOnTransientRpc`), never open-ended;
|
|
212
|
+
* - on exhaustion it **rethrows the original error object**, with its identity,
|
|
213
|
+
* message, `code` and `transaction.data` intact, so the caller's
|
|
214
|
+
* `UpshiftSDKError` cause and Sentry grouping are exactly what they are today;
|
|
215
|
+
* - it has **no fallback**: it never substitutes another address, never resolves
|
|
216
|
+
* the vault address itself, and never resolves `null`/`undefined`. It either
|
|
217
|
+
* returns a real receipt-token address or throws.
|
|
218
|
+
*
|
|
219
|
+
* Net effect: a blip costs a retry, a misroute costs three `eth_call`s and then
|
|
220
|
+
* fails exactly as loudly as before.
|
|
221
|
+
*
|
|
222
|
+
* **Deliberately not cached.** Unlike `decimals()`, the vault→receipt-token
|
|
223
|
+
* mapping is not memoized here. Caching it would make a misroute's first
|
|
224
|
+
* (failed) probe and every subsequent one diverge, and would put a
|
|
225
|
+
* vault-identity mapping in the cache on the money path. The lenient, cached
|
|
226
|
+
* reader is {@link getReceiptTokenAddress} — use that on read paths that can
|
|
227
|
+
* tolerate `undefined`.
|
|
228
|
+
*
|
|
229
|
+
* RPC cost: exactly 1 `eth_call` on success; at most 3 when the provider keeps
|
|
230
|
+
* faulting.
|
|
231
|
+
*
|
|
232
|
+
* @param runner - Provider or signer to read through.
|
|
233
|
+
* @param vault - Address of the `evm-2` tokenized vault.
|
|
234
|
+
* @param tag - Low-cardinality label for retry breadcrumbs (e.g.
|
|
235
|
+
* `'vaultRequestRedeem:receiptToken'`).
|
|
236
|
+
* @returns The vault's receipt (LP) token address. Never `null`/`undefined`.
|
|
237
|
+
* @throws The underlying read error, unmodified, once the bounded retries are
|
|
238
|
+
* exhausted — or immediately when the failure is neither a transport fault nor
|
|
239
|
+
* an empty response to this exact selector (e.g. a genuine revert carrying
|
|
240
|
+
* revert data).
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* const receiptToken = await getReceiptTokenAddressOrThrow(
|
|
245
|
+
* signer,
|
|
246
|
+
* vault,
|
|
247
|
+
* 'vaultRequestRedeem:receiptToken',
|
|
248
|
+
* );
|
|
249
|
+
* const decimals = await getDecimalsOrThrow(signer, receiptToken, 'tag');
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare const getReceiptTokenAddressOrThrow: (runner: IContractRunner, vault: IAddress, tag: string) => Promise<IAddress>;
|
|
253
|
+
/**
|
|
254
|
+
* Fetch receipt token address from tokenized vault contract.
|
|
255
|
+
* Results are cached to minimize RPC calls.
|
|
256
|
+
*
|
|
257
|
+
* **Never throws** — a failed read logs at error level and resolves
|
|
258
|
+
* `undefined`, which several read paths depend on. The underlying
|
|
259
|
+
* `lpTokenAddress()` call is made through
|
|
260
|
+
* {@link getReceiptTokenAddressOrThrow}, so a transient provider blip is
|
|
261
|
+
* absorbed by a bounded retry before that happens; a deterministic failure (a
|
|
262
|
+
* vault that has no `lpTokenAddress()` because it is not `evm-2`) still resolves
|
|
263
|
+
* `undefined` after the attempts are spent, exactly as before. Callers on a
|
|
264
|
+
* money path must use {@link getReceiptTokenAddressOrThrow} directly instead —
|
|
265
|
+
* an `undefined` receipt-token address there would silently mis-address a
|
|
266
|
+
* `decimals()` read.
|
|
267
|
+
*
|
|
268
|
+
* @param provider Web3 provider
|
|
269
|
+
* @param address Tokenized vault contract address
|
|
270
|
+
* @returns Receipt token address, or `undefined` when the read failed.
|
|
271
|
+
*/
|
|
272
|
+
export declare const getReceiptTokenAddress: (provider: IContractRunner, address: IAddress) => Promise<`0x${string}`>;
|
|
273
|
+
/**
|
|
274
|
+
* Fetch token symbol from contract.
|
|
275
|
+
* Results are cached to minimize RPC calls.
|
|
276
|
+
* @param provider Web3 provider
|
|
277
|
+
* @param address Token contract address
|
|
278
|
+
* @returns Token symbol string
|
|
279
|
+
*/
|
|
280
|
+
export declare const getSymbol: (provider: IContractRunner, address: IAddress | undefined, isVault?: boolean) => Promise<string>;
|
|
281
|
+
/**
|
|
282
|
+
* Batch fetch multiple token metadata fields in a single call.
|
|
283
|
+
* Efficiently retrieves name, symbol, decimals, and totalSupply.
|
|
284
|
+
* @param provider Web3 provider
|
|
285
|
+
* @param asset Token contract address
|
|
286
|
+
* @param meta Array of metadata fields to fetch
|
|
287
|
+
* @returns Array of metadata values in same order as requested
|
|
288
|
+
*/
|
|
289
|
+
export declare function getTokenMetadata(provider: IContractRunner, asset: IAddress, meta: ('symbol' | 'decimals' | 'name' | 'totalSupply')[]): Promise<any[]>;
|
|
290
|
+
/**
|
|
291
|
+
* Fetch management fee percentage from vault contract.
|
|
292
|
+
*
|
|
293
|
+
* A single `eth_call` to `managementFeePercent()`. Vaults that do not expose
|
|
294
|
+
* the method (older lending pools) revert, which is absorbed and reported as
|
|
295
|
+
* `undefined` — the previous implementation issued an identical `staticCall`
|
|
296
|
+
* probe first, doubling the RPC cost for no extra information since a view
|
|
297
|
+
* call that reverts fails the same way either time.
|
|
298
|
+
*
|
|
299
|
+
* @param provider Web3 provider
|
|
300
|
+
* @param address Vault contract address
|
|
301
|
+
* @returns Management fee as a percentage (basis points ÷ 100), or `undefined`
|
|
302
|
+
* when the vault does not support the method or the call fails.
|
|
303
|
+
* @worstCaseRpcCalls 1 — one `eth_call`.
|
|
304
|
+
*/
|
|
305
|
+
export declare const getManagementFeePercent: (provider: IContractRunner, address: IAddress) => Promise<number>;
|
|
306
|
+
/**
|
|
307
|
+
* Simulate contract transaction without executing on-chain.
|
|
308
|
+
* Useful for testing transaction viability before sending.
|
|
309
|
+
* @param provider Web3 provider
|
|
310
|
+
* @param abi Contract ABI
|
|
311
|
+
* @param functionName Function to simulate
|
|
312
|
+
* @param options Transaction parameters including args, from, to
|
|
313
|
+
* @returns Decoded function result or false if simulation fails
|
|
314
|
+
*/
|
|
315
|
+
export declare function simulateTransaction(provider: IContractRunner, abi: string[] | any, functionName: string, options?: {
|
|
316
|
+
args?: (string | number | bigint)[][];
|
|
317
|
+
from?: string;
|
|
318
|
+
to?: string;
|
|
319
|
+
}): Promise<boolean | ethers.Result>;
|
|
320
|
+
/**
|
|
321
|
+
* Validate Ethereum address format and checksum.
|
|
322
|
+
* @param address Address string to validate
|
|
323
|
+
* @param logger Optional logger for error messages
|
|
324
|
+
* @param type Context type for logging
|
|
325
|
+
* @returns True if address is valid and checksummed
|
|
326
|
+
*/
|
|
327
|
+
export declare function checkAddress(address: string, logger?: any, type?: 'wallet' | 'contract'): boolean;
|
|
328
|
+
type ILoanOracleFeeCategories = 'LOAN.REPAY.INTERESTS';
|
|
329
|
+
/**
|
|
330
|
+
* Fetch dynamic fee rate from on-chain oracle contract.
|
|
331
|
+
* Used for calculating loan interest repayment fees.
|
|
332
|
+
* @param provider Web3 provider
|
|
333
|
+
* @param category_id Fee category identifier
|
|
334
|
+
* @param address Context address for fee calculation
|
|
335
|
+
* @param chainId Optional chain ID (auto-detected if not provided)
|
|
336
|
+
* @returns Fee rate as decimal number
|
|
337
|
+
*/
|
|
338
|
+
export declare function getLoanOracleFeeRate(provider: IContractRunner, category_id: ILoanOracleFeeCategories, address: IAddress, chainId?: number): Promise<number>;
|
|
339
|
+
/**
|
|
340
|
+
* Query historical contract state across a block range.
|
|
341
|
+
* Useful for reconstructing historical data like TVL over time.
|
|
342
|
+
* @param provider Web3 provider
|
|
343
|
+
* @param contractAddress Target contract address
|
|
344
|
+
* @param abi Contract ABI
|
|
345
|
+
* @param methodName View function to call
|
|
346
|
+
* @param args Function arguments
|
|
347
|
+
* @param startBlock Starting block number
|
|
348
|
+
* @param endBlock Ending block number (current block if not specified)
|
|
349
|
+
* @param blockInterval Blocks between each query
|
|
350
|
+
* @returns Array of results with block numbers and timestamps
|
|
351
|
+
*/
|
|
352
|
+
export declare function getHistoricalContractData(provider: IContractRunner, contractAddress: IAddress, abi: Interface | InterfaceAbi, methodName: string, args: (string | number | bigint | boolean)[], startBlock: number, endBlock: number, blockInterval?: number): Promise<any[]>;
|
|
353
|
+
/**
|
|
354
|
+
* Query historical contract state at regular time intervals.
|
|
355
|
+
* Uses binary search to find blocks closest to target timestamps.
|
|
356
|
+
* @param provider Web3 provider
|
|
357
|
+
* @param contractAddress Target contract address
|
|
358
|
+
* @param abi Contract ABI
|
|
359
|
+
* @param methodName View function to call
|
|
360
|
+
* @param args Function arguments
|
|
361
|
+
* @param startDate Start date (string or timestamp)
|
|
362
|
+
* @param endDate End date (string or timestamp)
|
|
363
|
+
* @param intervalHours Hours between each query
|
|
364
|
+
* @returns Array of results with dates, blocks, and values
|
|
365
|
+
*/
|
|
366
|
+
export declare function getHistoricalContractDataByDate(provider: IContractRunner, contractAddress: IAddress, abi: Interface | InterfaceAbi, methodName: string, args: (string | number | bigint | boolean)[], startDate: string | number, endDate: string | number, intervalHours?: number): Promise<any[]>;
|