@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,891 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchInstantRedemptionFee = fetchInstantRedemptionFee;
4
+ exports.vaultAllowance = vaultAllowance;
5
+ exports.sendersWhitelistAddress = sendersWhitelistAddress;
6
+ exports.isWhitelisted = isWhitelisted;
7
+ exports.getDeposited = getDeposited;
8
+ exports.getRemainingAllocations = getRemainingAllocations;
9
+ exports.previewRwaRedemption = previewRwaRedemption;
10
+ exports.previewDeposit = previewDeposit;
11
+ exports.previewRedeem = previewRedeem;
12
+ exports.allowance = allowance;
13
+ exports.balanceOf = balanceOf;
14
+ exports.maxDeposit = maxDeposit;
15
+ exports.getIdleLiquidity = getIdleLiquidity;
16
+ exports.lagDuration = lagDuration;
17
+ exports.getWithdrawalEpoch = getWithdrawalEpoch;
18
+ exports.getBurnableAmountByReceiver = getBurnableAmountByReceiver;
19
+ exports.getRequirementByDate = getRequirementByDate;
20
+ exports.getScheduledTransactionsByDate = getScheduledTransactionsByDate;
21
+ const abis_1 = require("../../abis");
22
+ const core_1 = require("../../core");
23
+ /**
24
+ * Function to fetch instant redemption fee
25
+ * @param signer - signer / provider object
26
+ * @param options - object including pool contract address, user wallet address
27
+ * @returns normalized number object of the instant redemption fee
28
+ */
29
+ async function fetchInstantRedemptionFee(signer, options) {
30
+ const { wallet, target } = options;
31
+ const [goodWallet, goodPool] = [
32
+ (0, core_1.checkAddress)(wallet, console, 'wallet'),
33
+ (0, core_1.checkAddress)(target, console),
34
+ ];
35
+ if (!goodWallet || !goodPool)
36
+ return;
37
+ try {
38
+ if (signer && target) {
39
+ const poolContract = (0, core_1.createContract)({
40
+ address: target,
41
+ abi: abis_1.ABI_LENDING_POOL_V3,
42
+ provider: signer,
43
+ });
44
+ const instantRedemptionResult = await poolContract.instantRedemptionFee();
45
+ return (0, core_1.toNormalizedBn)(instantRedemptionResult);
46
+ }
47
+ }
48
+ catch (e) {
49
+ (0, core_1.logChainError)('failed to fetch instant redeem fee', e, (0, core_1.isExpectedRevertError)(e));
50
+ throw new Error(`Failed to fetch instant redeem fee for ${target}: ${e instanceof Error ? e.message : 'Unknown error'}`);
51
+ }
52
+ }
53
+ /**
54
+ * allowance checks user's current allowance per pool
55
+ * @param signer - signer / provider object
56
+ * @param options - object including pool contract address, user wallet address
57
+ * @returns normalized number object of the user's current allowance
58
+ */
59
+ async function vaultAllowance(signer, options) {
60
+ const { wallet, target } = options;
61
+ const [goodWallet, goodPool] = [
62
+ (0, core_1.checkAddress)(wallet, console, 'wallet'),
63
+ (0, core_1.checkAddress)(target, console),
64
+ ];
65
+ if (!goodWallet || !goodPool)
66
+ return;
67
+ try {
68
+ // ERC4626 vault
69
+ const poolContract = (0, core_1.createContract)({
70
+ address: target,
71
+ abi: abis_1.ABI_LENDING_POOLS,
72
+ provider: signer,
73
+ });
74
+ // get vault asset address and decimals
75
+ const [asset, rawDecimals] = await Promise.all([
76
+ poolContract.asset(),
77
+ poolContract.decimals(),
78
+ ]);
79
+ const decimals = Number(rawDecimals);
80
+ // check amount vault approves user for
81
+ const depositTokenContract = (0, core_1.createContract)({
82
+ address: asset,
83
+ abi: abis_1.ABI_ERC20,
84
+ provider: signer,
85
+ });
86
+ const _allowance = (await depositTokenContract.allowance(wallet, target));
87
+ const normalized = (0, core_1.toNormalizedBn)(_allowance, decimals);
88
+ core_1.Logger.log.info('allowance', normalized);
89
+ return normalized;
90
+ }
91
+ catch (e) {
92
+ (0, core_1.logChainError)('allowance', e, (0, core_1.isExpectedRevertError)(e));
93
+ throw new Error(`Failed to fetch allowance: ${e instanceof Error ? e.message : 'Unknown error'}`);
94
+ }
95
+ }
96
+ /**
97
+ * Fetches the senders whitelist contract address from a whitelisted allocation vault
98
+ * @param signer - signer / provider object
99
+ * @param options - object including vault contract address
100
+ * @returns the senders whitelist contract address
101
+ */
102
+ async function sendersWhitelistAddress(signer, options) {
103
+ const { vault } = options;
104
+ const goodTarget = (0, core_1.checkAddress)(vault, console);
105
+ if (!goodTarget)
106
+ return;
107
+ try {
108
+ const vaultContract = (0, core_1.createContract)({
109
+ address: vault,
110
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
111
+ provider: signer,
112
+ });
113
+ const whitelistAddress = await vaultContract.sendersWhitelistAddress();
114
+ core_1.Logger.log.info('sendersWhitelistAddress', whitelistAddress);
115
+ return whitelistAddress;
116
+ }
117
+ catch (e) {
118
+ (0, core_1.logChainError)('sendersWhitelistAddress', e, (0, core_1.isExpectedRevertError)(e));
119
+ throw new Error(`Failed to fetch senders whitelist address: ${e instanceof Error ? e.message : 'Unknown error'}`);
120
+ }
121
+ }
122
+ /**
123
+ * Checks if an address is whitelisted on a whitelist contract
124
+ * @param signer - signer / provider object
125
+ * @param options - object including whitelist contract address and wallet address to check
126
+ * @returns boolean indicating if the address is whitelisted
127
+ */
128
+ async function isWhitelisted(signer, options) {
129
+ const { whitelist, wallet } = options;
130
+ const [goodWhitelist, goodWallet] = [
131
+ (0, core_1.checkAddress)(whitelist, console, 'contract'),
132
+ (0, core_1.checkAddress)(wallet, console, 'wallet'),
133
+ ];
134
+ if (!goodWhitelist || !goodWallet)
135
+ return;
136
+ try {
137
+ const whitelistContract = (0, core_1.createContract)({
138
+ address: whitelist,
139
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
140
+ provider: signer,
141
+ });
142
+ const result = await whitelistContract.isWhitelisted(wallet);
143
+ core_1.Logger.log.info('isWhitelisted', result);
144
+ return result;
145
+ }
146
+ catch (e) {
147
+ (0, core_1.logChainError)('isWhitelisted', e, (0, core_1.isExpectedRevertError)(e));
148
+ throw new Error(`Failed to check whitelist status: ${e instanceof Error ? e.message : 'Unknown error'}`);
149
+ }
150
+ }
151
+ /**
152
+ * Fetches the total amount deposited by an address on a whitelist contract
153
+ * @param signer - signer / provider object
154
+ * @param options - object including whitelist contract address, wallet address, and vault address
155
+ * @returns normalized number of the deposited amount
156
+ */
157
+ async function getDeposited(signer, options) {
158
+ const { whitelist, wallet, vault } = options;
159
+ const [goodWhitelist, goodWallet, goodVault] = [
160
+ (0, core_1.checkAddress)(whitelist, console, 'contract'),
161
+ (0, core_1.checkAddress)(wallet, console, 'wallet'),
162
+ (0, core_1.checkAddress)(vault, console, 'contract'),
163
+ ];
164
+ if (!goodWhitelist || !goodWallet || !goodVault)
165
+ return;
166
+ try {
167
+ const vaultContract = (0, core_1.createContract)({
168
+ address: vault,
169
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
170
+ provider: signer,
171
+ });
172
+ const whitelistContract = (0, core_1.createContract)({
173
+ address: whitelist,
174
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
175
+ provider: signer,
176
+ });
177
+ const [deposited, asset] = await Promise.all([
178
+ whitelistContract.getDeposited(wallet),
179
+ vaultContract.asset(),
180
+ ]);
181
+ const assetContract = (0, core_1.createContract)({
182
+ address: asset,
183
+ abi: abis_1.ABI_ERC20,
184
+ provider: signer,
185
+ });
186
+ const decimals = Number(await assetContract.decimals());
187
+ const normalized = (0, core_1.toNormalizedBn)(deposited, decimals);
188
+ core_1.Logger.log.info('getDeposited', normalized);
189
+ return normalized;
190
+ }
191
+ catch (e) {
192
+ (0, core_1.logChainError)('getDeposited', e, (0, core_1.isExpectedRevertError)(e));
193
+ throw new Error(`Failed to fetch deposited amount: ${e instanceof Error ? e.message : 'Unknown error'}`);
194
+ }
195
+ }
196
+ /**
197
+ * Fetches the remaining allocation for an address on a whitelist contract
198
+ * @param signer - signer / provider object
199
+ * @param options - object including whitelist contract address, wallet address, vault address, and optional deposit cap amount
200
+ * @returns the remaining allocation as normalized number
201
+ */
202
+ async function getRemainingAllocations(signer, options) {
203
+ const { whitelist, wallet, vault, depositCapAmount } = options;
204
+ const [goodWhitelist, goodWallet, goodVault] = [
205
+ (0, core_1.checkAddress)(whitelist, console, 'contract'),
206
+ (0, core_1.checkAddress)(wallet, console, 'wallet'),
207
+ (0, core_1.checkAddress)(vault, console, 'contract'),
208
+ ];
209
+ if (!goodWhitelist || !goodWallet || !goodVault)
210
+ return;
211
+ try {
212
+ const vaultContract = (0, core_1.createContract)({
213
+ address: vault,
214
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ALLOCATION,
215
+ provider: signer,
216
+ });
217
+ const whitelistContract = (0, core_1.createContract)({
218
+ address: whitelist,
219
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2_SENDER_ALLOCATION_WHITELIST,
220
+ provider: signer,
221
+ });
222
+ // Fetch depositCap if not provided, along with asset address
223
+ const [capAmount, asset] = await Promise.all([
224
+ depositCapAmount !== undefined
225
+ ? Promise.resolve(depositCapAmount)
226
+ : vaultContract.depositCap(),
227
+ vaultContract.asset(),
228
+ ]);
229
+ const assetContract = (0, core_1.createContract)({
230
+ address: asset,
231
+ abi: abis_1.ABI_ERC20,
232
+ provider: signer,
233
+ });
234
+ const decimals = Number(await assetContract.decimals());
235
+ const remaining = await whitelistContract.getRemainingAllocation(wallet, capAmount);
236
+ const normalized = (0, core_1.toNormalizedBn)(remaining, decimals);
237
+ core_1.Logger.log.info('getRemainingAllocations', normalized);
238
+ return normalized;
239
+ }
240
+ catch (e) {
241
+ (0, core_1.logChainError)('getRemainingAllocations', e, (0, core_1.isExpectedRevertError)(e));
242
+ throw new Error(`Failed to fetch remaining allocations: ${e instanceof Error ? e.message : 'Unknown error'}`);
243
+ }
244
+ }
245
+ /**
246
+ * Preview the output amount for an RWA instant redemption via the RwaRedeemSubaccount contract.
247
+ * @param signer - signer / provider object
248
+ * @param options - object including subaccount address, asset, amount, decimals, and outputDecimals
249
+ * @returns normalized number of the expected output amount (in output asset decimals)
250
+ */
251
+ async function previewRwaRedemption(signer, options) {
252
+ const { target, asset, amount, decimals, outputDecimals } = options;
253
+ const goodTarget = (0, core_1.checkAddress)(target, console, 'contract');
254
+ const goodAsset = (0, core_1.checkAddress)(asset, console, 'contract');
255
+ if (!goodTarget || !goodAsset)
256
+ return;
257
+ try {
258
+ const subaccountContract = (0, core_1.createContract)({
259
+ address: target,
260
+ provider: signer,
261
+ abi: abis_1.RWA_REDEEM_SUBACCOUNT,
262
+ });
263
+ if (!subaccountContract)
264
+ return;
265
+ const normalizedAmt = (0, core_1.toNormalizedBn)(amount, decimals);
266
+ const result = await subaccountContract.previewRedemption(asset, BigInt(normalizedAmt.raw));
267
+ const normalized = (0, core_1.toNormalizedBn)(result, outputDecimals);
268
+ core_1.Logger.log.info('previewRwaRedemption', normalized);
269
+ return normalized;
270
+ }
271
+ catch (e) {
272
+ (0, core_1.logChainError)('previewRwaRedemption', e, (0, core_1.isExpectedRevertError)(e), {
273
+ target,
274
+ asset,
275
+ amount,
276
+ });
277
+ throw new Error(`Preview RWA redemption failed: ${e instanceof Error ? e.message : 'Unknown error'}`);
278
+ }
279
+ }
280
+ /**
281
+ * Preview the number of shares that would be minted for a deposit, without
282
+ * touching on-chain state. Routes between single-asset ERC-4626 and EVM-2
283
+ * multi-asset vaults using the vault version detected from backend metadata.
284
+ *
285
+ * @returns The number of shares (raw on-chain units, share-token decimals).
286
+ * @throws UpshiftValidationError on invalid vault address or amount.
287
+ * @throws UpshiftSDKError when the underlying contract call fails.
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * const shares = await upshiftSdk.evm.previewDeposit({
292
+ * vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
293
+ * amount: 1_000_000n, // 1 USDC (6 decimals)
294
+ * });
295
+ * ```
296
+ */
297
+ async function previewDeposit(signer, options) {
298
+ const { vault, amount, asset } = options;
299
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
300
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `previewDeposit: invalid vault address ${vault}`);
301
+ }
302
+ const amountRaw = (0, core_1.toRawBigInt)(amount, 'previewDeposit');
303
+ try {
304
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
305
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
306
+ const isMultiAsset = vaultVersion === 'evm-2';
307
+ if (isMultiAsset) {
308
+ if (!asset || !(0, core_1.checkAddress)(asset, console, 'contract')) {
309
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'previewDeposit: multi-asset vaults require an explicit `asset` parameter');
310
+ }
311
+ const contract = (0, core_1.createContract)({
312
+ address: vault,
313
+ provider: signer,
314
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
315
+ });
316
+ const result = await contract.previewDeposit(asset, amountRaw);
317
+ // TokenizedVaultV2 previewDeposit returns (shares, _); take shares.
318
+ const shares = Array.isArray(result) ? result[0] : result;
319
+ return BigInt(shares);
320
+ }
321
+ const contract = (0, core_1.createContract)({
322
+ address: vault,
323
+ provider: signer,
324
+ abi: abis_1.ABI_LENDING_POOLS,
325
+ });
326
+ const result = await contract.previewDeposit(amountRaw);
327
+ return BigInt(result);
328
+ }
329
+ catch (e) {
330
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
331
+ throw e;
332
+ }
333
+ (0, core_1.logChainError)('previewDeposit', e, (0, core_1.isExpectedRevertError)(e), {
334
+ vault,
335
+ amount: amount.toString(),
336
+ });
337
+ throw new core_1.UpshiftSDKError('UNKNOWN', `previewDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, amount: amount.toString() } });
338
+ }
339
+ }
340
+ /**
341
+ * Preview the number of underlying assets returned by redeeming a given
342
+ * number of shares, without touching on-chain state. Routes between single-
343
+ * asset ERC-4626 (`previewRedeem`) and EVM-2 multi-asset
344
+ * (`previewRedemption(shares, isInstant=false)`) using the vault version.
345
+ *
346
+ * @returns The assets that would be redeemed (raw on-chain units, asset
347
+ * decimals).
348
+ * @throws UpshiftValidationError on invalid vault or share input.
349
+ * @throws UpshiftSDKError when the underlying contract call fails.
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * const assets = await upshiftSdk.evm.previewRedeem({
354
+ * vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
355
+ * shares: 1_000_000_000_000_000_000n, // 1 share (18 decimals)
356
+ * });
357
+ * ```
358
+ */
359
+ async function previewRedeem(signer, options) {
360
+ const { vault, shares } = options;
361
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
362
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `previewRedeem: invalid vault address ${vault}`);
363
+ }
364
+ const sharesRaw = (0, core_1.toRawBigInt)(shares, 'previewRedeem');
365
+ try {
366
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
367
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
368
+ const isMultiAsset = vaultVersion === 'evm-2';
369
+ if (isMultiAsset) {
370
+ const contract = (0, core_1.createContract)({
371
+ address: vault,
372
+ provider: signer,
373
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
374
+ });
375
+ const result = await contract.previewRedemption(sharesRaw, false);
376
+ // EVM-2 previewRedemption returns (assetsAmount, assetsAfterFee); take gross.
377
+ const assets = Array.isArray(result) ? result[0] : result;
378
+ return BigInt(assets);
379
+ }
380
+ const contract = (0, core_1.createContract)({
381
+ address: vault,
382
+ provider: signer,
383
+ abi: abis_1.ABI_LENDING_POOLS,
384
+ });
385
+ const result = await contract.previewRedeem(sharesRaw);
386
+ return BigInt(result);
387
+ }
388
+ catch (e) {
389
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
390
+ throw e;
391
+ }
392
+ (0, core_1.logChainError)('previewRedeem', e, (0, core_1.isExpectedRevertError)(e), {
393
+ vault,
394
+ shares: shares.toString(),
395
+ });
396
+ throw new core_1.UpshiftSDKError('UNKNOWN', `previewRedeem failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, shares: shares.toString() } });
397
+ }
398
+ }
399
+ /**
400
+ * Read the ERC-20 allowance an `owner` has granted to a vault (the spender).
401
+ * If `asset` is omitted, the vault's underlying asset is resolved via
402
+ * `IERC4626.asset()` and used as the token.
403
+ *
404
+ * Returns a raw `bigint` to keep BigInt math precise — call
405
+ * {@link toNormalizedBn} if you need a UI-shaped {@link INormalizedNumber}.
406
+ *
407
+ * @returns Allowance in raw on-chain units of `asset`.
408
+ * @throws UpshiftValidationError on invalid addresses.
409
+ * @throws UpshiftSDKError when the underlying contract call fails.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * const raw = await upshiftSdk.evm.allowance({
414
+ * vault: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
415
+ * owner: walletAddress,
416
+ * });
417
+ * if (raw < requiredAmount) {
418
+ * await upshiftSdk.evm.vaultApprove({
419
+ * target: vault,
420
+ * wallet: walletAddress,
421
+ * amount: requiredAmount.toString(),
422
+ * });
423
+ * }
424
+ * ```
425
+ */
426
+ async function allowance(signer, options) {
427
+ const { vault, owner, asset } = options;
428
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
429
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `allowance: invalid vault address ${vault}`);
430
+ }
431
+ if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
432
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `allowance: invalid owner address ${owner}`);
433
+ }
434
+ if (asset && !(0, core_1.checkAddress)(asset, console, 'contract')) {
435
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `allowance: invalid asset address ${asset}`);
436
+ }
437
+ try {
438
+ let tokenAddress;
439
+ if (asset) {
440
+ tokenAddress = asset;
441
+ }
442
+ else {
443
+ const vaultContract = (0, core_1.createContract)({
444
+ address: vault,
445
+ provider: signer,
446
+ abi: abis_1.ABI_LENDING_POOLS,
447
+ });
448
+ tokenAddress = (await vaultContract.asset());
449
+ }
450
+ const tokenContract = (0, core_1.createContract)({
451
+ address: tokenAddress,
452
+ provider: signer,
453
+ abi: abis_1.ABI_ERC20,
454
+ });
455
+ const raw = (await tokenContract.allowance(owner, vault));
456
+ return BigInt(raw);
457
+ }
458
+ catch (e) {
459
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
460
+ throw e;
461
+ }
462
+ (0, core_1.logChainError)('allowance', e, (0, core_1.isExpectedRevertError)(e), {
463
+ vault,
464
+ owner,
465
+ asset,
466
+ });
467
+ throw new core_1.UpshiftSDKError('UNKNOWN', `allowance failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, owner, asset } });
468
+ }
469
+ }
470
+ /**
471
+ * Read an ERC-20 balance directly. Returns the raw on-chain value as
472
+ * `bigint`; call {@link toNormalizedBn} if you need a {@link INormalizedNumber}.
473
+ *
474
+ * @returns Balance in raw on-chain units of `asset`.
475
+ * @throws UpshiftValidationError on invalid asset / owner addresses.
476
+ * @throws UpshiftSDKError when the underlying contract call fails.
477
+ *
478
+ * @example
479
+ * ```ts
480
+ * const raw = await upshiftSdk.evm.balanceOf({
481
+ * asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
482
+ * owner: walletAddress,
483
+ * });
484
+ * ```
485
+ */
486
+ async function balanceOf(signer, options) {
487
+ const { asset, owner } = options;
488
+ if (!(0, core_1.checkAddress)(asset, console, 'contract')) {
489
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `balanceOf: invalid asset address ${asset}`);
490
+ }
491
+ if (!(0, core_1.checkAddress)(owner, console, 'wallet')) {
492
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `balanceOf: invalid owner address ${owner}`);
493
+ }
494
+ try {
495
+ const tokenContract = (0, core_1.createContract)({
496
+ address: asset,
497
+ provider: signer,
498
+ abi: abis_1.ABI_ERC20,
499
+ });
500
+ const raw = (await tokenContract.balanceOf(owner));
501
+ return BigInt(raw);
502
+ }
503
+ catch (e) {
504
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
505
+ throw e;
506
+ }
507
+ (0, core_1.logChainError)('balanceOf', e, (0, core_1.isExpectedRevertError)(e), { asset, owner });
508
+ throw new core_1.UpshiftSDKError('UNKNOWN', `balanceOf failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { asset, owner } });
509
+ }
510
+ }
511
+ /**
512
+ * Read the maximum deposit currently accepted by a vault. Routes between
513
+ * single-asset ERC-4626 (`maxDeposit(receiver)`) and EVM-2 multi-asset
514
+ * (`maxDepositAmount()`, vault-level cap, no receiver dependence).
515
+ *
516
+ * @returns Max deposit in raw on-chain units of the deposit asset.
517
+ * @throws UpshiftValidationError on invalid vault address.
518
+ * @throws UpshiftSDKError when the underlying contract call fails.
519
+ *
520
+ * @example
521
+ * ```ts
522
+ * const cap = await upshiftSdk.evm.maxDeposit({ vault });
523
+ * if (cap === 0n) showVaultIsFullToast();
524
+ * ```
525
+ */
526
+ async function maxDeposit(signer, options) {
527
+ const { vault, receiver } = options;
528
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
529
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `maxDeposit: invalid vault address ${vault}`);
530
+ }
531
+ if (receiver && !(0, core_1.checkAddress)(receiver, console, 'wallet')) {
532
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `maxDeposit: invalid receiver address ${receiver}`);
533
+ }
534
+ try {
535
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
536
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
537
+ const isMultiAsset = vaultVersion === 'evm-2';
538
+ if (isMultiAsset) {
539
+ const contract = (0, core_1.createContract)({
540
+ address: vault,
541
+ provider: signer,
542
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
543
+ });
544
+ const raw = (await contract.maxDepositAmount());
545
+ return BigInt(raw);
546
+ }
547
+ const contract = (0, core_1.createContract)({
548
+ address: vault,
549
+ provider: signer,
550
+ abi: abis_1.ABI_LENDING_POOLS,
551
+ });
552
+ // Zero-address default: vaults that require a receiver arg won't revert.
553
+ const target = receiver ?? '0x0000000000000000000000000000000000000000';
554
+ const raw = (await contract.maxDeposit(target));
555
+ return BigInt(raw);
556
+ }
557
+ catch (e) {
558
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
559
+ throw e;
560
+ }
561
+ (0, core_1.logChainError)('maxDeposit', e, (0, core_1.isExpectedRevertError)(e), {
562
+ vault,
563
+ receiver,
564
+ });
565
+ throw new core_1.UpshiftSDKError('UNKNOWN', `maxDeposit failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, receiver } });
566
+ }
567
+ }
568
+ /**
569
+ * Read an EVM-2 vault's idle (uncommitted) liquidity — the balance available
570
+ * to satisfy an instant redemption without a synchronous recall from the
571
+ * settlement module, computed as `getTotalAssets() - externalAssets()`.
572
+ *
573
+ * EVM-2 only. Two on-chain reads with no caching — call it immediately
574
+ * before sizing an instant redemption rather than reusing a stale value, and
575
+ * size the redemption against the result rather than against total assets.
576
+ *
577
+ * @returns Idle liquidity, in the vault's reference-asset raw units.
578
+ * @throws UpshiftValidationError on invalid vault address or a non-EVM-2 vault.
579
+ * @throws UpshiftSDKError when either underlying contract read fails.
580
+ *
581
+ * @worstCaseRpcCalls 3 — vault-version lookup, `getTotalAssets`, `externalAssets`.
582
+ *
583
+ * @example
584
+ * ```ts
585
+ * const idle = await upshiftSdk.evm.getIdleLiquidity({ vault: vaultAddress });
586
+ * if (redeemAmount > idle) {
587
+ * // fall back to a queued withdrawal instead of an instant one
588
+ * }
589
+ * ```
590
+ */
591
+ async function getIdleLiquidity(signer, options) {
592
+ const { vault } = options;
593
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
594
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getIdleLiquidity: invalid vault address ${vault}`);
595
+ }
596
+ try {
597
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
598
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
599
+ if (vaultVersion !== 'evm-2') {
600
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `getIdleLiquidity: only EVM-2 (Tokenized Vault V2) vaults expose externalAssets() — ${vault} resolved to ${vaultVersion}`);
601
+ }
602
+ const contract = (0, core_1.createContract)({
603
+ address: vault,
604
+ provider: signer,
605
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
606
+ });
607
+ const [totalAssets, externalAssets] = await Promise.all([
608
+ contract.getTotalAssets(),
609
+ contract.externalAssets(),
610
+ ]);
611
+ return BigInt(totalAssets) - BigInt(externalAssets);
612
+ }
613
+ catch (e) {
614
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
615
+ throw e;
616
+ }
617
+ (0, core_1.logChainError)('getIdleLiquidity', e, (0, core_1.isExpectedRevertError)(e), { vault });
618
+ throw new core_1.UpshiftSDKError('UNKNOWN', `getIdleLiquidity failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault } });
619
+ }
620
+ }
621
+ /**
622
+ * Read an EVM-2 vault's queued-withdrawal lag — the delay, in seconds,
623
+ * between `requestRedeem` and the withdrawal epoch becoming claimable.
624
+ *
625
+ * EVM-2 only. This value is per-vault (259,200s / 3 days on sentUSD, but
626
+ * shorter on other deployments) and can change after launch — read it live
627
+ * rather than hardcoding it.
628
+ *
629
+ * @returns Lag duration, in seconds.
630
+ * @throws UpshiftValidationError on invalid vault address or a non-EVM-2 vault.
631
+ * @throws UpshiftSDKError when the underlying contract read fails.
632
+ *
633
+ * @worstCaseRpcCalls 2 — vault-version lookup, `lagDuration`.
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * const seconds = await upshiftSdk.evm.lagDuration({ vault: vaultAddress });
638
+ * ```
639
+ */
640
+ async function lagDuration(signer, options) {
641
+ const { vault } = options;
642
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
643
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `lagDuration: invalid vault address ${vault}`);
644
+ }
645
+ try {
646
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
647
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
648
+ if (vaultVersion !== 'evm-2') {
649
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `lagDuration: only EVM-2 (Tokenized Vault V2) vaults are supported by this wrapper — ${vault} resolved to ${vaultVersion}`);
650
+ }
651
+ const contract = (0, core_1.createContract)({
652
+ address: vault,
653
+ provider: signer,
654
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
655
+ });
656
+ const raw = (await contract.lagDuration());
657
+ return BigInt(raw);
658
+ }
659
+ catch (e) {
660
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
661
+ throw e;
662
+ }
663
+ (0, core_1.logChainError)('lagDuration', e, (0, core_1.isExpectedRevertError)(e), { vault });
664
+ throw new core_1.UpshiftSDKError('UNKNOWN', `lagDuration failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault } });
665
+ }
666
+ }
667
+ /**
668
+ * Read an EVM-2 vault's current withdrawal epoch.
669
+ *
670
+ * The on-chain return order is `(year, month, day, claimableEpoch)` —
671
+ * `claimableEpoch` last, not first. This is the opposite order from what
672
+ * `requestRedeem` returns (`(claimableEpoch, year, month, day)`, epoch
673
+ * first); treat that call's return value, not this one, as the source of
674
+ * truth for a specific withdrawal's claim date.
675
+ *
676
+ * @returns The vault's current withdrawal epoch, by named field.
677
+ * @throws UpshiftValidationError on invalid vault address or a non-EVM-2 vault.
678
+ * @throws UpshiftSDKError when the underlying contract read fails.
679
+ *
680
+ * @worstCaseRpcCalls 2 — vault-version lookup, `getWithdrawalEpoch`.
681
+ *
682
+ * @example
683
+ * ```ts
684
+ * const { year, month, day, claimableEpoch } = await upshiftSdk.evm.getWithdrawalEpoch({
685
+ * vault: vaultAddress,
686
+ * });
687
+ * ```
688
+ */
689
+ async function getWithdrawalEpoch(signer, options) {
690
+ const { vault } = options;
691
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
692
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getWithdrawalEpoch: invalid vault address ${vault}`);
693
+ }
694
+ try {
695
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
696
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
697
+ if (vaultVersion !== 'evm-2') {
698
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `getWithdrawalEpoch: only EVM-2 (Tokenized Vault V2) vaults are supported by this wrapper — ${vault} resolved to ${vaultVersion}`);
699
+ }
700
+ const contract = (0, core_1.createContract)({
701
+ address: vault,
702
+ provider: signer,
703
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
704
+ });
705
+ const [year, month, day, claimableEpoch] = (await contract.getWithdrawalEpoch());
706
+ return {
707
+ year: BigInt(year),
708
+ month: BigInt(month),
709
+ day: BigInt(day),
710
+ claimableEpoch: BigInt(claimableEpoch),
711
+ };
712
+ }
713
+ catch (e) {
714
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
715
+ throw e;
716
+ }
717
+ (0, core_1.logChainError)('getWithdrawalEpoch', e, (0, core_1.isExpectedRevertError)(e), {
718
+ vault,
719
+ });
720
+ throw new core_1.UpshiftSDKError('UNKNOWN', `getWithdrawalEpoch failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault } });
721
+ }
722
+ }
723
+ /**
724
+ * Read how much of a withdrawal-epoch date's queue a given receiver can
725
+ * currently claim via `claim`, before sending the claim transaction.
726
+ *
727
+ * EVM-2 only.
728
+ *
729
+ * @returns The claimable amount, in share-token raw units.
730
+ * @throws UpshiftValidationError on invalid address input or a non-EVM-2 vault.
731
+ * @throws UpshiftSDKError when the underlying contract read fails.
732
+ *
733
+ * @worstCaseRpcCalls 2 — vault-version lookup, `getBurnableAmountByReceiver`.
734
+ *
735
+ * @example
736
+ * ```ts
737
+ * const claimable = await upshiftSdk.evm.getBurnableAmountByReceiver({
738
+ * vault: vaultAddress,
739
+ * receiver: walletAddress,
740
+ * year, month, day,
741
+ * });
742
+ * ```
743
+ */
744
+ async function getBurnableAmountByReceiver(signer, options) {
745
+ const { vault, year, month, day, receiver } = options;
746
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
747
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getBurnableAmountByReceiver: invalid vault address ${vault}`);
748
+ }
749
+ if (!(0, core_1.checkAddress)(receiver, console, 'wallet')) {
750
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getBurnableAmountByReceiver: invalid receiver address ${receiver}`);
751
+ }
752
+ const yearRaw = (0, core_1.toRawBigInt)(year, 'getBurnableAmountByReceiver', 'year');
753
+ const monthRaw = (0, core_1.toRawBigInt)(month, 'getBurnableAmountByReceiver', 'month');
754
+ const dayRaw = (0, core_1.toRawBigInt)(day, 'getBurnableAmountByReceiver', 'day');
755
+ try {
756
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
757
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
758
+ if (vaultVersion !== 'evm-2') {
759
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `getBurnableAmountByReceiver: only EVM-2 (Tokenized Vault V2) vaults are supported by this wrapper — ${vault} resolved to ${vaultVersion}`);
760
+ }
761
+ const contract = (0, core_1.createContract)({
762
+ address: vault,
763
+ provider: signer,
764
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
765
+ });
766
+ const raw = (await contract.getBurnableAmountByReceiver(yearRaw, monthRaw, dayRaw, receiver));
767
+ return BigInt(raw);
768
+ }
769
+ catch (e) {
770
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
771
+ throw e;
772
+ }
773
+ (0, core_1.logChainError)('getBurnableAmountByReceiver', e, (0, core_1.isExpectedRevertError)(e), {
774
+ vault,
775
+ year,
776
+ month,
777
+ day,
778
+ receiver,
779
+ });
780
+ throw new core_1.UpshiftSDKError('UNKNOWN', `getBurnableAmountByReceiver failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, year, month, day, receiver } });
781
+ }
782
+ }
783
+ /**
784
+ * Read the total shares required to settle a withdrawal-epoch date's entire
785
+ * queue.
786
+ *
787
+ * EVM-2 only.
788
+ *
789
+ * @returns Required shares, in share-token raw units.
790
+ * @throws UpshiftValidationError on invalid vault address or a non-EVM-2 vault.
791
+ * @throws UpshiftSDKError when the underlying contract read fails.
792
+ *
793
+ * @worstCaseRpcCalls 2 — vault-version lookup, `getRequirementByDate`.
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * const shares = await upshiftSdk.evm.getRequirementByDate({
798
+ * vault: vaultAddress,
799
+ * year, month, day,
800
+ * });
801
+ * ```
802
+ */
803
+ async function getRequirementByDate(signer, options) {
804
+ const { vault, year, month, day } = options;
805
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
806
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getRequirementByDate: invalid vault address ${vault}`);
807
+ }
808
+ const yearRaw = (0, core_1.toRawBigInt)(year, 'getRequirementByDate', 'year');
809
+ const monthRaw = (0, core_1.toRawBigInt)(month, 'getRequirementByDate', 'month');
810
+ const dayRaw = (0, core_1.toRawBigInt)(day, 'getRequirementByDate', 'day');
811
+ try {
812
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
813
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
814
+ if (vaultVersion !== 'evm-2') {
815
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `getRequirementByDate: only EVM-2 (Tokenized Vault V2) vaults are supported by this wrapper — ${vault} resolved to ${vaultVersion}`);
816
+ }
817
+ const contract = (0, core_1.createContract)({
818
+ address: vault,
819
+ provider: signer,
820
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
821
+ });
822
+ const raw = (await contract.getRequirementByDate(yearRaw, monthRaw, dayRaw));
823
+ return BigInt(raw);
824
+ }
825
+ catch (e) {
826
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
827
+ throw e;
828
+ }
829
+ (0, core_1.logChainError)('getRequirementByDate', e, (0, core_1.isExpectedRevertError)(e), {
830
+ vault,
831
+ year,
832
+ month,
833
+ day,
834
+ });
835
+ throw new core_1.UpshiftSDKError('UNKNOWN', `getRequirementByDate failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, year, month, day } });
836
+ }
837
+ }
838
+ /**
839
+ * Read the scheduled queued-withdrawal volume for a withdrawal-epoch date.
840
+ *
841
+ * EVM-2 only.
842
+ *
843
+ * @returns Total scheduled transactions and their execution epoch.
844
+ * @throws UpshiftValidationError on invalid vault address or a non-EVM-2 vault.
845
+ * @throws UpshiftSDKError when the underlying contract read fails.
846
+ *
847
+ * @worstCaseRpcCalls 2 — vault-version lookup, `getScheduledTransactionsByDate`.
848
+ *
849
+ * @example
850
+ * ```ts
851
+ * const { totalTransactions, executionEpoch } =
852
+ * await upshiftSdk.evm.getScheduledTransactionsByDate({
853
+ * vault: vaultAddress,
854
+ * year, month, day,
855
+ * });
856
+ * ```
857
+ */
858
+ async function getScheduledTransactionsByDate(signer, options) {
859
+ const { vault, year, month, day } = options;
860
+ if (!(0, core_1.checkAddress)(vault, console, 'contract')) {
861
+ throw new core_1.UpshiftValidationError('INVALID_ADDRESS', `getScheduledTransactionsByDate: invalid vault address ${vault}`);
862
+ }
863
+ const yearRaw = (0, core_1.toRawBigInt)(year, 'getScheduledTransactionsByDate', 'year');
864
+ const monthRaw = (0, core_1.toRawBigInt)(month, 'getScheduledTransactionsByDate', 'month');
865
+ const dayRaw = (0, core_1.toRawBigInt)(day, 'getScheduledTransactionsByDate', 'day');
866
+ try {
867
+ const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vault, undefined, false, false))?.[0];
868
+ const vaultVersion = (0, core_1.getVaultVersionV2)(tokenizedVault);
869
+ if (vaultVersion !== 'evm-2') {
870
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `getScheduledTransactionsByDate: only EVM-2 (Tokenized Vault V2) vaults are supported by this wrapper — ${vault} resolved to ${vaultVersion}`);
871
+ }
872
+ const contract = (0, core_1.createContract)({
873
+ address: vault,
874
+ provider: signer,
875
+ abi: abis_1.ABI_TOKENIZED_VAULT_V2,
876
+ });
877
+ const [totalTransactions, executionEpoch] = (await contract.getScheduledTransactionsByDate(yearRaw, monthRaw, dayRaw));
878
+ return {
879
+ totalTransactions: BigInt(totalTransactions),
880
+ executionEpoch: BigInt(executionEpoch),
881
+ };
882
+ }
883
+ catch (e) {
884
+ if (e instanceof core_1.UpshiftValidationError || e instanceof core_1.UpshiftSDKError) {
885
+ throw e;
886
+ }
887
+ (0, core_1.logChainError)('getScheduledTransactionsByDate', e, (0, core_1.isExpectedRevertError)(e), { vault, year, month, day });
888
+ throw new core_1.UpshiftSDKError('UNKNOWN', `getScheduledTransactionsByDate failed: ${e instanceof Error ? e.message : 'Unknown error'}`, { cause: e, context: { vault, year, month, day } });
889
+ }
890
+ }
891
+ //# sourceMappingURL=read.actions.js.map