@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,194 @@
1
+ "use strict";
2
+ /**
3
+ * ERC-8021 transaction attribution (Base Builder Codes).
4
+ *
5
+ * ERC-8021 appends an attribution suffix to transaction calldata. Contracts
6
+ * decode their ABI-encoded arguments normally and ignore the trailing bytes,
7
+ * while offchain indexers (e.g. base.dev analytics for Base Builder Codes)
8
+ * read the suffix to attribute the transaction to the originating app.
9
+ *
10
+ * This is a leaf module: process-global state configured once via
11
+ * {@link IUpshiftBase.attribution} in the SDK constructor and read by the
12
+ * EVM write paths (the normalized-signer wrap in the EVM adapter and the
13
+ * cross-chain vault `writeContract` calls).
14
+ *
15
+ * @module attribution
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ERC8021_MARKER = void 0;
19
+ exports.buildAttributionSuffix = buildAttributionSuffix;
20
+ exports.setAttribution = setAttribution;
21
+ exports.isStrictOrigin = isStrictOrigin;
22
+ exports.getOriginCode = getOriginCode;
23
+ exports.isAttributionEnabled = isAttributionEnabled;
24
+ exports.getAttributionSuffix = getAttributionSuffix;
25
+ exports.appendAttributionSuffix = appendAttributionSuffix;
26
+ const swap_router_1 = require("./constants/swap-router");
27
+ const errors_1 = require("./errors");
28
+ /**
29
+ * The 16-byte ERC-8021 suffix terminator. The last 16 bytes of an attributed
30
+ * transaction's calldata are always this marker; parsers read backwards from
31
+ * it to recover the schema ID and builder codes.
32
+ */
33
+ exports.ERC8021_MARKER = '80218021802180218021802180218021';
34
+ /**
35
+ * Build an ERC-8021 schema-0 attribution suffix from builder codes.
36
+ *
37
+ * Layout (appended to calldata, read back-to-front by parsers):
38
+ * `ascii(codes.join(','))` ∥ codesLength (1 byte) ∥ schemaId `0x00` ∥
39
+ * 16-byte marker `0x80218021802180218021802180218021`.
40
+ *
41
+ * @param codes Builder codes as printable-ASCII strings (e.g. `bc_abc123`),
42
+ * each 1–64 chars, no commas; the comma-joined list must be ≤ 255 bytes.
43
+ * @returns `0x`-prefixed hex suffix ready to concatenate onto calldata.
44
+ * @throws Error when `codes` is empty, a code contains a comma or
45
+ * non-printable/non-ASCII characters, or the joined list exceeds 255 bytes.
46
+ * @example
47
+ * ```typescript
48
+ * buildAttributionSuffix(['baseapp', 'morpho']);
49
+ * // '0x626173656170702c6d6f7270686f0e0080218021802180218021802180218021'
50
+ * ```
51
+ */
52
+ function buildAttributionSuffix(codes) {
53
+ if (!Array.isArray(codes) || codes.length === 0) {
54
+ throw new Error('Upshift SDK: attribution.builderCodes must be a non-empty array of builder-code strings (e.g. ["bc_abc123"]). Register at https://base.dev to obtain one.');
55
+ }
56
+ for (const code of codes) {
57
+ if (typeof code !== 'string' ||
58
+ code.length === 0 ||
59
+ code.length > 64 ||
60
+ !/^[\x21-\x7e]+$/.test(code) ||
61
+ code.includes(',')) {
62
+ throw new Error(`Upshift SDK: invalid builder code "${code}". Codes must be 1-64 printable ASCII characters with no commas or whitespace.`);
63
+ }
64
+ }
65
+ const joined = codes.join(',');
66
+ if (joined.length > 255) {
67
+ throw new Error(`Upshift SDK: attribution builder codes exceed 255 bytes when comma-joined (got ${joined.length}). Use fewer or shorter codes.`);
68
+ }
69
+ let hex = '';
70
+ for (let i = 0; i < joined.length; i++) {
71
+ hex += joined.charCodeAt(i).toString(16).padStart(2, '0');
72
+ }
73
+ const length = joined.length.toString(16).padStart(2, '0');
74
+ return `0x${hex}${length}00${exports.ERC8021_MARKER}`;
75
+ }
76
+ let activeSuffix = null;
77
+ let activeChains = null;
78
+ let activeOriginCode = null;
79
+ let activeStrictOrigin = false;
80
+ /**
81
+ * Set (or clear) the process-global attribution config.
82
+ *
83
+ * Called unconditionally on every `UpshiftSDK` construction — an instance
84
+ * that omits `attribution` passes `null` and RESETS the state, so a prior
85
+ * instance's builder codes or origin code never leak into a later instance
86
+ * in the same process (same semantics as `setPublicApiBaseUrl`).
87
+ *
88
+ * @param config Attribution config from the SDK constructor, or `null` to
89
+ * disable attribution.
90
+ * @throws Error when the config's builder codes fail validation — thrown
91
+ * synchronously from the constructor so misconfiguration is caught at
92
+ * init, not on the first write.
93
+ * @throws {@link UpshiftValidationError} when `originCode` is not a 32-byte
94
+ * hex string.
95
+ */
96
+ function setAttribution(config) {
97
+ if (!config) {
98
+ activeSuffix = null;
99
+ activeChains = null;
100
+ activeOriginCode = null;
101
+ activeStrictOrigin = false;
102
+ return;
103
+ }
104
+ const { originCode } = config;
105
+ if (originCode !== undefined && !swap_router_1.ORIGIN_CODE_PATTERN.test(originCode)) {
106
+ throw new errors_1.UpshiftValidationError('INVALID_INPUT', `Upshift SDK: attribution.originCode must be a 32-byte hex string (0x + 64 hex chars), got ${String(originCode).length} chars. Pass the bytes32 code registered on the SwapRouter via addOrigin.`, { context: { expectedLength: 66 } });
107
+ }
108
+ activeSuffix =
109
+ config.builderCodes === undefined
110
+ ? null
111
+ : buildAttributionSuffix(config.builderCodes);
112
+ activeChains =
113
+ Array.isArray(config.chains) && config.chains.length > 0
114
+ ? config.chains
115
+ : null;
116
+ activeOriginCode = originCode ?? null;
117
+ activeStrictOrigin = config.strictOrigin === true;
118
+ }
119
+ /**
120
+ * Whether {@link IAttributionConfig.strictOrigin} is set on the SDK instance.
121
+ *
122
+ * @returns `true` when an unregistered origin code must fail a deposit.
123
+ */
124
+ function isStrictOrigin() {
125
+ return activeStrictOrigin;
126
+ }
127
+ /**
128
+ * The SwapRouter origin code configured on the SDK instance via
129
+ * {@link IAttributionConfig.originCode}.
130
+ *
131
+ * @returns The `bytes32` code, or `null` when none is configured.
132
+ */
133
+ function getOriginCode() {
134
+ return activeOriginCode;
135
+ }
136
+ /**
137
+ * Whether attribution is configured at all, independent of any chain gate.
138
+ *
139
+ * Call sites that need to know whether to resolve a chain ID before asking
140
+ * for the suffix use this; {@link getAttributionSuffix} applies the gate.
141
+ *
142
+ * @returns `true` when builder codes are configured.
143
+ */
144
+ function isAttributionEnabled() {
145
+ return activeSuffix !== null;
146
+ }
147
+ /**
148
+ * Return the active ERC-8021 suffix for a write on the given chain, or
149
+ * `undefined` when attribution is off or the chain is not attributed.
150
+ *
151
+ * @param chainId EVM chain ID of the transaction, when the call site knows
152
+ * it. When a `chains` restriction is configured, gating is fail-closed: an
153
+ * omitted chain ID yields no suffix, since a suffix on an unattributed
154
+ * chain buys nothing and breaks hardware-wallet clear-signing (see
155
+ * {@link IAttributionConfig.chains}).
156
+ * @returns `0x`-prefixed hex suffix, or `undefined` when nothing should be
157
+ * appended.
158
+ */
159
+ function getAttributionSuffix(chainId) {
160
+ if (!activeSuffix)
161
+ return undefined;
162
+ if (activeChains) {
163
+ if (typeof chainId !== 'number')
164
+ return undefined;
165
+ if (!activeChains.includes(chainId))
166
+ return undefined;
167
+ }
168
+ return activeSuffix;
169
+ }
170
+ /**
171
+ * Append the active attribution suffix to calldata.
172
+ *
173
+ * No-ops (returns `data` unchanged) when attribution is off, the chain is
174
+ * not attributed (including an unknown chain under a `chains` restriction),
175
+ * `data` is empty/absent (plain value transfers are never
176
+ * attributed), or `data` already ends with the ERC-8021 marker (guards
177
+ * against double-appending when an upstream layer — e.g. a wagmi config
178
+ * `dataSuffix` — already attributed the transaction).
179
+ *
180
+ * @param data `0x`-prefixed calldata of the outgoing transaction.
181
+ * @param chainId EVM chain ID of the transaction, when known.
182
+ * @returns Calldata with the suffix appended, or the input unchanged.
183
+ */
184
+ function appendAttributionSuffix(data, chainId) {
185
+ const suffix = getAttributionSuffix(chainId);
186
+ if (!suffix)
187
+ return data;
188
+ if (typeof data !== 'string' || data === '' || data === '0x')
189
+ return data;
190
+ if (data.toLowerCase().endsWith(exports.ERC8021_MARKER))
191
+ return data;
192
+ return data + suffix.slice(2);
193
+ }
194
+ //# sourceMappingURL=attribution.js.map
@@ -0,0 +1 @@
1
+ export * from './verify';
@@ -0,0 +1,18 @@
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("./verify"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare function verifyInfuraKey(key: string): Promise<boolean>;
2
+ export declare function verifyUpshiftKey(key: string): Promise<boolean>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyInfuraKey = verifyInfuraKey;
4
+ exports.verifyUpshiftKey = verifyUpshiftKey;
5
+ const analytics_1 = require("../analytics");
6
+ const core_1 = require("../constants/core");
7
+ const fetcher_1 = require("../fetcher");
8
+ async function verifyInfuraKey(key) {
9
+ if (key.length !== 32)
10
+ return false;
11
+ const regex = /[a-z0-9]+/i;
12
+ if (!regex.test(key))
13
+ return false;
14
+ return true;
15
+ }
16
+ async function verifyUpshiftKey(key) {
17
+ // Fast path: no key means no verification possible. Returning false here
18
+ // preserves the historical contract (`init()` throws a generic "API key is
19
+ // invalid") and saves a request the backend would reject with a 401.
20
+ if (!key)
21
+ return false;
22
+ try {
23
+ const verify = await (0, fetcher_1.fetchUpshiftWithKey)(key, core_1.WEBSERVER_ENDPOINTS.auth.verify);
24
+ const success = verify.status === 200;
25
+ (0, analytics_1.trackKeyVerification)('upshift', success);
26
+ return success;
27
+ }
28
+ catch {
29
+ // Network errors, timeouts, and any future thrown auth errors all
30
+ // resolve to "key not verified" here. Callers handle this as a boolean.
31
+ (0, analytics_1.trackKeyVerification)('upshift', false);
32
+ return false;
33
+ }
34
+ }
35
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1,193 @@
1
+ import type { ISolanaConfig, IStellarConfig, ISuiConfig, IAddress, IChainId, IEnv, IProvidersConfig, IWSMonitorHeaders } from '../types';
2
+ import { type IAnalyticsConfig } from './analytics';
3
+ import { type IVersionCheckConfig } from './version-check';
4
+ import { type IAttributionConfig } from './attribution';
5
+ import { type ICuratorAlertsConfig } from './logger/curator-alert';
6
+ interface IKeys {
7
+ upshift?: string;
8
+ graph?: string;
9
+ coingecko?: string;
10
+ }
11
+ interface IMonitoring extends IWSMonitorHeaders {
12
+ slackWebhookUrl?: string;
13
+ env?: IEnv;
14
+ /**
15
+ * Curator notifications for failed vault redemptions. Enabled by default
16
+ * (opt-out model, like `analytics`).
17
+ *
18
+ * Stellar vaults are instant-redeem only, so when a redemption fails the
19
+ * vault's curator has no other way to learn about it. The SDK relays the
20
+ * failure to Upshift's notification service, which routes it to that curator's
21
+ * own channel — no credentials or curator identities are held here.
22
+ *
23
+ * Set `enabled: false` (or, in Node, the
24
+ * `UPSHIFT_SDK_DISABLE_CURATOR_ALERTS` env var) to stop emitting; set
25
+ * `endpoint` only to point a non-prod deployment at a test relay. Nothing is
26
+ * emitted unless `monitoring.env` is `PROD`, `NODE_ENV` is neither
27
+ * `development` nor `test`, and — in a browser, where `NODE_ENV` is not
28
+ * readable — the page is not served from localhost.
29
+ *
30
+ * `enabled: true` is the one exception: it bypasses all three gates, so a
31
+ * `DEV` or test integration that sets it can page a real curator. See
32
+ * {@link ICuratorAlertsConfig}.
33
+ */
34
+ curatorAlerts?: ICuratorAlertsConfig;
35
+ }
36
+ export interface IUpshiftBase {
37
+ /**
38
+ * Identifier-shaped name for the integrating application. Required.
39
+ *
40
+ * Pick a stable, kebab-case slug that identifies your product (e.g.
41
+ * `"acme-trader"`, `"my-defi-app"`). The SDK includes it on outbound
42
+ * analytics events so Upshift can see who's hitting which methods
43
+ * and reach out about breaking changes or critical bugs.
44
+ *
45
+ * Despite the friendly `appName` label, the value is used as a Sentry
46
+ * tag and HTTP header, so it must be identifier-shaped:
47
+ * 3–64 characters, `[a-zA-Z0-9._-]` only. Use a slug ("acme-trader"),
48
+ * not a display name ("Acme Trader").
49
+ *
50
+ * @throws UpshiftValidationError synchronously from the constructor if
51
+ * missing, empty, or malformed.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const sdk = new UpshiftSDK({
56
+ * appName: 'acme-trader',
57
+ * providers: { 1: 'https://...' },
58
+ * keys: { upshift: '...' },
59
+ * });
60
+ * ```
61
+ */
62
+ appName: string;
63
+ providers?: IProvidersConfig;
64
+ solana?: ISolanaConfig;
65
+ stellar?: IStellarConfig;
66
+ /**
67
+ * Sui configuration (network and an optional RPC endpoint). Omit to target
68
+ * Sui mainnet.
69
+ */
70
+ sui?: ISuiConfig;
71
+ /**
72
+ * Provider keys. Optional: vault reads and vault-linked sub-account reads
73
+ * work without an Upshift key. Supply `upshift` for admin and curator methods,
74
+ * for authenticated-user reads such as `getDiscountFactors`, and for
75
+ * sub-account reads where the subaccount is not linked to a vault.
76
+ */
77
+ keys?: IKeys;
78
+ monitoring?: IMonitoring;
79
+ /** Analytics configuration. Enabled by default (opt-out model). */
80
+ analytics?: IAnalyticsConfig;
81
+ /**
82
+ * Best-effort npm-registry version check. Enabled by default in
83
+ * non-production environments; never runs in `NODE_ENV=production`.
84
+ * Set `enabled: false` to disable entirely (or set the
85
+ * `UPSHIFT_SDK_DISABLE_VERSION_CHECK` env var).
86
+ */
87
+ versionCheck?: IVersionCheckConfig;
88
+ /**
89
+ * Default request timeout (in milliseconds) for backend API calls made by
90
+ * this SDK instance. Falls back to the SDK's compiled-in
91
+ * `REQUEST_TIMEOUT_MS` (15 s) when omitted.
92
+ *
93
+ * Per-call `timeoutMs` (when threaded through to the fetcher) still wins
94
+ * over this value. Setting this only changes the default that's used when
95
+ * no per-call value is supplied.
96
+ *
97
+ * Note: this is a process-global override on the underlying fetcher
98
+ * helpers, so the last `UpshiftSDK` instantiated wins if you create several
99
+ * with different timeouts in the same process.
100
+ */
101
+ timeoutMs?: number;
102
+ /**
103
+ * Override the base URL for the SDK's unauthenticated `public` vault-catalog
104
+ * API (what `getVault` / `getVaults` / `fetchTokenizedVault` read from).
105
+ * Defaults to the compiled-in prod base
106
+ * (`https://api.augustdigital.io/api/v1`) when omitted — so production apps
107
+ * pass nothing and behaviour is unchanged.
108
+ *
109
+ * Set this ONLY for a non-prod deployment that runs against an isolated
110
+ * backend (e.g. a staging API serving staging-only vaults). Must be an
111
+ * absolute http(s) URL including any base path, e.g.
112
+ * `https://api.staging.augustdigital.io/api/v1`. Invalid values are ignored.
113
+ *
114
+ * Note: this is a process-global override on the underlying fetcher helpers,
115
+ * applied on EVERY construction — so the last `UpshiftSDK` instantiated is
116
+ * authoritative, and one that omits `publicApiBaseUrl` RESETS to the prod
117
+ * default. (Stricter than `timeoutMs`, which stays sticky when omitted, since
118
+ * a stale cross-environment base is higher blast-radius than a stale timeout.)
119
+ */
120
+ publicApiBaseUrl?: string;
121
+ /**
122
+ * ERC-8021 calldata-suffix attribution (Base Builder Codes). When set,
123
+ * every EVM write sent through the SDK — ethers vault writes and the
124
+ * cross-chain (OVault) viem writes — carries the attribution suffix so
125
+ * offchain indexers (base.dev) can credit the transaction to your app.
126
+ * Omit to send unattributed transactions (the default).
127
+ *
128
+ * `attribution.originCode` sets the SwapRouter origin (referral /
129
+ * fee-sharing) code that every Ethereum mainnet SwapRouter deposit made
130
+ * through the SDK carries unless the call passes its own.
131
+ *
132
+ * Note: this is a process-global override applied on EVERY construction —
133
+ * the last `UpshiftSDK` instantiated is authoritative, and one that omits
134
+ * `attribution` RESETS it (same semantics as `publicApiBaseUrl`).
135
+ *
136
+ * @throws Throws synchronously from the constructor when the builder codes
137
+ * are malformed — see {@link IAttributionConfig}.
138
+ * @throws UpshiftValidationError synchronously from the constructor when
139
+ * `originCode` is not a 32-byte hex string.
140
+ */
141
+ attribution?: IAttributionConfig;
142
+ }
143
+ interface IActiveNetwork {
144
+ chainId: IChainId;
145
+ rpcUrl: string;
146
+ }
147
+ /**
148
+ * Base class providing core SDK functionality including provider management,
149
+ * network switching, and authentication state.
150
+ */
151
+ export declare class UpshiftBase {
152
+ keys: IKeys;
153
+ monitoring: IMonitoring;
154
+ authorized: boolean;
155
+ activeNetwork?: IActiveNetwork;
156
+ providers: IProvidersConfig;
157
+ /** Validated app-name slug from the constructor. */
158
+ appName: string;
159
+ /**
160
+ * Initialize base SDK with provider configuration and API keys.
161
+ * Sets up the first provider as the active network by default.
162
+ *
163
+ * @throws UpshiftValidationError if `appName` is missing, malformed, or
164
+ * out of the allowed length range — see {@link IUpshiftBase.appName}.
165
+ */
166
+ constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, publicApiBaseUrl, attribution, }: IUpshiftBase);
167
+ /**
168
+ * Verify the configured Upshift API key and mark this instance as authorized.
169
+ * Only for SDKs built with `keys.upshift`; a keyless SDK skips `init()`.
170
+ * @throws Error when `keys.upshift` is missing or rejected by the API.
171
+ */
172
+ init(): Promise<void>;
173
+ /**
174
+ * Return the active network or throw a clear error.
175
+ * Use this in methods that require an EVM provider.
176
+ */
177
+ protected requireActiveNetwork(): IActiveNetwork;
178
+ /**
179
+ * Switch the active blockchain network.
180
+ * Updates both chain ID and RPC URL for subsequent operations.
181
+ */
182
+ switchNetwork(chainId: IChainId): void;
183
+ /**
184
+ * Set active wallet address and update monitoring headers.
185
+ * Preserves existing environment setting.
186
+ */
187
+ updateWallet(address: IAddress): void;
188
+ /**
189
+ * Remove wallet address from SDK state and monitoring headers.
190
+ */
191
+ clearWallet(): void;
192
+ }
193
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpshiftBase = void 0;
4
+ const auth_1 = require("./auth");
5
+ const logger_1 = require("./logger");
6
+ const analytics_1 = require("./analytics");
7
+ const app_name_1 = require("./analytics/app-name");
8
+ const version_check_1 = require("./version-check");
9
+ const fetcher_1 = require("./fetcher");
10
+ const attribution_1 = require("./attribution");
11
+ const curator_alert_1 = require("./logger/curator-alert");
12
+ /**
13
+ * Base class providing core SDK functionality including provider management,
14
+ * network switching, and authentication state.
15
+ */
16
+ class UpshiftBase {
17
+ keys;
18
+ monitoring = {
19
+ 'x-user-id': undefined,
20
+ 'x-environment': undefined,
21
+ };
22
+ authorized;
23
+ activeNetwork;
24
+ providers;
25
+ /** Validated app-name slug from the constructor. */
26
+ appName;
27
+ /**
28
+ * Initialize base SDK with provider configuration and API keys.
29
+ * Sets up the first provider as the active network by default.
30
+ *
31
+ * @throws UpshiftValidationError if `appName` is missing, malformed, or
32
+ * out of the allowed length range — see {@link IUpshiftBase.appName}.
33
+ */
34
+ constructor({ appName, providers = {}, keys, monitoring, analytics, versionCheck, timeoutMs, publicApiBaseUrl, attribution, }) {
35
+ // Validate first so the failure mode is a clear, actionable error before
36
+ // any provider / analytics side effects run.
37
+ this.appName = (0, app_name_1.validateAppName)(appName);
38
+ // TODO: change this to false later when upshift key is required
39
+ this.authorized = true;
40
+ this.providers = providers;
41
+ // Set active network from the first provider (if any).
42
+ // An empty providers map is valid for backend-only chains (e.g. Stellar).
43
+ if (Object.keys(providers).length > 0) {
44
+ this.activeNetwork = {
45
+ chainId: Number(Object.keys(providers)[0]),
46
+ rpcUrl: Object.values(providers)[0],
47
+ };
48
+ }
49
+ // Default to an empty set so the api and sub-account modules can read
50
+ // `this.keys.upshift` (undefined) instead of throwing on a keyless SDK.
51
+ this.keys = keys ?? {};
52
+ // Set environment (defaults to PROD for safety)
53
+ const environment = monitoring?.env || monitoring?.['x-environment'] || 'PROD';
54
+ this.monitoring = {
55
+ ...monitoring,
56
+ 'x-environment': environment,
57
+ };
58
+ // Set dev mode for logging (only true if explicitly set to DEV)
59
+ logger_1.Logger.setDevMode(environment === 'DEV');
60
+ // Initialize analytics (pass API key for hashed identification + the
61
+ // appName so events can be filtered by consuming application).
62
+ (0, analytics_1.initializeSentry)(analytics ?? { enabled: true }, environment, this.appName, monitoring?.['x-user-id'], keys?.upshift);
63
+ // Best-effort version nudge — fire-and-forget, never blocks init, no
64
+ // network call in production. See `core/version-check.ts` for details.
65
+ (0, version_check_1.runVersionCheck)(versionCheck);
66
+ if (typeof timeoutMs === 'number') {
67
+ (0, fetcher_1.setSdkRequestTimeout)(timeoutMs);
68
+ }
69
+ // Repoint the unauthenticated `public` vault-catalog API when a non-prod
70
+ // deployment supplies an isolated backend. Called UNCONDITIONALLY so each
71
+ // instance is authoritative: an instance that omits `publicApiBaseUrl`
72
+ // passes `null` and RESETS to the compiled-in prod default. Without this a
73
+ // prior staging instance would leak into a later prod instance in the same
74
+ // process — the inverse of the isolation this option exists to provide.
75
+ (0, fetcher_1.setPublicApiBaseUrl)(publicApiBaseUrl ?? null);
76
+ // Every backend request from this process now identifies the app
77
+ // (`x-august-app`) — same last-instance-wins contract as the base URL.
78
+ (0, fetcher_1.setSdkAppName)(this.appName);
79
+ // ERC-8021 attribution follows the same reset-on-omit contract as
80
+ // `publicApiBaseUrl`: called unconditionally so a prior instance's
81
+ // builder codes never leak into a later instance in the same process.
82
+ (0, attribution_1.setAttribution)(attribution ?? null);
83
+ // Same reset-on-omit contract, for the same reason: an instance that says
84
+ // nothing about curator alerts gets the default (on in production), not
85
+ // whatever a previously-constructed instance asked for.
86
+ // Reports follow the API this instance reads from — resolved AFTER
87
+ // `setPublicApiBaseUrl` above, so a staging deployment alerts staging.
88
+ (0, curator_alert_1.configureCuratorAlerts)(monitoring?.curatorAlerts ?? null, {
89
+ appName: this.appName,
90
+ environment: environment,
91
+ apiBaseUrl: (0, fetcher_1.getPublicApiBaseUrl)(),
92
+ });
93
+ }
94
+ /**
95
+ * Verify the configured Upshift API key and mark this instance as authorized.
96
+ * Only for SDKs built with `keys.upshift`; a keyless SDK skips `init()`.
97
+ * @throws Error when `keys.upshift` is missing or rejected by the API.
98
+ */
99
+ async init() {
100
+ const [upshiftCheck] = await Promise.all([
101
+ (0, auth_1.verifyUpshiftKey)(this.keys?.upshift),
102
+ ]);
103
+ if (!upshiftCheck)
104
+ throw new Error('Upshift API key is invalid.');
105
+ this.authorized = true;
106
+ logger_1.Logger.log.info('init', 'Upshift SDK successfully initialized');
107
+ return;
108
+ }
109
+ /**
110
+ * Return the active network or throw a clear error.
111
+ * Use this in methods that require an EVM provider.
112
+ */
113
+ requireActiveNetwork() {
114
+ if (!this.activeNetwork) {
115
+ throw new Error('No active network configured. This operation requires an EVM provider. ' +
116
+ 'Pass at least one provider in the SDK constructor, or call switchNetwork() first.');
117
+ }
118
+ return this.activeNetwork;
119
+ }
120
+ /**
121
+ * Switch the active blockchain network.
122
+ * Updates both chain ID and RPC URL for subsequent operations.
123
+ */
124
+ switchNetwork(chainId) {
125
+ if (!this.providers[chainId]) {
126
+ throw new Error(`No provider configured for chainId ${chainId}. Available chains: ${Object.keys(this.providers).join(', ')}`);
127
+ }
128
+ this.activeNetwork = {
129
+ chainId,
130
+ rpcUrl: this.providers[chainId],
131
+ };
132
+ }
133
+ /**
134
+ * Set active wallet address and update monitoring headers.
135
+ * Preserves existing environment setting.
136
+ */
137
+ updateWallet(address) {
138
+ if (!address)
139
+ return;
140
+ const lowercasedAddress = address.toLowerCase();
141
+ this.monitoring = {
142
+ ...this.monitoring,
143
+ 'x-user-id': lowercasedAddress,
144
+ };
145
+ // Update analytics user identity
146
+ (0, analytics_1.updateUser)(lowercasedAddress, this.monitoring['x-environment']);
147
+ }
148
+ /**
149
+ * Remove wallet address from SDK state and monitoring headers.
150
+ */
151
+ clearWallet() {
152
+ if (this.monitoring) {
153
+ this.monitoring = {
154
+ ...this.monitoring,
155
+ 'x-user-id': undefined,
156
+ };
157
+ }
158
+ // Clear wallet from analytics user identity
159
+ (0, analytics_1.clearUser)();
160
+ }
161
+ }
162
+ exports.UpshiftBase = UpshiftBase;
163
+ //# sourceMappingURL=base.class.js.map
@@ -0,0 +1,9 @@
1
+ import { LRUCache } from 'lru-cache';
2
+ /**
3
+ * Process-wide LRU used by core helpers for memoizing RPC / fetch results.
4
+ * Kept in a leaf module so importers don't pull in the broader `core/fetcher.ts`
5
+ * graph (which would cycle through `core/helpers/web3.ts`).
6
+ */
7
+ export declare const CACHE: LRUCache<string, any, unknown>;
8
+ export declare const getSafeCache: <T>(key: string) => Promise<T | null>;
9
+ export declare const setSafeCache: <T>(key: string, value: T) => Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSafeCache = exports.getSafeCache = exports.CACHE = void 0;
4
+ const lru_cache_1 = require("lru-cache");
5
+ /**
6
+ * Process-wide LRU used by core helpers for memoizing RPC / fetch results.
7
+ * Kept in a leaf module so importers don't pull in the broader `core/fetcher.ts`
8
+ * graph (which would cycle through `core/helpers/web3.ts`).
9
+ */
10
+ // biome-ignore lint/suspicious/noExplicitAny: shared heterogeneous cache keyed by string; a concrete value type would force casts at every call site and risk a dependency cycle through core/helpers/web3.ts.
11
+ exports.CACHE = new lru_cache_1.LRUCache({
12
+ max: 1000,
13
+ ttl: 1000 * 60 * 60 * 24,
14
+ allowStale: true,
15
+ });
16
+ const getSafeCache = async (key) => {
17
+ if (!key)
18
+ return null;
19
+ if (exports.CACHE.has(key)) {
20
+ return exports.CACHE.get(key);
21
+ }
22
+ return null;
23
+ };
24
+ exports.getSafeCache = getSafeCache;
25
+ const setSafeCache = async (key, value) => {
26
+ if (key && value) {
27
+ exports.CACHE.set(key, value);
28
+ }
29
+ };
30
+ exports.setSafeCache = setSafeCache;
31
+ //# sourceMappingURL=cache.js.map