@upshiftfinance/sdk 0.0.0-stage → 0.2.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/client.d.ts +83 -0
- package/lib/adapters/sui/client.js +216 -0
- package/lib/adapters/sui/constants.d.ts +33 -0
- package/lib/adapters/sui/constants.js +31 -0
- package/lib/adapters/sui/index.d.ts +57 -0
- package/lib/adapters/sui/index.js +100 -0
- package/lib/adapters/sui/targets.d.ts +171 -0
- package/lib/adapters/sui/targets.js +225 -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 +30173 -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 +100 -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 +79 -3
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.NON_EVM_CHAIN_IDS = exports.SUI_CHAIN_ID = exports.SPECIAL_CHAINS = void 0;
|
|
4
|
+
// Special Chains
|
|
5
|
+
/**
|
|
6
|
+
* Non-EVM chains the SDK routes to its own adapters, keyed by adapter name.
|
|
7
|
+
*
|
|
8
|
+
* Each gets a synthetic negative `chainId` so it can share numeric chain-ID
|
|
9
|
+
* parameters with EVM chains without ever colliding with a real EVM ID. The
|
|
10
|
+
* IDs match the backend's `chain` column (Solana `-1`, Sui `-2`, Stellar `-3`),
|
|
11
|
+
* so a backend vault row's `chain` can be compared to these directly.
|
|
12
|
+
*/
|
|
13
|
+
exports.SPECIAL_CHAINS = {
|
|
14
|
+
solana: {
|
|
15
|
+
name: 'Solana',
|
|
16
|
+
chainId: -1,
|
|
17
|
+
explorer: 'https://solscan.io',
|
|
18
|
+
},
|
|
19
|
+
sui: {
|
|
20
|
+
name: 'Sui',
|
|
21
|
+
chainId: -2,
|
|
22
|
+
explorer: 'https://suiscan.xyz',
|
|
23
|
+
},
|
|
24
|
+
stellar: {
|
|
25
|
+
name: 'Stellar',
|
|
26
|
+
chainId: -3,
|
|
27
|
+
explorer: 'https://stellar.expert',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Chain ID used to address Sui vaults: `-2`, the same synthetic ID the backend
|
|
32
|
+
* stores for Sui vault rows (see {@link SPECIAL_CHAINS}).
|
|
33
|
+
*
|
|
34
|
+
* Kept as its own export because callers and the Sui adapter import it by
|
|
35
|
+
* name. It lives in `core/` rather than `adapters/sui/constants.ts` so `core/`
|
|
36
|
+
* can recognise it without importing the adapter layer (which would create a
|
|
37
|
+
* `core → adapters` back-edge); the adapter re-exports it.
|
|
38
|
+
*/
|
|
39
|
+
exports.SUI_CHAIN_ID = exports.SPECIAL_CHAINS.sui.chainId;
|
|
40
|
+
/**
|
|
41
|
+
* Chain IDs the SDK understands that are **not** served by an EVM JSON-RPC
|
|
42
|
+
* provider. Callers may legitimately pass these to vault methods without a
|
|
43
|
+
* matching entry in the `providers` map — the request routes through the
|
|
44
|
+
* Solana / Stellar / Sui adapter instead.
|
|
45
|
+
*/
|
|
46
|
+
exports.NON_EVM_CHAIN_IDS = new Set([
|
|
47
|
+
exports.SPECIAL_CHAINS.solana.chainId,
|
|
48
|
+
exports.SPECIAL_CHAINS.sui.chainId,
|
|
49
|
+
exports.SPECIAL_CHAINS.stellar.chainId,
|
|
50
|
+
]);
|
|
51
|
+
// General
|
|
52
|
+
exports.NATIVE_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
53
|
+
/**
|
|
54
|
+
* Decimal precision of the native gas token on every EVM chain this SDK
|
|
55
|
+
* supports (ETH, Base, Arbitrum, Avalanche, Polygon, BNB, HyperEVM, Unichain,
|
|
56
|
+
* Mezo, Monad, Plasma, Ink, Flare, Katana, Citrea, Fluent, Tempo, X Layer —
|
|
57
|
+
* whose native OKB is also 18 decimals).
|
|
58
|
+
*
|
|
59
|
+
* All of them use 18-decimal native tokens, so this is a single constant rather
|
|
60
|
+
* than a per-chain map. It exists because the native token has no ERC-20
|
|
61
|
+
* `decimals()` to read on-chain: when a subgraph row denominates an amount in
|
|
62
|
+
* the native token it is flagged with a sentinel address ({@link NATIVE_ADDRESS}
|
|
63
|
+
* or the zero address) instead of a real contract, and callers must substitute
|
|
64
|
+
* this value rather than attempting (and failing) a `decimals()` read.
|
|
65
|
+
*
|
|
66
|
+
* Non-EVM natives differ (SOL is 9, XLM is 7) and are handled by their own
|
|
67
|
+
* adapters — those chains never flow through the EVM `decimals()` path this
|
|
68
|
+
* constant serves.
|
|
69
|
+
*/
|
|
70
|
+
exports.EVM_NATIVE_DECIMALS = 18;
|
|
71
|
+
exports.MIN_ABIS = {
|
|
72
|
+
name: 'function name() view returns (string)',
|
|
73
|
+
symbol: 'function symbol() view returns (string)',
|
|
74
|
+
decimals: 'function decimals() view returns (uint8)',
|
|
75
|
+
totalSupply: 'function totalSupply() view returns (uint256)',
|
|
76
|
+
approve: 'function approve(address spender, uint256 value) external returns (bool success)',
|
|
77
|
+
allowance: 'function allowance(address owner, address spender) external view returns (uint256)',
|
|
78
|
+
managementFeePercent: 'function managementFeePercent() view returns (uint256)',
|
|
79
|
+
};
|
|
80
|
+
// Search: New Chain
|
|
81
|
+
exports.ORACLE_CONTRACTS = {
|
|
82
|
+
1: '0xA4E24C498D5B28517787D8407eFdcB157A4FbF50', // mainnet
|
|
83
|
+
43114: '0x755537Cb5C76E06Bb492CF7c73567e252769c5f5', // avax
|
|
84
|
+
42161: '0x24F7BC5CA6E4b53cF7311dE1f5bF8Ba528400E1e', // arbitrum
|
|
85
|
+
8453: '0x07858dF2D8D9aB1DCAAA8b743eb80C6250DFA947', // base
|
|
86
|
+
10: '0xe0049eBCCB23Cb81c3d4C9Fa175b32876b70C2AB', // OP
|
|
87
|
+
};
|
|
88
|
+
// Networks
|
|
89
|
+
// Search: New Chain
|
|
90
|
+
// @todo: this should be used for wagmi configs
|
|
91
|
+
exports.NETWORKS = {
|
|
92
|
+
1: {
|
|
93
|
+
name: 'Ethereum',
|
|
94
|
+
chainId: 1,
|
|
95
|
+
explorer: 'https://etherscan.io',
|
|
96
|
+
},
|
|
97
|
+
42161: {
|
|
98
|
+
name: 'Arbitrum One',
|
|
99
|
+
chainId: 42161,
|
|
100
|
+
explorer: 'https://arbiscan.io',
|
|
101
|
+
},
|
|
102
|
+
8453: {
|
|
103
|
+
name: 'Base',
|
|
104
|
+
chainId: 8453,
|
|
105
|
+
explorer: 'https://basescan.org',
|
|
106
|
+
},
|
|
107
|
+
43114: {
|
|
108
|
+
name: 'Avalanche',
|
|
109
|
+
chainId: 43114,
|
|
110
|
+
explorer: 'https://snowscan.xyz',
|
|
111
|
+
},
|
|
112
|
+
137: {
|
|
113
|
+
name: 'Polygon',
|
|
114
|
+
chainId: 137,
|
|
115
|
+
explorer: 'https://polygonscan.com',
|
|
116
|
+
},
|
|
117
|
+
56: {
|
|
118
|
+
name: 'BNB Smart Chain',
|
|
119
|
+
chainId: 56,
|
|
120
|
+
explorer: 'https://bscscan.com',
|
|
121
|
+
},
|
|
122
|
+
999: {
|
|
123
|
+
name: 'HyperEVM',
|
|
124
|
+
chainId: 999,
|
|
125
|
+
explorer: 'https://hyperevmscan.io',
|
|
126
|
+
},
|
|
127
|
+
130: {
|
|
128
|
+
name: 'Unichain',
|
|
129
|
+
chainId: 130,
|
|
130
|
+
explorer: 'https://uniscan.xyz',
|
|
131
|
+
},
|
|
132
|
+
31612: {
|
|
133
|
+
name: 'Mezo',
|
|
134
|
+
chainId: 31612,
|
|
135
|
+
explorer: 'https://explorer.mezo.org',
|
|
136
|
+
},
|
|
137
|
+
143: {
|
|
138
|
+
name: 'Monad',
|
|
139
|
+
chainId: 143,
|
|
140
|
+
explorer: 'https://monadscan.com',
|
|
141
|
+
},
|
|
142
|
+
9745: {
|
|
143
|
+
name: 'Plasma',
|
|
144
|
+
chainId: 9745,
|
|
145
|
+
explorer: 'https://plasmascan.to',
|
|
146
|
+
},
|
|
147
|
+
57073: {
|
|
148
|
+
name: 'Ink',
|
|
149
|
+
chainId: 57073,
|
|
150
|
+
explorer: 'https://explorer.inkonchain.com',
|
|
151
|
+
},
|
|
152
|
+
14: {
|
|
153
|
+
name: 'Flare',
|
|
154
|
+
chainId: 14,
|
|
155
|
+
explorer: 'https://flarescan.com',
|
|
156
|
+
},
|
|
157
|
+
747474: {
|
|
158
|
+
name: 'Katana',
|
|
159
|
+
chainId: 747474,
|
|
160
|
+
explorer: 'https://explorer.katanarpc.com',
|
|
161
|
+
},
|
|
162
|
+
4114: {
|
|
163
|
+
name: 'Citrea',
|
|
164
|
+
chainId: 4114,
|
|
165
|
+
explorer: 'https://explorer.mainnet.citrea.xyz',
|
|
166
|
+
},
|
|
167
|
+
25363: {
|
|
168
|
+
name: 'Fluent',
|
|
169
|
+
chainId: 25363,
|
|
170
|
+
explorer: 'https://fluentscan.xyz',
|
|
171
|
+
},
|
|
172
|
+
4217: {
|
|
173
|
+
name: 'Tempo',
|
|
174
|
+
chainId: 4217,
|
|
175
|
+
explorer: 'https://explore.tempo.xyz',
|
|
176
|
+
},
|
|
177
|
+
196: {
|
|
178
|
+
name: 'X Layer',
|
|
179
|
+
chainId: 196,
|
|
180
|
+
explorer: 'https://xlayerscan.com',
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
exports.AVAILABLE_CHAINS = Object.keys(exports.NETWORKS).map((c) => Number(c));
|
|
184
|
+
/**
|
|
185
|
+
* Canonical [Multicall3](https://github.com/mds1/multicall) address, deployed
|
|
186
|
+
* via the deterministic deployer to the same address on most EVM chains.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
exports.MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
190
|
+
/**
|
|
191
|
+
* Chains where the canonical Multicall3 deployment was **verified on-chain**
|
|
192
|
+
* (`eth_getCode` returned the 3808-byte runtime at {@link MULTICALL3_ADDRESS};
|
|
193
|
+
* checked per chain on 2026-07-14, Tempo checked separately on 2026-07-15,
|
|
194
|
+
* X Layer on 2026-08-11) —
|
|
195
|
+
* deterministic-deployer presence is NOT assumed. Chains outside this set
|
|
196
|
+
* keep the per-call read path.
|
|
197
|
+
*
|
|
198
|
+
* Deliberately excluded from `NETWORKS`:
|
|
199
|
+
* - 4114 (Citrea) — `eth_getCode` returned `0x` (not deployed).
|
|
200
|
+
* - -1 (Solana), -3 (Stellar) — non-EVM, no Multicall3.
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
exports.MULTICALL3_VERIFIED_CHAINS = new Set([
|
|
204
|
+
1, // Ethereum
|
|
205
|
+
42161, // Arbitrum One
|
|
206
|
+
8453, // Base
|
|
207
|
+
43114, // Avalanche
|
|
208
|
+
137, // Polygon
|
|
209
|
+
56, // BNB Smart Chain
|
|
210
|
+
999, // HyperEVM
|
|
211
|
+
130, // Unichain
|
|
212
|
+
31612, // Mezo
|
|
213
|
+
143, // Monad
|
|
214
|
+
9745, // Plasma
|
|
215
|
+
57073, // Ink
|
|
216
|
+
14, // Flare
|
|
217
|
+
747474, // Katana
|
|
218
|
+
25363, // Fluent
|
|
219
|
+
4217, // Tempo
|
|
220
|
+
196, // X Layer
|
|
221
|
+
]);
|
|
222
|
+
/**
|
|
223
|
+
* Fallbacks
|
|
224
|
+
*/
|
|
225
|
+
exports.FALLBACK_DECIMALS = 18;
|
|
226
|
+
exports.FALLBACK_CHAINID = 42161;
|
|
227
|
+
exports.FALLBACK_RPC_URLS = {
|
|
228
|
+
// Ethereum Mainnet
|
|
229
|
+
1: ['https://ethereum-rpc.publicnode.com'],
|
|
230
|
+
42161: ['https://arbitrum-one-rpc.publicnode.com'],
|
|
231
|
+
8453: ['https://base-rpc.publicnode.com'],
|
|
232
|
+
43114: ['https://avalanche-c-chain-rpc.publicnode.com'],
|
|
233
|
+
143: ['https://monad-mainnet.g.alchemy.com/v2/public'],
|
|
234
|
+
999: ['https://rpc.hyperliquid.xyz/evm'],
|
|
235
|
+
239: ['https://rpc.ankr.com/tac'],
|
|
236
|
+
80094: ['https://berachain-rpc.publicnode.com'],
|
|
237
|
+
59144: ['https://linea-rpc.publicnode.com'],
|
|
238
|
+
43111: ['https://rpc.hemi.network/rpc'],
|
|
239
|
+
146: ['https://rpc.soniclabs.com'],
|
|
240
|
+
534352: ['https://scroll.api.onfinality.io/public'],
|
|
241
|
+
10: ['https://optimism-mainnet.public.blastapi.io'],
|
|
242
|
+
9745: ['https://rpc.plasma.to'],
|
|
243
|
+
57073: ['https://rpc-gel.inkonchain.com'],
|
|
244
|
+
14: ['https://flare-api.flare.network/ext/C/rpc'],
|
|
245
|
+
747474: ['https://rpc.katana.network'],
|
|
246
|
+
4114: ['https://rpc.mainnet.citrea.xyz'],
|
|
247
|
+
25363: ['https://rpc.fluent.xyz'],
|
|
248
|
+
4217: ['https://rpc.mainnet.tempo.xyz'],
|
|
249
|
+
196: ['https://rpc.xlayer.tech'],
|
|
250
|
+
};
|
|
251
|
+
//# sourceMappingURL=web3.js.map
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error class hierarchy for the SDK. All subclasses extend `UpshiftSDKError`,
|
|
3
|
+
* which extends the native `Error`.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { UpshiftAuthError, UpshiftTimeoutError } from '@upshiftfinance/sdk';
|
|
7
|
+
*
|
|
8
|
+
* try {
|
|
9
|
+
* await sdk.getVault(...);
|
|
10
|
+
* } catch (err) {
|
|
11
|
+
* if (err instanceof UpshiftAuthError) refreshKey();
|
|
12
|
+
* else if (err instanceof UpshiftTimeoutError) retry();
|
|
13
|
+
* else throw err;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/** Stable error codes attached to SDK errors. */
|
|
18
|
+
export type UpshiftErrorCode = 'AUTH_MISSING_KEY' | 'AUTH_INVALID_KEY' | 'AUTH_FORBIDDEN' | 'AUTH_UNAUTHORIZED' | 'INVALID_URL' | 'INVALID_INPUT' | 'INVALID_CHAIN' | 'INVALID_ADDRESS' | 'ACCOUNT_NOT_FUNDED' | 'NO_SIGNER' | 'NETWORK_ERROR' | 'TIMEOUT' | 'RATE_LIMITED' | 'SERVER_ERROR' | 'TRANSACTION_UNCONFIRMED' | 'HISTORY_UNAVAILABLE' | 'PRICE_UNAVAILABLE' | 'UNKNOWN';
|
|
19
|
+
/** Options accepted by every SDK error constructor. */
|
|
20
|
+
export interface UpshiftErrorOptions {
|
|
21
|
+
/** Original error preserved for stack-trace chaining. */
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
/** Set from the response `x-correlation-id` header when available. */
|
|
24
|
+
correlationId?: string;
|
|
25
|
+
/** Structured context attached to the error for logging. */
|
|
26
|
+
context?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** Base class for all SDK errors. */
|
|
29
|
+
export declare class UpshiftSDKError extends Error {
|
|
30
|
+
readonly code: UpshiftErrorCode;
|
|
31
|
+
readonly correlationId?: string;
|
|
32
|
+
readonly context?: Record<string, unknown>;
|
|
33
|
+
constructor(code: UpshiftErrorCode, message: string, options?: UpshiftErrorOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Serialize own properties to a plain object. Native `Error` enumerates
|
|
36
|
+
* nothing, so `JSON.stringify(err)` returns `"{}"` without this.
|
|
37
|
+
*/
|
|
38
|
+
toJSON(): Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/** Authentication/authorization failure: missing key, invalid key, forbidden. */
|
|
41
|
+
export declare class UpshiftAuthError extends UpshiftSDKError {
|
|
42
|
+
constructor(code: Extract<UpshiftErrorCode, 'AUTH_MISSING_KEY' | 'AUTH_INVALID_KEY' | 'AUTH_FORBIDDEN' | 'AUTH_UNAUTHORIZED'>, message: string, options?: UpshiftErrorOptions);
|
|
43
|
+
}
|
|
44
|
+
/** Network-level failure: connection refused, DNS, fetch failed. */
|
|
45
|
+
export declare class UpshiftNetworkError extends UpshiftSDKError {
|
|
46
|
+
constructor(message: string, options?: UpshiftErrorOptions);
|
|
47
|
+
}
|
|
48
|
+
/** Request exceeded its deadline. */
|
|
49
|
+
export declare class UpshiftTimeoutError extends UpshiftSDKError {
|
|
50
|
+
/** Time elapsed (ms) before the request was aborted. */
|
|
51
|
+
readonly timeoutMs: number;
|
|
52
|
+
constructor(message: string, timeoutMs: number, options?: UpshiftErrorOptions);
|
|
53
|
+
toJSON(): Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
/** Caller-side input failed validation. */
|
|
56
|
+
export declare class UpshiftValidationError extends UpshiftSDKError {
|
|
57
|
+
constructor(code: Extract<UpshiftErrorCode, 'INVALID_URL' | 'INVALID_INPUT' | 'INVALID_CHAIN' | 'INVALID_ADDRESS' | 'ACCOUNT_NOT_FUNDED'>, message: string, options?: UpshiftErrorOptions);
|
|
58
|
+
}
|
|
59
|
+
/** Backend rate-limited the request (HTTP 429 or equivalent). */
|
|
60
|
+
export declare class UpshiftRateLimitError extends UpshiftSDKError {
|
|
61
|
+
/** Suggested wait before retrying, in milliseconds. */
|
|
62
|
+
readonly retryAfterMs?: number;
|
|
63
|
+
constructor(message: string, options?: UpshiftErrorOptions & {
|
|
64
|
+
retryAfterMs?: number;
|
|
65
|
+
});
|
|
66
|
+
toJSON(): Record<string, unknown>;
|
|
67
|
+
}
|
|
68
|
+
/** Backend returned a non-OK status that isn't auth, rate-limit, or timeout. */
|
|
69
|
+
export declare class UpshiftServerError extends UpshiftSDKError {
|
|
70
|
+
/** HTTP status code returned by the backend. */
|
|
71
|
+
readonly status: number;
|
|
72
|
+
constructor(status: number, message: string, options?: UpshiftErrorOptions);
|
|
73
|
+
toJSON(): Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Transaction/position history required to compute a value could not be
|
|
77
|
+
* retrieved or was empty, so the computed result would be wrong rather than
|
|
78
|
+
* merely missing.
|
|
79
|
+
*
|
|
80
|
+
* Motivation — the 2026-07-09 lifetime-PnL over-inflation incident. Lifetime
|
|
81
|
+
* PnL is `currentPosition + totalWithdrawn - totalDeposited`. Every
|
|
82
|
+
* history-fetch failure (deleted subgraph, subgraph deployed against the wrong
|
|
83
|
+
* ABI, missing archive backfill, deposits indexed on a different
|
|
84
|
+
* chain/contract) collapses the deposit/withdrawal history to empty. With
|
|
85
|
+
* `deposited = 0` and `withdrawn = 0` but a live on-chain `position > 0`, the
|
|
86
|
+
* formula degenerates to reporting the entire position as profit. Throwing this
|
|
87
|
+
* typed error makes that unrecoverable state fail loudly instead of returning
|
|
88
|
+
* an inflated number that looks plausible.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* try {
|
|
93
|
+
* await sdk.vaults.getVaultUserLifetimePnl({ vault, wallet, options });
|
|
94
|
+
* } catch (err) {
|
|
95
|
+
* if (err instanceof UpshiftHistoryUnavailableError) {
|
|
96
|
+
* // History backfill is broken — surface "temporarily unavailable",
|
|
97
|
+
* // never a fabricated PnL number.
|
|
98
|
+
* showUnavailable(err.context);
|
|
99
|
+
* } else throw err;
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class UpshiftHistoryUnavailableError extends UpshiftSDKError {
|
|
104
|
+
/**
|
|
105
|
+
* @param message - Human-readable description of the missing history. Callers
|
|
106
|
+
* pass the same `#<method>::<vault>::<wallet>` prefix the surrounding getter
|
|
107
|
+
* uses so log grouping stays consistent.
|
|
108
|
+
* @param options - Standard SDK error options. `context` should carry the
|
|
109
|
+
* `{ vault, wallet }` (or equivalent) identifiers that scope the failure.
|
|
110
|
+
*/
|
|
111
|
+
constructor(message: string, options?: UpshiftErrorOptions);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The USD price needed to convert a computed value could not be resolved, so
|
|
115
|
+
* any USD figure derived from it would be fabricated rather than merely
|
|
116
|
+
* missing.
|
|
117
|
+
*
|
|
118
|
+
* Motivation — `getVaultUserLifetimePnl` used to substitute a price of `1`
|
|
119
|
+
* whenever the price server returned nothing, which reported every
|
|
120
|
+
* USD field of a non-dollar vault (lsETH, tETH, BTC) at $1 per asset: a
|
|
121
|
+
* position worth ~$40k read as ~$13, indistinguishable from a real result.
|
|
122
|
+
* Throwing this typed error makes a missing price explicit so callers can hide
|
|
123
|
+
* the USD value instead of displaying a wrong one.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* try {
|
|
128
|
+
* await sdk.getVaultUserLifetimePnl({ vault, wallet, chainId });
|
|
129
|
+
* } catch (err) {
|
|
130
|
+
* if (err instanceof UpshiftPriceUnavailableError) {
|
|
131
|
+
* // No USD price for the vault asset — hide the USD figures rather than
|
|
132
|
+
* // show a fabricated one.
|
|
133
|
+
* hideUsd(err.context);
|
|
134
|
+
* } else throw err;
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare class UpshiftPriceUnavailableError extends UpshiftSDKError {
|
|
139
|
+
/**
|
|
140
|
+
* @param message - Human-readable description of the missing price. Callers
|
|
141
|
+
* pass the same `#<method>::<vault>::<wallet>` prefix the surrounding getter
|
|
142
|
+
* uses so log grouping stays consistent.
|
|
143
|
+
* @param options - Standard SDK error options. `context` should carry the
|
|
144
|
+
* identifiers that scope the failure (e.g. `{ vault, wallet, asset }`).
|
|
145
|
+
*/
|
|
146
|
+
constructor(message: string, options?: UpshiftErrorOptions);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A transaction was sent but its outcome could not be established
|
|
150
|
+
* (`TRANSACTION_UNCONFIRMED`). It may have landed: check {@link signature}
|
|
151
|
+
* before resubmitting, or a deposit or redeem can execute twice.
|
|
152
|
+
* `context.reason` says what was seen (e.g. `expired_not_found`: the blockhash
|
|
153
|
+
* expired and no lookup found it, so it very likely never landed).
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* try {
|
|
158
|
+
* await sdk.solana.vaultDeposit(programId, idl, wallet, amount, undefined, vault);
|
|
159
|
+
* } catch (err) {
|
|
160
|
+
* if (err instanceof UpshiftTransactionError) showPending(err.signature);
|
|
161
|
+
* else throw err;
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare class UpshiftTransactionError extends UpshiftSDKError {
|
|
166
|
+
/** Signature of the transaction that was sent. */
|
|
167
|
+
readonly signature: string;
|
|
168
|
+
/**
|
|
169
|
+
* @param message - Human-readable description, naming the signature.
|
|
170
|
+
* @param signature - Signature of the transaction that was sent.
|
|
171
|
+
* @param options - Standard SDK error options.
|
|
172
|
+
*/
|
|
173
|
+
constructor(message: string, signature: string, options?: UpshiftErrorOptions);
|
|
174
|
+
toJSON(): Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
/** Type guard. Works across realms (e.g. Web Worker / VM contexts). */
|
|
177
|
+
export declare function isUpshiftSDKError(err: unknown): err is UpshiftSDKError;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error class hierarchy for the SDK. All subclasses extend `UpshiftSDKError`,
|
|
4
|
+
* which extends the native `Error`.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { UpshiftAuthError, UpshiftTimeoutError } from '@upshiftfinance/sdk';
|
|
8
|
+
*
|
|
9
|
+
* try {
|
|
10
|
+
* await sdk.getVault(...);
|
|
11
|
+
* } catch (err) {
|
|
12
|
+
* if (err instanceof UpshiftAuthError) refreshKey();
|
|
13
|
+
* else if (err instanceof UpshiftTimeoutError) retry();
|
|
14
|
+
* else throw err;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.UpshiftTransactionError = exports.UpshiftPriceUnavailableError = exports.UpshiftHistoryUnavailableError = exports.UpshiftServerError = exports.UpshiftRateLimitError = exports.UpshiftValidationError = exports.UpshiftTimeoutError = exports.UpshiftNetworkError = exports.UpshiftAuthError = exports.UpshiftSDKError = void 0;
|
|
20
|
+
exports.isUpshiftSDKError = isUpshiftSDKError;
|
|
21
|
+
/** Base class for all SDK errors. */
|
|
22
|
+
class UpshiftSDKError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
correlationId;
|
|
25
|
+
context;
|
|
26
|
+
constructor(code, message, options = {}) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'UpshiftSDKError';
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.correlationId = options.correlationId;
|
|
31
|
+
this.context = options.context;
|
|
32
|
+
if (options.cause !== undefined) {
|
|
33
|
+
this.cause = options.cause;
|
|
34
|
+
}
|
|
35
|
+
// Restore prototype chain for transpilation targets that downlevel `extends Error`.
|
|
36
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Serialize own properties to a plain object. Native `Error` enumerates
|
|
40
|
+
* nothing, so `JSON.stringify(err)` returns `"{}"` without this.
|
|
41
|
+
*/
|
|
42
|
+
toJSON() {
|
|
43
|
+
const out = {
|
|
44
|
+
name: this.name,
|
|
45
|
+
message: this.message,
|
|
46
|
+
code: this.code,
|
|
47
|
+
};
|
|
48
|
+
if (this.correlationId !== undefined)
|
|
49
|
+
out.correlationId = this.correlationId;
|
|
50
|
+
if (this.context !== undefined)
|
|
51
|
+
out.context = this.context;
|
|
52
|
+
if (this.stack !== undefined)
|
|
53
|
+
out.stack = this.stack;
|
|
54
|
+
const cause = this.cause;
|
|
55
|
+
if (cause !== undefined) {
|
|
56
|
+
out.cause =
|
|
57
|
+
cause instanceof Error
|
|
58
|
+
? { name: cause.name, message: cause.message }
|
|
59
|
+
: cause;
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.UpshiftSDKError = UpshiftSDKError;
|
|
65
|
+
/** Authentication/authorization failure: missing key, invalid key, forbidden. */
|
|
66
|
+
class UpshiftAuthError extends UpshiftSDKError {
|
|
67
|
+
constructor(code, message, options) {
|
|
68
|
+
super(code, message, options);
|
|
69
|
+
this.name = 'UpshiftAuthError';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.UpshiftAuthError = UpshiftAuthError;
|
|
73
|
+
/** Network-level failure: connection refused, DNS, fetch failed. */
|
|
74
|
+
class UpshiftNetworkError extends UpshiftSDKError {
|
|
75
|
+
constructor(message, options) {
|
|
76
|
+
super('NETWORK_ERROR', message, options);
|
|
77
|
+
this.name = 'UpshiftNetworkError';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.UpshiftNetworkError = UpshiftNetworkError;
|
|
81
|
+
/** Request exceeded its deadline. */
|
|
82
|
+
class UpshiftTimeoutError extends UpshiftSDKError {
|
|
83
|
+
/** Time elapsed (ms) before the request was aborted. */
|
|
84
|
+
timeoutMs;
|
|
85
|
+
constructor(message, timeoutMs, options) {
|
|
86
|
+
super('TIMEOUT', message, options);
|
|
87
|
+
this.name = 'UpshiftTimeoutError';
|
|
88
|
+
this.timeoutMs = timeoutMs;
|
|
89
|
+
}
|
|
90
|
+
toJSON() {
|
|
91
|
+
return { ...super.toJSON(), timeoutMs: this.timeoutMs };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.UpshiftTimeoutError = UpshiftTimeoutError;
|
|
95
|
+
/** Caller-side input failed validation. */
|
|
96
|
+
class UpshiftValidationError extends UpshiftSDKError {
|
|
97
|
+
constructor(code, message, options) {
|
|
98
|
+
super(code, message, options);
|
|
99
|
+
this.name = 'UpshiftValidationError';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.UpshiftValidationError = UpshiftValidationError;
|
|
103
|
+
/** Backend rate-limited the request (HTTP 429 or equivalent). */
|
|
104
|
+
class UpshiftRateLimitError extends UpshiftSDKError {
|
|
105
|
+
/** Suggested wait before retrying, in milliseconds. */
|
|
106
|
+
retryAfterMs;
|
|
107
|
+
constructor(message, options) {
|
|
108
|
+
super('RATE_LIMITED', message, options);
|
|
109
|
+
this.name = 'UpshiftRateLimitError';
|
|
110
|
+
this.retryAfterMs = options?.retryAfterMs;
|
|
111
|
+
}
|
|
112
|
+
toJSON() {
|
|
113
|
+
const base = super.toJSON();
|
|
114
|
+
if (this.retryAfterMs !== undefined)
|
|
115
|
+
base.retryAfterMs = this.retryAfterMs;
|
|
116
|
+
return base;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.UpshiftRateLimitError = UpshiftRateLimitError;
|
|
120
|
+
/** Backend returned a non-OK status that isn't auth, rate-limit, or timeout. */
|
|
121
|
+
class UpshiftServerError extends UpshiftSDKError {
|
|
122
|
+
/** HTTP status code returned by the backend. */
|
|
123
|
+
status;
|
|
124
|
+
constructor(status, message, options) {
|
|
125
|
+
super('SERVER_ERROR', message, options);
|
|
126
|
+
this.name = 'UpshiftServerError';
|
|
127
|
+
this.status = status;
|
|
128
|
+
}
|
|
129
|
+
toJSON() {
|
|
130
|
+
return { ...super.toJSON(), status: this.status };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.UpshiftServerError = UpshiftServerError;
|
|
134
|
+
/**
|
|
135
|
+
* Transaction/position history required to compute a value could not be
|
|
136
|
+
* retrieved or was empty, so the computed result would be wrong rather than
|
|
137
|
+
* merely missing.
|
|
138
|
+
*
|
|
139
|
+
* Motivation — the 2026-07-09 lifetime-PnL over-inflation incident. Lifetime
|
|
140
|
+
* PnL is `currentPosition + totalWithdrawn - totalDeposited`. Every
|
|
141
|
+
* history-fetch failure (deleted subgraph, subgraph deployed against the wrong
|
|
142
|
+
* ABI, missing archive backfill, deposits indexed on a different
|
|
143
|
+
* chain/contract) collapses the deposit/withdrawal history to empty. With
|
|
144
|
+
* `deposited = 0` and `withdrawn = 0` but a live on-chain `position > 0`, the
|
|
145
|
+
* formula degenerates to reporting the entire position as profit. Throwing this
|
|
146
|
+
* typed error makes that unrecoverable state fail loudly instead of returning
|
|
147
|
+
* an inflated number that looks plausible.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* try {
|
|
152
|
+
* await sdk.vaults.getVaultUserLifetimePnl({ vault, wallet, options });
|
|
153
|
+
* } catch (err) {
|
|
154
|
+
* if (err instanceof UpshiftHistoryUnavailableError) {
|
|
155
|
+
* // History backfill is broken — surface "temporarily unavailable",
|
|
156
|
+
* // never a fabricated PnL number.
|
|
157
|
+
* showUnavailable(err.context);
|
|
158
|
+
* } else throw err;
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
class UpshiftHistoryUnavailableError extends UpshiftSDKError {
|
|
163
|
+
/**
|
|
164
|
+
* @param message - Human-readable description of the missing history. Callers
|
|
165
|
+
* pass the same `#<method>::<vault>::<wallet>` prefix the surrounding getter
|
|
166
|
+
* uses so log grouping stays consistent.
|
|
167
|
+
* @param options - Standard SDK error options. `context` should carry the
|
|
168
|
+
* `{ vault, wallet }` (or equivalent) identifiers that scope the failure.
|
|
169
|
+
*/
|
|
170
|
+
constructor(message, options) {
|
|
171
|
+
super('HISTORY_UNAVAILABLE', message, options);
|
|
172
|
+
this.name = 'UpshiftHistoryUnavailableError';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.UpshiftHistoryUnavailableError = UpshiftHistoryUnavailableError;
|
|
176
|
+
/**
|
|
177
|
+
* The USD price needed to convert a computed value could not be resolved, so
|
|
178
|
+
* any USD figure derived from it would be fabricated rather than merely
|
|
179
|
+
* missing.
|
|
180
|
+
*
|
|
181
|
+
* Motivation — `getVaultUserLifetimePnl` used to substitute a price of `1`
|
|
182
|
+
* whenever the price server returned nothing, which reported every
|
|
183
|
+
* USD field of a non-dollar vault (lsETH, tETH, BTC) at $1 per asset: a
|
|
184
|
+
* position worth ~$40k read as ~$13, indistinguishable from a real result.
|
|
185
|
+
* Throwing this typed error makes a missing price explicit so callers can hide
|
|
186
|
+
* the USD value instead of displaying a wrong one.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* try {
|
|
191
|
+
* await sdk.getVaultUserLifetimePnl({ vault, wallet, chainId });
|
|
192
|
+
* } catch (err) {
|
|
193
|
+
* if (err instanceof UpshiftPriceUnavailableError) {
|
|
194
|
+
* // No USD price for the vault asset — hide the USD figures rather than
|
|
195
|
+
* // show a fabricated one.
|
|
196
|
+
* hideUsd(err.context);
|
|
197
|
+
* } else throw err;
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
class UpshiftPriceUnavailableError extends UpshiftSDKError {
|
|
202
|
+
/**
|
|
203
|
+
* @param message - Human-readable description of the missing price. Callers
|
|
204
|
+
* pass the same `#<method>::<vault>::<wallet>` prefix the surrounding getter
|
|
205
|
+
* uses so log grouping stays consistent.
|
|
206
|
+
* @param options - Standard SDK error options. `context` should carry the
|
|
207
|
+
* identifiers that scope the failure (e.g. `{ vault, wallet, asset }`).
|
|
208
|
+
*/
|
|
209
|
+
constructor(message, options) {
|
|
210
|
+
super('PRICE_UNAVAILABLE', message, options);
|
|
211
|
+
this.name = 'UpshiftPriceUnavailableError';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.UpshiftPriceUnavailableError = UpshiftPriceUnavailableError;
|
|
215
|
+
/**
|
|
216
|
+
* A transaction was sent but its outcome could not be established
|
|
217
|
+
* (`TRANSACTION_UNCONFIRMED`). It may have landed: check {@link signature}
|
|
218
|
+
* before resubmitting, or a deposit or redeem can execute twice.
|
|
219
|
+
* `context.reason` says what was seen (e.g. `expired_not_found`: the blockhash
|
|
220
|
+
* expired and no lookup found it, so it very likely never landed).
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* try {
|
|
225
|
+
* await sdk.solana.vaultDeposit(programId, idl, wallet, amount, undefined, vault);
|
|
226
|
+
* } catch (err) {
|
|
227
|
+
* if (err instanceof UpshiftTransactionError) showPending(err.signature);
|
|
228
|
+
* else throw err;
|
|
229
|
+
* }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
class UpshiftTransactionError extends UpshiftSDKError {
|
|
233
|
+
/** Signature of the transaction that was sent. */
|
|
234
|
+
signature;
|
|
235
|
+
/**
|
|
236
|
+
* @param message - Human-readable description, naming the signature.
|
|
237
|
+
* @param signature - Signature of the transaction that was sent.
|
|
238
|
+
* @param options - Standard SDK error options.
|
|
239
|
+
*/
|
|
240
|
+
constructor(message, signature, options) {
|
|
241
|
+
super('TRANSACTION_UNCONFIRMED', message, options);
|
|
242
|
+
this.name = 'UpshiftTransactionError';
|
|
243
|
+
this.signature = signature;
|
|
244
|
+
}
|
|
245
|
+
toJSON() {
|
|
246
|
+
return { ...super.toJSON(), signature: this.signature };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.UpshiftTransactionError = UpshiftTransactionError;
|
|
250
|
+
/** Type guard. Works across realms (e.g. Web Worker / VM contexts). */
|
|
251
|
+
function isUpshiftSDKError(err) {
|
|
252
|
+
return (err instanceof UpshiftSDKError ||
|
|
253
|
+
(err instanceof Error &&
|
|
254
|
+
typeof err.code === 'string' &&
|
|
255
|
+
err.name.startsWith('Upshift')));
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=index.js.map
|