@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.
Files changed (346) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +408 -2
  3. package/lib/abis/AddressResolver.d.ts +28 -0
  4. package/lib/abis/AddressResolver.js +23 -0
  5. package/lib/abis/ChainlinkV3.d.ts +87 -0
  6. package/lib/abis/ChainlinkV3.js +117 -0
  7. package/lib/abis/ERC20.d.ts +168 -0
  8. package/lib/abis/ERC20.js +226 -0
  9. package/lib/abis/ERC20_Bytes32.d.ts +139 -0
  10. package/lib/abis/ERC20_Bytes32.js +196 -0
  11. package/lib/abis/ERC4626.d.ts +364 -0
  12. package/lib/abis/ERC4626.js +507 -0
  13. package/lib/abis/ERC721.d.ts +231 -0
  14. package/lib/abis/ERC721.js +321 -0
  15. package/lib/abis/FeeOracle.d.ts +120 -0
  16. package/lib/abis/FeeOracle.js +162 -0
  17. package/lib/abis/LendingPool.d.ts +1393 -0
  18. package/lib/abis/LendingPool.js +1807 -0
  19. package/lib/abis/LendingPoolV2.d.ts +1413 -0
  20. package/lib/abis/LendingPoolV2.js +1833 -0
  21. package/lib/abis/LendingPoolV3.d.ts +1677 -0
  22. package/lib/abis/LendingPoolV3.js +1160 -0
  23. package/lib/abis/Loan.d.ts +837 -0
  24. package/lib/abis/Loan.js +1080 -0
  25. package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
  26. package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
  27. package/lib/abis/Multicall3.d.ts +30 -0
  28. package/lib/abis/Multicall3.js +97 -0
  29. package/lib/abis/OFT.d.ts +116 -0
  30. package/lib/abis/OFT.js +85 -0
  31. package/lib/abis/PoolAdapter.d.ts +36 -0
  32. package/lib/abis/PoolAdapter.js +51 -0
  33. package/lib/abis/RewardDistributor.d.ts +267 -0
  34. package/lib/abis/RewardDistributor.js +352 -0
  35. package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
  36. package/lib/abis/RwaRedeemSubaccount.js +548 -0
  37. package/lib/abis/SmartAccount.d.ts +17 -0
  38. package/lib/abis/SmartAccount.js +19 -0
  39. package/lib/abis/SwapRouter.d.ts +953 -0
  40. package/lib/abis/SwapRouter.js +1228 -0
  41. package/lib/abis/TextResolver.d.ts +16 -0
  42. package/lib/abis/TextResolver.js +16 -0
  43. package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
  44. package/lib/abis/TokenizedVaultV2.js +1041 -0
  45. package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
  46. package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
  47. package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
  48. package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
  49. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
  50. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
  51. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
  52. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
  53. package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
  54. package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
  55. package/lib/abis/UniversalResolverResolve.d.ts +69 -0
  56. package/lib/abis/UniversalResolverResolve.js +35 -0
  57. package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
  58. package/lib/abis/UniversalSignatureValidator.js +30 -0
  59. package/lib/abis/WrapperAdapter.d.ts +71 -0
  60. package/lib/abis/WrapperAdapter.js +77 -0
  61. package/lib/abis/index.d.ts +34 -0
  62. package/lib/abis/index.js +51 -0
  63. package/lib/adapters/evm/getters.d.ts +19 -0
  64. package/lib/adapters/evm/getters.js +249 -0
  65. package/lib/adapters/evm/index.d.ts +539 -0
  66. package/lib/adapters/evm/index.js +656 -0
  67. package/lib/adapters/evm/utils.d.ts +8 -0
  68. package/lib/adapters/evm/utils.js +51 -0
  69. package/lib/adapters/solana/confirm.d.ts +88 -0
  70. package/lib/adapters/solana/confirm.js +291 -0
  71. package/lib/adapters/solana/constants.d.ts +42 -0
  72. package/lib/adapters/solana/constants.js +59 -0
  73. package/lib/adapters/solana/getters.d.ts +42 -0
  74. package/lib/adapters/solana/getters.js +275 -0
  75. package/lib/adapters/solana/idl/vault-idl.d.ts +700 -0
  76. package/lib/adapters/solana/idl/vault-idl.js +2101 -0
  77. package/lib/adapters/solana/idl/withdrawal-queue-idl.d.ts +795 -0
  78. package/lib/adapters/solana/idl/withdrawal-queue-idl.js +1864 -0
  79. package/lib/adapters/solana/index.d.ts +372 -0
  80. package/lib/adapters/solana/index.js +459 -0
  81. package/lib/adapters/solana/pricing.d.ts +184 -0
  82. package/lib/adapters/solana/pricing.js +239 -0
  83. package/lib/adapters/solana/queue-hints.d.ts +29 -0
  84. package/lib/adapters/solana/queue-hints.js +59 -0
  85. package/lib/adapters/solana/queue.actions.d.ts +97 -0
  86. package/lib/adapters/solana/queue.actions.js +468 -0
  87. package/lib/adapters/solana/token-reads.d.ts +108 -0
  88. package/lib/adapters/solana/token-reads.js +145 -0
  89. package/lib/adapters/solana/types.d.ts +325 -0
  90. package/lib/adapters/solana/types.js +3 -0
  91. package/lib/adapters/solana/utils.d.ts +229 -0
  92. package/lib/adapters/solana/utils.js +773 -0
  93. package/lib/adapters/solana/vault.actions.d.ts +140 -0
  94. package/lib/adapters/solana/vault.actions.js +657 -0
  95. package/lib/adapters/solana/withdrawal-queue.d.ts +125 -0
  96. package/lib/adapters/solana/withdrawal-queue.js +301 -0
  97. package/lib/adapters/stellar/actions.d.ts +41 -0
  98. package/lib/adapters/stellar/actions.js +126 -0
  99. package/lib/adapters/stellar/constants.d.ts +43 -0
  100. package/lib/adapters/stellar/constants.js +53 -0
  101. package/lib/adapters/stellar/getters.d.ts +68 -0
  102. package/lib/adapters/stellar/getters.js +290 -0
  103. package/lib/adapters/stellar/index.d.ts +126 -0
  104. package/lib/adapters/stellar/index.js +187 -0
  105. package/lib/adapters/stellar/invocation.d.ts +55 -0
  106. package/lib/adapters/stellar/invocation.js +92 -0
  107. package/lib/adapters/stellar/soroban.d.ts +131 -0
  108. package/lib/adapters/stellar/soroban.js +617 -0
  109. package/lib/adapters/stellar/submit.d.ts +42 -0
  110. package/lib/adapters/stellar/submit.js +195 -0
  111. package/lib/adapters/stellar/types.d.ts +57 -0
  112. package/lib/adapters/stellar/types.js +6 -0
  113. package/lib/adapters/stellar/utils.d.ts +24 -0
  114. package/lib/adapters/stellar/utils.js +34 -0
  115. package/lib/adapters/sui/constants.d.ts +1 -0
  116. package/lib/adapters/sui/constants.js +9 -0
  117. package/lib/adapters/sui/getters.d.ts +24 -0
  118. package/lib/adapters/sui/getters.js +134 -0
  119. package/lib/adapters/sui/index.d.ts +53 -0
  120. package/lib/adapters/sui/index.js +96 -0
  121. package/lib/adapters/sui/transformer.d.ts +10 -0
  122. package/lib/adapters/sui/transformer.js +115 -0
  123. package/lib/adapters/sui/types.d.ts +70 -0
  124. package/lib/adapters/sui/types.js +3 -0
  125. package/lib/adapters/sui/utils.d.ts +8 -0
  126. package/lib/adapters/sui/utils.js +17 -0
  127. package/lib/core/analytics/app-name.d.ts +27 -0
  128. package/lib/core/analytics/app-name.js +48 -0
  129. package/lib/core/analytics/chain-name.d.ts +9 -0
  130. package/lib/core/analytics/chain-name.js +34 -0
  131. package/lib/core/analytics/constants.d.ts +15 -0
  132. package/lib/core/analytics/constants.js +28 -0
  133. package/lib/core/analytics/env.d.ts +46 -0
  134. package/lib/core/analytics/env.js +147 -0
  135. package/lib/core/analytics/index.d.ts +39 -0
  136. package/lib/core/analytics/index.js +83 -0
  137. package/lib/core/analytics/instrumentation.d.ts +29 -0
  138. package/lib/core/analytics/instrumentation.js +292 -0
  139. package/lib/core/analytics/method-taxonomy.d.ts +19 -0
  140. package/lib/core/analytics/method-taxonomy.js +156 -0
  141. package/lib/core/analytics/metrics.d.ts +48 -0
  142. package/lib/core/analytics/metrics.js +142 -0
  143. package/lib/core/analytics/sanitize.d.ts +57 -0
  144. package/lib/core/analytics/sanitize.js +272 -0
  145. package/lib/core/analytics/sentry-runtime.d.ts +15 -0
  146. package/lib/core/analytics/sentry-runtime.js +131 -0
  147. package/lib/core/analytics/sentry.d.ts +100 -0
  148. package/lib/core/analytics/sentry.js +696 -0
  149. package/lib/core/analytics/types.d.ts +55 -0
  150. package/lib/core/analytics/types.js +3 -0
  151. package/lib/core/analytics/user-identity.d.ts +55 -0
  152. package/lib/core/analytics/user-identity.js +218 -0
  153. package/lib/core/analytics/version.d.ts +6 -0
  154. package/lib/core/analytics/version.js +10 -0
  155. package/lib/core/attribution.d.ts +159 -0
  156. package/lib/core/attribution.js +194 -0
  157. package/lib/core/auth/index.d.ts +1 -0
  158. package/lib/core/auth/index.js +18 -0
  159. package/lib/core/auth/verify.d.ts +2 -0
  160. package/lib/core/auth/verify.js +35 -0
  161. package/lib/core/base.class.d.ts +193 -0
  162. package/lib/core/base.class.js +163 -0
  163. package/lib/core/cache.d.ts +9 -0
  164. package/lib/core/cache.js +31 -0
  165. package/lib/core/constants/adapters.d.ts +103 -0
  166. package/lib/core/constants/adapters.js +180 -0
  167. package/lib/core/constants/core.d.ts +162 -0
  168. package/lib/core/constants/core.js +281 -0
  169. package/lib/core/constants/swap-router.d.ts +180 -0
  170. package/lib/core/constants/swap-router.js +203 -0
  171. package/lib/core/constants/vaults.d.ts +93 -0
  172. package/lib/core/constants/vaults.js +277 -0
  173. package/lib/core/constants/web3.d.ts +106 -0
  174. package/lib/core/constants/web3.js +251 -0
  175. package/lib/core/errors/index.d.ts +177 -0
  176. package/lib/core/errors/index.js +257 -0
  177. package/lib/core/fetcher.d.ts +237 -0
  178. package/lib/core/fetcher.js +1103 -0
  179. package/lib/core/helpers/adapters.d.ts +13 -0
  180. package/lib/core/helpers/adapters.js +39 -0
  181. package/lib/core/helpers/chain-address.d.ts +13 -0
  182. package/lib/core/helpers/chain-address.js +47 -0
  183. package/lib/core/helpers/chain-error.d.ts +207 -0
  184. package/lib/core/helpers/chain-error.js +697 -0
  185. package/lib/core/helpers/chain-support.d.ts +98 -0
  186. package/lib/core/helpers/chain-support.js +139 -0
  187. package/lib/core/helpers/concurrency.d.ts +51 -0
  188. package/lib/core/helpers/concurrency.js +79 -0
  189. package/lib/core/helpers/core.d.ts +92 -0
  190. package/lib/core/helpers/core.js +368 -0
  191. package/lib/core/helpers/explorer-link.d.ts +16 -0
  192. package/lib/core/helpers/explorer-link.js +26 -0
  193. package/lib/core/helpers/multicall.d.ts +68 -0
  194. package/lib/core/helpers/multicall.js +103 -0
  195. package/lib/core/helpers/revert-decode.d.ts +248 -0
  196. package/lib/core/helpers/revert-decode.js +515 -0
  197. package/lib/core/helpers/signer.d.ts +61 -0
  198. package/lib/core/helpers/signer.js +184 -0
  199. package/lib/core/helpers/swap-router.d.ts +269 -0
  200. package/lib/core/helpers/swap-router.js +542 -0
  201. package/lib/core/helpers/vault-version.d.ts +24 -0
  202. package/lib/core/helpers/vault-version.js +83 -0
  203. package/lib/core/helpers/vaults.d.ts +89 -0
  204. package/lib/core/helpers/vaults.js +241 -0
  205. package/lib/core/helpers/web3.d.ts +366 -0
  206. package/lib/core/helpers/web3.js +1034 -0
  207. package/lib/core/index.d.ts +23 -0
  208. package/lib/core/index.js +40 -0
  209. package/lib/core/logger/curator-alert.d.ts +217 -0
  210. package/lib/core/logger/curator-alert.js +276 -0
  211. package/lib/core/logger/index.d.ts +99 -0
  212. package/lib/core/logger/index.js +163 -0
  213. package/lib/core/logger/slack.d.ts +49 -0
  214. package/lib/core/logger/slack.js +111 -0
  215. package/lib/core/vault-metadata.d.ts +12 -0
  216. package/lib/core/vault-metadata.js +42 -0
  217. package/lib/core/version-check.d.ts +58 -0
  218. package/lib/core/version-check.js +182 -0
  219. package/lib/evm/index.d.ts +2 -0
  220. package/lib/evm/index.js +19 -0
  221. package/lib/evm/methods/crossChainVault.d.ts +132 -0
  222. package/lib/evm/methods/crossChainVault.js +857 -0
  223. package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
  224. package/lib/evm/methods/crossChainVaultRegistry.js +239 -0
  225. package/lib/evm/methods/index.d.ts +2 -0
  226. package/lib/evm/methods/index.js +19 -0
  227. package/lib/evm/types/crossChain.d.ts +363 -0
  228. package/lib/evm/types/crossChain.js +20 -0
  229. package/lib/evm/types/index.d.ts +1 -0
  230. package/lib/evm/types/index.js +18 -0
  231. package/lib/index.d.ts +30 -0
  232. package/lib/index.js +52 -0
  233. package/lib/main.d.ts +596 -0
  234. package/lib/main.js +681 -0
  235. package/lib/modules/api/fetcher.d.ts +108 -0
  236. package/lib/modules/api/fetcher.js +187 -0
  237. package/lib/modules/api/index.d.ts +1 -0
  238. package/lib/modules/api/index.js +6 -0
  239. package/lib/modules/api/main.d.ts +587 -0
  240. package/lib/modules/api/main.js +911 -0
  241. package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
  242. package/lib/modules/sub-accounts/fetcher.js +96 -0
  243. package/lib/modules/sub-accounts/index.d.ts +2 -0
  244. package/lib/modules/sub-accounts/index.js +19 -0
  245. package/lib/modules/sub-accounts/main.d.ts +249 -0
  246. package/lib/modules/sub-accounts/main.js +211 -0
  247. package/lib/modules/sub-accounts/utils.d.ts +106 -0
  248. package/lib/modules/sub-accounts/utils.js +112 -0
  249. package/lib/modules/vaults/adapter.helpers.d.ts +84 -0
  250. package/lib/modules/vaults/adapter.helpers.js +202 -0
  251. package/lib/modules/vaults/fetcher.d.ts +147 -0
  252. package/lib/modules/vaults/fetcher.js +357 -0
  253. package/lib/modules/vaults/getters.d.ts +1060 -0
  254. package/lib/modules/vaults/getters.js +4079 -0
  255. package/lib/modules/vaults/index.d.ts +20 -0
  256. package/lib/modules/vaults/index.js +44 -0
  257. package/lib/modules/vaults/main.d.ts +607 -0
  258. package/lib/modules/vaults/main.js +1687 -0
  259. package/lib/modules/vaults/prefetch.d.ts +65 -0
  260. package/lib/modules/vaults/prefetch.js +120 -0
  261. package/lib/modules/vaults/read.actions.d.ts +406 -0
  262. package/lib/modules/vaults/read.actions.js +891 -0
  263. package/lib/modules/vaults/types.d.ts +149 -0
  264. package/lib/modules/vaults/types.js +3 -0
  265. package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
  266. package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
  267. package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
  268. package/lib/modules/vaults/utils/date-utils.js +84 -0
  269. package/lib/modules/vaults/utils.d.ts +153 -0
  270. package/lib/modules/vaults/utils.js +818 -0
  271. package/lib/modules/vaults/write.actions.d.ts +812 -0
  272. package/lib/modules/vaults/write.actions.js +2377 -0
  273. package/lib/polyfills.d.ts +1 -0
  274. package/lib/polyfills.js +12 -0
  275. package/lib/sdk.d.ts +30154 -0
  276. package/lib/services/coingecko/fetcher.d.ts +15 -0
  277. package/lib/services/coingecko/fetcher.js +67 -0
  278. package/lib/services/coingecko/index.d.ts +2 -0
  279. package/lib/services/coingecko/index.js +19 -0
  280. package/lib/services/coingecko/utils.d.ts +1 -0
  281. package/lib/services/coingecko/utils.js +24 -0
  282. package/lib/services/debank/fetcher.d.ts +126 -0
  283. package/lib/services/debank/fetcher.js +47 -0
  284. package/lib/services/debank/index.d.ts +2 -0
  285. package/lib/services/debank/index.js +19 -0
  286. package/lib/services/debank/utils.d.ts +50 -0
  287. package/lib/services/debank/utils.js +325 -0
  288. package/lib/services/layerzero/deposits.d.ts +55 -0
  289. package/lib/services/layerzero/deposits.js +174 -0
  290. package/lib/services/layerzero/redeems.d.ts +20 -0
  291. package/lib/services/layerzero/redeems.js +92 -0
  292. package/lib/services/layerzero/utils.d.ts +9 -0
  293. package/lib/services/layerzero/utils.js +22 -0
  294. package/lib/services/octavfi/fetcher.d.ts +33 -0
  295. package/lib/services/octavfi/fetcher.js +39 -0
  296. package/lib/services/octavfi/index.d.ts +3 -0
  297. package/lib/services/octavfi/index.js +20 -0
  298. package/lib/services/octavfi/types.d.ts +34 -0
  299. package/lib/services/octavfi/types.js +3 -0
  300. package/lib/services/octavfi/utils.d.ts +16 -0
  301. package/lib/services/octavfi/utils.js +244 -0
  302. package/lib/services/subgraph/fetcher.d.ts +2 -0
  303. package/lib/services/subgraph/fetcher.js +66 -0
  304. package/lib/services/subgraph/index.d.ts +2 -0
  305. package/lib/services/subgraph/index.js +19 -0
  306. package/lib/services/subgraph/schema.d.ts +48 -0
  307. package/lib/services/subgraph/schema.js +87 -0
  308. package/lib/services/subgraph/vaults.d.ts +83 -0
  309. package/lib/services/subgraph/vaults.js +1282 -0
  310. package/lib/services/swap-quotes/index.d.ts +105 -0
  311. package/lib/services/swap-quotes/index.js +77 -0
  312. package/lib/services/swap-quotes/paraswap.d.ts +51 -0
  313. package/lib/services/swap-quotes/paraswap.js +138 -0
  314. package/lib/services/untangled/fetcher.d.ts +40 -0
  315. package/lib/services/untangled/fetcher.js +110 -0
  316. package/lib/services/untangled/index.d.ts +3 -0
  317. package/lib/services/untangled/index.js +20 -0
  318. package/lib/services/untangled/types.d.ts +83 -0
  319. package/lib/services/untangled/types.js +10 -0
  320. package/lib/services/untangled/utils.d.ts +91 -0
  321. package/lib/services/untangled/utils.js +339 -0
  322. package/lib/types/api.d.ts +498 -0
  323. package/lib/types/api.js +3 -0
  324. package/lib/types/index.d.ts +12 -0
  325. package/lib/types/index.js +28 -0
  326. package/lib/types/points.d.ts +28 -0
  327. package/lib/types/points.js +3 -0
  328. package/lib/types/pools.d.ts +144 -0
  329. package/lib/types/pools.js +3 -0
  330. package/lib/types/staking.d.ts +28 -0
  331. package/lib/types/staking.js +3 -0
  332. package/lib/types/sub-accounts.d.ts +150 -0
  333. package/lib/types/sub-accounts.js +3 -0
  334. package/lib/types/subgraph.d.ts +84 -0
  335. package/lib/types/subgraph.js +3 -0
  336. package/lib/types/typed-contract.d.ts +102 -0
  337. package/lib/types/typed-contract.js +3 -0
  338. package/lib/types/user.d.ts +1 -0
  339. package/lib/types/user.js +3 -0
  340. package/lib/types/vaults.d.ts +886 -0
  341. package/lib/types/vaults.js +30 -0
  342. package/lib/types/web3.d.ts +81 -0
  343. package/lib/types/web3.js +14 -0
  344. package/lib/types/webserver.d.ts +730 -0
  345. package/lib/types/webserver.js +3 -0
  346. package/package.json +78 -3
@@ -0,0 +1,91 @@
1
+ import type { IDebankTokenExposure } from '../../types';
2
+ import type { IDebankNormalizedResponse } from '../debank/utils';
3
+ import type { IUntangledVaultExposure } from './types';
4
+ /** Display metadata for an Untangled protocol slug. */
5
+ export interface IUntangledProtocolMetadata {
6
+ /** Name rendered in the exposure breakdown. */
7
+ name: string;
8
+ /** Chain the protocol position lives on — not always the vault's own chain. */
9
+ chain: string;
10
+ }
11
+ /**
12
+ * Display metadata for the protocol slugs Untangled reports today.
13
+ *
14
+ * Untangled does not return protocol names or chains, so they are mapped here.
15
+ * Unknown slugs fall back to a capitalized slug on the vault's chain rather than
16
+ * being dropped, so a newly integrated protocol still shows up (unlabelled)
17
+ * instead of silently vanishing from the breakdown.
18
+ */
19
+ export declare const UNTANGLED_PROTOCOL_REGISTRY: Record<string, IUntangledProtocolMetadata>;
20
+ /**
21
+ * The vault's asset composition, as vault-level token exposure.
22
+ *
23
+ * This is the one asset breakdown Untangled actually publishes, and it is
24
+ * authoritative: `byAsset` decomposes the same `tvlUsd` that `byProtocol` does.
25
+ * It is returned separately from {@link transformUntangledToDebank} because it
26
+ * cannot be folded into that structure — attributing an asset to a position
27
+ * would require a join the API does not provide, and adding these on top of the
28
+ * synthesized position tokens would double-count the vault.
29
+ *
30
+ * Negative rows are kept. A vault that has moved capital into another Upshift
31
+ * vault is reported holding the receipt token and owing the asset it spent —
32
+ * earnXLM carries `earnUSDC +$1,170,913` against `USDC -$1,170,271` — and those
33
+ * only sum back to `tvlUsd` together. Dropping the liability would overstate the
34
+ * vault's assets by the full size of the position.
35
+ *
36
+ * @param exposure - A resolved Untangled report, or `null`/`undefined` when the
37
+ * fetch failed.
38
+ * @returns One row per asset clearing `filterOutBySize` in absolute terms,
39
+ * largest first, with `amount` denominated in USD. Empty when `exposure` is
40
+ * absent. `id` carries the asset symbol rather than an address — Untangled
41
+ * reports assets by ticker and publishes no contract address for them — so it
42
+ * is safe as a display key and must not be read as an on-chain address.
43
+ */
44
+ export declare function untangledAssetExposure(exposure: IUntangledVaultExposure | null | undefined): IDebankTokenExposure[];
45
+ /**
46
+ * Transform an Untangled vault exposure report into the DeBank-normalized shape
47
+ * that `parseVaultLevelDebank` and `parseLoanLevelDebank` consume.
48
+ *
49
+ * This is the Stellar equivalent of `transformOctavfiToDebank`: a foreign
50
+ * portfolio shape is mapped onto the one normalized structure the vault
51
+ * allocation parser understands, so Stellar vaults populate the same
52
+ * `exposurePerCategory` / `protocolExposure` / `tokenExposure` outputs as EVM
53
+ * vaults with no parser changes.
54
+ *
55
+ * Mapping:
56
+ * - Each `byProtocol` entry becomes one position with a single supplying token,
57
+ * valued in USD (`price: 1`), on the chain from
58
+ * {@link UNTANGLED_PROTOCOL_REGISTRY}. The token is labelled with the vault's
59
+ * asset only when one asset covers essentially all of it (see
60
+ * {@link vaultAssetSymbol}); otherwise it carries the value with no symbol,
61
+ * and {@link untangledAssetExposure} supplies the composition separately.
62
+ * - `stellar-wallet` becomes a wallet token, because custody cash is undeployed
63
+ * capital rather than protocol exposure.
64
+ * - `upshift` is split: the vault's own idle buffer (the `idle` location) joins
65
+ * that wallet token, and whatever is left is a real position in another
66
+ * Upshift vault, named after its receipt token. Untangled reports one
67
+ * `upshift` slice however many vaults that is, so a vault holding receipts in
68
+ * two others emits one merged position under the generic name — the value is
69
+ * still right, only the label is coarser.
70
+ * - Dust is left in place: `filterOutBySize` in the parser applies the same
71
+ * threshold Stellar and EVM vaults share.
72
+ *
73
+ * Only the `idle` entries of `locations` are consumed, to size the buffer inside
74
+ * `upshift`. `asOf`, `stale` and `tvlUsd` are not — TVL already comes from
75
+ * `getVaultTvl`, and freshness is not yet surfaced on `IVaultAllocations`.
76
+ *
77
+ * @param exposure - A resolved Untangled report, or `null`/`undefined` when the
78
+ * fetch failed.
79
+ * @returns A DeBank-normalized response. Empty positions and tokens when
80
+ * `exposure` is absent, so callers can pass a failed fetch straight through.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const exposure = await fetchUntangledVaultExposure(vault);
85
+ * const normalized = transformUntangledToDebank(exposure);
86
+ * parseVaultLevelDebank(
87
+ * normalized, protocolExposure, tokenExposure, vault, exposurePerCategory, netValue,
88
+ * );
89
+ * ```
90
+ */
91
+ export declare function transformUntangledToDebank(exposure: IUntangledVaultExposure | null | undefined): IDebankNormalizedResponse;
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNTANGLED_PROTOCOL_REGISTRY = void 0;
4
+ exports.untangledAssetExposure = untangledAssetExposure;
5
+ exports.transformUntangledToDebank = transformUntangledToDebank;
6
+ const core_1 = require("../../core/helpers/core");
7
+ /**
8
+ * Display metadata for the protocol slugs Untangled reports today.
9
+ *
10
+ * Untangled does not return protocol names or chains, so they are mapped here.
11
+ * Unknown slugs fall back to a capitalized slug on the vault's chain rather than
12
+ * being dropped, so a newly integrated protocol still shows up (unlabelled)
13
+ * instead of silently vanishing from the breakdown.
14
+ */
15
+ exports.UNTANGLED_PROTOCOL_REGISTRY = {
16
+ blend: { name: 'Blend', chain: 'stellar' },
17
+ templar: { name: 'Templar (NEAR)', chain: 'near' },
18
+ aquarius: { name: 'Aquarius', chain: 'stellar' },
19
+ upshift: { name: 'Upshift', chain: 'stellar' },
20
+ };
21
+ /**
22
+ * Custody wallet cash — undeployed capital, which the exposure breakdown renders
23
+ * as wallet holdings, the same treatment EVM vaults get for funds sitting
24
+ * outside a protocol.
25
+ */
26
+ const CUSTODY_WALLET_PROTOCOL_ID = 'stellar-wallet';
27
+ /**
28
+ * Capital held inside Upshift itself. This slug is NOT purely idle: it is the
29
+ * vault's own idle buffer PLUS any receipt tokens the vault holds in another
30
+ * Upshift vault. Gami earnXLM on 2026-09-11 reported `upshift: $1,371,484` made
31
+ * up of a `$200,572` idle buffer and `$1,170,913` of earnUSDC shares — counting
32
+ * all of it as idle hid a third of the vault's deployed capital and overstated
33
+ * the idle bucket almost sixfold.
34
+ */
35
+ const UPSHIFT_PROTOCOL_ID = 'upshift';
36
+ /** `locations[].label` for the capital still sitting in the vault contract. */
37
+ const IDLE_LOCATION_LABEL = 'idle';
38
+ /** Tightness of the `byAsset` lookup in {@link matchingAssetSymbol}. */
39
+ const ASSET_MATCH_TOLERANCE = 0.001;
40
+ /**
41
+ * Smallest `upshift` remainder treated as a real position rather than as float
42
+ * disagreement between the `idle` location and the `byProtocol` slice. One cent
43
+ * sits orders of magnitude above double-precision noise on million-dollar
44
+ * values and orders of magnitude below any holding worth naming.
45
+ */
46
+ const MIN_POSITION_USD = 0.01;
47
+ /**
48
+ * Share of `tvlUsd` the largest `byAsset` entry must cover before a synthesized
49
+ * position may be labelled with it.
50
+ *
51
+ * `byProtocol` and `byAsset` are two orthogonal decompositions of the same TVL,
52
+ * and Untangled publishes no join between them, so which venue holds which asset
53
+ * is genuinely unknown. Tagging every position with the largest asset is only
54
+ * honest when there is effectively nothing else in the vault; below that, the
55
+ * label would assert a holding the report does not support.
56
+ */
57
+ const SINGLE_ASSET_SHARE = 0.99;
58
+ /**
59
+ * USD the vault holds in its own contract, summed from the `idle` locations.
60
+ *
61
+ * Returns `null` when no location carries that label, so a caller can tell
62
+ * "nothing is idle" from "this report does not say".
63
+ *
64
+ * The whole sum is charged against the `upshift` slice, which assumes idle
65
+ * capital never belongs to another protocol. That holds for the shape Untangled
66
+ * serves — the buffer sitting in the vault contract is exactly what it files
67
+ * under `upshift` — and the `Math.min` at the call site caps the subtraction, so
68
+ * a report that broke the assumption would understate the position rather than
69
+ * invent one.
70
+ */
71
+ function idleLocationUsd(exposure) {
72
+ let total = null;
73
+ (exposure.locations || []).forEach((location) => {
74
+ if (location?.label?.toLowerCase() !== IDLE_LOCATION_LABEL)
75
+ return;
76
+ total = (total ?? 0) + (Number(location.valueUsd) || 0);
77
+ });
78
+ return total;
79
+ }
80
+ /**
81
+ * The `byAsset` symbol whose value matches this position's, within
82
+ * {@link ASSET_MATCH_TOLERANCE}.
83
+ *
84
+ * Untangled splits assets vault-wide, so a position's asset can normally only be
85
+ * guessed. A vault's holding in another Upshift vault is the exception: the
86
+ * receipt token is its own `byAsset` entry carrying exactly that position's
87
+ * value, so it can be named instead of falling back to the vault's dominant
88
+ * asset.
89
+ *
90
+ * This only ever chooses a *label* — the USD value is taken from `byProtocol`
91
+ * either way — so it is built to abstain rather than guess. Two cases reach it
92
+ * legitimately and get no answer: a vault holding receipts in two other Upshift
93
+ * vaults, which Untangled reports as one `upshift` slice whose remainder matches
94
+ * neither entry on its own, and a remainder small enough that the relative
95
+ * window closes around rounding noise.
96
+ *
97
+ * @param valueUsd - The position's USD value. The caller has already cleared it
98
+ * past {@link MIN_POSITION_USD}, so the relative window is never taken around
99
+ * zero.
100
+ * @returns The matching symbol, or `null` when no entry matches or more than one
101
+ * does — the caller names the position generically instead.
102
+ */
103
+ function matchingAssetSymbol(exposure, valueUsd) {
104
+ const matches = (exposure.byAsset || []).filter((asset) => {
105
+ const assetUsd = Number(asset?.valueUsd) || 0;
106
+ return (assetUsd > 0 &&
107
+ Math.abs(assetUsd - valueUsd) <= valueUsd * ASSET_MATCH_TOLERANCE);
108
+ });
109
+ return matches.length === 1 ? matches[0].symbol || null : null;
110
+ }
111
+ const DEFAULT_CHAIN = 'stellar';
112
+ /**
113
+ * Stellar's asset precision, carried only to satisfy the DeBank token shape.
114
+ * The synthesized tokens hold USD values (`price: 1`), so no consumer scales by
115
+ * this.
116
+ */
117
+ const SYNTHETIC_TOKEN_DECIMALS = 7;
118
+ /**
119
+ * Build a DeBank-shaped token carrying a USD value.
120
+ *
121
+ * `parseVaultLevelDebank` computes USD as `price * amount`, so a value already
122
+ * denominated in dollars is expressed as `price: 1, amount: <usd>`.
123
+ *
124
+ * @param symbol - The asset this slice holds, or `null` when the report cannot
125
+ * say. A null symbol still produces a token — the value has to reach
126
+ * `netValue` and the protocol totals either way — but carries no asset label,
127
+ * so consumers render the slice's value without naming an asset.
128
+ */
129
+ function toDebankToken(symbol, chain, valueUsd, exposureType, protocolId) {
130
+ return {
131
+ id: symbol ?? '',
132
+ chain,
133
+ name: symbol ?? '',
134
+ symbol: symbol ?? '',
135
+ optimized_symbol: symbol ?? '',
136
+ decimals: SYNTHETIC_TOKEN_DECIMALS,
137
+ logo_url: '',
138
+ amount: valueUsd,
139
+ price: 1,
140
+ protocol_id: protocolId ?? '',
141
+ supplying_exposure: exposureType === 'supply' ? 'true' : undefined,
142
+ };
143
+ }
144
+ /**
145
+ * The symbol every synthesized position may be tagged with, or `null` when the
146
+ * report cannot support tagging them at all.
147
+ *
148
+ * Untangled splits assets vault-wide rather than per protocol, so the only
149
+ * defensible label is the dominant asset, and only while it covers essentially
150
+ * the whole vault ({@link SINGLE_ASSET_SHARE}). Gami earnXLM qualifies (99.98%
151
+ * XLM); earnUSDC does not (84.18% USDC, 15.82% deJTRSY), and labelling its
152
+ * positions USDC claimed the whole $25.3M was USDC while $4.0M of deJTRSY went
153
+ * unmentioned. Callers that get `null` emit no asset label and let
154
+ * {@link untangledAssetExposure} carry the composition instead.
155
+ *
156
+ * An exact per-protocol split needs `byProtocol[].assets[]` from Untangled.
157
+ */
158
+ function vaultAssetSymbol(exposure) {
159
+ const dominant = (exposure.byAsset || []).reduce((best, asset) => !best || Number(asset?.valueUsd || 0) > Number(best.valueUsd || 0)
160
+ ? asset
161
+ : best, null);
162
+ if (!dominant?.symbol)
163
+ return null;
164
+ const tvlUsd = Number(exposure.tvlUsd) || 0;
165
+ if (tvlUsd <= 0)
166
+ return null;
167
+ const share = (Number(dominant.valueUsd) || 0) / tvlUsd;
168
+ return share >= SINGLE_ASSET_SHARE ? dominant.symbol : null;
169
+ }
170
+ /**
171
+ * The vault's asset composition, as vault-level token exposure.
172
+ *
173
+ * This is the one asset breakdown Untangled actually publishes, and it is
174
+ * authoritative: `byAsset` decomposes the same `tvlUsd` that `byProtocol` does.
175
+ * It is returned separately from {@link transformUntangledToDebank} because it
176
+ * cannot be folded into that structure — attributing an asset to a position
177
+ * would require a join the API does not provide, and adding these on top of the
178
+ * synthesized position tokens would double-count the vault.
179
+ *
180
+ * Negative rows are kept. A vault that has moved capital into another Upshift
181
+ * vault is reported holding the receipt token and owing the asset it spent —
182
+ * earnXLM carries `earnUSDC +$1,170,913` against `USDC -$1,170,271` — and those
183
+ * only sum back to `tvlUsd` together. Dropping the liability would overstate the
184
+ * vault's assets by the full size of the position.
185
+ *
186
+ * @param exposure - A resolved Untangled report, or `null`/`undefined` when the
187
+ * fetch failed.
188
+ * @returns One row per asset clearing `filterOutBySize` in absolute terms,
189
+ * largest first, with `amount` denominated in USD. Empty when `exposure` is
190
+ * absent. `id` carries the asset symbol rather than an address — Untangled
191
+ * reports assets by ticker and publishes no contract address for them — so it
192
+ * is safe as a display key and must not be read as an on-chain address.
193
+ */
194
+ function untangledAssetExposure(exposure) {
195
+ if (!exposure)
196
+ return [];
197
+ const chain = exposure.vault?.chain || DEFAULT_CHAIN;
198
+ return (exposure.byAsset || [])
199
+ .filter((asset) => asset?.symbol && (0, core_1.filterOutBySize)(Math.abs(Number(asset.valueUsd) || 0)))
200
+ .map((asset) => ({
201
+ amount: Number(asset.valueUsd) || 0,
202
+ chain,
203
+ decimals: SYNTHETIC_TOKEN_DECIMALS,
204
+ id: asset.symbol,
205
+ logoUrl: '',
206
+ name: asset.symbol,
207
+ symbol: asset.symbol,
208
+ }))
209
+ .sort((a, b) => b.amount - a.amount);
210
+ }
211
+ /**
212
+ * Transform an Untangled vault exposure report into the DeBank-normalized shape
213
+ * that `parseVaultLevelDebank` and `parseLoanLevelDebank` consume.
214
+ *
215
+ * This is the Stellar equivalent of `transformOctavfiToDebank`: a foreign
216
+ * portfolio shape is mapped onto the one normalized structure the vault
217
+ * allocation parser understands, so Stellar vaults populate the same
218
+ * `exposurePerCategory` / `protocolExposure` / `tokenExposure` outputs as EVM
219
+ * vaults with no parser changes.
220
+ *
221
+ * Mapping:
222
+ * - Each `byProtocol` entry becomes one position with a single supplying token,
223
+ * valued in USD (`price: 1`), on the chain from
224
+ * {@link UNTANGLED_PROTOCOL_REGISTRY}. The token is labelled with the vault's
225
+ * asset only when one asset covers essentially all of it (see
226
+ * {@link vaultAssetSymbol}); otherwise it carries the value with no symbol,
227
+ * and {@link untangledAssetExposure} supplies the composition separately.
228
+ * - `stellar-wallet` becomes a wallet token, because custody cash is undeployed
229
+ * capital rather than protocol exposure.
230
+ * - `upshift` is split: the vault's own idle buffer (the `idle` location) joins
231
+ * that wallet token, and whatever is left is a real position in another
232
+ * Upshift vault, named after its receipt token. Untangled reports one
233
+ * `upshift` slice however many vaults that is, so a vault holding receipts in
234
+ * two others emits one merged position under the generic name — the value is
235
+ * still right, only the label is coarser.
236
+ * - Dust is left in place: `filterOutBySize` in the parser applies the same
237
+ * threshold Stellar and EVM vaults share.
238
+ *
239
+ * Only the `idle` entries of `locations` are consumed, to size the buffer inside
240
+ * `upshift`. `asOf`, `stale` and `tvlUsd` are not — TVL already comes from
241
+ * `getVaultTvl`, and freshness is not yet surfaced on `IVaultAllocations`.
242
+ *
243
+ * @param exposure - A resolved Untangled report, or `null`/`undefined` when the
244
+ * fetch failed.
245
+ * @returns A DeBank-normalized response. Empty positions and tokens when
246
+ * `exposure` is absent, so callers can pass a failed fetch straight through.
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const exposure = await fetchUntangledVaultExposure(vault);
251
+ * const normalized = transformUntangledToDebank(exposure);
252
+ * parseVaultLevelDebank(
253
+ * normalized, protocolExposure, tokenExposure, vault, exposurePerCategory, netValue,
254
+ * );
255
+ * ```
256
+ */
257
+ function transformUntangledToDebank(exposure) {
258
+ if (!exposure) {
259
+ return { subaccount: { positions: [], tokens: [] } };
260
+ }
261
+ const symbol = vaultAssetSymbol(exposure);
262
+ const vaultChain = exposure.vault?.chain || DEFAULT_CHAIN;
263
+ const idleUsd = idleLocationUsd(exposure);
264
+ const positions = [];
265
+ let walletValueUsd = 0;
266
+ (exposure.byProtocol || []).forEach((entry) => {
267
+ if (!entry?.protocolId)
268
+ return;
269
+ const valueUsd = Number(entry.valueUsd) || 0;
270
+ if (entry.protocolId === CUSTODY_WALLET_PROTOCOL_ID) {
271
+ walletValueUsd += valueUsd;
272
+ return;
273
+ }
274
+ let positionUsd = valueUsd;
275
+ let positionSymbol = symbol;
276
+ let receiptSymbol = null;
277
+ if (entry.protocolId === UPSHIFT_PROTOCOL_ID) {
278
+ // A report with no idle location cannot say how much of this is the
279
+ // buffer, so it claims the whole slice. That leaves a remainder of exactly
280
+ // zero, which the guard below turns back into the pre-split behaviour —
281
+ // the two are coupled, so don't change one without the other.
282
+ const idleShare = idleUsd === null ? valueUsd : Math.min(valueUsd, idleUsd);
283
+ positionUsd = valueUsd - idleShare;
284
+ // The buffer reaches us twice, from two different fields, so a vault that
285
+ // holds nothing in another Upshift vault can still leave a sub-cent
286
+ // remainder behind. That is disagreement between the fields, not a
287
+ // position: keep the slice whole in the wallet bucket rather than emit a
288
+ // phantom the parser's size filter would have to clean up. Genuine dust is
289
+ // still passed through for that filter to judge.
290
+ if (positionUsd < MIN_POSITION_USD) {
291
+ walletValueUsd += valueUsd;
292
+ return;
293
+ }
294
+ walletValueUsd += idleShare;
295
+ receiptSymbol = matchingAssetSymbol(exposure, positionUsd);
296
+ positionSymbol = receiptSymbol ?? symbol;
297
+ }
298
+ const metadata = exports.UNTANGLED_PROTOCOL_REGISTRY[entry.protocolId];
299
+ const chain = metadata?.chain || vaultChain;
300
+ const baseName = metadata?.name ||
301
+ entry.protocolId.charAt(0).toUpperCase() + entry.protocolId.slice(1);
302
+ // "Upshift" alone reads as the whole product inside Upshift's own UI, so the
303
+ // slice names the vault it sits in whenever the receipt token identifies it.
304
+ const name = receiptSymbol ? `${baseName} (${receiptSymbol})` : baseName;
305
+ positions.push({
306
+ id: entry.protocolId,
307
+ chain,
308
+ name,
309
+ logo_url: '',
310
+ site_url: '',
311
+ portfolio_item_list: [
312
+ {
313
+ name,
314
+ stats: {
315
+ asset_usd_value: positionUsd,
316
+ debt_usd_value: 0,
317
+ net_usd_value: positionUsd,
318
+ },
319
+ detail: {
320
+ supply_token_list: [
321
+ toDebankToken(positionSymbol, chain, positionUsd, 'supply', entry.protocolId),
322
+ ],
323
+ borrow_token_list: [],
324
+ },
325
+ },
326
+ ],
327
+ });
328
+ });
329
+ const tokens = [];
330
+ if (walletValueUsd > 0) {
331
+ tokens.push({
332
+ ...toDebankToken(symbol, vaultChain, walletValueUsd, 'wallet'),
333
+ is_wallet: true,
334
+ is_core: true,
335
+ });
336
+ }
337
+ return { subaccount: { positions, tokens } };
338
+ }
339
+ //# sourceMappingURL=utils.js.map