@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,53 @@
|
|
|
1
|
+
import { type IFetchUpshiftOptions } from '../../core';
|
|
2
|
+
import type { IAddress, ILoanBookInfo, IOTCPosition, ISubaccountDebank, ISubaccountTransaction, IWSSubaccountCefi, IWSSubAccountHealthFactor, IWSSubaccountListItem, IWSSubaccountLoan, IWSSubaccountSummary } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Fetch one page of the subaccount directory (admin-only backend endpoint)
|
|
5
|
+
*/
|
|
6
|
+
export declare const fetchAllSubaccounts: (pagination: {
|
|
7
|
+
offset?: number;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IWSSubaccountListItem[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Fetch a subaccount's transaction history (authenticated `GET
|
|
12
|
+
* /transactions/v2`), optionally windowed by ISO-8601 start/end datetimes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const fetchSubaccountTransactions: (payload: {
|
|
15
|
+
address: IAddress;
|
|
16
|
+
startTime?: string;
|
|
17
|
+
endTime?: string;
|
|
18
|
+
}, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<ISubaccountTransaction[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch a single loan's loan-book detail by loan address + chain
|
|
21
|
+
* (admin-only `GET /subaccount/loans/{loan_address}`).
|
|
22
|
+
*/
|
|
23
|
+
export declare const fetchSubaccountLoanByAddress: (loanAddress: string, chainId: number, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<ILoanBookInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetch cross-chain DeBank positions for a subaccount (`GET
|
|
26
|
+
* /subaccount/{subaccount_address}/debank`). Slow endpoint (300-second
|
|
27
|
+
* server-side cache) — it fans out across every supported chain.
|
|
28
|
+
*/
|
|
29
|
+
export declare const fetchSubaccountDebank: (address: IAddress, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<ISubaccountDebank>;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch subaccount health factor for a given subaccount address
|
|
32
|
+
*/
|
|
33
|
+
export declare const fetchSubaccountHeathFactor: (address: IAddress, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IWSSubAccountHealthFactor>;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch subaccount loans details
|
|
36
|
+
*/
|
|
37
|
+
export declare const fetchSubaccountLoans: (payload: {
|
|
38
|
+
address: IAddress;
|
|
39
|
+
side?: "BOTH" | "BORROWER" | "LENDER";
|
|
40
|
+
active?: boolean;
|
|
41
|
+
}, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IWSSubaccountLoan[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Fetch the subaccount CeFi positions
|
|
44
|
+
*/
|
|
45
|
+
export declare const fetchSubaccountCefiPositions: (address: IAddress, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IWSSubaccountCefi[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch the subaccount OTC positions
|
|
48
|
+
*/
|
|
49
|
+
export declare const fetchSubaccountOtcPositions: (address: IAddress, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IOTCPosition[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch the subaccount summary view
|
|
52
|
+
*/
|
|
53
|
+
export declare const fetchSubaccountSummary: (address: IAddress, upshiftKey: string, headers?: IFetchUpshiftOptions["headers"]) => Promise<IWSSubaccountSummary>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchSubaccountSummary = exports.fetchSubaccountOtcPositions = exports.fetchSubaccountCefiPositions = exports.fetchSubaccountLoans = exports.fetchSubaccountHeathFactor = exports.fetchSubaccountDebank = exports.fetchSubaccountLoanByAddress = exports.fetchSubaccountTransactions = exports.fetchAllSubaccounts = void 0;
|
|
4
|
+
const core_1 = require("../../core");
|
|
5
|
+
/**
|
|
6
|
+
* Fetch one page of the subaccount directory (admin-only backend endpoint)
|
|
7
|
+
*/
|
|
8
|
+
const fetchAllSubaccounts = async (pagination, upshiftKey, headers) => {
|
|
9
|
+
// fetchUpshiftWithKey throws a typed UpshiftSDKError (via
|
|
10
|
+
// errorFromResponseStatus) on any non-2xx response, so a returned
|
|
11
|
+
// response is always ok.
|
|
12
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.list(pagination.offset, pagination.limit), {
|
|
13
|
+
headers,
|
|
14
|
+
});
|
|
15
|
+
return response.json();
|
|
16
|
+
};
|
|
17
|
+
exports.fetchAllSubaccounts = fetchAllSubaccounts;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch a subaccount's transaction history (authenticated `GET
|
|
20
|
+
* /transactions/v2`), optionally windowed by ISO-8601 start/end datetimes.
|
|
21
|
+
*/
|
|
22
|
+
const fetchSubaccountTransactions = async (payload, upshiftKey, headers) => {
|
|
23
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.transactions.v2(payload.address, payload.startTime, payload.endTime), { headers });
|
|
24
|
+
return response.json();
|
|
25
|
+
};
|
|
26
|
+
exports.fetchSubaccountTransactions = fetchSubaccountTransactions;
|
|
27
|
+
/**
|
|
28
|
+
* Fetch a single loan's loan-book detail by loan address + chain
|
|
29
|
+
* (admin-only `GET /subaccount/loans/{loan_address}`).
|
|
30
|
+
*/
|
|
31
|
+
const fetchSubaccountLoanByAddress = async (loanAddress, chainId, upshiftKey, headers) => {
|
|
32
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.loanByAddress(loanAddress, chainId), { headers });
|
|
33
|
+
return response.json();
|
|
34
|
+
};
|
|
35
|
+
exports.fetchSubaccountLoanByAddress = fetchSubaccountLoanByAddress;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch cross-chain DeBank positions for a subaccount (`GET
|
|
38
|
+
* /subaccount/{subaccount_address}/debank`). Slow endpoint (300-second
|
|
39
|
+
* server-side cache) — it fans out across every supported chain.
|
|
40
|
+
*/
|
|
41
|
+
const fetchSubaccountDebank = async (address, upshiftKey, headers) => {
|
|
42
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.debank(address), { headers });
|
|
43
|
+
return response.json();
|
|
44
|
+
};
|
|
45
|
+
exports.fetchSubaccountDebank = fetchSubaccountDebank;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch subaccount health factor for a given subaccount address
|
|
48
|
+
*/
|
|
49
|
+
const fetchSubaccountHeathFactor = async (address, upshiftKey, headers) => {
|
|
50
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.health_factor(address), {
|
|
51
|
+
headers,
|
|
52
|
+
});
|
|
53
|
+
return response.json();
|
|
54
|
+
};
|
|
55
|
+
exports.fetchSubaccountHeathFactor = fetchSubaccountHeathFactor;
|
|
56
|
+
/**
|
|
57
|
+
* Fetch subaccount loans details
|
|
58
|
+
*/
|
|
59
|
+
const fetchSubaccountLoans = async (payload, upshiftKey, headers) => {
|
|
60
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.loans(payload.address, payload.side, payload.active), {
|
|
61
|
+
headers,
|
|
62
|
+
});
|
|
63
|
+
return response.json();
|
|
64
|
+
};
|
|
65
|
+
exports.fetchSubaccountLoans = fetchSubaccountLoans;
|
|
66
|
+
/**
|
|
67
|
+
* Fetch the subaccount CeFi positions
|
|
68
|
+
*/
|
|
69
|
+
const fetchSubaccountCefiPositions = async (address, upshiftKey, headers) => {
|
|
70
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.cefi(address), {
|
|
71
|
+
headers,
|
|
72
|
+
});
|
|
73
|
+
return response.json();
|
|
74
|
+
};
|
|
75
|
+
exports.fetchSubaccountCefiPositions = fetchSubaccountCefiPositions;
|
|
76
|
+
/**
|
|
77
|
+
* Fetch the subaccount OTC positions
|
|
78
|
+
*/
|
|
79
|
+
const fetchSubaccountOtcPositions = async (address, upshiftKey, headers) => {
|
|
80
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.otc_positions(address), {
|
|
81
|
+
headers,
|
|
82
|
+
});
|
|
83
|
+
return response.json();
|
|
84
|
+
};
|
|
85
|
+
exports.fetchSubaccountOtcPositions = fetchSubaccountOtcPositions;
|
|
86
|
+
/**
|
|
87
|
+
* Fetch the subaccount summary view
|
|
88
|
+
*/
|
|
89
|
+
const fetchSubaccountSummary = async (address, upshiftKey, headers) => {
|
|
90
|
+
const response = await (0, core_1.fetchUpshiftWithKey)(upshiftKey, core_1.WEBSERVER_ENDPOINTS.subaccount.summary(address), {
|
|
91
|
+
headers,
|
|
92
|
+
});
|
|
93
|
+
return response.json();
|
|
94
|
+
};
|
|
95
|
+
exports.fetchSubaccountSummary = fetchSubaccountSummary;
|
|
96
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fetcher"), exports);
|
|
18
|
+
__exportStar(require("./main"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { UpshiftBase, type IUpshiftBase } from '../../core';
|
|
2
|
+
import type { IAddress, ILoanBookInfo, ISubaccountDebank, ISubaccountTransaction, IWSSubaccountListItem } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Subaccount operation class interacting with Upshift Subaccounts
|
|
5
|
+
* Subaccount is a smart contract wallet that serves as the fundamental infrastructure for Upshift's platform.
|
|
6
|
+
* It functions as a cross-margin account designed for optimal capital efficiency.
|
|
7
|
+
*
|
|
8
|
+
* `getSubaccountSummary`, `getSubaccountHealthFactor`, `getSubaccountLoans`,
|
|
9
|
+
* `getSubaccountCefiPositions` and `getSubaccountOtcPositions` work without an
|
|
10
|
+
* Upshift API key for subaccounts linked to a vault; `getSubaccountDebank` is
|
|
11
|
+
* public. `getSubaccountTransactions` needs a key authorized for the
|
|
12
|
+
* subaccount, and `getAllSubaccounts` and `getSubaccountLoanByAddress` need an
|
|
13
|
+
* admin key.
|
|
14
|
+
*/
|
|
15
|
+
export declare class UpshiftSubAccounts extends UpshiftBase {
|
|
16
|
+
private headers;
|
|
17
|
+
constructor(baseConfig: IUpshiftBase);
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves one page of the directory of all Upshift subaccounts.
|
|
20
|
+
*
|
|
21
|
+
* Backed by the admin-only `GET /subaccount` backend endpoint, so the
|
|
22
|
+
* Upshift API key configured on the SDK must belong to an admin user —
|
|
23
|
+
* non-admin keys are rejected with an auth error by the backend. Makes
|
|
24
|
+
* exactly one HTTP request and no RPC calls.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Pagination window over the subaccount directory
|
|
27
|
+
* @param options.offset - Number of records to skip. Defaults to 0; must be a non-negative integer.
|
|
28
|
+
* @param options.limit - Page size. Defaults to 100; must be an integer between 1 and 1000 (backend maximum).
|
|
29
|
+
* @returns The page of subaccount records (address, internal/friendly names, status, type, linked chains, risk metadata). An empty array means the offset is past the end of the directory.
|
|
30
|
+
* @throws UpshiftValidationError when `offset` or `limit` is out of range
|
|
31
|
+
* @throws UpshiftAuthError when the API key is missing or not admin-scoped
|
|
32
|
+
* @example
|
|
33
|
+
* const page = await upshiftSdk.subAccountsModule.getAllSubaccounts({
|
|
34
|
+
* offset: 0,
|
|
35
|
+
* limit: 200,
|
|
36
|
+
* });
|
|
37
|
+
* console.log(page.map((s) => `${s.internal_name}: ${s.address}`));
|
|
38
|
+
*/
|
|
39
|
+
getAllSubaccounts(options?: {
|
|
40
|
+
offset?: number;
|
|
41
|
+
limit?: number;
|
|
42
|
+
}): Promise<IWSSubaccountListItem[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the health factor for a subaccount.
|
|
45
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
46
|
+
* @returns The health factor data including collateral value, loan value, and health factor ratio
|
|
47
|
+
*/
|
|
48
|
+
getSubaccountHealthFactor(subaccountAddress: IAddress): Promise<{
|
|
49
|
+
id: `0x${string}`;
|
|
50
|
+
dateTime: string;
|
|
51
|
+
healthFactor: number;
|
|
52
|
+
totalCollateral: number;
|
|
53
|
+
totalLoan: number;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves loan positions for a subaccount.
|
|
57
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
58
|
+
* @param side - Filter by loan side: 'BOTH' for all loans, 'LENDER' for lent positions, 'BORROWER' for borrowed positions
|
|
59
|
+
* @param active - When true, returns only active loans; when false, returns all loans including closed ones
|
|
60
|
+
* @returns List of loan positions matching the specified filters
|
|
61
|
+
*/
|
|
62
|
+
getSubaccountLoans(subaccountAddress: IAddress, side: 'BOTH' | 'LENDER' | 'BORROWER', active: boolean): Promise<import("../../types").IWSSubaccountLoan[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves CeFi (Centralized Finance) positions for a subaccount.
|
|
65
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
66
|
+
* @returns List of CeFi positions held by the subaccount
|
|
67
|
+
*/
|
|
68
|
+
getSubaccountCefiPositions(subaccountAddress: IAddress): Promise<import("../../types").IWSSubaccountCefi[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves OTC (Over-The-Counter) positions for a subaccount.
|
|
71
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
72
|
+
* @returns List of OTC positions held by the subaccount
|
|
73
|
+
*/
|
|
74
|
+
getSubaccountOtcPositions(subaccountAddress: IAddress): Promise<import("../../types").IOTCPosition[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves the summary view for a subaccount or EOA operator.
|
|
77
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
78
|
+
* @returns The full summary including portfolio, loanbook, tokens, and account values
|
|
79
|
+
*/
|
|
80
|
+
getSubaccountSummary(subaccountAddress: IAddress): Promise<{
|
|
81
|
+
address: `0x${string}`;
|
|
82
|
+
name: string;
|
|
83
|
+
type: "eoa" | "subaccount";
|
|
84
|
+
portfolio: {
|
|
85
|
+
tokens: {
|
|
86
|
+
value: number;
|
|
87
|
+
balance: number;
|
|
88
|
+
token: {
|
|
89
|
+
type: string;
|
|
90
|
+
name: string;
|
|
91
|
+
address: string;
|
|
92
|
+
chain: number;
|
|
93
|
+
symbol: string;
|
|
94
|
+
decimals: number;
|
|
95
|
+
imgUrl: string;
|
|
96
|
+
};
|
|
97
|
+
}[];
|
|
98
|
+
marginBalances: unknown[];
|
|
99
|
+
collateralBalances: unknown[];
|
|
100
|
+
cefiPositions: unknown[];
|
|
101
|
+
defiPositions: unknown[];
|
|
102
|
+
trsPositions: unknown[];
|
|
103
|
+
strategyContractPositions: unknown[];
|
|
104
|
+
legacyHedgerPositions: unknown[];
|
|
105
|
+
otcPositions: unknown[];
|
|
106
|
+
totalValue: number;
|
|
107
|
+
discountedValue: number;
|
|
108
|
+
};
|
|
109
|
+
loanbook: {
|
|
110
|
+
loans: {
|
|
111
|
+
subaccountAddress: `0x${string}`;
|
|
112
|
+
book: {
|
|
113
|
+
address: `0x${string}`;
|
|
114
|
+
lender: `0x${string}`;
|
|
115
|
+
borrower: `0x${string}`;
|
|
116
|
+
state: string;
|
|
117
|
+
totalRepaid: number;
|
|
118
|
+
principalToken: {
|
|
119
|
+
type: string;
|
|
120
|
+
name: string;
|
|
121
|
+
address: string;
|
|
122
|
+
chain: number;
|
|
123
|
+
symbol: string;
|
|
124
|
+
decimals: number;
|
|
125
|
+
imgUrl: string;
|
|
126
|
+
tokenType: number;
|
|
127
|
+
discountFactor: number;
|
|
128
|
+
price: number;
|
|
129
|
+
};
|
|
130
|
+
principalAmount: number;
|
|
131
|
+
interestAmount: number;
|
|
132
|
+
upcomingPayment: {
|
|
133
|
+
amount: number;
|
|
134
|
+
dueDate: string;
|
|
135
|
+
};
|
|
136
|
+
apr: number;
|
|
137
|
+
initialPrincipalAmount: number;
|
|
138
|
+
deployedDate: string;
|
|
139
|
+
paymentInterval: number;
|
|
140
|
+
totalInterestPaymentFees: number;
|
|
141
|
+
};
|
|
142
|
+
isBorrow: boolean;
|
|
143
|
+
debtInfo: {
|
|
144
|
+
interestOwed: number;
|
|
145
|
+
principalDebtOwed: number;
|
|
146
|
+
interestRepaid: number;
|
|
147
|
+
};
|
|
148
|
+
creditInfo: {
|
|
149
|
+
netInterestOwed: number;
|
|
150
|
+
principalDebtOwed: number;
|
|
151
|
+
netInterestRepaid: number;
|
|
152
|
+
};
|
|
153
|
+
}[];
|
|
154
|
+
totalDebt: number;
|
|
155
|
+
totalCredit: number;
|
|
156
|
+
aggregatesByToken: unknown[];
|
|
157
|
+
};
|
|
158
|
+
chains: {
|
|
159
|
+
name: string;
|
|
160
|
+
chainId: number;
|
|
161
|
+
}[];
|
|
162
|
+
tokens: {
|
|
163
|
+
type: string;
|
|
164
|
+
name: string;
|
|
165
|
+
address: string;
|
|
166
|
+
chain: number;
|
|
167
|
+
symbol: string;
|
|
168
|
+
decimals: number;
|
|
169
|
+
imgUrl: string;
|
|
170
|
+
price: number;
|
|
171
|
+
rawBalance: number;
|
|
172
|
+
balance: number;
|
|
173
|
+
value: number;
|
|
174
|
+
}[];
|
|
175
|
+
totalAccountValue: number;
|
|
176
|
+
totalCollateralValue: number;
|
|
177
|
+
totalLoanValue: number;
|
|
178
|
+
healthFactor: number;
|
|
179
|
+
netAccountValue: number;
|
|
180
|
+
totalEquityValue: number;
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves a subaccount's on-chain transaction history, newest first,
|
|
184
|
+
* optionally windowed by a time range.
|
|
185
|
+
*
|
|
186
|
+
* Backed by the authenticated `GET /transactions/v2` backend endpoint,
|
|
187
|
+
* which resolves and authorizes the subaccount, so the configured Upshift
|
|
188
|
+
* API key must be authorized for it (an admin-scoped key always is). Makes
|
|
189
|
+
* exactly one HTTP request and no RPC calls.
|
|
190
|
+
*
|
|
191
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
192
|
+
* @param options - Optional time window
|
|
193
|
+
* @param options.startTime - ISO-8601 datetime lower bound (inclusive); omit for no lower bound
|
|
194
|
+
* @param options.endTime - ISO-8601 datetime upper bound (inclusive); omit for no upper bound
|
|
195
|
+
* @returns The subaccount's transactions with decoded logs, transfers, and function names
|
|
196
|
+
* @throws UpshiftValidationError When `subaccountAddress` is not a valid EVM address
|
|
197
|
+
* @throws UpshiftAuthError When the API key is missing or not authorized for the subaccount
|
|
198
|
+
* @throws UpshiftServerError When the API responds with a non-2xx status
|
|
199
|
+
* @example
|
|
200
|
+
* const txs = await upshiftSdk.subAccountsModule.getSubaccountTransactions(
|
|
201
|
+
* '0xabc…',
|
|
202
|
+
* { startTime: '2026-01-01T00:00:00Z' },
|
|
203
|
+
* );
|
|
204
|
+
*/
|
|
205
|
+
getSubaccountTransactions(subaccountAddress: IAddress, options?: {
|
|
206
|
+
startTime?: string;
|
|
207
|
+
endTime?: string;
|
|
208
|
+
}): Promise<ISubaccountTransaction[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Retrieves the full loan-book detail for a single loan by its address and
|
|
211
|
+
* chain.
|
|
212
|
+
*
|
|
213
|
+
* Backed by the admin-only `GET /subaccount/loans/{loan_address}` backend
|
|
214
|
+
* endpoint (60-second server-side cache), so the configured Upshift API key
|
|
215
|
+
* must belong to an admin user. Makes exactly one HTTP request and no RPC
|
|
216
|
+
* calls.
|
|
217
|
+
*
|
|
218
|
+
* @param loanAddress - The loan contract address
|
|
219
|
+
* @param chainId - Numeric Upshift chain id the loan lives on (e.g. `1` for Ethereum mainnet)
|
|
220
|
+
* @returns The loan's {@link ILoanBookInfo} detail
|
|
221
|
+
* @throws UpshiftValidationError When `chainId` is not an integer
|
|
222
|
+
* @throws UpshiftAuthError When the API key is missing or not admin-scoped
|
|
223
|
+
* @throws UpshiftServerError When the loan or chain is not found, or the API otherwise responds non-2xx
|
|
224
|
+
* @example
|
|
225
|
+
* const loan = await upshiftSdk.subAccountsModule.getSubaccountLoanByAddress(
|
|
226
|
+
* '0xloan…',
|
|
227
|
+
* 1,
|
|
228
|
+
* );
|
|
229
|
+
*/
|
|
230
|
+
getSubaccountLoanByAddress(loanAddress: string, chainId: number): Promise<ILoanBookInfo>;
|
|
231
|
+
/**
|
|
232
|
+
* Retrieves cross-chain DeBank protocol positions and token balances for a
|
|
233
|
+
* subaccount and its associated strategies.
|
|
234
|
+
*
|
|
235
|
+
* Backed by `GET /subaccount/{subaccount_address}/debank` (300-second
|
|
236
|
+
* server-side cache). This is a slow endpoint — it fans out to DeBank
|
|
237
|
+
* across every supported chain — so expect higher latency than other
|
|
238
|
+
* subaccount reads. Makes exactly one HTTP request and no RPC calls.
|
|
239
|
+
*
|
|
240
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
241
|
+
* @returns The subaccount's DeBank positions/tokens plus per-strategy breakdowns
|
|
242
|
+
* @throws UpshiftValidationError When `subaccountAddress` is not a valid EVM address
|
|
243
|
+
* @throws UpshiftServerError When the API responds with a non-2xx status
|
|
244
|
+
* @example
|
|
245
|
+
* const debank = await upshiftSdk.subAccountsModule.getSubaccountDebank('0xabc…');
|
|
246
|
+
* console.log(debank.subaccount.positions.length);
|
|
247
|
+
*/
|
|
248
|
+
getSubaccountDebank(subaccountAddress: IAddress): Promise<ISubaccountDebank>;
|
|
249
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpshiftSubAccounts = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The Upshift Sub Accounts Module.
|
|
6
|
+
*
|
|
7
|
+
* @module UpshiftSubAccounts
|
|
8
|
+
*/
|
|
9
|
+
const fetcher_1 = require("./fetcher");
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const core_1 = require("../../core");
|
|
13
|
+
/**
|
|
14
|
+
* Validates that a subaccount address is a well-formed EVM address, throwing a
|
|
15
|
+
* typed {@link UpshiftValidationError} if not. Upshift subaccounts are EVM
|
|
16
|
+
* smart-contract wallets, so an invalid value should fail fast in the SDK
|
|
17
|
+
* rather than reaching the backend.
|
|
18
|
+
*/
|
|
19
|
+
function assertSubaccountAddress(address, method) {
|
|
20
|
+
if (typeof address !== 'string' || !(0, ethers_1.isAddress)(address)) {
|
|
21
|
+
throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `${method}: "${address}" is not a valid subaccount address — pass the subaccount's EVM (0x…) address.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Subaccount operation class interacting with Upshift Subaccounts
|
|
26
|
+
* Subaccount is a smart contract wallet that serves as the fundamental infrastructure for Upshift's platform.
|
|
27
|
+
* It functions as a cross-margin account designed for optimal capital efficiency.
|
|
28
|
+
*
|
|
29
|
+
* `getSubaccountSummary`, `getSubaccountHealthFactor`, `getSubaccountLoans`,
|
|
30
|
+
* `getSubaccountCefiPositions` and `getSubaccountOtcPositions` work without an
|
|
31
|
+
* Upshift API key for subaccounts linked to a vault; `getSubaccountDebank` is
|
|
32
|
+
* public. `getSubaccountTransactions` needs a key authorized for the
|
|
33
|
+
* subaccount, and `getAllSubaccounts` and `getSubaccountLoanByAddress` need an
|
|
34
|
+
* admin key.
|
|
35
|
+
*/
|
|
36
|
+
class UpshiftSubAccounts extends core_1.UpshiftBase {
|
|
37
|
+
headers = null;
|
|
38
|
+
constructor(baseConfig) {
|
|
39
|
+
super(baseConfig);
|
|
40
|
+
this.headers = {
|
|
41
|
+
'x-environment': this.monitoring?.['x-environment'],
|
|
42
|
+
'x-user-id': this.monitoring?.['x-user-id'],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves one page of the directory of all Upshift subaccounts.
|
|
47
|
+
*
|
|
48
|
+
* Backed by the admin-only `GET /subaccount` backend endpoint, so the
|
|
49
|
+
* Upshift API key configured on the SDK must belong to an admin user —
|
|
50
|
+
* non-admin keys are rejected with an auth error by the backend. Makes
|
|
51
|
+
* exactly one HTTP request and no RPC calls.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Pagination window over the subaccount directory
|
|
54
|
+
* @param options.offset - Number of records to skip. Defaults to 0; must be a non-negative integer.
|
|
55
|
+
* @param options.limit - Page size. Defaults to 100; must be an integer between 1 and 1000 (backend maximum).
|
|
56
|
+
* @returns The page of subaccount records (address, internal/friendly names, status, type, linked chains, risk metadata). An empty array means the offset is past the end of the directory.
|
|
57
|
+
* @throws UpshiftValidationError when `offset` or `limit` is out of range
|
|
58
|
+
* @throws UpshiftAuthError when the API key is missing or not admin-scoped
|
|
59
|
+
* @example
|
|
60
|
+
* const page = await upshiftSdk.subAccountsModule.getAllSubaccounts({
|
|
61
|
+
* offset: 0,
|
|
62
|
+
* limit: 200,
|
|
63
|
+
* });
|
|
64
|
+
* console.log(page.map((s) => `${s.internal_name}: ${s.address}`));
|
|
65
|
+
*/
|
|
66
|
+
async getAllSubaccounts(options = {}) {
|
|
67
|
+
const offset = options.offset ?? 0;
|
|
68
|
+
const limit = options.limit ?? 100;
|
|
69
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
70
|
+
throw new core_1.UpshiftValidationError('INVALID_INPUT', `getAllSubaccounts: offset must be a non-negative integer, got ${offset}`);
|
|
71
|
+
}
|
|
72
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1000) {
|
|
73
|
+
throw new core_1.UpshiftValidationError('INVALID_INPUT', `getAllSubaccounts: limit must be an integer between 1 and 1000, got ${limit}`);
|
|
74
|
+
}
|
|
75
|
+
return (0, fetcher_1.fetchAllSubaccounts)({ offset, limit }, this.keys.upshift, this.headers);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves the health factor for a subaccount.
|
|
79
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
80
|
+
* @returns The health factor data including collateral value, loan value, and health factor ratio
|
|
81
|
+
*/
|
|
82
|
+
async getSubaccountHealthFactor(subaccountAddress) {
|
|
83
|
+
const response = await (0, fetcher_1.fetchSubaccountHeathFactor)(subaccountAddress, this.keys.upshift, this.headers);
|
|
84
|
+
return {
|
|
85
|
+
id: response.id,
|
|
86
|
+
dateTime: response.datetime,
|
|
87
|
+
healthFactor: response.health_factor,
|
|
88
|
+
totalCollateral: response.total_collateral_value,
|
|
89
|
+
totalLoan: response.total_loan_value,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retrieves loan positions for a subaccount.
|
|
94
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
95
|
+
* @param side - Filter by loan side: 'BOTH' for all loans, 'LENDER' for lent positions, 'BORROWER' for borrowed positions
|
|
96
|
+
* @param active - When true, returns only active loans; when false, returns all loans including closed ones
|
|
97
|
+
* @returns List of loan positions matching the specified filters
|
|
98
|
+
*/
|
|
99
|
+
async getSubaccountLoans(subaccountAddress, side, active) {
|
|
100
|
+
const response = await (0, fetcher_1.fetchSubaccountLoans)({ address: subaccountAddress, active, side }, this.keys.upshift, this.headers);
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves CeFi (Centralized Finance) positions for a subaccount.
|
|
105
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
106
|
+
* @returns List of CeFi positions held by the subaccount
|
|
107
|
+
*/
|
|
108
|
+
async getSubaccountCefiPositions(subaccountAddress) {
|
|
109
|
+
const response = await (0, fetcher_1.fetchSubaccountCefiPositions)(subaccountAddress, this.keys.upshift, this.headers);
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves OTC (Over-The-Counter) positions for a subaccount.
|
|
114
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
115
|
+
* @returns List of OTC positions held by the subaccount
|
|
116
|
+
*/
|
|
117
|
+
async getSubaccountOtcPositions(subaccountAddress) {
|
|
118
|
+
const response = await (0, fetcher_1.fetchSubaccountOtcPositions)(subaccountAddress, this.keys.upshift, this.headers);
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves the summary view for a subaccount or EOA operator.
|
|
123
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
124
|
+
* @returns The full summary including portfolio, loanbook, tokens, and account values
|
|
125
|
+
*/
|
|
126
|
+
async getSubaccountSummary(subaccountAddress) {
|
|
127
|
+
const response = await (0, fetcher_1.fetchSubaccountSummary)(subaccountAddress, this.keys.upshift, this.headers);
|
|
128
|
+
return (0, utils_1.transformSubaccountSummary)(response);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Retrieves a subaccount's on-chain transaction history, newest first,
|
|
132
|
+
* optionally windowed by a time range.
|
|
133
|
+
*
|
|
134
|
+
* Backed by the authenticated `GET /transactions/v2` backend endpoint,
|
|
135
|
+
* which resolves and authorizes the subaccount, so the configured Upshift
|
|
136
|
+
* API key must be authorized for it (an admin-scoped key always is). Makes
|
|
137
|
+
* exactly one HTTP request and no RPC calls.
|
|
138
|
+
*
|
|
139
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
140
|
+
* @param options - Optional time window
|
|
141
|
+
* @param options.startTime - ISO-8601 datetime lower bound (inclusive); omit for no lower bound
|
|
142
|
+
* @param options.endTime - ISO-8601 datetime upper bound (inclusive); omit for no upper bound
|
|
143
|
+
* @returns The subaccount's transactions with decoded logs, transfers, and function names
|
|
144
|
+
* @throws UpshiftValidationError When `subaccountAddress` is not a valid EVM address
|
|
145
|
+
* @throws UpshiftAuthError When the API key is missing or not authorized for the subaccount
|
|
146
|
+
* @throws UpshiftServerError When the API responds with a non-2xx status
|
|
147
|
+
* @example
|
|
148
|
+
* const txs = await upshiftSdk.subAccountsModule.getSubaccountTransactions(
|
|
149
|
+
* '0xabc…',
|
|
150
|
+
* { startTime: '2026-01-01T00:00:00Z' },
|
|
151
|
+
* );
|
|
152
|
+
*/
|
|
153
|
+
async getSubaccountTransactions(subaccountAddress, options = {}) {
|
|
154
|
+
assertSubaccountAddress(subaccountAddress, 'getSubaccountTransactions');
|
|
155
|
+
return (0, fetcher_1.fetchSubaccountTransactions)({
|
|
156
|
+
address: subaccountAddress,
|
|
157
|
+
startTime: options.startTime,
|
|
158
|
+
endTime: options.endTime,
|
|
159
|
+
}, this.keys.upshift, this.headers);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Retrieves the full loan-book detail for a single loan by its address and
|
|
163
|
+
* chain.
|
|
164
|
+
*
|
|
165
|
+
* Backed by the admin-only `GET /subaccount/loans/{loan_address}` backend
|
|
166
|
+
* endpoint (60-second server-side cache), so the configured Upshift API key
|
|
167
|
+
* must belong to an admin user. Makes exactly one HTTP request and no RPC
|
|
168
|
+
* calls.
|
|
169
|
+
*
|
|
170
|
+
* @param loanAddress - The loan contract address
|
|
171
|
+
* @param chainId - Numeric Upshift chain id the loan lives on (e.g. `1` for Ethereum mainnet)
|
|
172
|
+
* @returns The loan's {@link ILoanBookInfo} detail
|
|
173
|
+
* @throws UpshiftValidationError When `chainId` is not an integer
|
|
174
|
+
* @throws UpshiftAuthError When the API key is missing or not admin-scoped
|
|
175
|
+
* @throws UpshiftServerError When the loan or chain is not found, or the API otherwise responds non-2xx
|
|
176
|
+
* @example
|
|
177
|
+
* const loan = await upshiftSdk.subAccountsModule.getSubaccountLoanByAddress(
|
|
178
|
+
* '0xloan…',
|
|
179
|
+
* 1,
|
|
180
|
+
* );
|
|
181
|
+
*/
|
|
182
|
+
async getSubaccountLoanByAddress(loanAddress, chainId) {
|
|
183
|
+
if (!Number.isInteger(chainId)) {
|
|
184
|
+
throw new core_1.UpshiftValidationError('INVALID_CHAIN', `getSubaccountLoanByAddress: chainId must be an integer Upshift chain id, got ${chainId}.`);
|
|
185
|
+
}
|
|
186
|
+
return (0, fetcher_1.fetchSubaccountLoanByAddress)(loanAddress, chainId, this.keys.upshift, this.headers);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Retrieves cross-chain DeBank protocol positions and token balances for a
|
|
190
|
+
* subaccount and its associated strategies.
|
|
191
|
+
*
|
|
192
|
+
* Backed by `GET /subaccount/{subaccount_address}/debank` (300-second
|
|
193
|
+
* server-side cache). This is a slow endpoint — it fans out to DeBank
|
|
194
|
+
* across every supported chain — so expect higher latency than other
|
|
195
|
+
* subaccount reads. Makes exactly one HTTP request and no RPC calls.
|
|
196
|
+
*
|
|
197
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
198
|
+
* @returns The subaccount's DeBank positions/tokens plus per-strategy breakdowns
|
|
199
|
+
* @throws UpshiftValidationError When `subaccountAddress` is not a valid EVM address
|
|
200
|
+
* @throws UpshiftServerError When the API responds with a non-2xx status
|
|
201
|
+
* @example
|
|
202
|
+
* const debank = await upshiftSdk.subAccountsModule.getSubaccountDebank('0xabc…');
|
|
203
|
+
* console.log(debank.subaccount.positions.length);
|
|
204
|
+
*/
|
|
205
|
+
async getSubaccountDebank(subaccountAddress) {
|
|
206
|
+
assertSubaccountAddress(subaccountAddress, 'getSubaccountDebank');
|
|
207
|
+
return (0, fetcher_1.fetchSubaccountDebank)(subaccountAddress, this.keys.upshift, this.headers);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.UpshiftSubAccounts = UpshiftSubAccounts;
|
|
211
|
+
//# sourceMappingURL=main.js.map
|