@upshiftfinance/sdk 0.0.0-stage → 0.2.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 (344) 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/client.d.ts +83 -0
  116. package/lib/adapters/sui/client.js +216 -0
  117. package/lib/adapters/sui/constants.d.ts +33 -0
  118. package/lib/adapters/sui/constants.js +31 -0
  119. package/lib/adapters/sui/index.d.ts +57 -0
  120. package/lib/adapters/sui/index.js +100 -0
  121. package/lib/adapters/sui/targets.d.ts +171 -0
  122. package/lib/adapters/sui/targets.js +225 -0
  123. package/lib/adapters/sui/utils.d.ts +8 -0
  124. package/lib/adapters/sui/utils.js +17 -0
  125. package/lib/core/analytics/app-name.d.ts +27 -0
  126. package/lib/core/analytics/app-name.js +48 -0
  127. package/lib/core/analytics/chain-name.d.ts +9 -0
  128. package/lib/core/analytics/chain-name.js +34 -0
  129. package/lib/core/analytics/constants.d.ts +15 -0
  130. package/lib/core/analytics/constants.js +28 -0
  131. package/lib/core/analytics/env.d.ts +46 -0
  132. package/lib/core/analytics/env.js +147 -0
  133. package/lib/core/analytics/index.d.ts +39 -0
  134. package/lib/core/analytics/index.js +83 -0
  135. package/lib/core/analytics/instrumentation.d.ts +29 -0
  136. package/lib/core/analytics/instrumentation.js +292 -0
  137. package/lib/core/analytics/method-taxonomy.d.ts +19 -0
  138. package/lib/core/analytics/method-taxonomy.js +156 -0
  139. package/lib/core/analytics/metrics.d.ts +48 -0
  140. package/lib/core/analytics/metrics.js +142 -0
  141. package/lib/core/analytics/sanitize.d.ts +57 -0
  142. package/lib/core/analytics/sanitize.js +272 -0
  143. package/lib/core/analytics/sentry-runtime.d.ts +15 -0
  144. package/lib/core/analytics/sentry-runtime.js +131 -0
  145. package/lib/core/analytics/sentry.d.ts +100 -0
  146. package/lib/core/analytics/sentry.js +696 -0
  147. package/lib/core/analytics/types.d.ts +55 -0
  148. package/lib/core/analytics/types.js +3 -0
  149. package/lib/core/analytics/user-identity.d.ts +55 -0
  150. package/lib/core/analytics/user-identity.js +218 -0
  151. package/lib/core/analytics/version.d.ts +6 -0
  152. package/lib/core/analytics/version.js +10 -0
  153. package/lib/core/attribution.d.ts +159 -0
  154. package/lib/core/attribution.js +194 -0
  155. package/lib/core/auth/index.d.ts +1 -0
  156. package/lib/core/auth/index.js +18 -0
  157. package/lib/core/auth/verify.d.ts +2 -0
  158. package/lib/core/auth/verify.js +35 -0
  159. package/lib/core/base.class.d.ts +193 -0
  160. package/lib/core/base.class.js +163 -0
  161. package/lib/core/cache.d.ts +9 -0
  162. package/lib/core/cache.js +31 -0
  163. package/lib/core/constants/adapters.d.ts +103 -0
  164. package/lib/core/constants/adapters.js +180 -0
  165. package/lib/core/constants/core.d.ts +162 -0
  166. package/lib/core/constants/core.js +281 -0
  167. package/lib/core/constants/swap-router.d.ts +180 -0
  168. package/lib/core/constants/swap-router.js +203 -0
  169. package/lib/core/constants/vaults.d.ts +93 -0
  170. package/lib/core/constants/vaults.js +277 -0
  171. package/lib/core/constants/web3.d.ts +106 -0
  172. package/lib/core/constants/web3.js +251 -0
  173. package/lib/core/errors/index.d.ts +177 -0
  174. package/lib/core/errors/index.js +257 -0
  175. package/lib/core/fetcher.d.ts +237 -0
  176. package/lib/core/fetcher.js +1103 -0
  177. package/lib/core/helpers/adapters.d.ts +13 -0
  178. package/lib/core/helpers/adapters.js +39 -0
  179. package/lib/core/helpers/chain-address.d.ts +13 -0
  180. package/lib/core/helpers/chain-address.js +47 -0
  181. package/lib/core/helpers/chain-error.d.ts +207 -0
  182. package/lib/core/helpers/chain-error.js +697 -0
  183. package/lib/core/helpers/chain-support.d.ts +98 -0
  184. package/lib/core/helpers/chain-support.js +139 -0
  185. package/lib/core/helpers/concurrency.d.ts +51 -0
  186. package/lib/core/helpers/concurrency.js +79 -0
  187. package/lib/core/helpers/core.d.ts +92 -0
  188. package/lib/core/helpers/core.js +368 -0
  189. package/lib/core/helpers/explorer-link.d.ts +16 -0
  190. package/lib/core/helpers/explorer-link.js +26 -0
  191. package/lib/core/helpers/multicall.d.ts +68 -0
  192. package/lib/core/helpers/multicall.js +103 -0
  193. package/lib/core/helpers/revert-decode.d.ts +248 -0
  194. package/lib/core/helpers/revert-decode.js +515 -0
  195. package/lib/core/helpers/signer.d.ts +61 -0
  196. package/lib/core/helpers/signer.js +184 -0
  197. package/lib/core/helpers/swap-router.d.ts +269 -0
  198. package/lib/core/helpers/swap-router.js +542 -0
  199. package/lib/core/helpers/vault-version.d.ts +24 -0
  200. package/lib/core/helpers/vault-version.js +83 -0
  201. package/lib/core/helpers/vaults.d.ts +89 -0
  202. package/lib/core/helpers/vaults.js +241 -0
  203. package/lib/core/helpers/web3.d.ts +366 -0
  204. package/lib/core/helpers/web3.js +1034 -0
  205. package/lib/core/index.d.ts +23 -0
  206. package/lib/core/index.js +40 -0
  207. package/lib/core/logger/curator-alert.d.ts +217 -0
  208. package/lib/core/logger/curator-alert.js +276 -0
  209. package/lib/core/logger/index.d.ts +99 -0
  210. package/lib/core/logger/index.js +163 -0
  211. package/lib/core/logger/slack.d.ts +49 -0
  212. package/lib/core/logger/slack.js +111 -0
  213. package/lib/core/vault-metadata.d.ts +12 -0
  214. package/lib/core/vault-metadata.js +42 -0
  215. package/lib/core/version-check.d.ts +58 -0
  216. package/lib/core/version-check.js +182 -0
  217. package/lib/evm/index.d.ts +2 -0
  218. package/lib/evm/index.js +19 -0
  219. package/lib/evm/methods/crossChainVault.d.ts +132 -0
  220. package/lib/evm/methods/crossChainVault.js +857 -0
  221. package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
  222. package/lib/evm/methods/crossChainVaultRegistry.js +239 -0
  223. package/lib/evm/methods/index.d.ts +2 -0
  224. package/lib/evm/methods/index.js +19 -0
  225. package/lib/evm/types/crossChain.d.ts +363 -0
  226. package/lib/evm/types/crossChain.js +20 -0
  227. package/lib/evm/types/index.d.ts +1 -0
  228. package/lib/evm/types/index.js +18 -0
  229. package/lib/index.d.ts +30 -0
  230. package/lib/index.js +52 -0
  231. package/lib/main.d.ts +596 -0
  232. package/lib/main.js +681 -0
  233. package/lib/modules/api/fetcher.d.ts +108 -0
  234. package/lib/modules/api/fetcher.js +187 -0
  235. package/lib/modules/api/index.d.ts +1 -0
  236. package/lib/modules/api/index.js +6 -0
  237. package/lib/modules/api/main.d.ts +587 -0
  238. package/lib/modules/api/main.js +911 -0
  239. package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
  240. package/lib/modules/sub-accounts/fetcher.js +96 -0
  241. package/lib/modules/sub-accounts/index.d.ts +2 -0
  242. package/lib/modules/sub-accounts/index.js +19 -0
  243. package/lib/modules/sub-accounts/main.d.ts +249 -0
  244. package/lib/modules/sub-accounts/main.js +211 -0
  245. package/lib/modules/sub-accounts/utils.d.ts +106 -0
  246. package/lib/modules/sub-accounts/utils.js +112 -0
  247. package/lib/modules/vaults/adapter.helpers.d.ts +84 -0
  248. package/lib/modules/vaults/adapter.helpers.js +202 -0
  249. package/lib/modules/vaults/fetcher.d.ts +147 -0
  250. package/lib/modules/vaults/fetcher.js +357 -0
  251. package/lib/modules/vaults/getters.d.ts +1060 -0
  252. package/lib/modules/vaults/getters.js +4079 -0
  253. package/lib/modules/vaults/index.d.ts +20 -0
  254. package/lib/modules/vaults/index.js +44 -0
  255. package/lib/modules/vaults/main.d.ts +607 -0
  256. package/lib/modules/vaults/main.js +1687 -0
  257. package/lib/modules/vaults/prefetch.d.ts +65 -0
  258. package/lib/modules/vaults/prefetch.js +120 -0
  259. package/lib/modules/vaults/read.actions.d.ts +406 -0
  260. package/lib/modules/vaults/read.actions.js +891 -0
  261. package/lib/modules/vaults/types.d.ts +149 -0
  262. package/lib/modules/vaults/types.js +3 -0
  263. package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
  264. package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
  265. package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
  266. package/lib/modules/vaults/utils/date-utils.js +84 -0
  267. package/lib/modules/vaults/utils.d.ts +153 -0
  268. package/lib/modules/vaults/utils.js +818 -0
  269. package/lib/modules/vaults/write.actions.d.ts +812 -0
  270. package/lib/modules/vaults/write.actions.js +2377 -0
  271. package/lib/polyfills.d.ts +1 -0
  272. package/lib/polyfills.js +12 -0
  273. package/lib/sdk.d.ts +30173 -0
  274. package/lib/services/coingecko/fetcher.d.ts +15 -0
  275. package/lib/services/coingecko/fetcher.js +67 -0
  276. package/lib/services/coingecko/index.d.ts +2 -0
  277. package/lib/services/coingecko/index.js +19 -0
  278. package/lib/services/coingecko/utils.d.ts +1 -0
  279. package/lib/services/coingecko/utils.js +24 -0
  280. package/lib/services/debank/fetcher.d.ts +126 -0
  281. package/lib/services/debank/fetcher.js +47 -0
  282. package/lib/services/debank/index.d.ts +2 -0
  283. package/lib/services/debank/index.js +19 -0
  284. package/lib/services/debank/utils.d.ts +50 -0
  285. package/lib/services/debank/utils.js +325 -0
  286. package/lib/services/layerzero/deposits.d.ts +55 -0
  287. package/lib/services/layerzero/deposits.js +174 -0
  288. package/lib/services/layerzero/redeems.d.ts +20 -0
  289. package/lib/services/layerzero/redeems.js +92 -0
  290. package/lib/services/layerzero/utils.d.ts +9 -0
  291. package/lib/services/layerzero/utils.js +22 -0
  292. package/lib/services/octavfi/fetcher.d.ts +33 -0
  293. package/lib/services/octavfi/fetcher.js +39 -0
  294. package/lib/services/octavfi/index.d.ts +3 -0
  295. package/lib/services/octavfi/index.js +20 -0
  296. package/lib/services/octavfi/types.d.ts +34 -0
  297. package/lib/services/octavfi/types.js +3 -0
  298. package/lib/services/octavfi/utils.d.ts +16 -0
  299. package/lib/services/octavfi/utils.js +244 -0
  300. package/lib/services/subgraph/fetcher.d.ts +2 -0
  301. package/lib/services/subgraph/fetcher.js +66 -0
  302. package/lib/services/subgraph/index.d.ts +2 -0
  303. package/lib/services/subgraph/index.js +19 -0
  304. package/lib/services/subgraph/schema.d.ts +48 -0
  305. package/lib/services/subgraph/schema.js +87 -0
  306. package/lib/services/subgraph/vaults.d.ts +83 -0
  307. package/lib/services/subgraph/vaults.js +1282 -0
  308. package/lib/services/swap-quotes/index.d.ts +105 -0
  309. package/lib/services/swap-quotes/index.js +77 -0
  310. package/lib/services/swap-quotes/paraswap.d.ts +51 -0
  311. package/lib/services/swap-quotes/paraswap.js +138 -0
  312. package/lib/services/untangled/fetcher.d.ts +40 -0
  313. package/lib/services/untangled/fetcher.js +110 -0
  314. package/lib/services/untangled/index.d.ts +3 -0
  315. package/lib/services/untangled/index.js +20 -0
  316. package/lib/services/untangled/types.d.ts +83 -0
  317. package/lib/services/untangled/types.js +10 -0
  318. package/lib/services/untangled/utils.d.ts +91 -0
  319. package/lib/services/untangled/utils.js +339 -0
  320. package/lib/types/api.d.ts +498 -0
  321. package/lib/types/api.js +3 -0
  322. package/lib/types/index.d.ts +12 -0
  323. package/lib/types/index.js +28 -0
  324. package/lib/types/points.d.ts +28 -0
  325. package/lib/types/points.js +3 -0
  326. package/lib/types/pools.d.ts +144 -0
  327. package/lib/types/pools.js +3 -0
  328. package/lib/types/staking.d.ts +28 -0
  329. package/lib/types/staking.js +3 -0
  330. package/lib/types/sub-accounts.d.ts +150 -0
  331. package/lib/types/sub-accounts.js +3 -0
  332. package/lib/types/subgraph.d.ts +84 -0
  333. package/lib/types/subgraph.js +3 -0
  334. package/lib/types/typed-contract.d.ts +102 -0
  335. package/lib/types/typed-contract.js +3 -0
  336. package/lib/types/user.d.ts +1 -0
  337. package/lib/types/user.js +3 -0
  338. package/lib/types/vaults.d.ts +886 -0
  339. package/lib/types/vaults.js +30 -0
  340. package/lib/types/web3.d.ts +100 -0
  341. package/lib/types/web3.js +14 -0
  342. package/lib/types/webserver.d.ts +730 -0
  343. package/lib/types/webserver.js +3 -0
  344. package/package.json +79 -3
@@ -0,0 +1,55 @@
1
+ import type { IEnv } from '../../types';
2
+ /**
3
+ * Configuration for SDK analytics/telemetry.
4
+ * Analytics are enabled by default (opt-out model).
5
+ */
6
+ export interface IAnalyticsConfig {
7
+ /** Set to false to disable analytics. Default: true */
8
+ enabled?: boolean;
9
+ /**
10
+ * Sentry trace sample rate. Defaults to `0.1`; values outside `[0, 1]`
11
+ * are clamped.
12
+ */
13
+ tracesSampleRate?: number;
14
+ /**
15
+ * Which Upshift surface is emitting telemetry, recorded once at init as the
16
+ * sticky `sdk.surface` tag on every event and span. The CLI passes `'cli'`
17
+ * and the MCP server `'mcp'`; applications embedding the SDK directly can
18
+ * leave the default `'sdk'`.
19
+ */
20
+ surface?: 'sdk' | 'cli' | 'mcp' | 'react' | string;
21
+ }
22
+ /**
23
+ * User identity for analytics tracking.
24
+ * Multiple identifiers are used with priority: apiKeyHash \> wallet \> domain \> fingerprint \> session
25
+ */
26
+ export interface IUserIdentity {
27
+ /** Hex-encoded SHA-256 hash of the API key. Never stores the raw key. */
28
+ apiKeyHash?: string;
29
+ /** User's wallet address (lowercased) */
30
+ walletAddress?: string;
31
+ /** Random UUID generated per SDK instance */
32
+ sessionId: string;
33
+ /** Browser/environment fingerprint for cross-session tracking */
34
+ fingerprint?: string;
35
+ /** Current environment */
36
+ environment: IEnv;
37
+ /** Domain of the current environment */
38
+ domain?: string;
39
+ }
40
+ /**
41
+ * Metrics for tracking SDK method calls.
42
+ */
43
+ export interface IMethodCallMetrics {
44
+ method: string;
45
+ /**
46
+ * Coarse-grained category from {@link METHOD_CATEGORIES} — e.g. `'read.vault'`,
47
+ * `'write.deposit'`. Used to roll calls up in the partner-usage dashboard
48
+ * without having to enumerate every method name.
49
+ */
50
+ category?: string;
51
+ chainId?: number;
52
+ duration: number;
53
+ success: boolean;
54
+ errorType?: string;
55
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,55 @@
1
+ import type { IEnv } from '../../types';
2
+ import type { IUserIdentity } from './types';
3
+ /**
4
+ * Hash an API key with SHA-256 for use as a Sentry-safe identity token.
5
+ *
6
+ * Only the hash is ever returned. The most recently hashed key and its hash
7
+ * are cached in memory, so a repeat call skips the digest and a different key
8
+ * replaces the cache instead of returning the previous key's hash.
9
+ *
10
+ * When the runtime has no usable `crypto.createHash` (e.g. a browser bundle
11
+ * without a `crypto` shim) this returns `''` rather than throwing, so the
12
+ * Sentry identity falls back to the next identifier instead of being dropped.
13
+ *
14
+ * @param apiKey - The raw API key to hash
15
+ * @returns Hex-encoded SHA-256 hash of `apiKey`, or `''` for an empty input or
16
+ * when hashing is unavailable
17
+ */
18
+ export declare function hashApiKey(apiKey: string): string;
19
+ /**
20
+ * Generate a session ID that persists for the SDK instance lifetime.
21
+ * Provides user continuity even when wallet is not connected.
22
+ *
23
+ * @returns UUID v4 session identifier
24
+ */
25
+ export declare function getSessionId(): string;
26
+ /**
27
+ * Generate a browser/environment fingerprint for cross-session tracking.
28
+ * Falls back gracefully in different environments.
29
+ *
30
+ * @returns Base64 encoded fingerprint string or undefined if unavailable
31
+ */
32
+ export declare function generateFingerprint(): string | undefined;
33
+ /**
34
+ * Create a composite user identity for analytics.
35
+ *
36
+ * @param apiKey - Optional API key (will be hashed, never stored raw)
37
+ * @param walletAddress - Optional wallet address
38
+ * @param environment - Current environment (DEV or PROD)
39
+ * @returns User identity object
40
+ */
41
+ export declare function createUserIdentity(apiKey?: string, walletAddress?: string, environment?: IEnv): IUserIdentity;
42
+ /**
43
+ * Generate a unique user ID for Sentry from identity components.
44
+ * Priority: apiKeyHash \> wallet \> domain \> fingerprint \> session
45
+ *
46
+ * An API key identifies the integrator and a wallet identifies the end user,
47
+ * so both outrank the hosting domain — otherwise every visitor of one web app
48
+ * collapses into a single Sentry user. `domain` still ranks above the
49
+ * fingerprint, which nearly every runtime produces, so hostname attribution
50
+ * is not lost.
51
+ *
52
+ * @param identity - User identity object
53
+ * @returns Prefixed user ID string
54
+ */
55
+ export declare function getUserId(identity: IUserIdentity): string;
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hashApiKey = hashApiKey;
4
+ exports.getSessionId = getSessionId;
5
+ exports.generateFingerprint = generateFingerprint;
6
+ exports.createUserIdentity = createUserIdentity;
7
+ exports.getUserId = getUserId;
8
+ const uuid_1 = require("uuid");
9
+ /** Memoised result of {@link loadCreateHash}; `null` once resolution has failed. */
10
+ let cachedCreateHash;
11
+ /**
12
+ * Resolve Node's `crypto.createHash` without a static `import`.
13
+ *
14
+ * Why: this module is reachable from the browser bundle, and a top-level
15
+ * `import { createHash } from 'crypto'` either breaks the bundle (no Node
16
+ * built-in in the browser) or forces consumers to ship a polyfill. Instead
17
+ * the built-in is looked up at call time:
18
+ *
19
+ * 1. `process.getBuiltinModule('crypto')` (Node >= 22.3, the SDK's supported
20
+ * floor is Node 22). A plain property access, so bundlers never see a
21
+ * `crypto` import, and it works under both CJS and ESM loaders.
22
+ * 2. The `new Function('return require')` trick from
23
+ * `core/analytics/sentry-runtime.ts`, for CJS hosts that expose a global
24
+ * `require` (opaque to bundler static analysis).
25
+ *
26
+ * In a browser, or under a strict CSP that blocks `new Function`, both steps
27
+ * yield `null`: hashing is reported unavailable and callers fall back to the
28
+ * next identifier (wallet / domain / session) instead of throwing.
29
+ *
30
+ * Node output is byte-for-byte the same SHA-256 hex as the former static
31
+ * import produced — partner ids persisted in Sentry stay stable.
32
+ *
33
+ * @returns The `createHash` function, or `null` when it cannot be loaded.
34
+ */
35
+ function loadCreateHash() {
36
+ if (cachedCreateHash !== undefined)
37
+ return cachedCreateHash;
38
+ cachedCreateHash = null;
39
+ try {
40
+ const getBuiltin = globalThis.process?.getBuiltinModule;
41
+ const mod = typeof getBuiltin === 'function'
42
+ ? getBuiltin('crypto')
43
+ : undefined;
44
+ if (typeof mod?.createHash === 'function') {
45
+ cachedCreateHash = mod.createHash;
46
+ return cachedCreateHash;
47
+ }
48
+ }
49
+ catch {
50
+ // fall through to the require-based lookup
51
+ }
52
+ try {
53
+ const req = new Function('return typeof require === "function" ? require : null')();
54
+ const mod = req ? req('crypto') : null;
55
+ if (typeof mod?.createHash === 'function') {
56
+ cachedCreateHash = mod.createHash;
57
+ }
58
+ }
59
+ catch {
60
+ // leave null: hashing unavailable in this runtime
61
+ }
62
+ return cachedCreateHash;
63
+ }
64
+ /**
65
+ * SHA-256 a string to lowercase hex, or `undefined` when no hash
66
+ * implementation is available in this runtime.
67
+ */
68
+ function sha256Hex(value) {
69
+ const createHash = loadCreateHash();
70
+ if (!createHash)
71
+ return undefined;
72
+ return createHash('sha256').update(value).digest('hex');
73
+ }
74
+ /** Session ID persists for SDK instance lifetime */
75
+ let sessionId = null;
76
+ /** Raw API key the cached hash below was computed from — lets a key change invalidate the cache. */
77
+ let cachedApiKey = null;
78
+ /** SHA-256 hash of {@link cachedApiKey}. */
79
+ let cachedApiKeyHash = null;
80
+ /**
81
+ * Hash an API key with SHA-256 for use as a Sentry-safe identity token.
82
+ *
83
+ * Only the hash is ever returned. The most recently hashed key and its hash
84
+ * are cached in memory, so a repeat call skips the digest and a different key
85
+ * replaces the cache instead of returning the previous key's hash.
86
+ *
87
+ * When the runtime has no usable `crypto.createHash` (e.g. a browser bundle
88
+ * without a `crypto` shim) this returns `''` rather than throwing, so the
89
+ * Sentry identity falls back to the next identifier instead of being dropped.
90
+ *
91
+ * @param apiKey - The raw API key to hash
92
+ * @returns Hex-encoded SHA-256 hash of `apiKey`, or `''` for an empty input or
93
+ * when hashing is unavailable
94
+ */
95
+ function hashApiKey(apiKey) {
96
+ if (!apiKey)
97
+ return '';
98
+ if (cachedApiKey === apiKey && cachedApiKeyHash) {
99
+ return cachedApiKeyHash;
100
+ }
101
+ try {
102
+ const hash = sha256Hex(apiKey);
103
+ if (!hash)
104
+ return '';
105
+ cachedApiKeyHash = hash;
106
+ cachedApiKey = apiKey;
107
+ return cachedApiKeyHash;
108
+ }
109
+ catch {
110
+ return '';
111
+ }
112
+ }
113
+ /**
114
+ * Generate a session ID that persists for the SDK instance lifetime.
115
+ * Provides user continuity even when wallet is not connected.
116
+ *
117
+ * @returns UUID v4 session identifier
118
+ */
119
+ function getSessionId() {
120
+ if (!sessionId) {
121
+ sessionId = (0, uuid_1.v4)();
122
+ }
123
+ return sessionId;
124
+ }
125
+ /**
126
+ * Generate a browser/environment fingerprint for cross-session tracking.
127
+ * Falls back gracefully in different environments.
128
+ *
129
+ * @returns Base64 encoded fingerprint string or undefined if unavailable
130
+ */
131
+ function generateFingerprint() {
132
+ try {
133
+ // Browser environment
134
+ if (typeof window !== 'undefined' && typeof navigator !== 'undefined') {
135
+ const components = [
136
+ navigator.userAgent,
137
+ navigator.language,
138
+ new Date().getTimezoneOffset().toString(),
139
+ typeof screen !== 'undefined' ? screen.width?.toString() : '',
140
+ typeof screen !== 'undefined' ? screen.height?.toString() : '',
141
+ typeof screen !== 'undefined' ? screen.colorDepth?.toString() : '',
142
+ ].filter(Boolean);
143
+ // Create a simple hash from components
144
+ const hash = sha256Hex(components.join('|'));
145
+ return hash?.substring(0, 32);
146
+ }
147
+ // Node.js environment
148
+ if (typeof process !== 'undefined' && process.platform) {
149
+ const components = [process.platform, process.arch, process.version];
150
+ const hash = sha256Hex(components.join('|'));
151
+ return hash?.substring(0, 32);
152
+ }
153
+ }
154
+ catch {
155
+ // Silently fail if fingerprinting is not possible
156
+ return undefined;
157
+ }
158
+ return undefined;
159
+ }
160
+ /**
161
+ * Create a composite user identity for analytics.
162
+ *
163
+ * @param apiKey - Optional API key (will be hashed, never stored raw)
164
+ * @param walletAddress - Optional wallet address
165
+ * @param environment - Current environment (DEV or PROD)
166
+ * @returns User identity object
167
+ */
168
+ function createUserIdentity(apiKey, walletAddress, environment = 'PROD') {
169
+ let domain;
170
+ try {
171
+ if (typeof window !== 'undefined' && window.location) {
172
+ domain = window.location.hostname;
173
+ }
174
+ else if (typeof process !== 'undefined' && process.env) {
175
+ domain = process.env.VERCEL_PROJECT_PRODUCTION_URL || undefined;
176
+ }
177
+ }
178
+ catch {
179
+ // Silently fail - domain is optional
180
+ }
181
+ return {
182
+ apiKeyHash: apiKey ? hashApiKey(apiKey) : undefined,
183
+ walletAddress: walletAddress?.toLowerCase(),
184
+ sessionId: getSessionId(),
185
+ fingerprint: generateFingerprint(),
186
+ environment,
187
+ domain,
188
+ };
189
+ }
190
+ /**
191
+ * Generate a unique user ID for Sentry from identity components.
192
+ * Priority: apiKeyHash \> wallet \> domain \> fingerprint \> session
193
+ *
194
+ * An API key identifies the integrator and a wallet identifies the end user,
195
+ * so both outrank the hosting domain — otherwise every visitor of one web app
196
+ * collapses into a single Sentry user. `domain` still ranks above the
197
+ * fingerprint, which nearly every runtime produces, so hostname attribution
198
+ * is not lost.
199
+ *
200
+ * @param identity - User identity object
201
+ * @returns Prefixed user ID string
202
+ */
203
+ function getUserId(identity) {
204
+ if (identity.apiKeyHash) {
205
+ return `apikey:${identity.apiKeyHash}`;
206
+ }
207
+ if (identity.walletAddress) {
208
+ return `wallet:${identity.walletAddress}`;
209
+ }
210
+ if (identity.domain) {
211
+ return `domain:${identity.domain}`;
212
+ }
213
+ if (identity.fingerprint) {
214
+ return `fp:${identity.fingerprint}`;
215
+ }
216
+ return `session:${identity.sessionId}`;
217
+ }
218
+ //# sourceMappingURL=user-identity.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * AUTO-GENERATED FILE - DO NOT EDIT
3
+ * Generated at build time from package.json version
4
+ * This file is gitignored and regenerated by every build
5
+ */
6
+ export declare const SDK_VERSION = "0.2.0";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_VERSION = void 0;
4
+ /**
5
+ * AUTO-GENERATED FILE - DO NOT EDIT
6
+ * Generated at build time from package.json version
7
+ * This file is gitignored and regenerated by every build
8
+ */
9
+ exports.SDK_VERSION = '0.2.0';
10
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1,159 @@
1
+ /**
2
+ * ERC-8021 transaction attribution (Base Builder Codes).
3
+ *
4
+ * ERC-8021 appends an attribution suffix to transaction calldata. Contracts
5
+ * decode their ABI-encoded arguments normally and ignore the trailing bytes,
6
+ * while offchain indexers (e.g. base.dev analytics for Base Builder Codes)
7
+ * read the suffix to attribute the transaction to the originating app.
8
+ *
9
+ * This is a leaf module: process-global state configured once via
10
+ * {@link IUpshiftBase.attribution} in the SDK constructor and read by the
11
+ * EVM write paths (the normalized-signer wrap in the EVM adapter and the
12
+ * cross-chain vault `writeContract` calls).
13
+ *
14
+ * @module attribution
15
+ */
16
+ /**
17
+ * The 16-byte ERC-8021 suffix terminator. The last 16 bytes of an attributed
18
+ * transaction's calldata are always this marker; parsers read backwards from
19
+ * it to recover the schema ID and builder codes.
20
+ */
21
+ export declare const ERC8021_MARKER = "80218021802180218021802180218021";
22
+ /**
23
+ * ERC-8021 builder-code attribution and the SwapRouter origin code — independent; set either or both.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const sdk = new UpshiftSDK({
28
+ * appName: 'my-app',
29
+ * providers: { 8453: 'https://...' },
30
+ * keys: { upshift: '...' },
31
+ * attribution: { builderCodes: ['bc_abc123'] },
32
+ * });
33
+ * ```
34
+ */
35
+ export interface IAttributionConfig {
36
+ /**
37
+ * Builder codes to embed in the suffix, e.g. from base.dev registration
38
+ * (`bc_…`). ASCII strings of 1–64 characters each; the comma-joined list
39
+ * must fit in 255 bytes (schema 0 length prefix is a single byte). Omit to
40
+ * send no ERC-8021 suffix.
41
+ */
42
+ builderCodes?: string[];
43
+ /**
44
+ * EVM chain IDs to attribute. Omit to attribute writes on every EVM chain
45
+ * (the suffix is inert on chains without an ERC-8021 indexer and costs
46
+ * ~16 gas per non-zero byte). When set, gating is fail-closed: writes on
47
+ * other chains — and writes whose chain ID cannot be determined — are sent
48
+ * without the suffix.
49
+ *
50
+ * Over-attribution is not harmless. The suffix makes calldata longer than
51
+ * the ABI encoding of the call, which breaks clear-signing on hardware
52
+ * wallets: a Ledger rejects an over-long ERC-20 `approve` with
53
+ * `EthAppCommandError: Invalid data 6a80`, so an unattributed chain that
54
+ * receives the suffix anyway cannot be transacted on from a Ledger at all.
55
+ */
56
+ chains?: number[];
57
+ /**
58
+ * SwapRouter origin (referral / fee-sharing) code: the `bytes32` registered
59
+ * via the router's `addOrigin`, as `0x` + 64 hex chars. Every Ethereum
60
+ * mainnet SwapRouter deposit carries it unless the call passes its own
61
+ * `originCode`; it is never sent on another chain. Omit to send the
62
+ * all-zero sentinel (no origin fee). Unaffected by `chains`. An
63
+ * unregistered code reverts with `InvalidOrigin` — check it with
64
+ * `getOriginInfo` first.
65
+ */
66
+ originCode?: `0x${string}`;
67
+ /**
68
+ * When `true`, a deposit route that would use the SwapRouter with an
69
+ * `originCode` not registered there throws `UpshiftValidationError` before
70
+ * any transaction, instead of falling back to the vault's native path.
71
+ */
72
+ strictOrigin?: boolean;
73
+ }
74
+ /**
75
+ * Build an ERC-8021 schema-0 attribution suffix from builder codes.
76
+ *
77
+ * Layout (appended to calldata, read back-to-front by parsers):
78
+ * `ascii(codes.join(','))` ∥ codesLength (1 byte) ∥ schemaId `0x00` ∥
79
+ * 16-byte marker `0x80218021802180218021802180218021`.
80
+ *
81
+ * @param codes Builder codes as printable-ASCII strings (e.g. `bc_abc123`),
82
+ * each 1–64 chars, no commas; the comma-joined list must be ≤ 255 bytes.
83
+ * @returns `0x`-prefixed hex suffix ready to concatenate onto calldata.
84
+ * @throws Error when `codes` is empty, a code contains a comma or
85
+ * non-printable/non-ASCII characters, or the joined list exceeds 255 bytes.
86
+ * @example
87
+ * ```typescript
88
+ * buildAttributionSuffix(['baseapp', 'morpho']);
89
+ * // '0x626173656170702c6d6f7270686f0e0080218021802180218021802180218021'
90
+ * ```
91
+ */
92
+ export declare function buildAttributionSuffix(codes: string[]): string;
93
+ /**
94
+ * Set (or clear) the process-global attribution config.
95
+ *
96
+ * Called unconditionally on every `UpshiftSDK` construction — an instance
97
+ * that omits `attribution` passes `null` and RESETS the state, so a prior
98
+ * instance's builder codes or origin code never leak into a later instance
99
+ * in the same process (same semantics as `setPublicApiBaseUrl`).
100
+ *
101
+ * @param config Attribution config from the SDK constructor, or `null` to
102
+ * disable attribution.
103
+ * @throws Error when the config's builder codes fail validation — thrown
104
+ * synchronously from the constructor so misconfiguration is caught at
105
+ * init, not on the first write.
106
+ * @throws {@link UpshiftValidationError} when `originCode` is not a 32-byte
107
+ * hex string.
108
+ */
109
+ export declare function setAttribution(config: IAttributionConfig | null): void;
110
+ /**
111
+ * Whether {@link IAttributionConfig.strictOrigin} is set on the SDK instance.
112
+ *
113
+ * @returns `true` when an unregistered origin code must fail a deposit.
114
+ */
115
+ export declare function isStrictOrigin(): boolean;
116
+ /**
117
+ * The SwapRouter origin code configured on the SDK instance via
118
+ * {@link IAttributionConfig.originCode}.
119
+ *
120
+ * @returns The `bytes32` code, or `null` when none is configured.
121
+ */
122
+ export declare function getOriginCode(): `0x${string}` | null;
123
+ /**
124
+ * Whether attribution is configured at all, independent of any chain gate.
125
+ *
126
+ * Call sites that need to know whether to resolve a chain ID before asking
127
+ * for the suffix use this; {@link getAttributionSuffix} applies the gate.
128
+ *
129
+ * @returns `true` when builder codes are configured.
130
+ */
131
+ export declare function isAttributionEnabled(): boolean;
132
+ /**
133
+ * Return the active ERC-8021 suffix for a write on the given chain, or
134
+ * `undefined` when attribution is off or the chain is not attributed.
135
+ *
136
+ * @param chainId EVM chain ID of the transaction, when the call site knows
137
+ * it. When a `chains` restriction is configured, gating is fail-closed: an
138
+ * omitted chain ID yields no suffix, since a suffix on an unattributed
139
+ * chain buys nothing and breaks hardware-wallet clear-signing (see
140
+ * {@link IAttributionConfig.chains}).
141
+ * @returns `0x`-prefixed hex suffix, or `undefined` when nothing should be
142
+ * appended.
143
+ */
144
+ export declare function getAttributionSuffix(chainId?: number): string | undefined;
145
+ /**
146
+ * Append the active attribution suffix to calldata.
147
+ *
148
+ * No-ops (returns `data` unchanged) when attribution is off, the chain is
149
+ * not attributed (including an unknown chain under a `chains` restriction),
150
+ * `data` is empty/absent (plain value transfers are never
151
+ * attributed), or `data` already ends with the ERC-8021 marker (guards
152
+ * against double-appending when an upstream layer — e.g. a wagmi config
153
+ * `dataSuffix` — already attributed the transaction).
154
+ *
155
+ * @param data `0x`-prefixed calldata of the outgoing transaction.
156
+ * @param chainId EVM chain ID of the transaction, when known.
157
+ * @returns Calldata with the suffix appended, or the input unchanged.
158
+ */
159
+ export declare function appendAttributionSuffix(data: string | undefined | null, chainId?: number): string | undefined | null;