@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,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isViemWalletClient = isViemWalletClient;
4
+ exports.viemToEthersSigner = viemToEthersSigner;
5
+ exports.normalizeSigner = normalizeSigner;
6
+ exports.wrapSignerWithAttribution = wrapSignerWithAttribution;
7
+ const ethers_1 = require("ethers");
8
+ const attribution_1 = require("../attribution");
9
+ /**
10
+ * Signer Compatibility Helpers
11
+ *
12
+ * Utilities for supporting both ethers and viem/wagmi signers.
13
+ * Provides conversion layer from viem WalletClient to ethers Signer.
14
+ */
15
+ /**
16
+ * Type guard to check if a signer is from viem/wagmi
17
+ * @param signer The signer to check
18
+ * @returns True if the signer is a viem WalletClient
19
+ */
20
+ function isViemWalletClient(signer) {
21
+ // Viem WalletClient has specific properties that ethers Signer doesn't
22
+ return !!(signer &&
23
+ typeof signer === 'object' &&
24
+ 'account' in signer &&
25
+ 'chain' in signer &&
26
+ 'transport' in signer &&
27
+ typeof signer.writeContract === 'function');
28
+ }
29
+ function toBigInt(value) {
30
+ return value == null ? undefined : BigInt(value);
31
+ }
32
+ function toViemTransaction(tx) {
33
+ return {
34
+ to: tx.to ?? undefined,
35
+ data: tx.data,
36
+ accessList: tx.accessList,
37
+ value: toBigInt(tx.value),
38
+ gas: toBigInt(tx.gas),
39
+ gasPrice: toBigInt(tx.gasPrice),
40
+ maxFeePerGas: toBigInt(tx.maxFeePerGas),
41
+ maxPriorityFeePerGas: toBigInt(tx.maxPriorityFeePerGas),
42
+ nonce: tx.nonce == null ? undefined : Number(tx.nonce),
43
+ };
44
+ }
45
+ /**
46
+ * Convert a viem WalletClient to an ethers-compatible Signer.
47
+ *
48
+ * The account and chain are answered from the client itself, and
49
+ * transactions, personal messages and EIP-712 typed data are signed through
50
+ * the client's own `sendTransaction` / `signMessage` / `signTypedData`, so a
51
+ * local account (for example an embedded wallet built with
52
+ * `createWalletClient({ account, transport: http() })`) signs locally and
53
+ * broadcasts the raw transaction. Every other request goes to the client's
54
+ * transport.
55
+ *
56
+ * @param walletClient - Viem WalletClient from wagmi or viem
57
+ * @returns Ethers Signer that can be used with the SDK
58
+ */
59
+ async function viemToEthersSigner(walletClient) {
60
+ if (!walletClient) {
61
+ throw new Error('WalletClient is required');
62
+ }
63
+ const { account, chain, transport } = walletClient;
64
+ if (!account) {
65
+ throw new Error('WalletClient must have an account');
66
+ }
67
+ const provider = new ethers_1.BrowserProvider({
68
+ request: async ({ method, params = [] }) => {
69
+ switch (method) {
70
+ case 'eth_accounts':
71
+ case 'eth_requestAccounts':
72
+ return [account.address];
73
+ case 'eth_chainId':
74
+ if (chain)
75
+ return (0, ethers_1.toQuantity)(chain.id);
76
+ break;
77
+ case 'eth_sendTransaction':
78
+ return walletClient.sendTransaction({
79
+ ...toViemTransaction(params[0]),
80
+ account,
81
+ chain,
82
+ });
83
+ case 'personal_sign':
84
+ return walletClient.signMessage({
85
+ account,
86
+ message: { raw: params[0] },
87
+ });
88
+ case 'eth_signTypedData_v4':
89
+ return walletClient.signTypedData({
90
+ account,
91
+ ...(typeof params[1] === 'string'
92
+ ? JSON.parse(params[1])
93
+ : params[1]),
94
+ });
95
+ }
96
+ return transport.request({ method, params });
97
+ },
98
+ }, chain?.id);
99
+ return provider.getSigner(account.address);
100
+ }
101
+ /**
102
+ * Type guard to check if a signer is from ethers
103
+ * @param signer The signer to check
104
+ * @returns True if the signer is an ethers Signer or Wallet
105
+ */
106
+ function isEthersSigner(signer) {
107
+ // Check for ethers Signer/Wallet properties
108
+ return (signer &&
109
+ typeof signer === 'object' &&
110
+ typeof signer.signMessage === 'function' &&
111
+ typeof signer.signTransaction === 'function' &&
112
+ (signer.provider !== undefined || signer._isSigner === true));
113
+ }
114
+ /**
115
+ * Normalize a signer to ensure it's ethers-compatible
116
+ * Accepts both ethers Signer and viem WalletClient
117
+ * @param signer Either an ethers Signer or viem WalletClient
118
+ * @returns Ethers-compatible Signer
119
+ */
120
+ async function normalizeSigner(signer) {
121
+ // If it's already an ethers signer, return as-is
122
+ if (isEthersSigner(signer)) {
123
+ return signer;
124
+ }
125
+ // If it's a viem wallet client, convert it
126
+ if (isViemWalletClient(signer)) {
127
+ return viemToEthersSigner(signer);
128
+ }
129
+ // If we can't determine the type, throw an error
130
+ throw new Error('Invalid signer type. Expected ethers Signer, ethers Wallet, or viem WalletClient');
131
+ }
132
+ /**
133
+ * Wrap an ethers signer so every transaction it sends carries the active
134
+ * ERC-8021 attribution suffix (Base Builder Codes).
135
+ *
136
+ * Every ethers write in the SDK funnels through the wrapped signer's
137
+ * `sendTransaction`, so this single wrap attributes all vault writes. The
138
+ * wrapper is a Proxy — the caller's signer object is never mutated, so a
139
+ * signer reused outside the SDK sends unattributed transactions. Attribution
140
+ * state is read at send time, not wrap time; when no attribution is
141
+ * configured (see `IUpshiftBase.attribution`) the wrapper is a pass-through.
142
+ *
143
+ * Plain value transfers (no calldata) are never attributed, and calldata
144
+ * already ending in the ERC-8021 marker is left untouched. When the
145
+ * configured `chains` list requires a chain check and the transaction does
146
+ * not carry a `chainId`, the signer's provider network is consulted (one
147
+ * cached RPC call); if that lookup fails the transaction is sent
148
+ * unattributed.
149
+ *
150
+ * @param signer Normalized ethers Signer or Wallet.
151
+ * @returns A proxied signer with an attribution-aware `sendTransaction`.
152
+ */
153
+ function wrapSignerWithAttribution(signer) {
154
+ return new Proxy(signer, {
155
+ get(target, prop) {
156
+ if (prop === 'sendTransaction') {
157
+ return async (tx) => {
158
+ if (!(0, attribution_1.isAttributionEnabled)() || typeof tx?.data !== 'string') {
159
+ return target.sendTransaction(tx);
160
+ }
161
+ let chainId = tx.chainId != null ? Number(tx.chainId) : undefined;
162
+ if (chainId === undefined && target.provider) {
163
+ try {
164
+ chainId = Number((await target.provider.getNetwork()).chainId);
165
+ }
166
+ catch {
167
+ // Unknown chain: fall through with chainId undefined. Under a
168
+ // `chains` restriction that means no suffix — attributing a
169
+ // chain we cannot identify risks breaking hardware-wallet
170
+ // clear-signing for a gain we cannot confirm.
171
+ }
172
+ }
173
+ const data = (0, attribution_1.appendAttributionSuffix)(tx.data, chainId);
174
+ return target.sendTransaction(data === tx.data ? tx : { ...tx, data });
175
+ };
176
+ }
177
+ // `this`-bind reads to the target, not the proxy — ethers classes use
178
+ // private fields, which throw when methods run with a Proxy receiver.
179
+ const value = Reflect.get(target, prop, target);
180
+ return typeof value === 'function' ? value.bind(target) : value;
181
+ },
182
+ });
183
+ }
184
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1,269 @@
1
+ import { type Signer, type Wallet } from 'ethers';
2
+ import type { IAddress, IContractRunner, IGetOriginInfoOptions, IOriginInfo, ISwapRouterDepositResult, ISwapRouterDepositResultOptions } from '../../types';
3
+ /**
4
+ * Resolve the `SwapRouter` address for a chain.
5
+ *
6
+ * @param chainId - EVM chain ID.
7
+ * @returns The router address, or `undefined` if no SwapRouter is deployed.
8
+ * @example
9
+ * ```ts
10
+ * const router = getSwapRouterAddress(1);
11
+ * // '0xC11c6d8fD8FfFB2045d57b149125C44414d8160B'
12
+ * ```
13
+ */
14
+ export declare function getSwapRouterAddress(chainId: number): IAddress | undefined;
15
+ /**
16
+ * Resolve the human-readable display name of the `SwapRouter` periphery
17
+ * contract for a chain.
18
+ *
19
+ * The contract exposes no name on-chain, so this reads the SDK-maintained
20
+ * {@link SWAP_ROUTER_NAMES} registry. Intended for UI surfaces that label the
21
+ * contract a swap-and-deposit routes through (e.g. a "Router" row in a
22
+ * transaction overview) — display metadata only, never routing logic.
23
+ *
24
+ * @param chainId - EVM chain ID.
25
+ * @returns The display name (e.g. `'Upshift Swap Router'`), or `undefined`
26
+ * when no SwapRouter is deployed on the chain — callers should omit the
27
+ * label rather than show an address.
28
+ * @example
29
+ * ```ts
30
+ * const name = getSwapRouterName(1);
31
+ * // 'Upshift Swap Router'
32
+ * ```
33
+ */
34
+ export declare function getSwapRouterName(chainId: number): string | undefined;
35
+ /**
36
+ * Whether a vault is eligible for the any-token `SwapRouter` deposit surface
37
+ * (swap tokens). Address comparison is case-insensitive.
38
+ *
39
+ * This gates the (flag-controlled) swap-router deposit UI and can fail-fast a
40
+ * {@link swapRouterDeposit} call. It does **not** affect {@link vaultDeposit},
41
+ * which never swaps (see `getDepositRoute` for when it uses the router).
42
+ *
43
+ * @param vaultAddress - Upshift vault address.
44
+ * @returns `true` when the vault is in {@link SWAP_ROUTER_ELIGIBLE_VAULTS}.
45
+ * @deprecated Superseded by {@link getSwapRouterEligibleVaults}, which resolves
46
+ * eligibility from the backend `swaps_enabled` flag instead of this static
47
+ * snapshot. Kept functional as
48
+ * the zero-RPC sync fallback (seed data, fail-fast checks); migrate UI gates
49
+ * to the async resolver.
50
+ */
51
+ export declare function isSwapRouterEligible(vaultAddress: IAddress): boolean;
52
+ /**
53
+ * @deprecated Renamed to {@link isSwapRouterEligible} (itself now superseded by
54
+ * {@link getSwapRouterEligibleVaults}, the `swaps_enabled` resolver). The
55
+ * meaning also changed: it no longer implies `vaultDeposit` routes the vault
56
+ * through the SwapRouter (that behavior was removed) — it only reports
57
+ * swap-router *eligibility* for the opt-in deposit surface. Kept as an alias
58
+ * for one release; migrate to the async resolver.
59
+ */
60
+ export declare const vaultUsesSwapRouter: typeof isSwapRouterEligible;
61
+ /**
62
+ * Normalize an optional origin code to the value to send on-chain.
63
+ *
64
+ * Returns the caller-supplied code when present (an explicit all-zero
65
+ * sentinel opts one call out), otherwise the SDK instance's
66
+ * `attribution.originCode` when `chainId` is in
67
+ * {@link ORIGIN_ATTRIBUTION_CHAINS} (Ethereum mainnet only), otherwise the
68
+ * default (all-zero) sentinel from {@link ORIGIN_CODES}. Validates that any
69
+ * supplied code is exactly 32 bytes (66 chars including the `0x` prefix);
70
+ * the on-chain SwapRouter reverts with `InvalidOrigin` otherwise, but
71
+ * surfacing the failure here as a typed SDK error gives partners a
72
+ * grepable Sentry event instead of a generic `execution reverted`.
73
+ *
74
+ * @param provided - Optional caller-supplied origin code.
75
+ * @param chainId - Chain the deposit is sent on. The instance code is never
76
+ * returned without it, or on a chain outside
77
+ * {@link ORIGIN_ATTRIBUTION_CHAINS}.
78
+ * @returns The 32-byte origin code to pass to the router.
79
+ * @throws {@link UpshiftValidationError} when `provided` is not a 32-byte hex string.
80
+ */
81
+ export declare function resolveOriginCode(provided?: `0x${string}`, chainId?: number): `0x${string}`;
82
+ /**
83
+ * Resolves the real, post-execution outcome of a SwapRouter deposit from its
84
+ * mined transaction receipt. The SwapRouter contract itself emits no
85
+ * deposit/amount-out event — only the vault does, via its own `Deposit` event
86
+ * — so this decodes that log directly rather than trusting the pre-trade quote
87
+ * a UI shows before the user submits (the true post-swap amount depends on
88
+ * execution-time price and can differ from that estimate).
89
+ *
90
+ * Works for both vault generations without the caller resolving the version
91
+ * first: evm-1 (ERC-4626-style `Deposit(sender, owner, assets, shares)`) and
92
+ * evm-2 (`Deposit(assetIn, amountIn, shares, senderAddr, receiverAddr)`) have
93
+ * different event signatures (different topic0), so both are registered and
94
+ * whichever matches the vault's actual log is decoded.
95
+ *
96
+ * @param signer - ethers `Signer` or `Wallet` connected to a provider (used
97
+ * read-only here — no transaction is sent).
98
+ * @param options - {@link ISwapRouterDepositResultOptions}.
99
+ * @returns The decoded {@link ISwapRouterDepositResult}, or `null` if the
100
+ * receipt isn't found yet or carries no `Deposit` log from `vault` (e.g. the
101
+ * hash is wrong, or the tx hasn't mined).
102
+ * @throws {@link UpshiftValidationError} if `signer` has no connected provider.
103
+ * @worstCaseRpcCalls 1 — a single `getTransactionReceipt` call; decoding is
104
+ * local.
105
+ * @example
106
+ * ```ts
107
+ * const hash = await upshiftSdk.evm.swapRouterDeposit({ ... });
108
+ * const result = await upshiftSdk.evm.getSwapRouterDepositResult({
109
+ * txHash: hash,
110
+ * vault: '0x74ad2f789ed583dbd141bbdafc673fe1f033718b',
111
+ * });
112
+ * // result?.amountOut — actual reference-asset amount received after the swap
113
+ * ```
114
+ */
115
+ export declare function getSwapRouterDepositResult(signer: Signer | Wallet, { txHash, vault }: ISwapRouterDepositResultOptions): Promise<ISwapRouterDepositResult | null>;
116
+ /**
117
+ * Read how an origin code is registered on a chain's `SwapRouter`: whether it
118
+ * exists, its origin fee, and its fee collector.
119
+ *
120
+ * Check a partner code with this before configuring it as
121
+ * `attribution.originCode` — the router reverts every deposit carrying an
122
+ * unregistered code with `InvalidOrigin`. A code is registered when its
123
+ * collector is non-zero (`addOrigin` always sets one); a zero-fee code is
124
+ * still registered but never emits `OriginFeeApplied`. Cached per (chain,
125
+ * router, code) for 5 minutes.
126
+ *
127
+ * @param options - {@link IGetOriginInfoOptions}.
128
+ * @returns {@link IOriginInfo}; `registered: false` with a zero fee and
129
+ * collector, and no RPC, on a chain with no SwapRouter deployment.
130
+ * @throws {@link UpshiftValidationError} when `originCode` is not a 32-byte hex
131
+ * string.
132
+ * @throws {@link UpshiftSDKError} when the `origins(bytes32)` read fails.
133
+ * @worstCaseRpcCalls 1 — one `origins(bytes32)` call; none on a cache hit.
134
+ * @example
135
+ * ```ts
136
+ * const info = await getOriginInfo({ chainId: 1, originCode, rpcUrl });
137
+ * if (!info.registered) throw new Error('origin code is not registered');
138
+ * ```
139
+ */
140
+ export declare function getOriginInfo({ chainId, originCode, rpcUrl, }: IGetOriginInfoOptions): Promise<IOriginInfo>;
141
+ /**
142
+ * {@link getOriginInfo} without input validation, reading through a caller
143
+ * runner (created lazily, only on a cache miss). Shared with the deposit-route
144
+ * resolver so both hit the same cache entry.
145
+ * @internal
146
+ */
147
+ export declare function readOriginInfo(chainId: number, originCode: `0x${string}`, runner: () => IContractRunner): Promise<IOriginInfo>;
148
+ /**
149
+ * Read whether a Tokenized Vault V2 restricts depositors with a senders
150
+ * whitelist (KYC), cached for 5 minutes like the router reads.
151
+ *
152
+ * The v2 SwapRouter accepts any vault, so this is the check that keeps KYC
153
+ * vaults off the router: such a vault only accepts deposits from whitelisted
154
+ * senders, so a router deposit either reverts `SenderNotWhitelisted` or, on an
155
+ * implementation that checks only `msg.sender`, would let any wallet deposit
156
+ * through a whitelisted router.
157
+ *
158
+ * @param runner - Provider or signer used for the read.
159
+ * @param chainId - Chain the vault is on (part of the cache key).
160
+ * @param vault - Tokenized Vault V2 address.
161
+ * @returns `true` when `sendersWhitelistAddress()` is non-zero.
162
+ * @throws When the `sendersWhitelistAddress()` read fails. Callers wrap it in
163
+ * their own error handling.
164
+ * @worstCaseRpcCalls 1 — one `sendersWhitelistAddress()` call; none on a cache hit.
165
+ * @internal
166
+ */
167
+ export declare function readVaultHasSendersWhitelist(runner: IContractRunner, chainId: number, vault: IAddress): Promise<boolean>;
168
+ /**
169
+ * Read whether a chain's `SwapRouter` is paused (`isPaused()`), cached for 15
170
+ * seconds. Every router entry point (`deposit`, `swapAndDeposit`,
171
+ * `depositNativeToken`) reverts with `ContractIsPaused` while the router is
172
+ * paused, so callers check this before routing a deposit or sending an
173
+ * approval to the router.
174
+ *
175
+ * @param runner - Contract runner (provider or signer) used for the read.
176
+ * @param chainId - EVM chain ID.
177
+ * @returns `true` while the router is paused; `false` when it is not, or on a
178
+ * chain with no SwapRouter (no RPC).
179
+ * @throws When the `isPaused()` read fails. Callers wrap it in
180
+ * {@link UpshiftSDKError}.
181
+ * @worstCaseRpcCalls 1 — one `isPaused()` call; none on a cache hit.
182
+ * @internal
183
+ */
184
+ export declare function readSwapRouterPaused(runner: IContractRunner, chainId: number): Promise<boolean>;
185
+ /**
186
+ * Resolve the ERC-20 tokens currently whitelisted for the `SwapRouter` on a
187
+ * chain — the any-token set a UI can offer as swap-and-deposit inputs.
188
+ *
189
+ * The router exposes its allowlist only as `mapping(address => bool)
190
+ * whitelistedTokens` with **no on-chain enumeration**, so this cannot be a
191
+ * single view call. It runs in two stages:
192
+ * 1. Scan the router's `TokenEnabled(address)` event history (from the chain's
193
+ * {@link SWAP_ROUTER_DEPLOY_BLOCKS} floor, in `eth_getLogs` chunks sized by
194
+ * {@link determineBlockSkipInternal}) to reconstruct the candidate set of
195
+ * every token ever enabled.
196
+ * 2. Re-read `whitelistedTokens(token)` for each candidate — batched via
197
+ * Multicall3 where verified, else per-call — and keep only those the
198
+ * mapping currently returns `true` for. This step makes later disables (and
199
+ * disable-then-re-enable) correct without replaying `TokenDisabled`, and is
200
+ * the fail-closed source of truth: a token surfaces only on a definite
201
+ * on-chain `true`.
202
+ *
203
+ * The resolved list is cached per chain for 5 minutes — the allowlist changes
204
+ * only via an admin `enableToken`/`disableToken` transaction, so a short TTL
205
+ * keeps the (multi-RPC) scan off the hot path without going stale for long.
206
+ *
207
+ * @param chainId - EVM chain ID. Chains without a {@link SWAP_ROUTER_ADDRESSES}
208
+ * entry resolve to `[]` with no RPC.
209
+ * @param options - `rpcUrl` (required) must point at `chainId`'s network;
210
+ * `fromBlock` overrides the default deploy-block scan floor (e.g. to widen a
211
+ * scan on a chain missing from {@link SWAP_ROUTER_DEPLOY_BLOCKS}).
212
+ * @returns Checksummed addresses of the currently-whitelisted tokens, deduped.
213
+ * Empty when no router is deployed or none are enabled. Callers still filter
214
+ * out a given vault's natively-accepted assets (those deposit without a swap).
215
+ * @throws UpshiftValidationError when `rpcUrl` is missing/empty.
216
+ * @throws UpshiftSDKError when an `eth_getLogs` chunk fails — surfaced (not
217
+ * swallowed) so a partial scan never masquerades as a complete allowlist.
218
+ * @worstCaseRpcCalls 1 `eth_blockNumber` + ⌈(head − deploy block) ÷ window⌉
219
+ * `eth_getLogs` chunks + 1 Multicall3 `eth_call`, where `window` is
220
+ * {@link determineBlockSkipInternal} (10k blocks on mainnet, 1k on
221
+ * HyperEVM). The chunk count grows with the router's on-chain age (on
222
+ * mainnet roughly one more chunk every ~1.4 days since the deploy block,
223
+ * already in the tens), not with candidate count. Chunks run at most 8 at a
224
+ * time, so a cold scan never opens more than 8 concurrent requests.
225
+ * @example
226
+ * ```ts
227
+ * const tokens = await getSwapRouterWhitelistedTokens(1, {
228
+ * rpcUrl: 'https://eth-mainnet.example/v2/KEY',
229
+ * });
230
+ * // ['0xA0b8…', '0xdAC1…', '0xC02a…', '0x2260…'] (USDC, USDT, WETH, WBTC)
231
+ * ```
232
+ */
233
+ export declare function getSwapRouterWhitelistedTokens(chainId: number, options: {
234
+ rpcUrl: string;
235
+ fromBlock?: number;
236
+ }): Promise<IAddress[]>;
237
+ /**
238
+ * Resolve the vaults that offer the any-token `SwapRouter` deposit surface
239
+ * (swap tokens) on a chain: every vault the Upshift API marks `swaps_enabled`,
240
+ * on a chain with a SwapRouter.
241
+ *
242
+ * SwapRouter v2 has no on-chain vault registry, so the backend `swaps_enabled`
243
+ * flag is the source of truth. It fails closed: a vault without the flag, or
244
+ * with it `false`, is excluded. It only gates swap tokens — a normal deposit
245
+ * of an asset the vault accepts routes through the router whatever the flag
246
+ * (see {@link getDepositRoute}).
247
+ *
248
+ * App-level policy (e.g. excluding vaults with their own OVault deposit flow)
249
+ * remains the caller's responsibility.
250
+ *
251
+ * @param chainId - EVM chain ID. Chains without a {@link SWAP_ROUTER_ADDRESSES}
252
+ * entry resolve to `[]` with no request.
253
+ * @param _options - Kept for compatibility; `rpcUrl` and `fromBlock` are no
254
+ * longer read.
255
+ * @returns Checksummed addresses of the chain's `swaps_enabled` vaults. Empty
256
+ * when no router is deployed or no vault has the flag.
257
+ * @throws When the Upshift API vault-list request fails.
258
+ * @worstCaseRpcCalls 0 — one Upshift API request (the vault list, cached for
259
+ * 15 minutes), no RPC.
260
+ * @example
261
+ * ```ts
262
+ * const vaults = await getSwapRouterEligibleVaults(1);
263
+ * // ['0x74aD…718b', '0xE9B7…9D32']
264
+ * ```
265
+ */
266
+ export declare function getSwapRouterEligibleVaults(chainId: number, _options?: {
267
+ rpcUrl?: string;
268
+ fromBlock?: number;
269
+ }): Promise<IAddress[]>;