@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,98 @@
1
+ /**
2
+ * Chain-ID validation for public SDK entry points.
3
+ *
4
+ * Two distinct failure modes are covered here, and they are deliberately kept
5
+ * separate because they have different remediations:
6
+ *
7
+ * 1. **Unknown chain ID** — the caller passed an ID the SDK has no concept of
8
+ * (a typo, a stale constant, an off-by-one on a non-EVM synthetic ID). No
9
+ * configuration can make this work; the call site is wrong.
10
+ * 2. **Known EVM chain, no RPC configured** — the ID is valid but the SDK was
11
+ * constructed without a provider for it. Remediated by passing an RPC URL.
12
+ *
13
+ * Both used to be logged-and-ignored, letting execution continue with an
14
+ * `undefined` RPC URL. That produced a cascade of misleading downstream
15
+ * failures (`connect ECONNREFUSED 127.0.0.1:8545` from ethers' localhost
16
+ * default, `missing revert data` from `decimals()` reads issued against the
17
+ * wrong chain, and `TypeError: Cannot read properties of undefined`). Failing
18
+ * fast at the boundary replaces that cascade with one actionable error.
19
+ *
20
+ * @module core/helpers/chain-support
21
+ */
22
+ /**
23
+ * Whether `chainId` is an EVM chain the SDK knows about (i.e. has an entry in
24
+ * {@link NETWORKS}).
25
+ *
26
+ * @param chainId - Numeric chain ID to test.
27
+ * @returns `true` for supported EVM chains, `false` for non-EVM synthetic IDs
28
+ * (Solana, Stellar, Sui) and for anything unrecognised.
29
+ */
30
+ export declare function isEvmChainId(chainId: number): boolean;
31
+ /**
32
+ * Whether `chainId` is recognised by the SDK at all — either a supported EVM
33
+ * chain or one of the non-EVM chain IDs in {@link NON_EVM_CHAIN_IDS}.
34
+ *
35
+ * @param chainId - Numeric chain ID to test.
36
+ * @returns `true` when the ID maps to a chain the SDK can route to.
37
+ */
38
+ export declare function isKnownChainId(chainId: number): boolean;
39
+ /**
40
+ * Throw when `chainId` is not a chain the SDK recognises.
41
+ *
42
+ * Called at public vault entry points so an unroutable ID surfaces as one
43
+ * typed error instead of an opaque downstream RPC failure.
44
+ *
45
+ * @param chainId - Chain ID supplied by the caller. `undefined` is a no-op —
46
+ * omitting the chain is valid and falls back to the SDK's active network.
47
+ * @param providers - The SDK's configured `chainId → RPC URL` map. A chain
48
+ * with a caller-configured provider is routable even if it is missing from
49
+ * {@link NETWORKS} (the SDK ships fallback RPCs/oracles for some EVM chains
50
+ * ahead of adding them to `NETWORKS`), so it is accepted here too.
51
+ * @param method - Public method name, used to make the message actionable.
52
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` when the ID
53
+ * is not in {@link NETWORKS} or {@link NON_EVM_CHAIN_IDS}, and has no
54
+ * caller-configured provider.
55
+ * @example
56
+ * ```ts
57
+ * assertKnownChainId(-4, undefined, 'getVault');
58
+ * // UpshiftValidationError: getVault: unknown chainId -4.
59
+ * ```
60
+ */
61
+ export declare function assertKnownChainId(chainId: number | undefined, providers: Partial<Record<number, string>> | undefined, method: string): void;
62
+ /**
63
+ * Throw when a known EVM `chainId` has no RPC URL configured on the SDK.
64
+ *
65
+ * Non-EVM chain IDs are exempt: Solana, Stellar and Sui vaults route through
66
+ * their adapters and never read from the `providers` map, so a missing entry
67
+ * is expected rather than a misconfiguration.
68
+ *
69
+ * @param chainId - Chain ID supplied by the caller. `undefined` is a no-op.
70
+ * @param providers - The SDK's configured `chainId → RPC URL` map.
71
+ * @param method - Public method name, used to make the message actionable.
72
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` when
73
+ * `chainId` is an EVM chain with no configured provider.
74
+ * @example
75
+ * ```ts
76
+ * assertEvmProviderConfigured(143, {}, 'getVault');
77
+ * // UpshiftValidationError: getVault: no RPC URL configured for chainId 143 (Monad).
78
+ * ```
79
+ */
80
+ export declare function assertEvmProviderConfigured(chainId: number | undefined, providers: Partial<Record<number, string>> | undefined, method: string): void;
81
+ /**
82
+ * Throw when a vault read targets Sui, whose vault reads this SDK does not
83
+ * implement yet: either `chainId` is Sui's (`-2`) or `vault` is a Sui object ID
84
+ * (`0x` + 64 hex chars), with or without a `chainId`.
85
+ *
86
+ * Call it before any EVM address check. Sui (`-2`) is a known chain, so it
87
+ * passes {@link assertKnownChainId}, and a Sui object ID is not an EVM address;
88
+ * without this guard a Sui read fails later with a misleading "no RPC URL" or
89
+ * "not an address" error.
90
+ *
91
+ * @internal
92
+ * @param chainId - Chain ID supplied by the caller; may be `undefined`.
93
+ * @param vault - Vault address supplied by the caller.
94
+ * @param method - Public method name, used to make the message actionable.
95
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` for a Sui
96
+ * chain ID or a Sui vault address.
97
+ */
98
+ export declare function assertSuiReadsSupported(chainId: number | undefined, vault: string | undefined, method: string): void;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /**
3
+ * Chain-ID validation for public SDK entry points.
4
+ *
5
+ * Two distinct failure modes are covered here, and they are deliberately kept
6
+ * separate because they have different remediations:
7
+ *
8
+ * 1. **Unknown chain ID** — the caller passed an ID the SDK has no concept of
9
+ * (a typo, a stale constant, an off-by-one on a non-EVM synthetic ID). No
10
+ * configuration can make this work; the call site is wrong.
11
+ * 2. **Known EVM chain, no RPC configured** — the ID is valid but the SDK was
12
+ * constructed without a provider for it. Remediated by passing an RPC URL.
13
+ *
14
+ * Both used to be logged-and-ignored, letting execution continue with an
15
+ * `undefined` RPC URL. That produced a cascade of misleading downstream
16
+ * failures (`connect ECONNREFUSED 127.0.0.1:8545` from ethers' localhost
17
+ * default, `missing revert data` from `decimals()` reads issued against the
18
+ * wrong chain, and `TypeError: Cannot read properties of undefined`). Failing
19
+ * fast at the boundary replaces that cascade with one actionable error.
20
+ *
21
+ * @module core/helpers/chain-support
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.isEvmChainId = isEvmChainId;
25
+ exports.isKnownChainId = isKnownChainId;
26
+ exports.assertKnownChainId = assertKnownChainId;
27
+ exports.assertEvmProviderConfigured = assertEvmProviderConfigured;
28
+ exports.assertSuiReadsSupported = assertSuiReadsSupported;
29
+ const web3_1 = require("../constants/web3");
30
+ const chain_address_1 = require("./chain-address");
31
+ const errors_1 = require("../errors");
32
+ /**
33
+ * Whether `chainId` is an EVM chain the SDK knows about (i.e. has an entry in
34
+ * {@link NETWORKS}).
35
+ *
36
+ * @param chainId - Numeric chain ID to test.
37
+ * @returns `true` for supported EVM chains, `false` for non-EVM synthetic IDs
38
+ * (Solana, Stellar, Sui) and for anything unrecognised.
39
+ */
40
+ function isEvmChainId(chainId) {
41
+ return Object.hasOwn(web3_1.NETWORKS, chainId);
42
+ }
43
+ /**
44
+ * Whether `chainId` is recognised by the SDK at all — either a supported EVM
45
+ * chain or one of the non-EVM chain IDs in {@link NON_EVM_CHAIN_IDS}.
46
+ *
47
+ * @param chainId - Numeric chain ID to test.
48
+ * @returns `true` when the ID maps to a chain the SDK can route to.
49
+ */
50
+ function isKnownChainId(chainId) {
51
+ return isEvmChainId(chainId) || web3_1.NON_EVM_CHAIN_IDS.has(chainId);
52
+ }
53
+ /**
54
+ * Throw when `chainId` is not a chain the SDK recognises.
55
+ *
56
+ * Called at public vault entry points so an unroutable ID surfaces as one
57
+ * typed error instead of an opaque downstream RPC failure.
58
+ *
59
+ * @param chainId - Chain ID supplied by the caller. `undefined` is a no-op —
60
+ * omitting the chain is valid and falls back to the SDK's active network.
61
+ * @param providers - The SDK's configured `chainId → RPC URL` map. A chain
62
+ * with a caller-configured provider is routable even if it is missing from
63
+ * {@link NETWORKS} (the SDK ships fallback RPCs/oracles for some EVM chains
64
+ * ahead of adding them to `NETWORKS`), so it is accepted here too.
65
+ * @param method - Public method name, used to make the message actionable.
66
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` when the ID
67
+ * is not in {@link NETWORKS} or {@link NON_EVM_CHAIN_IDS}, and has no
68
+ * caller-configured provider.
69
+ * @example
70
+ * ```ts
71
+ * assertKnownChainId(-4, undefined, 'getVault');
72
+ * // UpshiftValidationError: getVault: unknown chainId -4.
73
+ * ```
74
+ */
75
+ function assertKnownChainId(chainId, providers, method) {
76
+ if (typeof chainId === 'undefined')
77
+ return;
78
+ if (isKnownChainId(chainId))
79
+ return;
80
+ if (providers?.[chainId])
81
+ return;
82
+ throw new errors_1.UpshiftValidationError('INVALID_CHAIN', `${method}: unknown chainId ${chainId}. ` +
83
+ 'Pass a supported EVM chain ID (see NETWORKS) or a non-EVM chain ID ' +
84
+ '(-1 Solana, -2 Sui, -3 Stellar).', { context: { method, chainId } });
85
+ }
86
+ /**
87
+ * Throw when a known EVM `chainId` has no RPC URL configured on the SDK.
88
+ *
89
+ * Non-EVM chain IDs are exempt: Solana, Stellar and Sui vaults route through
90
+ * their adapters and never read from the `providers` map, so a missing entry
91
+ * is expected rather than a misconfiguration.
92
+ *
93
+ * @param chainId - Chain ID supplied by the caller. `undefined` is a no-op.
94
+ * @param providers - The SDK's configured `chainId → RPC URL` map.
95
+ * @param method - Public method name, used to make the message actionable.
96
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` when
97
+ * `chainId` is an EVM chain with no configured provider.
98
+ * @example
99
+ * ```ts
100
+ * assertEvmProviderConfigured(143, {}, 'getVault');
101
+ * // UpshiftValidationError: getVault: no RPC URL configured for chainId 143 (Monad).
102
+ * ```
103
+ */
104
+ function assertEvmProviderConfigured(chainId, providers, method) {
105
+ if (typeof chainId === 'undefined')
106
+ return;
107
+ if (!isEvmChainId(chainId))
108
+ return;
109
+ if (providers?.[chainId])
110
+ return;
111
+ const name = web3_1.NETWORKS[chainId]?.name;
112
+ throw new errors_1.UpshiftValidationError('INVALID_CHAIN', `${method}: no RPC URL configured for chainId ${chainId}` +
113
+ `${name ? ` (${name})` : ''}. ` +
114
+ 'Pass one when constructing UpshiftSDK: ' +
115
+ `new UpshiftSDK({ providers: { ${chainId}: '<rpc-url>' } }).`, { context: { method, chainId } });
116
+ }
117
+ /**
118
+ * Throw when a vault read targets Sui, whose vault reads this SDK does not
119
+ * implement yet: either `chainId` is Sui's (`-2`) or `vault` is a Sui object ID
120
+ * (`0x` + 64 hex chars), with or without a `chainId`.
121
+ *
122
+ * Call it before any EVM address check. Sui (`-2`) is a known chain, so it
123
+ * passes {@link assertKnownChainId}, and a Sui object ID is not an EVM address;
124
+ * without this guard a Sui read fails later with a misleading "no RPC URL" or
125
+ * "not an address" error.
126
+ *
127
+ * @internal
128
+ * @param chainId - Chain ID supplied by the caller; may be `undefined`.
129
+ * @param vault - Vault address supplied by the caller.
130
+ * @param method - Public method name, used to make the message actionable.
131
+ * @throws {@link UpshiftValidationError} with code `INVALID_CHAIN` for a Sui
132
+ * chain ID or a Sui vault address.
133
+ */
134
+ function assertSuiReadsSupported(chainId, vault, method) {
135
+ if (chainId !== web3_1.SUI_CHAIN_ID && !(vault && (0, chain_address_1.isSuiAddress)(vault)))
136
+ return;
137
+ throw new errors_1.UpshiftValidationError('INVALID_CHAIN', `${method}: Sui vault reads are not supported yet (chainId ${web3_1.SUI_CHAIN_ID}).`, { context: { method, chainId } });
138
+ }
139
+ //# sourceMappingURL=chain-support.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Concurrency helpers.
3
+ *
4
+ * Internal only — deliberately not re-exported from `core/index.ts`, so it is
5
+ * not part of the published API surface.
6
+ *
7
+ * Leaf module: depends on nothing inside the SDK, so it is safe to import from
8
+ * any layer without forming a cycle (see CLAUDE.md §9).
9
+ */
10
+ /**
11
+ * Map over `items` running at most `limit` tasks at a time.
12
+ *
13
+ * Exists because `Promise.all` over a caller-sized array is unbounded: a vault
14
+ * with 40 borrowers opens 40 simultaneous connections to the same backend,
15
+ * which is how a slow endpoint turns into a timeout storm rather than a slow
16
+ * response. A small fixed window keeps latency close to the parallel case while
17
+ * bounding the load the SDK can put on one origin.
18
+ *
19
+ * Results preserve input order regardless of completion order. A rejected task
20
+ * rejects the returned promise (like `Promise.all`); callers that need
21
+ * per-item error isolation should catch inside `task`.
22
+ *
23
+ * @param items - Inputs to process. An empty array resolves to `[]` immediately.
24
+ * @param limit - Maximum tasks in flight. Values below 1 are treated as 1.
25
+ * @param task - Receives an item and its index; returns the value for that slot.
26
+ * @returns Results in the same order as `items`.
27
+ * @throws Whatever `task` rejects with, on the first rejection.
28
+ * @example
29
+ * ```ts
30
+ * // At most 5 concurrent requests, regardless of borrower count.
31
+ * const positions = await mapWithConcurrency(borrowers, 5, (b) =>
32
+ * fetchPosition(b).catch(() => null),
33
+ * );
34
+ * ```
35
+ * @internal
36
+ */
37
+ export declare function mapWithConcurrency<TIn, TOut>(items: readonly TIn[], limit: number, task: (item: TIn, index: number) => Promise<TOut>): Promise<TOut[]>;
38
+ /**
39
+ * Race a promise against a timeout so a hung call can't block indefinitely. The
40
+ * timer is always cleared, so a fast-resolving promise leaves nothing pending.
41
+ *
42
+ * @param promise - The call to bound. It keeps running after a timeout; only
43
+ * the wait is abandoned.
44
+ * @param ms - Timeout in milliseconds. Values below 0 are treated as 0.
45
+ * @param label - Names the call in the rejection message.
46
+ * @returns What `promise` resolves to.
47
+ * @throws `Error("<label> timed out after <ms>ms")` on timeout, or whatever
48
+ * `promise` rejects with.
49
+ * @internal
50
+ */
51
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Concurrency helpers.
4
+ *
5
+ * Internal only — deliberately not re-exported from `core/index.ts`, so it is
6
+ * not part of the published API surface.
7
+ *
8
+ * Leaf module: depends on nothing inside the SDK, so it is safe to import from
9
+ * any layer without forming a cycle (see CLAUDE.md §9).
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.mapWithConcurrency = mapWithConcurrency;
13
+ exports.withTimeout = withTimeout;
14
+ /**
15
+ * Map over `items` running at most `limit` tasks at a time.
16
+ *
17
+ * Exists because `Promise.all` over a caller-sized array is unbounded: a vault
18
+ * with 40 borrowers opens 40 simultaneous connections to the same backend,
19
+ * which is how a slow endpoint turns into a timeout storm rather than a slow
20
+ * response. A small fixed window keeps latency close to the parallel case while
21
+ * bounding the load the SDK can put on one origin.
22
+ *
23
+ * Results preserve input order regardless of completion order. A rejected task
24
+ * rejects the returned promise (like `Promise.all`); callers that need
25
+ * per-item error isolation should catch inside `task`.
26
+ *
27
+ * @param items - Inputs to process. An empty array resolves to `[]` immediately.
28
+ * @param limit - Maximum tasks in flight. Values below 1 are treated as 1.
29
+ * @param task - Receives an item and its index; returns the value for that slot.
30
+ * @returns Results in the same order as `items`.
31
+ * @throws Whatever `task` rejects with, on the first rejection.
32
+ * @example
33
+ * ```ts
34
+ * // At most 5 concurrent requests, regardless of borrower count.
35
+ * const positions = await mapWithConcurrency(borrowers, 5, (b) =>
36
+ * fetchPosition(b).catch(() => null),
37
+ * );
38
+ * ```
39
+ * @internal
40
+ */
41
+ async function mapWithConcurrency(items, limit, task) {
42
+ if (items.length === 0)
43
+ return [];
44
+ const width = Math.max(1, Math.min(Math.floor(limit), items.length));
45
+ const results = new Array(items.length);
46
+ // Shared cursor: each worker repeatedly claims the next unclaimed index, so
47
+ // a slow item never blocks the workers behind it (as a fixed chunked split
48
+ // would).
49
+ let cursor = 0;
50
+ const worker = async () => {
51
+ while (cursor < items.length) {
52
+ const index = cursor++;
53
+ results[index] = await task(items[index], index);
54
+ }
55
+ };
56
+ await Promise.all(Array.from({ length: width }, worker));
57
+ return results;
58
+ }
59
+ /**
60
+ * Race a promise against a timeout so a hung call can't block indefinitely. The
61
+ * timer is always cleared, so a fast-resolving promise leaves nothing pending.
62
+ *
63
+ * @param promise - The call to bound. It keeps running after a timeout; only
64
+ * the wait is abandoned.
65
+ * @param ms - Timeout in milliseconds. Values below 0 are treated as 0.
66
+ * @param label - Names the call in the rejection message.
67
+ * @returns What `promise` resolves to.
68
+ * @throws `Error("<label> timed out after <ms>ms")` on timeout, or whatever
69
+ * `promise` rejects with.
70
+ * @internal
71
+ */
72
+ function withTimeout(promise, ms, label) {
73
+ let timer;
74
+ const timeout = new Promise((_resolve, reject) => {
75
+ timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), Math.max(0, ms));
76
+ });
77
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
78
+ }
79
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1,92 @@
1
+ import type { INormalizedNumber } from '../../types';
2
+ /**
3
+ * Table of Contents
4
+ * - Formatters
5
+ * - Datetime
6
+ * - Arrays
7
+ * - Caching
8
+ */
9
+ /**
10
+ * Normalize an amount into both its human-readable and raw (integer) forms.
11
+ *
12
+ * @param value - Amount as a decimal string (`"1.5"`), a JS number, or a raw
13
+ * `bigint` already scaled by `decimals`. Strings/numbers are treated as
14
+ * human-readable values and scaled UP; bigints are treated as raw values
15
+ * and scaled DOWN. Exponential notation (`1e-7`, `1e21`) is accepted for
16
+ * strings and numbers.
17
+ * @param decimals - Token decimals used for scaling. Default `18`.
18
+ * @returns `{ normalized, raw }` where `normalized` is the decimal string
19
+ * (fraction trimmed to `decimals` places) and `raw` is the integer string.
20
+ * Falsy input yields `{ normalized: '0', raw: '0' }`.
21
+ * @throws Whatever ethers' `parseUnits` throws for a string that is not a
22
+ * decimal number (e.g. `"abc"`).
23
+ */
24
+ export declare function toNormalizedBn(value: string | bigint | number, decimals?: number | bigint): INormalizedNumber;
25
+ /**
26
+ * Get fallback RPC URLs for a specific chain
27
+ */
28
+ export declare function getFallbackRpcUrls(chainId: number): string[];
29
+ export declare const filterOutBySize: (usdAmount: number) => boolean;
30
+ /**
31
+ * Formatters
32
+ */
33
+ export declare function toTitleCase(str: string, type?: 'camel'): string;
34
+ export declare function truncate(s: string, amount?: number): string;
35
+ /**
36
+ * Formats any numeric value (number, string, or bigint) to a standardized string.
37
+ *
38
+ * @param value - amount to be formatted
39
+ * @param options - formatting options:
40
+ * `showing` is the number of decimals to cut off at (or `'all'`);
41
+ * `usd` toggles USD-value display;
42
+ * `decimals` is how many decimals to parse to when `value` is a bigint.
43
+ *
44
+ * @returns standardized string type value
45
+ */
46
+ export declare function round(value: number | string | bigint, options?: {
47
+ showing?: number | 'all';
48
+ usd?: boolean;
49
+ decimals?: number;
50
+ }): string;
51
+ export declare function loanStateToReadable(loanState: number | bigint): "PREAPPROVED" | "FUNDING_REQUIRED" | "FUNDED" | "ACTIVE" | "CANCELLED" | "MATURED" | "CLOSED";
52
+ /**
53
+ * Datetime
54
+ */
55
+ export declare function dateToUnix(date: Date): number;
56
+ export declare function unixToDate(epoch: number): Date;
57
+ export declare function isEarlierThanNow(startTime: Date): boolean;
58
+ export declare function daysAgo(days: number): Date;
59
+ export declare function prepareDateForDb(date: string | Date): string;
60
+ /**
61
+ * Arrays
62
+ */
63
+ export declare function orderObjArrByDate<T extends Record<string, unknown>>(objectArray: T[], options?: {
64
+ key?: string;
65
+ order?: 'asc' | 'desc';
66
+ }): T[];
67
+ /**
68
+ * Calculate weights based on a specific property in array of objects.
69
+ * @param data - Array of objects to calculate weights for
70
+ * @param weightProperty - Property name to base weights on
71
+ * @returns Original data with each item's `weight` added
72
+ */
73
+ export declare function calculateWeights<T extends Record<string, unknown>>(data?: T[], weightProperty?: string): Array<T & {
74
+ weight: number;
75
+ }>;
76
+ /**
77
+ * Calculate weighted average for array of objects.
78
+ * @param data - Array of objects with values
79
+ * @param valueProperty - Property name containing the value to average
80
+ * @param weightProperty - Optional property to base weights on
81
+ * @returns Weighted average
82
+ */
83
+ export declare function calculateWeightedAverage<T extends Record<string, unknown>>(data?: T[], valueProperty?: string, weightProperty?: string): number;
84
+ /**
85
+ * Coerce a caller-supplied integer (`string | bigint | number`) to a `bigint`,
86
+ * rejecting anything that is not a non-negative safe integer. `label` names the
87
+ * calling method and `noun` the field being validated, so bad input surfaces as
88
+ * `UpshiftValidationError('INVALID_INPUT')` at the SDK boundary instead of a
89
+ * `BigInt()` SyntaxError wrapped as `UNKNOWN`.
90
+ * @internal
91
+ */
92
+ export declare function toRawBigInt(value: string | bigint | number, label: string, noun?: string): bigint;