@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,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readPricingSnapshot = readPricingSnapshot;
4
+ exports.resolveUserTokenAccount = resolveUserTokenAccount;
5
+ /**
6
+ * Account reads shared by the Solana write handlers (`vault.actions.ts`,
7
+ * `queue.actions.ts`) and the withdrawal-queue readers.
8
+ *
9
+ * Internal: kept out of `vault.actions.ts` because `Solana.actions` is that
10
+ * whole module, so anything exported from it becomes public API.
11
+ */
12
+ const spl_token_1 = require("@solana/spl-token");
13
+ const core_1 = require("../../core");
14
+ const utils_1 = require("./utils");
15
+ /**
16
+ * The vault state and share-mint supply as of a **single slot**.
17
+ *
18
+ * Both figures price the quote, so they have to come from one snapshot. Read
19
+ * independently — even concurrently, as two RPC requests — a deposit or
20
+ * redemption landing in between combines a supply and an asset total that
21
+ * never coexisted, and the quote is wrong in whichever direction the
22
+ * interleaving fell. Seeing a 10% deposit's new assets against the old supply
23
+ * quotes ~10% high, and the floor then rejects a redemption whose share price
24
+ * never moved; the opposite ordering quotes low and silently weakens the
25
+ * protection. `getMultipleAccountsInfo` is served from one slot, so the pair
26
+ * is always coherent — and it costs one round trip instead of two.
27
+ *
28
+ * @param program - Anchor program, used only for its account coder; the
29
+ * provider it was built with is irrelevant, so no read-only program is needed.
30
+ * @param vaultStatePda - Vault state account to decode.
31
+ * @param shareMintAddr - Share mint whose supply and decimals are read.
32
+ * @param extraAccounts - Further accounts to read in the same call and slot,
33
+ * returned raw and in order (`null` for an absent one). Lets a caller that
34
+ * also needs, say, token accounts avoid a second round trip.
35
+ * @returns The decoded `VaultState`, the share mint's raw `supply`, its
36
+ * `decimals`, and `extraAccountInfos` — all from the same slot.
37
+ * @throws {@link UpshiftSDKError} when either account is absent, or is not the
38
+ * account type it should be.
39
+ */
40
+ async function readPricingSnapshot({ connection, program, vaultStatePda, shareMintAddr, extraAccounts = [], }) {
41
+ const [vaultStateInfo, shareMintInfo, ...extraAccountInfos] = await connection.getMultipleAccountsInfo([
42
+ vaultStatePda,
43
+ shareMintAddr,
44
+ ...extraAccounts,
45
+ ]);
46
+ if (!vaultStateInfo) {
47
+ throw new core_1.UpshiftSDKError('UNKNOWN', `Vault state account ${vaultStatePda.toBase58()} does not exist; it cannot be priced.`);
48
+ }
49
+ if (!shareMintInfo) {
50
+ throw new core_1.UpshiftSDKError('UNKNOWN', `Share mint ${shareMintAddr.toBase58()} does not exist; it cannot be priced.`);
51
+ }
52
+ // `vaultState`, not the IDL's own `VaultState`: `Program` runs the IDL
53
+ // through `convertIdlToCamelCase`, so its coder only answers to the
54
+ // camelCase name and the IDL spelling throws `Account not found`. (A coder
55
+ // built directly from the raw IDL behaves the opposite way — which is why
56
+ // this has to be checked against a real `Program`, as its test does.)
57
+ //
58
+ // Decoded by name rather than `decodeAny`, so a `vaultAddress` pointing at
59
+ // some other account of this program fails here instead of being decoded as
60
+ // whatever it happens to be.
61
+ let vaultStateData;
62
+ try {
63
+ vaultStateData = program.coder.accounts.decode('vaultState', vaultStateInfo.data);
64
+ }
65
+ catch (e) {
66
+ throw new core_1.UpshiftSDKError('UNKNOWN', `Account ${vaultStatePda.toBase58()} is not a vault state account for this program.`, { cause: e });
67
+ }
68
+ let mint;
69
+ try {
70
+ mint = (0, spl_token_1.unpackMint)(shareMintAddr, shareMintInfo, spl_token_1.TOKEN_PROGRAM_ID);
71
+ }
72
+ catch (e) {
73
+ throw new core_1.UpshiftSDKError('UNKNOWN', `Account ${shareMintAddr.toBase58()} is not an SPL Token mint.`, { cause: e });
74
+ }
75
+ return {
76
+ vaultStateData,
77
+ supply: mint.supply,
78
+ shareDecimals: mint.decimals,
79
+ extraAccountInfos,
80
+ };
81
+ }
82
+ /**
83
+ * Pick which token account to hand the vault program for a given mint, and
84
+ * describe how to create it when the user has none.
85
+ *
86
+ * The vault program constrains these accounts by `token::mint` +
87
+ * `token::authority` (not `associated_token::…`), so any account the signer
88
+ * owns qualifies. We therefore keep an existing account when there is one —
89
+ * that is where the user's balance already lives — and fall back to the
90
+ * associated token account otherwise.
91
+ *
92
+ * Two deliberate choices:
93
+ *
94
+ * - **The create is returned, not sent.** Prepended to the deposit/redeem via
95
+ * `.preInstructions()` it is atomic with the transfer, so there is no window
96
+ * in which the vault instruction can reference an account that has not
97
+ * landed. Sent as its own transaction — as this module used to — it raced
98
+ * its own confirmation. Observed in production (2026-08-11):
99
+ * a deposit failed with `Simulation failed … Logs: []` while the share-ATA
100
+ * create was still in flight, then succeeded 17s later on retry. The empty
101
+ * log array means the transaction never reached program execution, so there
102
+ * was nothing on-chain to debug from.
103
+ * - **Idempotent.** `createAssociatedTokenAccountIdempotentInstruction` is a
104
+ * no-op when the account already exists, so a concurrent create — another
105
+ * tab, a wallet's auto-provisioning — cannot turn into an
106
+ * `SystemError::AccountAlreadyInUse` ("already in use") failure between our
107
+ * read and our submit.
108
+ *
109
+ * Which account wins when several exist is decided by
110
+ * {@link selectRichestTokenAccount} — the same rule every balance *read* in
111
+ * this adapter uses, so the account a UI reports and the account a transfer
112
+ * names are never different accounts.
113
+ *
114
+ * Classic SPL Token only: the ATA is derived under `TOKEN_PROGRAM_ID`, matching
115
+ * the `tokenProgram` both handlers pass, even though the program's
116
+ * `TokenInterface` would also accept Token-2022.
117
+ *
118
+ * @param owner - Wallet that owns the account and pays rent for any creation.
119
+ * @throws UpshiftSDKError when a candidate account's balance cannot be read
120
+ * (propagated from the shared selector).
121
+ */
122
+ async function resolveUserTokenAccount({ connection, owner, mint, }) {
123
+ const existing = await connection.getParsedTokenAccountsByOwner(owner, {
124
+ mint,
125
+ });
126
+ const richest = (0, utils_1.selectRichestTokenAccount)(existing.value);
127
+ if (richest)
128
+ return {
129
+ address: richest.pubkey,
130
+ balance: richest.amount,
131
+ frozen: richest.frozen,
132
+ };
133
+ // Off-curve allowed: a multisig vault holds and signs as a PDA.
134
+ const ata = await (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
135
+ return {
136
+ address: ata,
137
+ balance: BigInt(0),
138
+ frozen: false,
139
+ createIx: (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(owner, // payer
140
+ ata, // associated token account
141
+ owner, // owner
142
+ mint),
143
+ };
144
+ }
145
+ //# sourceMappingURL=token-reads.js.map
@@ -0,0 +1,325 @@
1
+ import type { AnchorProvider, BN } from '@coral-xyz/anchor';
2
+ import type { Connection, PublicKey } from '@solana/web3.js';
3
+ export type ISolanaRpcEndpoint = `https://${string}`;
4
+ export type ISolanaNetwork = 'devnet' | 'mainnet-beta' | 'testnet' | 'localnet';
5
+ export interface ISolanaConnectionOptions {
6
+ endpoint?: ISolanaRpcEndpoint;
7
+ connection?: Connection;
8
+ provider?: AnchorProvider;
9
+ network?: ISolanaNetwork;
10
+ }
11
+ export interface ISolanaVaultState {
12
+ operator: PublicKey | null;
13
+ admin: PublicKey | null;
14
+ shareMint: PublicKey | null;
15
+ depositMint: PublicKey | null;
16
+ feeRecipient: PublicKey | null;
17
+ withdrawalFee: number | null;
18
+ /**
19
+ * On-vault reserve (raw u64 base units). Sum with `deployedAum` for total
20
+ * assets. Anchor decodes u64 as `BN`, never `number` — convert with
21
+ * `BigInt(localAum.toString())`, not `Number(...)`, to avoid precision loss.
22
+ */
23
+ localAum: BN | null;
24
+ /** Operator-deployed AUM (raw u64 base units, decoded by Anchor as `BN`). */
25
+ deployedAum: BN | null;
26
+ /**
27
+ * Virtual-share offset the program prices with (a power of ten). Absent on
28
+ * builds that predate it, and `0` on vaults created before it; read it
29
+ * through `resolveShareOffset`, which maps both to the default.
30
+ */
31
+ shareOffset?: BN | null;
32
+ aumIncreaseLimit: number | null;
33
+ aumDecreaseLimit: number | null;
34
+ pdaBump: number[] | null;
35
+ vaultVersion: number[] | null;
36
+ paused: boolean | null;
37
+ /**
38
+ * The only key the vault accepts a redeem from, or the default (all-zero)
39
+ * public key when no withdrawal queue is attached. When set it is this
40
+ * vault's withdrawal-queue PDA: a direct holder redeem is refused with
41
+ * `WithdrawalQueueRequired` (6021), and holders exit through the queue
42
+ * instead. Vaults created before the queue existed read the default key.
43
+ */
44
+ withdrawalQueueAuthority: PublicKey | null;
45
+ /**
46
+ * Number of registered operator subaccounts. Non-zero means operator
47
+ * transfers must go to a registered subaccount; `0` on vaults created before
48
+ * subaccounts existed, and on every mainnet vault today.
49
+ */
50
+ subaccountCount: BN | null;
51
+ /**
52
+ * Raw deposit-mint units taken out to subaccounts and not yet returned,
53
+ * across all of them. Distinct from `deployedAum`, which the operator marks
54
+ * without moving tokens. Informational: nothing on-chain trusts it.
55
+ */
56
+ deployedPrincipal: BN | null;
57
+ }
58
+ /**
59
+ * A vault's withdrawal queue account (`WithdrawalQueue` in the
60
+ * august_withdrawal_queue program), as Anchor decodes it.
61
+ *
62
+ * One per vault, at the PDA `["withdrawal_queue", vault_state]`. Integer fields
63
+ * are `BN`s in raw on-chain units; times are in seconds.
64
+ */
65
+ export interface ISolanaWithdrawalQueueState {
66
+ /** The vault this queue serves. */
67
+ vaultState: PublicKey;
68
+ /** The vault's deposit mint, copied at initialization. */
69
+ depositMint: PublicKey;
70
+ /** The vault's share mint, copied at initialization. */
71
+ shareMint: PublicKey;
72
+ /** The queue's share escrow: holds every pending request's shares. */
73
+ escrowShares: PublicKey;
74
+ /**
75
+ * The queue's deposit-mint escrow. Transit only: a payout passes through it
76
+ * within the finalizing transaction, so it normally holds nothing.
77
+ */
78
+ escrowAssets: PublicKey;
79
+ /**
80
+ * Seconds between a request and its eligibility. Stamped on each request when
81
+ * it is created, so a change applies to later requests only.
82
+ */
83
+ cooldownSeconds: BN;
84
+ /**
85
+ * Seconds after scheduled eligibility that a request may still be finalized,
86
+ * or `0` for no expiry. Stamped on each request when it is created.
87
+ */
88
+ fulfillmentWindowSeconds: BN;
89
+ /** Queue-wide counter; the last value stamped on a request (the first is 1). */
90
+ sequence: BN;
91
+ /** Number of live (unfinalized, uncancelled) requests. */
92
+ pendingRequests: BN;
93
+ /** Raw shares escrowed across all live requests. */
94
+ pendingShares: BN;
95
+ /** Canonical bump of the queue PDA. */
96
+ bump: number;
97
+ }
98
+ /**
99
+ * One withdrawal request (`WithdrawalRequest` in the august_withdrawal_queue
100
+ * program), as Anchor decodes it.
101
+ *
102
+ * At the PDA `["withdrawal_request", queue, owner, request_id as u64 LE]`. The
103
+ * account exists while the request is pending and is closed when it is
104
+ * finalized or cancelled. Integer fields are `BN`s; times are Unix seconds.
105
+ */
106
+ export interface ISolanaWithdrawalRequestState {
107
+ /** The queue holding this request's shares. */
108
+ queue: PublicKey;
109
+ /** Who requested; may cancel, and may always finalize. */
110
+ owner: PublicKey;
111
+ /** Deposit-mint token account the payout goes to. */
112
+ recipientTokenAccount: PublicKey;
113
+ /**
114
+ * Who may finalize besides the owner, or the default (all-zero) public key
115
+ * for anyone.
116
+ */
117
+ finalizer: PublicKey;
118
+ /** Raw shares escrowed for this request. */
119
+ shares: BN;
120
+ /** Owner-chosen id, unique per owner while the request exists. */
121
+ requestId: BN;
122
+ /**
123
+ * Queue-wide stamp given at creation. Instructions that target the request
124
+ * pass it as `expected_sequence`, so a delayed call cannot land on a
125
+ * recreated request with the same id.
126
+ */
127
+ sequence: BN;
128
+ /** When the request was created. */
129
+ requestedAt: BN;
130
+ /** `requestedAt + cooldown` at creation. Never changes. */
131
+ scheduledEligibleAt: BN;
132
+ /**
133
+ * When finalization may begin. Equals `scheduledEligibleAt` unless an admin
134
+ * or operator expedited the request, which only ever moves it earlier.
135
+ */
136
+ eligibleAt: BN;
137
+ /**
138
+ * When the request stops being finalizable (the instant itself counts as
139
+ * expired), or `0` for never. An expired request can only be cancelled.
140
+ */
141
+ expiresAt: BN;
142
+ /** Bump of the request PDA. */
143
+ bump: number;
144
+ /**
145
+ * The owner's floor on the net payout, in raw deposit-mint units; `0` for
146
+ * none. A claim that would pay less is refused with `PayoutBelowFloor`.
147
+ */
148
+ minAssetsOut: BN;
149
+ }
150
+ export interface ISolanaToken {
151
+ address: string;
152
+ symbol: any;
153
+ decimals: number;
154
+ name: any;
155
+ image: any;
156
+ program: any;
157
+ mintAuthority: any;
158
+ freezeAuthority: any;
159
+ supply: string;
160
+ shareMintAddress: string;
161
+ }
162
+ export interface ISolanaVaultConfig {
163
+ programId: string;
164
+ vaultState: string;
165
+ shareMint: string;
166
+ vaultTokenAta: string;
167
+ depositMint: string;
168
+ network: ISolanaNetwork;
169
+ }
170
+ export interface ISolanaDepositResult {
171
+ success: boolean;
172
+ signature?: string;
173
+ sharesMinted?: number;
174
+ error?: string;
175
+ }
176
+ export interface ISolanaWithdrawResult {
177
+ success: boolean;
178
+ signature?: string;
179
+ tokensWithdrawn?: number;
180
+ error?: string;
181
+ }
182
+ export interface ISolanaVaultStats {
183
+ totalAssets: number;
184
+ totalShares: number;
185
+ isPaused: boolean;
186
+ withdrawalFee: number;
187
+ admin: string;
188
+ operator: string;
189
+ feeRecipient: string;
190
+ lastUpdated: Date;
191
+ }
192
+ /**
193
+ * Slippage protection for {@link SolanaAdapter.vaultDeposit}.
194
+ *
195
+ * The SDK quotes the shares a deposit should mint from the vault's current
196
+ * state and passes a floor to the program's `deposit_checked` instruction,
197
+ * which reverts with `SlippageExceeded` if the share price moves past it
198
+ * before execution.
199
+ */
200
+ export interface ISolanaDepositOptions {
201
+ /**
202
+ * Tolerance below the quoted shares, in basis points (`0` to `10000`).
203
+ * `0` demands the quote exactly. Ignored when `minSharesOut` is given.
204
+ * @defaultValue 50 (0.5%)
205
+ */
206
+ slippageBps?: number;
207
+ /**
208
+ * Explicit floor in raw share units, passed to `deposit_checked` as is.
209
+ * Skips the quote and the single snapshot read it needs. `0n` restores the
210
+ * unguarded behaviour of the plain `deposit` instruction.
211
+ *
212
+ * When the handler's `idl` predates `deposit_checked`, a non-zero floor or
213
+ * any `slippageBps` throws {@link UpshiftValidationError} instead of being
214
+ * silently dropped; with neither, the plain `deposit` is sent.
215
+ *
216
+ * Must be a `bigint` in `0 .. 2^64-1`; anything else throws
217
+ * {@link UpshiftValidationError} before the transaction is built.
218
+ */
219
+ minSharesOut?: bigint;
220
+ }
221
+ /**
222
+ * Slippage protection for {@link SolanaAdapter.vaultRedeem}.
223
+ *
224
+ * The floor is measured **net of the withdrawal fee**, i.e. on what the wallet
225
+ * actually receives, matching the program's `redeem_checked`.
226
+ */
227
+ export interface ISolanaRedeemOptions {
228
+ /**
229
+ * Tolerance below the quoted net payout, in basis points (`0` to `10000`).
230
+ * `0` demands the quote exactly. Ignored when `minAssetsOut` is given.
231
+ * @defaultValue 50 (0.5%)
232
+ */
233
+ slippageBps?: number;
234
+ /**
235
+ * Explicit floor in raw deposit-mint units, net of the withdrawal fee,
236
+ * passed to `redeem_checked` as is. Skips the quote. `0n` restores the
237
+ * unguarded behaviour of the plain `redeem` instruction.
238
+ *
239
+ * When the handler's `idl` predates `redeem_checked`, a non-zero floor or
240
+ * any `slippageBps` throws {@link UpshiftValidationError} instead of being
241
+ * silently dropped; with neither, the plain `redeem` is sent.
242
+ */
243
+ minAssetsOut?: bigint;
244
+ /**
245
+ * Claim this withdrawal request instead of redeeming instantly: the request
246
+ * account's address, as `id` on the entries `getVaultAvailableRedemptions`
247
+ * returns. Its shares, recipient and vault come from the request, so the
248
+ * `redeemShares` and `vaultAddress` arguments are ignored. The queue pays
249
+ * at the share price of the moment it settles, held to the floor the request
250
+ * was made with, so `slippageBps` and `minAssetsOut` must not be set
251
+ * alongside it.
252
+ *
253
+ * Required on a vault with a withdrawal queue attached, which refuses a
254
+ * direct redeem. See {@link SolanaAdapter.vaultRequestRedeem}.
255
+ */
256
+ request?: PublicKey | string;
257
+ }
258
+ /**
259
+ * Input to {@link SolanaAdapter.vaultRequestRedeem}.
260
+ */
261
+ export interface ISolanaRequestRedeemParams {
262
+ /** The vault's `VaultState` account address. */
263
+ vault: PublicKey | string;
264
+ /** The holder, who signs, escrows the shares and pays rent for the request. */
265
+ wallet: PublicKey | string;
266
+ /** Shares to escrow: `bigint` in raw share units, or `number` as a UI amount. */
267
+ amount: number | bigint;
268
+ /**
269
+ * Wallet to pay when the request is claimed; its deposit-token account is
270
+ * created in the same transaction if it has none, at the holder's expense.
271
+ * Defaults to the holder.
272
+ */
273
+ recipient?: PublicKey | string;
274
+ /**
275
+ * The one key besides the holder that may claim the request, e.g. a keeper.
276
+ * Defaults to anyone, which is what lets a keeper settle requests for
277
+ * holders who do not come back.
278
+ */
279
+ finalizer?: PublicKey | string;
280
+ /**
281
+ * The request's id, unique per holder while it is pending. Defaults to a
282
+ * random `u64`; pass one only to choose it yourself.
283
+ */
284
+ requestId?: bigint;
285
+ /**
286
+ * Tolerance below the quoted net payout, in basis points (`0` to `10000`).
287
+ * The floor is fixed now and checked when the request is claimed, so it
288
+ * guards against a fee rise or an AUM mark-down in between; yield earned in
289
+ * the meantime only raises the payout. Ignored when `minAssetsOut` is given.
290
+ * @defaultValue 50 (0.5%)
291
+ */
292
+ slippageBps?: number;
293
+ /**
294
+ * Explicit floor on the net payout, in raw deposit-mint units, stored on the
295
+ * request as is. Skips the quote. `0n` means no floor: the claim pays
296
+ * whatever the shares are worth when it lands.
297
+ *
298
+ * Must be a `bigint` in `0 .. 2^64-1`; anything else throws
299
+ * {@link UpshiftValidationError} before the transaction is built.
300
+ */
301
+ minAssetsOut?: bigint;
302
+ }
303
+ /**
304
+ * What {@link SolanaAdapter.vaultRequestRedeem} returns.
305
+ */
306
+ export interface ISolanaRequestRedeemResult {
307
+ /** The confirmed transaction's signature. */
308
+ signature: string;
309
+ /**
310
+ * The new request account's address: pass it as `request` to claim or
311
+ * cancel. `getVaultAvailableRedemptions` lists it as `id`.
312
+ */
313
+ request: string;
314
+ /** The request id, as a decimal string (a `u64`). */
315
+ requestId: string;
316
+ }
317
+ /**
318
+ * Input to {@link SolanaAdapter.vaultCancelRedeemRequest}.
319
+ */
320
+ export interface ISolanaCancelRedeemRequestParams {
321
+ /** The holder who made the request; only they may cancel it. */
322
+ wallet: PublicKey | string;
323
+ /** The request account's address, as returned by `vaultRequestRedeem`. */
324
+ request: PublicKey | string;
325
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map