upshift-sdk 8.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch the latest USD price for a token symbol from CoinGecko's
|
|
3
|
+
* `/market_chart/range` endpoint, mapped through `COINGECKO_COIN_ID_MAP`.
|
|
4
|
+
*
|
|
5
|
+
* @param symbol - Token symbol (case-insensitive). Must be present in
|
|
6
|
+
* `COINGECKO_COIN_ID_MAP`.
|
|
7
|
+
* @param coinGeckoKey - CoinGecko Pro API key passed as `x-cg-pro-api-key`.
|
|
8
|
+
* @returns The latest price in USD (a number) on success; `null` when the
|
|
9
|
+
* response contains an empty or missing `prices` array. `musd` (mezo-usd)
|
|
10
|
+
* is a USD-pegged stablecoin and short-circuits to a price of `1`.
|
|
11
|
+
* @throws {@link AugustValidationError} When `symbol` is not in `COINGECKO_COIN_ID_MAP`.
|
|
12
|
+
* @throws {@link AugustRateLimitError} On a 429 response from CoinGecko.
|
|
13
|
+
* @throws {@link AugustServerError} On any other non-2xx response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function fetchTokenPricesFromCoinGecko(symbol: string, coinGeckoKey: string): Promise<number>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchTokenPricesFromCoinGecko = fetchTokenPricesFromCoinGecko;
|
|
4
|
+
const logger_1 = require("../../core/logger");
|
|
5
|
+
const errors_1 = require("../../core/errors");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
/**
|
|
8
|
+
* Fetch the latest USD price for a token symbol from CoinGecko's
|
|
9
|
+
* `/market_chart/range` endpoint, mapped through `COINGECKO_COIN_ID_MAP`.
|
|
10
|
+
*
|
|
11
|
+
* @param symbol - Token symbol (case-insensitive). Must be present in
|
|
12
|
+
* `COINGECKO_COIN_ID_MAP`.
|
|
13
|
+
* @param coinGeckoKey - CoinGecko Pro API key passed as `x-cg-pro-api-key`.
|
|
14
|
+
* @returns The latest price in USD (a number) on success; `null` when the
|
|
15
|
+
* response contains an empty or missing `prices` array. `musd` (mezo-usd)
|
|
16
|
+
* is a USD-pegged stablecoin and short-circuits to a price of `1`.
|
|
17
|
+
* @throws {@link AugustValidationError} When `symbol` is not in `COINGECKO_COIN_ID_MAP`.
|
|
18
|
+
* @throws {@link AugustRateLimitError} On a 429 response from CoinGecko.
|
|
19
|
+
* @throws {@link AugustServerError} On any other non-2xx response.
|
|
20
|
+
*/
|
|
21
|
+
async function fetchTokenPricesFromCoinGecko(symbol, coinGeckoKey) {
|
|
22
|
+
const coinId = utils_1.COINGECKO_COIN_ID_MAP[symbol.toLowerCase()];
|
|
23
|
+
if (coinId === 'mezo-usd') {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
if (!coinId) {
|
|
27
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', `fetchTokenPricesFromCoinGecko: symbol "${symbol}" is not in COINGECKO_COIN_ID_MAP`, { context: { symbol } });
|
|
28
|
+
}
|
|
29
|
+
const sevendDaysInS = 7 * 24 * 60 * 60;
|
|
30
|
+
const from = Date.now() / 1000 - sevendDaysInS;
|
|
31
|
+
const url = `https://pro-api.coingecko.com/api/v3/coins/${coinId}/market_chart/range?vs_currency=usd&from=${from}&to=${Math.floor(Date.now() / 1000)}&interval=daily`;
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'x-cg-pro-api-key': coinGeckoKey,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
if (response.status === 429) {
|
|
42
|
+
throw new errors_1.AugustRateLimitError(`CoinGecko rate-limited (429): symbol "${symbol}"`, { context: { symbol, coinId, status: response.status } });
|
|
43
|
+
}
|
|
44
|
+
throw new errors_1.AugustServerError(response.status, `CoinGecko API error ${response.status} ${response.statusText}: symbol "${symbol}"`, { context: { symbol, coinId } });
|
|
45
|
+
}
|
|
46
|
+
const data = (await response.json());
|
|
47
|
+
// `/market_chart/range` returns `{ prices, market_caps, total_volumes }` —
|
|
48
|
+
// an object. The previous `data.length` check was always falsy on the
|
|
49
|
+
// success path and silently collapsed every valid response to `null`.
|
|
50
|
+
if (data?.prices?.length) {
|
|
51
|
+
return data.prices[data.prices.length - 1][1];
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger_1.Logger.log.error('fetchTokenPricesFromCoinGecko', error, {
|
|
57
|
+
coinId,
|
|
58
|
+
symbol,
|
|
59
|
+
});
|
|
60
|
+
// Re-throw typed SDK errors (AugustRateLimitError, AugustServerError, etc.)
|
|
61
|
+
// so callers can distinguish rate-limits and server errors from "no data".
|
|
62
|
+
if (error instanceof errors_1.AugustSDKError)
|
|
63
|
+
throw error;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# 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("./utils"), exports);
|
|
18
|
+
__exportStar(require("./fetcher"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const COINGECKO_COIN_ID_MAP: Record<string, string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COINGECKO_COIN_ID_MAP = void 0;
|
|
4
|
+
exports.COINGECKO_COIN_ID_MAP = {
|
|
5
|
+
rseth: 'kelp-dao-restaked-eth',
|
|
6
|
+
usdc: 'usd-coin',
|
|
7
|
+
cbbtc: 'coinbase-wrapped-btc',
|
|
8
|
+
lbtc: 'lombard-staked-btc',
|
|
9
|
+
wsteth: 'wrapped-steth',
|
|
10
|
+
susde: 'ethena-staked-usde',
|
|
11
|
+
ausd: 'agora-dollar',
|
|
12
|
+
wavax: 'wrapped-avax',
|
|
13
|
+
cusdo: 'compounding-open-dollar',
|
|
14
|
+
whype: 'wrapped-hype',
|
|
15
|
+
usdt: 'binance-bridged-usdt-bnb-smart-chain',
|
|
16
|
+
usr: 'resolv-usr',
|
|
17
|
+
tbtc: 'tbtc',
|
|
18
|
+
ubtc: 'unit-bitcoin',
|
|
19
|
+
weth: 'weth',
|
|
20
|
+
teth: 'treehouse-eth',
|
|
21
|
+
musd: 'mezo-usd',
|
|
22
|
+
xbtc: 'tbtc',
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { IAddress, IWSMonitorHeaders } from '../../types';
|
|
2
|
+
export interface IDebankStatsObject {
|
|
3
|
+
asset_usd_value: number;
|
|
4
|
+
debt_usd_value: number;
|
|
5
|
+
net_usd_value: number;
|
|
6
|
+
}
|
|
7
|
+
export interface IDebankPoolObject {
|
|
8
|
+
controller: string;
|
|
9
|
+
id: string;
|
|
10
|
+
chain: string;
|
|
11
|
+
project_id: string;
|
|
12
|
+
adapter_id?: string | null;
|
|
13
|
+
time_at?: number | null;
|
|
14
|
+
}
|
|
15
|
+
export interface IDebankProxyDetailObject {
|
|
16
|
+
project?: Record<string, unknown> | null;
|
|
17
|
+
proxy_contract_id?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface IDebankTokenObject {
|
|
20
|
+
id: string;
|
|
21
|
+
chain: string;
|
|
22
|
+
name: string;
|
|
23
|
+
symbol: string;
|
|
24
|
+
display_symbol: unknown;
|
|
25
|
+
optimized_symbol: string;
|
|
26
|
+
decimals: number;
|
|
27
|
+
protocol_id: string;
|
|
28
|
+
is_core?: boolean | null;
|
|
29
|
+
price: number;
|
|
30
|
+
time_at?: number | null;
|
|
31
|
+
logo_url?: string | null;
|
|
32
|
+
price_24h_change?: number | null;
|
|
33
|
+
credit_score?: number | null;
|
|
34
|
+
is_verified?: boolean | null;
|
|
35
|
+
is_scam?: boolean | null;
|
|
36
|
+
is_suspicious?: boolean | null;
|
|
37
|
+
is_wallet?: boolean | null;
|
|
38
|
+
amount?: number | null;
|
|
39
|
+
raw_amount?: number | null;
|
|
40
|
+
}
|
|
41
|
+
export interface IDebankAppTokenObject {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
symbol: string;
|
|
45
|
+
decimals: number;
|
|
46
|
+
logo_url?: string | null;
|
|
47
|
+
app_id?: string | null;
|
|
48
|
+
price: number;
|
|
49
|
+
amount?: number | null;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
export interface IDebankDetailObject {
|
|
53
|
+
supply_token_list?: IDebankTokenObject[];
|
|
54
|
+
reward_token_list?: IDebankTokenObject[];
|
|
55
|
+
borrow_token_list?: IDebankTokenObject[];
|
|
56
|
+
health_rate?: number | null;
|
|
57
|
+
}
|
|
58
|
+
export interface IDebankAppPortfolioDetailObject {
|
|
59
|
+
supply_token_list?: IDebankAppTokenObject[];
|
|
60
|
+
reward_token_list?: IDebankAppTokenObject[];
|
|
61
|
+
borrow_token_list?: IDebankAppTokenObject[];
|
|
62
|
+
description?: string | null;
|
|
63
|
+
}
|
|
64
|
+
export type IDebankPortfolioItemName = 'Yield' | 'Deposit' | 'Staked' | 'Locked' | 'Farming' | 'Leveraged Farming' | 'Lending' | 'Vesting' | 'Rewards' | 'Airdrop' | 'Liquidity Pool' | 'Options Seller' | 'Options Buyer' | 'Insurance' | 'Investment' | 'Governance' | 'Perpetuals' | 'NFT Staked' | 'NFT Liquidity Pool' | 'NFT Lending' | 'NFT Fraction' | 'NFT P2P Borrower' | 'NFT P2P Lender';
|
|
65
|
+
export interface IDebankPortfolioItemObject {
|
|
66
|
+
stats: IDebankStatsObject;
|
|
67
|
+
update_at: number;
|
|
68
|
+
name: IDebankPortfolioItemName;
|
|
69
|
+
detail_types: string[];
|
|
70
|
+
detail: IDebankDetailObject;
|
|
71
|
+
proxy_detail?: IDebankProxyDetailObject | null;
|
|
72
|
+
position_index?: string | null;
|
|
73
|
+
pool: IDebankPoolObject;
|
|
74
|
+
}
|
|
75
|
+
export interface IDebankAppPortfolioItemObject {
|
|
76
|
+
stats: IDebankStatsObject;
|
|
77
|
+
update_at: number;
|
|
78
|
+
name: string;
|
|
79
|
+
detail_types: string[];
|
|
80
|
+
detail: IDebankAppPortfolioDetailObject;
|
|
81
|
+
proxy_detail?: IDebankProxyDetailObject | null;
|
|
82
|
+
position_index?: string | null;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface IDebankUserProtocol {
|
|
86
|
+
id: string;
|
|
87
|
+
chain: string;
|
|
88
|
+
name: string;
|
|
89
|
+
logo_url?: string | null;
|
|
90
|
+
site_url: string;
|
|
91
|
+
has_supported_portfolio: boolean;
|
|
92
|
+
portfolio_item_list: IDebankPortfolioItemObject[];
|
|
93
|
+
}
|
|
94
|
+
export interface IDebankAppProtocol {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
logo_url?: string | null;
|
|
98
|
+
site_url: string;
|
|
99
|
+
has_supported_portfolio: boolean;
|
|
100
|
+
portfolio_item_list: IDebankAppPortfolioItemObject[];
|
|
101
|
+
}
|
|
102
|
+
export interface IDebankAccountData {
|
|
103
|
+
positions: IDebankUserProtocol[];
|
|
104
|
+
app_positions: IDebankAppProtocol[];
|
|
105
|
+
tokens: IDebankTokenObject[];
|
|
106
|
+
}
|
|
107
|
+
export interface IDebankAccountDataError {
|
|
108
|
+
error: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Response type for vault-level DeBank data.
|
|
112
|
+
* Keys are subaccount addresses, values are either DeBank data or error objects.
|
|
113
|
+
*/
|
|
114
|
+
export type IVaultDebankResponse = Record<string, IDebankAccountData | IDebankAccountDataError>;
|
|
115
|
+
/**
|
|
116
|
+
* Fetch DeBank data for all subaccounts of a vault in a single request.
|
|
117
|
+
* @param vaultAddress The vault contract address
|
|
118
|
+
* @param headers Optional monitoring headers
|
|
119
|
+
* @returns Dictionary of subaccount addresses to DeBank data, or false on error
|
|
120
|
+
*/
|
|
121
|
+
export declare function fetchVaultDebankResponse(vaultAddress: IAddress, headers?: IWSMonitorHeaders): Promise<IVaultDebankResponse | false>;
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated Use fetchVaultDebankResponse for vault-level queries.
|
|
124
|
+
* Fetch DeBank data for a single subaccount address.
|
|
125
|
+
*/
|
|
126
|
+
export declare function fetchDebankResponse(address: IAddress, headers?: IWSMonitorHeaders): Promise<any>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVaultDebankResponse = fetchVaultDebankResponse;
|
|
4
|
+
exports.fetchDebankResponse = fetchDebankResponse;
|
|
5
|
+
const core_1 = require("../../core");
|
|
6
|
+
/**
|
|
7
|
+
* Fetch DeBank data for all subaccounts of a vault in a single request.
|
|
8
|
+
* @param vaultAddress The vault contract address
|
|
9
|
+
* @param headers Optional monitoring headers
|
|
10
|
+
* @returns Dictionary of subaccount addresses to DeBank data, or false on error
|
|
11
|
+
*/
|
|
12
|
+
async function fetchVaultDebankResponse(vaultAddress, headers) {
|
|
13
|
+
try {
|
|
14
|
+
const response = await (0, core_1.fetchAugustPublic)(core_1.WEBSERVER_ENDPOINTS.public.tokenizedVault.debank(vaultAddress), { headers: headers });
|
|
15
|
+
// 200 = success, 207 = partial success (some subaccounts failed)
|
|
16
|
+
if (response.status === 200 || response.status === 207) {
|
|
17
|
+
const data = (await response.json());
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
core_1.Logger.log.error('fetchVaultDebankResponse', new Error(`HTTP ${response.status} ${response.statusText}`), { status: response.status, statusText: response.statusText });
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
core_1.Logger.log.error('fetchVaultDebankResponse', e);
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use fetchVaultDebankResponse for vault-level queries.
|
|
30
|
+
* Fetch DeBank data for a single subaccount address.
|
|
31
|
+
*/
|
|
32
|
+
async function fetchDebankResponse(address, headers) {
|
|
33
|
+
// filter out hyperevm since debank does not yet support hyperevm
|
|
34
|
+
const debankResponse = await (0, core_1.fetchAugustWithKey)(undefined, core_1.WEBSERVER_ENDPOINTS.subaccount.debank(address), { override: true, headers: headers });
|
|
35
|
+
if (debankResponse.status !== 200) {
|
|
36
|
+
core_1.Logger.log.error('fetchDebankResponse', new Error(`HTTP ${debankResponse.status} ${debankResponse.statusText}`), {
|
|
37
|
+
status: debankResponse.status,
|
|
38
|
+
statusText: debankResponse.statusText,
|
|
39
|
+
});
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
else if (debankResponse.status === 200) {
|
|
43
|
+
const debankRes = await debankResponse.json();
|
|
44
|
+
return debankRes;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# 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("./utils"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IAddress, IDebankProtocolExposure, IDebankTokenExposure } from '../../types';
|
|
2
|
+
export interface IDebankNormalizedResponse {
|
|
3
|
+
subaccount: {
|
|
4
|
+
positions: any[];
|
|
5
|
+
tokens: any[];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare function parseVaultLevelDebank(debankRes: any, protocolExposure: IDebankProtocolExposure[], tokenExposure: IDebankTokenExposure[], borrower: IAddress, exposurePerCategory: any, netValue: any): {
|
|
9
|
+
tokenMap: Record<string, string>;
|
|
10
|
+
protocolTokenMap: Record<string, string[]>;
|
|
11
|
+
protocolExposures: any;
|
|
12
|
+
tokenExposures: any;
|
|
13
|
+
loansExposure: {
|
|
14
|
+
exposure: any[];
|
|
15
|
+
positions: any[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function getVaultExposure(debankResponse: any): {
|
|
19
|
+
borrowing_exposure: {
|
|
20
|
+
symbol: string;
|
|
21
|
+
chain: string;
|
|
22
|
+
amount: number;
|
|
23
|
+
}[];
|
|
24
|
+
supplying_exposure: {
|
|
25
|
+
symbol: string;
|
|
26
|
+
chain: string;
|
|
27
|
+
amount: number;
|
|
28
|
+
}[];
|
|
29
|
+
wallet_exposure: {
|
|
30
|
+
symbol: string;
|
|
31
|
+
chain: string;
|
|
32
|
+
amount: number;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
export declare function parseLoanLevelDebank(debankRes: any): {
|
|
36
|
+
exposure: any[];
|
|
37
|
+
positions: any[];
|
|
38
|
+
};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseVaultLevelDebank = parseVaultLevelDebank;
|
|
4
|
+
exports.getVaultExposure = getVaultExposure;
|
|
5
|
+
exports.parseLoanLevelDebank = parseLoanLevelDebank;
|
|
6
|
+
const core_1 = require("../../core");
|
|
7
|
+
const core_2 = require("../../core/helpers/core");
|
|
8
|
+
function addToTokenExposure(token, tokenExposure, exposureType, protocol, exposurePerCategory, netValue, borrower) {
|
|
9
|
+
const usdAmount = Number(token?.price || 0) * Number(token?.amount);
|
|
10
|
+
if (exposureType === 'wallet'
|
|
11
|
+
? !(0, core_2.filterOutBySize)(usdAmount)
|
|
12
|
+
: !(0, core_2.filterOutBySize)(usdAmount))
|
|
13
|
+
return;
|
|
14
|
+
if (exposureType === 'borrow') {
|
|
15
|
+
netValue.value -= usdAmount;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
netValue.value += usdAmount;
|
|
19
|
+
}
|
|
20
|
+
const foundTokenExposure = tokenExposure.find((t) => t.symbol === token?.symbol);
|
|
21
|
+
if (foundTokenExposure &&
|
|
22
|
+
foundTokenExposure?.exposureType === tokenExposure) {
|
|
23
|
+
foundTokenExposure.amount += usdAmount;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const protoReturnObj = {
|
|
27
|
+
id: token?.id,
|
|
28
|
+
chain: token?.chain,
|
|
29
|
+
name: token?.name,
|
|
30
|
+
symbol: token?.optimized_symbol || token?.symbol,
|
|
31
|
+
decimals: token?.decimals,
|
|
32
|
+
logoUrl: token?.logo_url,
|
|
33
|
+
amount: usdAmount,
|
|
34
|
+
protocol: protocol,
|
|
35
|
+
exposureType: exposureType,
|
|
36
|
+
};
|
|
37
|
+
if (exposureType === 'wallet') {
|
|
38
|
+
exposurePerCategory.wallet.push(protoReturnObj);
|
|
39
|
+
}
|
|
40
|
+
else if (exposureType === 'borrow') {
|
|
41
|
+
exposurePerCategory.borrowing.push(protoReturnObj);
|
|
42
|
+
}
|
|
43
|
+
else if (exposureType === 'supply') {
|
|
44
|
+
exposurePerCategory.supplying.push(protoReturnObj);
|
|
45
|
+
}
|
|
46
|
+
tokenExposure.push(protoReturnObj);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue) {
|
|
50
|
+
// new mapping to grab vault-level token and protocol exposure per
|
|
51
|
+
const tokenMap = {};
|
|
52
|
+
const protocolTokenMap = {};
|
|
53
|
+
const protocolExposures = debankRes?.subaccount?.positions || [];
|
|
54
|
+
const appProtocolExposures = debankRes?.subaccount?.app_positions || [];
|
|
55
|
+
const tokenExposures = debankRes?.subaccount?.tokens || [];
|
|
56
|
+
protocolExposures.forEach((pos) => {
|
|
57
|
+
// protocol-level data fetching
|
|
58
|
+
const protoReturnObj = {
|
|
59
|
+
id: pos?.id,
|
|
60
|
+
chain: pos?.chain,
|
|
61
|
+
protocol: pos?.name,
|
|
62
|
+
logoUrl: pos?.logo_url,
|
|
63
|
+
siteUrl: pos?.site_url,
|
|
64
|
+
assetUsdValue: 0,
|
|
65
|
+
debtUsdValue: 0,
|
|
66
|
+
netUsdValue: 0,
|
|
67
|
+
label: pos?.portfolio_item_list?.[0]?.name,
|
|
68
|
+
tokenExposure: tokenMap,
|
|
69
|
+
protocolExposure: protocolTokenMap,
|
|
70
|
+
address: borrower,
|
|
71
|
+
};
|
|
72
|
+
pos?.portfolio_item_list?.forEach((item) => {
|
|
73
|
+
// initialize protocol exposure
|
|
74
|
+
protoReturnObj.assetUsdValue += item?.stats?.asset_usd_value || 0;
|
|
75
|
+
protoReturnObj.debtUsdValue += item?.stats?.debt_usd_value || 0;
|
|
76
|
+
protoReturnObj.netUsdValue += item?.stats?.net_usd_value || 0;
|
|
77
|
+
});
|
|
78
|
+
const foundExistingProtocolExposure = protocolExposure.find((exp) => exp.id === pos.id);
|
|
79
|
+
if (!foundExistingProtocolExposure &&
|
|
80
|
+
(0, core_2.filterOutBySize)(protoReturnObj.netUsdValue)) {
|
|
81
|
+
protocolExposure.push(protoReturnObj);
|
|
82
|
+
}
|
|
83
|
+
else if (foundExistingProtocolExposure) {
|
|
84
|
+
foundExistingProtocolExposure.netUsdValue += protoReturnObj.netUsdValue;
|
|
85
|
+
foundExistingProtocolExposure.debtUsdValue += protoReturnObj.debtUsdValue;
|
|
86
|
+
foundExistingProtocolExposure.assetUsdValue +=
|
|
87
|
+
protoReturnObj.assetUsdValue;
|
|
88
|
+
}
|
|
89
|
+
// go through the debank portfolio
|
|
90
|
+
pos.portfolio_item_list.forEach((item) => {
|
|
91
|
+
item.detail.supply_token_list.forEach((sup) => {
|
|
92
|
+
// add protocol id for vault-level "protocol exposure"
|
|
93
|
+
if (sup?.protocol_id) {
|
|
94
|
+
const existingArray = protocolTokenMap[sup.protocol_id] || [];
|
|
95
|
+
if (!existingArray.includes(sup.symbol))
|
|
96
|
+
existingArray.push(sup.symbol);
|
|
97
|
+
}
|
|
98
|
+
// add token to vault "token exposure"
|
|
99
|
+
addToTokenExposure(sup, tokenExposure, 'supply', pos.id, exposurePerCategory, netValue, borrower);
|
|
100
|
+
// add token image url to token mapping for display
|
|
101
|
+
if (sup?.symbol && sup?.logo_url) {
|
|
102
|
+
tokenMap[sup.symbol] = sup.logo_url;
|
|
103
|
+
}
|
|
104
|
+
tokenMap[sup.supplying_exposure] = 'true';
|
|
105
|
+
});
|
|
106
|
+
item.detail.borrow_token_list.forEach((bor) => {
|
|
107
|
+
// add token to vault "token exposure"
|
|
108
|
+
addToTokenExposure(bor, tokenExposure, 'borrow', pos.id, exposurePerCategory, netValue, borrower);
|
|
109
|
+
// add token image url to token mapping for display
|
|
110
|
+
if (bor?.symbol && bor?.logo_url) {
|
|
111
|
+
tokenMap[bor.symbol] = bor.logo_url;
|
|
112
|
+
}
|
|
113
|
+
tokenMap[bor.supplying_exposure] = 'true';
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
// Process non-EVM app protocols (e.g. Hyperliquid, Lighter).
|
|
118
|
+
// These lack chain and protocol_id fields unlike EVM-based positions.
|
|
119
|
+
appProtocolExposures.forEach((pos) => {
|
|
120
|
+
const protoReturnObj = {
|
|
121
|
+
id: pos?.id,
|
|
122
|
+
chain: null,
|
|
123
|
+
protocol: pos?.name,
|
|
124
|
+
logoUrl: pos?.logo_url,
|
|
125
|
+
siteUrl: pos?.site_url,
|
|
126
|
+
assetUsdValue: 0,
|
|
127
|
+
debtUsdValue: 0,
|
|
128
|
+
netUsdValue: 0,
|
|
129
|
+
label: pos?.portfolio_item_list?.[0]?.name,
|
|
130
|
+
tokenExposure: tokenMap,
|
|
131
|
+
protocolExposure: protocolTokenMap,
|
|
132
|
+
address: borrower,
|
|
133
|
+
};
|
|
134
|
+
pos?.portfolio_item_list?.forEach((item) => {
|
|
135
|
+
protoReturnObj.assetUsdValue += item?.stats?.asset_usd_value || 0;
|
|
136
|
+
protoReturnObj.debtUsdValue += item?.stats?.debt_usd_value || 0;
|
|
137
|
+
protoReturnObj.netUsdValue += item?.stats?.net_usd_value || 0;
|
|
138
|
+
});
|
|
139
|
+
const foundExistingProtocolExposure = protocolExposure.find((exp) => exp.id === pos.id);
|
|
140
|
+
if (!foundExistingProtocolExposure &&
|
|
141
|
+
(0, core_2.filterOutBySize)(protoReturnObj.netUsdValue)) {
|
|
142
|
+
protocolExposure.push(protoReturnObj);
|
|
143
|
+
}
|
|
144
|
+
else if (foundExistingProtocolExposure) {
|
|
145
|
+
foundExistingProtocolExposure.netUsdValue += protoReturnObj.netUsdValue;
|
|
146
|
+
foundExistingProtocolExposure.debtUsdValue += protoReturnObj.debtUsdValue;
|
|
147
|
+
foundExistingProtocolExposure.assetUsdValue +=
|
|
148
|
+
protoReturnObj.assetUsdValue;
|
|
149
|
+
}
|
|
150
|
+
pos?.portfolio_item_list?.forEach((item) => {
|
|
151
|
+
(item?.detail?.supply_token_list || []).forEach((sup) => {
|
|
152
|
+
addToTokenExposure(sup, tokenExposure, 'supply', pos.id, exposurePerCategory, netValue, borrower);
|
|
153
|
+
if (sup?.symbol && sup?.logo_url) {
|
|
154
|
+
tokenMap[sup.symbol] = sup.logo_url;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
(item?.detail?.borrow_token_list || []).forEach((bor) => {
|
|
158
|
+
addToTokenExposure(bor, tokenExposure, 'borrow', pos.id, exposurePerCategory, netValue, borrower);
|
|
159
|
+
if (bor?.symbol && bor?.logo_url) {
|
|
160
|
+
tokenMap[bor.symbol] = bor.logo_url;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
tokenExposures?.forEach((token) => {
|
|
166
|
+
if (token?.is_wallet) {
|
|
167
|
+
addToTokenExposure(token, tokenExposure, 'wallet', null, exposurePerCategory, netValue, borrower);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const loanLevelExposure = parseLoanLevelDebank(debankRes);
|
|
171
|
+
return {
|
|
172
|
+
tokenMap,
|
|
173
|
+
protocolTokenMap,
|
|
174
|
+
protocolExposures,
|
|
175
|
+
tokenExposures,
|
|
176
|
+
loansExposure: loanLevelExposure,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function getVaultExposure(debankResponse) {
|
|
180
|
+
const borrowing_exposure = [];
|
|
181
|
+
const supplying_exposure = [];
|
|
182
|
+
const wallet_exposure = [];
|
|
183
|
+
const positions = debankResponse?.subaccount?.positions ?? [];
|
|
184
|
+
const tokens = debankResponse?.subaccount?.tokens ?? [];
|
|
185
|
+
for (const position of positions) {
|
|
186
|
+
const portfolioItems = position?.portfolio_item_list ?? [];
|
|
187
|
+
for (const item of portfolioItems) {
|
|
188
|
+
const borrowTokens = item?.detail?.borrow_token_list ?? [];
|
|
189
|
+
const supplyTokens = item?.detail?.supply_token_list ?? [];
|
|
190
|
+
for (const token of tokens) {
|
|
191
|
+
if (token?.symbol && token?.is_core) {
|
|
192
|
+
wallet_exposure.push({
|
|
193
|
+
symbol: token.symbol,
|
|
194
|
+
chain: token.chain,
|
|
195
|
+
amount: token.amount * token.price,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (const token of borrowTokens) {
|
|
200
|
+
if (token?.symbol &&
|
|
201
|
+
!token.is_suspicious &&
|
|
202
|
+
!token.is_scam &&
|
|
203
|
+
token?.is_core) {
|
|
204
|
+
borrowing_exposure.push({
|
|
205
|
+
symbol: token.symbol,
|
|
206
|
+
chain: token.chain,
|
|
207
|
+
amount: token.amount * token.price,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for (const token of supplyTokens) {
|
|
212
|
+
if (token?.symbol &&
|
|
213
|
+
!token.is_suspicious &&
|
|
214
|
+
!token.is_scam &&
|
|
215
|
+
token?.is_core) {
|
|
216
|
+
// Not sure what isWallet is, but I'm guessing is that this field means that it should be in wallet exposure...
|
|
217
|
+
// fwiw I have seen this double counted in supplyTokens AND tokens
|
|
218
|
+
if (!token.is_wallet) {
|
|
219
|
+
supplying_exposure.push({
|
|
220
|
+
symbol: token.symbol,
|
|
221
|
+
chain: token.chain,
|
|
222
|
+
amount: token.amount * token.price,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { borrowing_exposure, supplying_exposure, wallet_exposure };
|
|
230
|
+
}
|
|
231
|
+
function parseLoanLevelDebank(debankRes) {
|
|
232
|
+
let positions = [];
|
|
233
|
+
let exposure = [];
|
|
234
|
+
try {
|
|
235
|
+
// new mapping to grab token and protocol exposure
|
|
236
|
+
const protocolExposures = [
|
|
237
|
+
...(debankRes?.subaccount?.positions || []),
|
|
238
|
+
...(debankRes?.subaccount?.app_positions || []),
|
|
239
|
+
];
|
|
240
|
+
// Old mapping to grab token and protocol exposure
|
|
241
|
+
positions = protocolExposures?.map((p) => ({
|
|
242
|
+
value: p.logo_url,
|
|
243
|
+
label: p.name,
|
|
244
|
+
}));
|
|
245
|
+
exposure = protocolExposures?.map((p) => p.portfolio_item_list?.map((li) => {
|
|
246
|
+
const extra = {
|
|
247
|
+
value: li.pool?.controller,
|
|
248
|
+
label: li.pool?.adapter_id,
|
|
249
|
+
usd: li?.stats?.asset_usd_value,
|
|
250
|
+
};
|
|
251
|
+
if (li.detail?.supply_token_list?.length) {
|
|
252
|
+
const returnArr = li.detail?.supply_token_list?.map((t) => ({
|
|
253
|
+
value: t?.id,
|
|
254
|
+
label: t?.symbol,
|
|
255
|
+
usd: t?.amount * t?.price,
|
|
256
|
+
}));
|
|
257
|
+
return [...returnArr, extra];
|
|
258
|
+
}
|
|
259
|
+
return extra;
|
|
260
|
+
}));
|
|
261
|
+
// this is a request where if there is no protocol exposure then show any spots
|
|
262
|
+
// over 10k in collateral exposure
|
|
263
|
+
if (protocolExposures.length === 0) {
|
|
264
|
+
if (debankRes?.subaccount?.tokens) {
|
|
265
|
+
debankRes.subaccount.tokens.forEach((t) => {
|
|
266
|
+
if (t?.amount && t?.price && t.amount * t.price >= 10_000) {
|
|
267
|
+
exposure.push({
|
|
268
|
+
value: t?.id,
|
|
269
|
+
label: t?.symbol,
|
|
270
|
+
usd: t?.amount && t?.price ? t.amount * t.price : '',
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exposure = exposure?.flat()?.flat();
|
|
277
|
+
const uniqueExposure = [];
|
|
278
|
+
exposure?.forEach(function (a) {
|
|
279
|
+
if (!this[a.value]) {
|
|
280
|
+
if (a?.value === '0xa1290d69c65a6fe4df752f95823fae25cb99e5a7') {
|
|
281
|
+
this[a.value] = { ...a, label: 'rsETH' };
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this[a.value] = { ...a };
|
|
285
|
+
}
|
|
286
|
+
uniqueExposure.push(this[a.value]);
|
|
287
|
+
}
|
|
288
|
+
this[a.value].usd += a.usd;
|
|
289
|
+
}, Object.create(null));
|
|
290
|
+
exposure = uniqueExposure;
|
|
291
|
+
}
|
|
292
|
+
catch (err) {
|
|
293
|
+
core_1.Logger.log.error('getPoolLoansData.strategies', err);
|
|
294
|
+
}
|
|
295
|
+
return { exposure, positions };
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=utils.js.map
|