@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,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Stellar Transaction Submission
|
|
4
|
+
*
|
|
5
|
+
* Submits signed Soroban transactions and polls for confirmation.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.submitStellarTransaction = submitStellarTransaction;
|
|
9
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
10
|
+
const core_1 = require("../../core");
|
|
11
|
+
const curator_alert_1 = require("../../core/logger/curator-alert");
|
|
12
|
+
const soroban_1 = require("./soroban");
|
|
13
|
+
const invocation_1 = require("./invocation");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
/**
|
|
16
|
+
* Best-effort decode of the transaction-level result code (the XDR union
|
|
17
|
+
* discriminant, e.g. `"txBadSeq"`, `"txTooLate"`) from a Soroban
|
|
18
|
+
* `TransactionResult`. Typed `unknown` and probed structurally so it stays
|
|
19
|
+
* robust to RPC/SDK shape drift; returns `undefined` for anything that isn't a
|
|
20
|
+
* decoded union, so callers fall back to the stringified XDR in the message.
|
|
21
|
+
*/
|
|
22
|
+
function extractTxResultCode(result) {
|
|
23
|
+
try {
|
|
24
|
+
const decoded = result;
|
|
25
|
+
if (typeof decoded?.result !== 'function')
|
|
26
|
+
return undefined;
|
|
27
|
+
// `|| undefined`: an empty discriminant shares the clean "no code" path.
|
|
28
|
+
return decoded.result().switch().name || undefined;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// Only reached on a malformed / shape-drifted union (the non-union case
|
|
32
|
+
// already returned above). Breadcrumb it so decoder rot stays detectable;
|
|
33
|
+
// the caller still throws with the stringified XDR in the message.
|
|
34
|
+
core_1.Logger.log.warn('extractTxResultCode', { decodeError: String(e) });
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `JSON.stringify` that never throws. A real `xdr.TransactionResult` can hold
|
|
40
|
+
* `bigint` fields (e.g. `feeCharged`), which make `JSON.stringify` throw a
|
|
41
|
+
* `TypeError` — that would escape and replace the `UpshiftSDKError` this detail
|
|
42
|
+
* is only meant to enrich. Returns `''` on failure so the caller falls back to
|
|
43
|
+
* the status; the decoded `resultCode` still carries the precise reason.
|
|
44
|
+
*/
|
|
45
|
+
function safeStringify(value) {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.stringify(value) ?? '';
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Submit a signed Soroban transaction and poll until confirmed.
|
|
55
|
+
*
|
|
56
|
+
* @param signedXdr - Base64-encoded XDR of the signed transaction
|
|
57
|
+
* @param network - Stellar network name
|
|
58
|
+
* @param sorobanRpcUrl - Optional override Soroban RPC endpoint (e.g. a keyed
|
|
59
|
+
* Alchemy URL); becomes the primary with the SDK's public endpoints kept as
|
|
60
|
+
* failover. Omit to use the public endpoints.
|
|
61
|
+
* @returns The transaction hash once the network confirms it as successful
|
|
62
|
+
* @throws {@link UpshiftTimeoutError} when the transaction is not confirmed
|
|
63
|
+
* within the poll budget (`MAX_POLL_ATTEMPTS`).
|
|
64
|
+
* @throws {@link UpshiftSDKError} when the RPC rejects the submission or the
|
|
65
|
+
* transaction confirms as failed. Its `context` carries `{ network, status }`
|
|
66
|
+
* plus, when the result XDR decodes, a `resultCode` string holding the
|
|
67
|
+
* transaction-level reason (e.g. `"txBadSeq"`, `"txTooLate"`); `resultCode`
|
|
68
|
+
* is `undefined` when the code cannot be decoded.
|
|
69
|
+
*
|
|
70
|
+
* Side effect: a transaction whose `resultCode` is `txFailed` — the operation
|
|
71
|
+
* itself ran and failed — and whose envelope shows a vault `redeem` is relayed
|
|
72
|
+
* to that vault's curator (fire-and-forget, deduped — see
|
|
73
|
+
* {@link reportRedeemFailure}). Nothing else alerts: an RPC-rejected
|
|
74
|
+
* broadcast is a retryable race, a poll timeout is indeterminate (the
|
|
75
|
+
* transaction may yet succeed), and any other result code means the redeem
|
|
76
|
+
* never executed.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* try {
|
|
80
|
+
* const hash = await submitStellarTransaction(signedXdr, 'mainnet');
|
|
81
|
+
* } catch (err) {
|
|
82
|
+
* if (err instanceof UpshiftSDKError && err.context?.resultCode === 'txBadSeq') {
|
|
83
|
+
* // stale sequence number — rebuild the transaction and resubmit
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
async function submitStellarTransaction(signedXdr, network, sorobanRpcUrl) {
|
|
89
|
+
const config = (0, soroban_1.resolveNetworkConfig)(network, sorobanRpcUrl);
|
|
90
|
+
const { passphrase } = config;
|
|
91
|
+
const server = await (0, soroban_1.getHealthyServer)(config);
|
|
92
|
+
const tx = stellar_sdk_1.TransactionBuilder.fromXDR(signedXdr, passphrase);
|
|
93
|
+
const sendResult = await server.sendTransaction(tx);
|
|
94
|
+
if (sendResult.status === 'ERROR') {
|
|
95
|
+
const errorResult = 'errorResult' in sendResult ? sendResult.errorResult : undefined;
|
|
96
|
+
const resultCode = extractTxResultCode(errorResult);
|
|
97
|
+
const detail = errorResult ? safeStringify(errorResult) : '';
|
|
98
|
+
const msg = `Transaction submission failed: ${detail || sendResult.status}`;
|
|
99
|
+
core_1.Logger.log.error('submitStellarTransaction', msg, { network, resultCode });
|
|
100
|
+
throw new core_1.UpshiftSDKError('UNKNOWN', msg, {
|
|
101
|
+
context: { network, status: sendResult.status, resultCode },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Only PENDING (and DUPLICATE) mean the tx was accepted by the RPC.
|
|
105
|
+
// DUPLICATE means this exact transaction was already submitted — it may
|
|
106
|
+
// already be confirmed or still pending from a prior submission.
|
|
107
|
+
// TRY_AGAIN_LATER and any other status should be surfaced immediately
|
|
108
|
+
// so callers can retry submission instead of waiting for a poll timeout.
|
|
109
|
+
if (sendResult.status !== 'PENDING' && sendResult.status !== 'DUPLICATE') {
|
|
110
|
+
const msg = `Transaction not accepted by RPC (status: ${sendResult.status}). ` +
|
|
111
|
+
'This may be retryable — the RPC node could be overloaded.';
|
|
112
|
+
core_1.Logger.log.error('submitStellarTransaction', msg, { network });
|
|
113
|
+
throw new core_1.UpshiftSDKError('UNKNOWN', msg, {
|
|
114
|
+
context: { network, status: sendResult.status },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// Geometric backoff (start POLL_INTERVAL_MS, ×POLL_INTERVAL_BACKOFF up to
|
|
118
|
+
// POLL_INTERVAL_MAX_MS) — fast on the happy path, gentler on slow ledgers.
|
|
119
|
+
let getResult = await server.getTransaction(sendResult.hash);
|
|
120
|
+
let polls = 0;
|
|
121
|
+
let nextDelay = constants_1.POLL_INTERVAL_MS;
|
|
122
|
+
while (getResult.status === 'NOT_FOUND') {
|
|
123
|
+
if (++polls >= constants_1.MAX_POLL_ATTEMPTS) {
|
|
124
|
+
const msg = `Transaction ${sendResult.hash} not confirmed after ${constants_1.MAX_POLL_ATTEMPTS} poll attempts`;
|
|
125
|
+
core_1.Logger.log.error('submitStellarTransaction', msg, {
|
|
126
|
+
hash: sendResult.hash,
|
|
127
|
+
network,
|
|
128
|
+
});
|
|
129
|
+
throw new core_1.UpshiftTimeoutError(msg, constants_1.POLL_INTERVAL_MAX_MS * polls, {
|
|
130
|
+
context: { hash: sendResult.hash, network },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
await new Promise((r) => setTimeout(r, nextDelay));
|
|
134
|
+
nextDelay = Math.min(Math.round(nextDelay * constants_1.POLL_INTERVAL_BACKOFF), constants_1.POLL_INTERVAL_MAX_MS);
|
|
135
|
+
getResult = await server.getTransaction(sendResult.hash);
|
|
136
|
+
}
|
|
137
|
+
if (getResult.status === 'SUCCESS') {
|
|
138
|
+
return sendResult.hash;
|
|
139
|
+
}
|
|
140
|
+
const resultXdr = 'resultXdr' in getResult ? getResult.resultXdr : undefined;
|
|
141
|
+
const resultCode = extractTxResultCode(resultXdr);
|
|
142
|
+
const detail = resultXdr ? safeStringify(resultXdr) : '';
|
|
143
|
+
const failDetail = detail ? ` (${detail})` : '';
|
|
144
|
+
const msg = `Transaction failed: ${getResult.status}${failDetail}`;
|
|
145
|
+
core_1.Logger.log.error('submitStellarTransaction', msg, {
|
|
146
|
+
hash: sendResult.hash,
|
|
147
|
+
network,
|
|
148
|
+
resultCode,
|
|
149
|
+
});
|
|
150
|
+
// A redemption that executed and failed is the strongest form of the signal
|
|
151
|
+
// the curator needs — and the only one carrying a hash the relay can verify
|
|
152
|
+
// on chain. Two gates, because a FAILED confirmation is not by itself a vault
|
|
153
|
+
// failure:
|
|
154
|
+
// - `txFailed` is the only result code meaning the operations were applied
|
|
155
|
+
// and one of them failed. Everything else at this layer is
|
|
156
|
+
// transaction-level — `txBadSeq`, `txInsufficientBalance`,
|
|
157
|
+
// `txTooLate`, resource-limit overruns — where the redeem never ran, and
|
|
158
|
+
// which the caller resolves by retrying. An undecodable code is treated
|
|
159
|
+
// the same way: without it we cannot tell the two apart, and silence
|
|
160
|
+
// beats paging a curator over a sequence-number race.
|
|
161
|
+
// - the envelope must actually be a redeem: this function is handed an
|
|
162
|
+
// opaque XDR and would otherwise misattribute deposits.
|
|
163
|
+
const invocation = resultCode === 'txFailed' ? (0, invocation_1.describeVaultInvocation)(tx) : undefined;
|
|
164
|
+
// A partially-decoded envelope is not reported at all: an alert naming no
|
|
165
|
+
// wallet or no amount is one a curator cannot act on, and the reporting
|
|
166
|
+
// endpoint rejects it anyway.
|
|
167
|
+
const redeemer = invocation?.owner ?? invocation?.receiver;
|
|
168
|
+
if (invocation?.functionName === 'redeem' &&
|
|
169
|
+
redeemer &&
|
|
170
|
+
invocation.amountRaw) {
|
|
171
|
+
(0, curator_alert_1.reportRedeemFailure)({
|
|
172
|
+
phase: 'submission',
|
|
173
|
+
chain: 'stellar',
|
|
174
|
+
network,
|
|
175
|
+
contractId: invocation.contractId,
|
|
176
|
+
// `owner` is the account whose shares burn; `receiver` only receives the
|
|
177
|
+
// assets. They are the same for a self-redeem, and owner is the right one
|
|
178
|
+
// to name when they differ.
|
|
179
|
+
eoa: redeemer,
|
|
180
|
+
sharesRaw: invocation.amountRaw,
|
|
181
|
+
txHash: sendResult.hash,
|
|
182
|
+
resultCode,
|
|
183
|
+
error: msg,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
throw new core_1.UpshiftSDKError('UNKNOWN', msg, {
|
|
187
|
+
context: {
|
|
188
|
+
hash: sendResult.hash,
|
|
189
|
+
network,
|
|
190
|
+
status: getResult.status,
|
|
191
|
+
resultCode,
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=submit.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar Vault Types
|
|
3
|
+
*/
|
|
4
|
+
import type { IStellarNetwork } from '../../types/web3';
|
|
5
|
+
export type { IStellarNetwork };
|
|
6
|
+
/** Parameters for building an unsigned Stellar vault deposit transaction. */
|
|
7
|
+
export interface IStellarDepositParams {
|
|
8
|
+
contractId: string;
|
|
9
|
+
amount: string;
|
|
10
|
+
senderAddress: string;
|
|
11
|
+
network: IStellarNetwork;
|
|
12
|
+
/**
|
|
13
|
+
* Optional override Soroban RPC endpoint (e.g. a keyed Alchemy URL). When set
|
|
14
|
+
* it is the primary, with the SDK's public endpoints kept behind it as
|
|
15
|
+
* failover.
|
|
16
|
+
*/
|
|
17
|
+
sorobanRpcUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Parameters for building an unsigned Stellar vault redeem transaction. */
|
|
20
|
+
export interface IStellarRedeemParams {
|
|
21
|
+
contractId: string;
|
|
22
|
+
shares: string;
|
|
23
|
+
receiverAddress: string;
|
|
24
|
+
network: IStellarNetwork;
|
|
25
|
+
/**
|
|
26
|
+
* Optional override Soroban RPC endpoint (e.g. a keyed Alchemy URL). When set
|
|
27
|
+
* it is the primary, with the SDK's public endpoints kept behind it as
|
|
28
|
+
* failover.
|
|
29
|
+
*/
|
|
30
|
+
sorobanRpcUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* User vault position returned by on-chain balance queries.
|
|
34
|
+
*
|
|
35
|
+
* `decimals` carries the share-token scale used to interpret `shares`. When the
|
|
36
|
+
* on-chain `decimals()` read fails, it falls back to STELLAR_FALLBACK_DECIMALS
|
|
37
|
+
* (7) and `decimalsFromFallback` is set to `true`. Callers that size a redeem
|
|
38
|
+
* from this position MUST check `decimalsFromFallback` and refuse to settle
|
|
39
|
+
* when it is `true` — trusting a fabricated 7 against an ERC4626 offset vault
|
|
40
|
+
* (share decimals = asset + offset) under-redeems by `10^offset`.
|
|
41
|
+
*/
|
|
42
|
+
export interface IStellarUserPosition {
|
|
43
|
+
/** Raw share balance in smallest unit, as a non-negative integer string */
|
|
44
|
+
shares: string;
|
|
45
|
+
/** Share-token decimals; may be the fallback — see `decimalsFromFallback`. */
|
|
46
|
+
decimals: number;
|
|
47
|
+
/**
|
|
48
|
+
* `true` when `decimals` is the fallback (the on-chain `decimals()` read
|
|
49
|
+
* failed), `false` when it is the authoritative on-chain value. Treat `true`
|
|
50
|
+
* as a decimals read failure: do not trust `decimals` to scale or redeem.
|
|
51
|
+
*
|
|
52
|
+
* Optional for source back-compat (a consumer's existing object literal still
|
|
53
|
+
* compiles), but `getStellarUserPosition` always populates it — so a position
|
|
54
|
+
* obtained from the SDK never omits it.
|
|
55
|
+
*/
|
|
56
|
+
decimalsFromFallback?: boolean;
|
|
57
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar Utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { IStellarNetwork } from './types';
|
|
5
|
+
import { isStellarAddress } from '../../core/helpers/chain-address';
|
|
6
|
+
export { isStellarAddress };
|
|
7
|
+
/**
|
|
8
|
+
* Get the Stellar explorer URL for a given address or transaction.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getExplorerLink({ id, type, network, }: {
|
|
11
|
+
id: string;
|
|
12
|
+
type?: 'contract' | 'account' | 'tx';
|
|
13
|
+
network?: IStellarNetwork;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* Throw if the given address is a Stellar address.
|
|
17
|
+
* Used as a guard in vault operations that don't yet support Stellar.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertNotStellar(address: string, operation: string): void;
|
|
20
|
+
export declare const StellarUtils: {
|
|
21
|
+
isStellarAddress: typeof isStellarAddress;
|
|
22
|
+
getExplorerLink: typeof getExplorerLink;
|
|
23
|
+
assertNotStellar: typeof assertNotStellar;
|
|
24
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Stellar Utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StellarUtils = exports.isStellarAddress = void 0;
|
|
7
|
+
exports.getExplorerLink = getExplorerLink;
|
|
8
|
+
exports.assertNotStellar = assertNotStellar;
|
|
9
|
+
const core_1 = require("../../core");
|
|
10
|
+
const chain_address_1 = require("../../core/helpers/chain-address");
|
|
11
|
+
Object.defineProperty(exports, "isStellarAddress", { enumerable: true, get: function () { return chain_address_1.isStellarAddress; } });
|
|
12
|
+
/**
|
|
13
|
+
* Get the Stellar explorer URL for a given address or transaction.
|
|
14
|
+
*/
|
|
15
|
+
function getExplorerLink({ id, type = 'contract', network = 'mainnet', }) {
|
|
16
|
+
const baseUrl = 'https://stellar.expert/explorer';
|
|
17
|
+
const net = network === 'mainnet' ? 'public' : 'testnet';
|
|
18
|
+
return `${baseUrl}/${net}/${type}/${id}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Throw if the given address is a Stellar address.
|
|
22
|
+
* Used as a guard in vault operations that don't yet support Stellar.
|
|
23
|
+
*/
|
|
24
|
+
function assertNotStellar(address, operation) {
|
|
25
|
+
if ((0, chain_address_1.isStellarAddress)(address)) {
|
|
26
|
+
throw new core_1.UpshiftValidationError('INVALID_CHAIN', `${operation} is not yet supported for Stellar vaults: ${address}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.StellarUtils = {
|
|
30
|
+
isStellarAddress: chain_address_1.isStellarAddress,
|
|
31
|
+
getExplorerLink,
|
|
32
|
+
assertNotStellar,
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SUI_CHAIN_ID } from '../../core/constants/web3';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUI_CHAIN_ID = void 0;
|
|
4
|
+
// Canonical definition lives in `core/constants/web3.ts` so `core/` can
|
|
5
|
+
// recognise the Sui chain ID without importing the adapter layer. Re-exported
|
|
6
|
+
// here to keep `adapters/sui/constants` import sites unchanged.
|
|
7
|
+
var web3_1 = require("../../core/constants/web3");
|
|
8
|
+
Object.defineProperty(exports, "SUI_CHAIN_ID", { enumerable: true, get: function () { return web3_1.SUI_CHAIN_ID; } });
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IEmberVault, IFetchEmberVaultsOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetch Ember vaults from API.
|
|
4
|
+
*
|
|
5
|
+
* Results are cached for {@link EMBER_CACHE_TTL_MS} (keyed by the full request
|
|
6
|
+
* URL, so different query options cache independently) and the request is
|
|
7
|
+
* aborted after {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts —
|
|
8
|
+
* are never cached and resolve to `[]`, preserving the long-standing
|
|
9
|
+
* fail-tolerant contract of this getter.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getEmberVaults(options?: IFetchEmberVaultsOptions): Promise<IEmberVault[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch the latest Ember TVL (in whole units, i.e. `tvlE9 / 1e9`).
|
|
14
|
+
*
|
|
15
|
+
* Shares the timeout and cache of {@link getEmberVaults} via
|
|
16
|
+
* {@link fetchEmberArray}: the TVL history payload is cached for
|
|
17
|
+
* {@link EMBER_CACHE_TTL_MS} per `limit`, and a hung request is aborted after
|
|
18
|
+
* {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts — are never
|
|
19
|
+
* cached and resolve to `0`.
|
|
20
|
+
*
|
|
21
|
+
* @param limit - Number of history rows to request; only the newest is read.
|
|
22
|
+
* @returns The latest TVL, or `0` when unavailable.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEmberTVL(limit?: number): Promise<number>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEmberVaults = getEmberVaults;
|
|
4
|
+
exports.getEmberTVL = getEmberTVL;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const core_1 = require("../../core");
|
|
7
|
+
const cache_1 = require("../../core/cache");
|
|
8
|
+
const logger_1 = require("../../core/logger");
|
|
9
|
+
/**
|
|
10
|
+
* Hard ceiling on the Ember (Bluefin) vaults request. The endpoint is a
|
|
11
|
+
* third-party API awaited on the `getVaults` hot path; without a bound, a
|
|
12
|
+
* hung connection stalls every vault-list consumer indefinitely (the fetch
|
|
13
|
+
* options carry no signal and no timeout). Measured latency is 0.24–1.02s,
|
|
14
|
+
* so 5s is ~5× the observed worst case while still failing fast enough for
|
|
15
|
+
* callers racing `getVaults` against their own budgets.
|
|
16
|
+
*/
|
|
17
|
+
const EMBER_FETCH_TIMEOUT_MS = 5_000;
|
|
18
|
+
/**
|
|
19
|
+
* TTL for the cached Ember vaults payload. The set of active Ember vaults
|
|
20
|
+
* changes rarely (the SDK additionally filters it to a hardcoded allowlist),
|
|
21
|
+
* so 5 minutes matches the freshness of the other list-shaped caches without
|
|
22
|
+
* letting a stale payload outlive a delisting for long.
|
|
23
|
+
*/
|
|
24
|
+
const EMBER_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
25
|
+
/**
|
|
26
|
+
* GET an Ember endpoint as a JSON array, with the timeout + cache both Ember
|
|
27
|
+
* getters share.
|
|
28
|
+
*
|
|
29
|
+
* Why: `getEmberVaults` and `getEmberTVL` hit the same third-party API from
|
|
30
|
+
* the same hot paths, but only the former was bounded and cached — a hung TVL
|
|
31
|
+
* request stalled callers indefinitely. Centralising the plumbing keeps the
|
|
32
|
+
* two from drifting again.
|
|
33
|
+
*
|
|
34
|
+
* - Cached for {@link EMBER_CACHE_TTL_MS}, keyed by `cacheKey` (callers embed
|
|
35
|
+
* the full URL so different query options cache independently). Only
|
|
36
|
+
* successful array payloads are cached; failures are never cached.
|
|
37
|
+
* - Aborted after {@link EMBER_FETCH_TIMEOUT_MS}. AbortController (not
|
|
38
|
+
* AbortSignal.timeout) for browser + older-Node parity. The timer stays armed
|
|
39
|
+
* through the body read: `fetch` resolves as soon as headers arrive, so
|
|
40
|
+
* clearing it there would leave a stalled `json()` unbounded — the exact
|
|
41
|
+
* hang the ceiling exists to prevent.
|
|
42
|
+
*
|
|
43
|
+
* @param cacheKey - Shared-LRU key for this request.
|
|
44
|
+
* @param url - Fully-qualified Ember URL (query string included).
|
|
45
|
+
* @returns The parsed array, or `[]` when the endpoint returns a non-array.
|
|
46
|
+
* @throws On non-2xx responses, network failure, or timeout (AbortError) —
|
|
47
|
+
* callers own the fail-tolerant fallback.
|
|
48
|
+
*/
|
|
49
|
+
async function fetchEmberArray(cacheKey, url) {
|
|
50
|
+
// The shared LRU is constructed with `allowStale: true`; opt out here so a
|
|
51
|
+
// payload past its TTL is refetched rather than served one last time —
|
|
52
|
+
// keeping the 5-minute bound above an exact contract.
|
|
53
|
+
const cached = cache_1.CACHE.get(cacheKey, { allowStale: false });
|
|
54
|
+
if (cached)
|
|
55
|
+
return cached;
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const timer = setTimeout(() => controller.abort(), EMBER_FETCH_TIMEOUT_MS);
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(url, {
|
|
61
|
+
...core_1.DEFAULT_FETCH_OPTIONS,
|
|
62
|
+
signal: controller.signal,
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
66
|
+
}
|
|
67
|
+
data = await response.json();
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
}
|
|
72
|
+
const rows = Array.isArray(data) ? data : [];
|
|
73
|
+
cache_1.CACHE.set(cacheKey, rows, { ttl: EMBER_CACHE_TTL_MS });
|
|
74
|
+
return rows;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fetch Ember vaults from API.
|
|
78
|
+
*
|
|
79
|
+
* Results are cached for {@link EMBER_CACHE_TTL_MS} (keyed by the full request
|
|
80
|
+
* URL, so different query options cache independently) and the request is
|
|
81
|
+
* aborted after {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts —
|
|
82
|
+
* are never cached and resolve to `[]`, preserving the long-standing
|
|
83
|
+
* fail-tolerant contract of this getter.
|
|
84
|
+
*/
|
|
85
|
+
async function getEmberVaults(options) {
|
|
86
|
+
try {
|
|
87
|
+
const params = new URLSearchParams();
|
|
88
|
+
if (options?.limit)
|
|
89
|
+
params.append('limit', options.limit.toString());
|
|
90
|
+
if (options?.offset)
|
|
91
|
+
params.append('offset', options.offset.toString());
|
|
92
|
+
if (options?.status)
|
|
93
|
+
params.append('status', options.status);
|
|
94
|
+
const queryString = params.toString();
|
|
95
|
+
const url = `${constants_1.EMBER_API_BASE_URL}${queryString ? `?${queryString}` : ''}`;
|
|
96
|
+
return await fetchEmberArray(`ember-vaults-${url}`, url);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
logger_1.Logger.log.error('getEmberVaults', error);
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch the latest Ember TVL (in whole units, i.e. `tvlE9 / 1e9`).
|
|
105
|
+
*
|
|
106
|
+
* Shares the timeout and cache of {@link getEmberVaults} via
|
|
107
|
+
* {@link fetchEmberArray}: the TVL history payload is cached for
|
|
108
|
+
* {@link EMBER_CACHE_TTL_MS} per `limit`, and a hung request is aborted after
|
|
109
|
+
* {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts — are never
|
|
110
|
+
* cached and resolve to `0`.
|
|
111
|
+
*
|
|
112
|
+
* @param limit - Number of history rows to request; only the newest is read.
|
|
113
|
+
* @returns The latest TVL, or `0` when unavailable.
|
|
114
|
+
*/
|
|
115
|
+
async function getEmberTVL(limit = 1) {
|
|
116
|
+
try {
|
|
117
|
+
const params = new URLSearchParams();
|
|
118
|
+
if (limit)
|
|
119
|
+
params.append('limit', limit.toString());
|
|
120
|
+
const queryString = params.toString();
|
|
121
|
+
const url = `${constants_1.EMBER_API_BASE_URL}${constants_1.EMBER_ENDPOINTS.TVL}${queryString ? `?${queryString}` : ''}`;
|
|
122
|
+
const result = await fetchEmberArray(`ember-tvl-${url}`, url);
|
|
123
|
+
if (result.length > 0) {
|
|
124
|
+
const latestEntry = result[0];
|
|
125
|
+
return Number(latestEntry.tvlE9) / constants_1.EMBER_DEFAULTS.E9_DIVISOR;
|
|
126
|
+
}
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
logger_1.Logger.log.error('getEmberTVL', error);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=getters.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sui Adapter for Upshift SDK
|
|
3
|
+
*
|
|
4
|
+
* @module SuiAdapter
|
|
5
|
+
*/
|
|
6
|
+
import type { ISuiConfig, ISuiNetwork } from '../../types';
|
|
7
|
+
import * as SuiConstants from './constants';
|
|
8
|
+
import * as SuiUtils from './utils';
|
|
9
|
+
export declare const Sui: {
|
|
10
|
+
utils: typeof SuiUtils;
|
|
11
|
+
constants: typeof SuiConstants;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Sui Adapter for Upshift SDK.
|
|
15
|
+
*
|
|
16
|
+
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })` and the Sui
|
|
17
|
+
* chain-identity helpers. It makes no network calls.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const sdk = new UpshiftSDK({ appName: 'my-app', sui: { network: 'testnet' } });
|
|
22
|
+
* sdk.sui.network; // 'testnet'
|
|
23
|
+
* sdk.sui.isSuiAddress(vault.address);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare class SuiAdapter {
|
|
27
|
+
private readonly _config;
|
|
28
|
+
/**
|
|
29
|
+
* @param config - Optional Sui settings; omit to target Sui mainnet.
|
|
30
|
+
*/
|
|
31
|
+
constructor(config?: ISuiConfig);
|
|
32
|
+
/** The SDK's Sui chain ID, `-2` (same as the backend's `chain` for Sui vaults). */
|
|
33
|
+
get chainId(): number;
|
|
34
|
+
/** Configured Sui network; `'mainnet'` unless the SDK was built with another. */
|
|
35
|
+
get network(): ISuiNetwork;
|
|
36
|
+
/** Configured RPC endpoint override, or `undefined` when none was given. */
|
|
37
|
+
get rpcUrl(): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Check whether a string is a Sui address or object ID (`0x` + 64 hex chars).
|
|
40
|
+
*
|
|
41
|
+
* @param address - Candidate address.
|
|
42
|
+
* @returns `true` for the long, 64-hex-digit form only.
|
|
43
|
+
*/
|
|
44
|
+
isSuiAddress(address: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check whether a chain ID is Sui's (`-2`).
|
|
47
|
+
*
|
|
48
|
+
* @param chainId - Numeric chain ID, e.g. a backend vault row's `chain`.
|
|
49
|
+
* @returns `true` only for `-2`.
|
|
50
|
+
*/
|
|
51
|
+
isSuiVault(chainId: number): boolean;
|
|
52
|
+
}
|
|
53
|
+
export default SuiAdapter;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Sui = void 0;
|
|
37
|
+
const SuiConstants = __importStar(require("./constants"));
|
|
38
|
+
const SuiUtils = __importStar(require("./utils"));
|
|
39
|
+
exports.Sui = {
|
|
40
|
+
utils: SuiUtils,
|
|
41
|
+
constants: SuiConstants,
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Sui Adapter for Upshift SDK.
|
|
45
|
+
*
|
|
46
|
+
* Holds the Sui configuration passed to `new UpshiftSDK({ sui })` and the Sui
|
|
47
|
+
* chain-identity helpers. It makes no network calls.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const sdk = new UpshiftSDK({ appName: 'my-app', sui: { network: 'testnet' } });
|
|
52
|
+
* sdk.sui.network; // 'testnet'
|
|
53
|
+
* sdk.sui.isSuiAddress(vault.address);
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
class SuiAdapter {
|
|
57
|
+
_config;
|
|
58
|
+
/**
|
|
59
|
+
* @param config - Optional Sui settings; omit to target Sui mainnet.
|
|
60
|
+
*/
|
|
61
|
+
constructor(config = {}) {
|
|
62
|
+
this._config = { ...config };
|
|
63
|
+
}
|
|
64
|
+
/** The SDK's Sui chain ID, `-2` (same as the backend's `chain` for Sui vaults). */
|
|
65
|
+
get chainId() {
|
|
66
|
+
return SuiConstants.SUI_CHAIN_ID;
|
|
67
|
+
}
|
|
68
|
+
/** Configured Sui network; `'mainnet'` unless the SDK was built with another. */
|
|
69
|
+
get network() {
|
|
70
|
+
return this._config.network ?? 'mainnet';
|
|
71
|
+
}
|
|
72
|
+
/** Configured RPC endpoint override, or `undefined` when none was given. */
|
|
73
|
+
get rpcUrl() {
|
|
74
|
+
return this._config.rpcUrl;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check whether a string is a Sui address or object ID (`0x` + 64 hex chars).
|
|
78
|
+
*
|
|
79
|
+
* @param address - Candidate address.
|
|
80
|
+
* @returns `true` for the long, 64-hex-digit form only.
|
|
81
|
+
*/
|
|
82
|
+
isSuiAddress(address) {
|
|
83
|
+
return SuiUtils.isSuiAddress(address);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check whether a chain ID is Sui's (`-2`).
|
|
87
|
+
*
|
|
88
|
+
* @param chainId - Numeric chain ID, e.g. a backend vault row's `chain`.
|
|
89
|
+
* @returns `true` only for `-2`.
|
|
90
|
+
*/
|
|
91
|
+
isSuiVault(chainId) {
|
|
92
|
+
return SuiUtils.isSuiVault(chainId);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.default = SuiAdapter;
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IVault } from '../../types';
|
|
2
|
+
import type { IEmberVault } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Transform Ember vault to IVault format
|
|
5
|
+
*/
|
|
6
|
+
export declare function transformEmberVaultToIVault(emberVault: IEmberVault): IVault;
|
|
7
|
+
/**
|
|
8
|
+
* Transform multiple Ember vaults
|
|
9
|
+
*/
|
|
10
|
+
export declare function transformEmberVaultsToIVaults(emberVaults: IEmberVault[]): IVault[];
|