@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,239 @@
1
+ "use strict";
2
+ /**
3
+ * Off-chain mirror of the `august_vault` pricing math.
4
+ *
5
+ * Used to quote what a deposit or redeem is expected to return so a slippage
6
+ * floor can be handed to `deposit_checked` / `redeem_checked`. Mirrors
7
+ * `VaultState::shares_for_deposit_with_offset` and
8
+ * `assets_for_redeem_with_offset` (`programs/august-vault/src/state/vault.rs`):
9
+ * `u128` intermediates, a per-vault virtual-share offset defaulting to
10
+ * `EXTRA_SHARES = 1_000_000`, a pro-rata floor (deposit) or cap (redeem),
11
+ * every division rounded down; plus the withdrawal fee `redeem_checked` takes,
12
+ * `ceil(assets * fee / 1e6)` at `FEE_RATE_DENOMINATOR_VALUE = 1_000_000`.
13
+ *
14
+ * A quote is only a quote. The program prices at execution, against state
15
+ * that may have moved since the read; the floor derived here is what protects
16
+ * the caller when the two differ.
17
+ *
18
+ * This mirror cannot validate itself — agreeing with its own tests proves
19
+ * nothing about the program — so every claim below about program behaviour is
20
+ * cited to its handler in `fractal-protocol/solana-upshift-vault-programs`, by
21
+ * file and function rather than line. Verified against that repo at 3b91c86.
22
+ * Do not "fix" the math here against intuition; re-read the handler.
23
+ *
24
+ * Adapter-internal. These functions are exported for `vault.actions.ts` and
25
+ * the unit tests only — deliberately absent from the `adapters/solana` barrel,
26
+ * so they are not public SDK surface and carry no benchmark or telemetry
27
+ * taxonomy obligation. Promoting one to the barrel means taking both on.
28
+ *
29
+ * @packageDocumentation
30
+ */
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.DEFAULT_SLIPPAGE_BPS = exports.DEFAULT_SHARE_OFFSET = void 0;
33
+ exports.toBigInt = toBigInt;
34
+ exports.resolveShareOffset = resolveShareOffset;
35
+ exports.totalAssetsOf = totalAssetsOf;
36
+ exports.hasSharePrice = hasSharePrice;
37
+ exports.sharesForDeposit = sharesForDeposit;
38
+ exports.assetsForRedeem = assetsForRedeem;
39
+ exports.withdrawalFee = withdrawalFee;
40
+ exports.validateSlippageBps = validateSlippageBps;
41
+ exports.applySlippage = applySlippage;
42
+ exports.quoteDepositFloor = quoteDepositFloor;
43
+ exports.quoteRedeemFloor = quoteRedeemFloor;
44
+ const core_1 = require("../../core");
45
+ /** What the program uses when a vault stores `share_offset == 0` (vaults created before the field existed). */
46
+ exports.DEFAULT_SHARE_OFFSET = 1000000n;
47
+ /** Denominator of `VaultState.withdrawal_fee`: the fee is in parts per million. */
48
+ const FEE_RATE_DENOMINATOR = 1000000n;
49
+ /** Slippage tolerance applied when a caller gives neither `slippageBps` nor an explicit floor. */
50
+ exports.DEFAULT_SLIPPAGE_BPS = 50;
51
+ const BPS_DENOMINATOR = 10000n;
52
+ /**
53
+ * Coerce an on-chain integer as Anchor decodes it (`BN`, `number`, decimal
54
+ * string, or `bigint`) to `bigint`.
55
+ *
56
+ * @param value - The decoded field.
57
+ * @param label - Named in the error when the value is not a non-negative integer.
58
+ * @throws UpshiftSDKError when the value cannot be read as a non-negative integer.
59
+ */
60
+ function toBigInt(value, label) {
61
+ if (typeof value === 'bigint' && value >= 0n)
62
+ return value;
63
+ if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
64
+ return BigInt(value);
65
+ const text = typeof value === 'string'
66
+ ? value
67
+ : value !== null && typeof value === 'object'
68
+ ? String(value)
69
+ : '';
70
+ if (/^\d+$/.test(text))
71
+ return BigInt(text);
72
+ throw new core_1.UpshiftSDKError('UNKNOWN', `Solana vault pricing: ${label} is not a non-negative integer (got ${String(value)}).`);
73
+ }
74
+ /**
75
+ * The vault's effective share offset. A stored zero (or a state decoded from
76
+ * an IDL that predates the field) resolves to the program default, exactly as
77
+ * `VaultState::share_offset()` does on-chain.
78
+ *
79
+ * @param raw - `VaultState.shareOffset` as decoded, or `undefined`.
80
+ */
81
+ function resolveShareOffset(raw) {
82
+ if (raw === undefined || raw === null)
83
+ return exports.DEFAULT_SHARE_OFFSET;
84
+ const offset = toBigInt(raw, 'shareOffset');
85
+ return offset === 0n ? exports.DEFAULT_SHARE_OFFSET : offset;
86
+ }
87
+ /**
88
+ * `localAum + deployedAum`, the `total_assets()` the program prices against.
89
+ *
90
+ * @param state - Decoded `VaultState`.
91
+ * @throws UpshiftSDKError when either field is missing, which means the state
92
+ * was decoded with an IDL this SDK cannot price against.
93
+ */
94
+ function totalAssetsOf(state) {
95
+ return (toBigInt(state.localAum, 'localAum') +
96
+ toBigInt(state.deployedAum, 'deployedAum'));
97
+ }
98
+ /**
99
+ * Whether the vault has a share price. Mirrors `SharePriceUndefined`:
100
+ * outstanding shares against no assets has no price in either direction.
101
+ */
102
+ function hasSharePrice(supply, totalAssets) {
103
+ return totalAssets !== 0n || supply === 0n;
104
+ }
105
+ function requireSharePrice(supply, totalAssets) {
106
+ // The program would refuse the instruction.
107
+ if (!hasSharePrice(supply, totalAssets)) {
108
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', 'This vault holds no assets while shares are outstanding, so it has no share price; deposits and redemptions are refused until the operator recapitalises it.');
109
+ }
110
+ }
111
+ /**
112
+ * Shares minted for depositing `amount` base units.
113
+ *
114
+ * `floor(max(amount * (supply + offset) / (totalAssets + offset), amount * supply / totalAssets))`.
115
+ * Above par the offset term is the larger and binds; below par the pro-rata
116
+ * floor binds so a depositor never hands value to incumbents on arrival.
117
+ *
118
+ * @param input - Share supply, total assets and the vault's resolved offset,
119
+ * all in raw base units.
120
+ * @throws UpshiftValidationError when the vault has no share price.
121
+ */
122
+ function sharesForDeposit(input) {
123
+ const { supply, totalAssets, amount, offset } = input;
124
+ requireSharePrice(supply, totalAssets);
125
+ const withOffsets = (amount * (supply + offset)) / (totalAssets + offset);
126
+ if (totalAssets === 0n)
127
+ return withOffsets;
128
+ const proRata = (amount * supply) / totalAssets;
129
+ return withOffsets > proRata ? withOffsets : proRata;
130
+ }
131
+ /**
132
+ * Assets paid, before the withdrawal fee, for burning `shares`.
133
+ *
134
+ * `floor(min(shares * (totalAssets + offset) / (supply + offset), shares * totalAssets / supply))`.
135
+ * The mirror of {@link sharesForDeposit}: above par the offset term binds,
136
+ * below par the pro-rata cap does, so no redeemer takes more than its share.
137
+ *
138
+ * @param input - Share supply, total assets and the vault's resolved offset,
139
+ * all in raw base units.
140
+ * @throws UpshiftValidationError when the vault has no share price.
141
+ */
142
+ function assetsForRedeem(input) {
143
+ const { supply, totalAssets, shares, offset } = input;
144
+ requireSharePrice(supply, totalAssets);
145
+ const withOffsets = (shares * (totalAssets + offset)) / (supply + offset);
146
+ if (supply === 0n)
147
+ return withOffsets;
148
+ const proRata = (shares * totalAssets) / supply;
149
+ return withOffsets < proRata ? withOffsets : proRata;
150
+ }
151
+ /**
152
+ * The withdrawal fee the program takes from a gross redemption:
153
+ * `ceil(assets * feePpm / 1e6)`, rounded **up** as on-chain.
154
+ *
155
+ * @param assets - Gross assets from {@link assetsForRedeem}.
156
+ * @param feePpm - `VaultState.withdrawalFee`, parts per million.
157
+ */
158
+ function withdrawalFee(assets, feePpm) {
159
+ return (assets * feePpm + FEE_RATE_DENOMINATOR - 1n) / FEE_RATE_DENOMINATOR;
160
+ }
161
+ /**
162
+ * Refuse a `slippageBps` that is not an integer in `0 .. 10_000`.
163
+ *
164
+ * @throws UpshiftValidationError when it is out of range or not an integer.
165
+ */
166
+ function validateSlippageBps(slippageBps) {
167
+ if (!Number.isInteger(slippageBps) ||
168
+ slippageBps < 0 ||
169
+ slippageBps > Number(BPS_DENOMINATOR)) {
170
+ throw new core_1.UpshiftValidationError('INVALID_INPUT', `slippageBps must be an integer between 0 and 10000, got ${slippageBps}.`);
171
+ }
172
+ }
173
+ /**
174
+ * Lower `expected` by `slippageBps` basis points, rounding down.
175
+ *
176
+ * @param expected - The quoted output in raw base units.
177
+ * @param slippageBps - Integer basis points, `0` to `10_000`.
178
+ * @throws UpshiftValidationError when `slippageBps` is out of range or not an integer.
179
+ */
180
+ function applySlippage(expected, slippageBps) {
181
+ validateSlippageBps(slippageBps);
182
+ return (expected * (BPS_DENOMINATOR - BigInt(slippageBps))) / BPS_DENOMINATOR;
183
+ }
184
+ /**
185
+ * The `min_shares_out` to pass to `deposit_checked`: the quoted shares for
186
+ * `amount`, lowered by `slippageBps`.
187
+ *
188
+ * Nothing is netted out, because there is no deposit-side fee. In
189
+ * `instructions/deposit.rs::handler_checked` the comparison is
190
+ * `require!(shares >= min_shares_out, SlippageExceeded)` directly on the
191
+ * `shares_for_deposit` result, with no fee term anywhere in the handler.
192
+ * Structurally too: `VaultState` carries exactly one fee field,
193
+ * `withdrawal_fee`, and `deposit_checked` takes no `fee_recipient_account`
194
+ * among its accounts (`redeem_checked` does), so it has no account to pay one
195
+ * to. Gross and net are the same quantity here.
196
+ *
197
+ * Quoting from state read *before* the transaction is correct despite the
198
+ * handler transferring the deposit in first: `transfer_in_ctx` moves SPL
199
+ * tokens into the vault ATA, but `total_assets()` sums the stored `local_aum`
200
+ * and `deployed_aum` fields, and `local_aum` is incremented only *after*
201
+ * `shares_for_deposit` has been computed. Supply is likewise read before the
202
+ * mint. The handler prices against the same pre-deposit figures this quote
203
+ * does.
204
+ *
205
+ * @param input - Vault state, deposit amount and tolerance.
206
+ */
207
+ function quoteDepositFloor(input) {
208
+ return applySlippage(sharesForDeposit(input), input.slippageBps);
209
+ }
210
+ /**
211
+ * The `min_assets_out` to pass to `redeem_checked`: the quoted payout for
212
+ * `shares` **net of the withdrawal fee** — which is what `redeem_checked`
213
+ * compares against — lowered by `slippageBps`.
214
+ *
215
+ * Net rather than gross is the hinge of the whole guarantee, so it is pinned
216
+ * here rather than left to be re-derived. In
217
+ * `instructions/redeem.rs::handler_checked` the program computes the gross
218
+ * `assets`, subtracts `fees` — the `ceil_div` of `assets * withdrawal_fee`
219
+ * over `FEE_RATE_DENOMINATOR_VALUE` — and compares `min_assets_out` against
220
+ * that difference, which is the figure the caller actually receives.
221
+ * `Redeem::ceil_div` is `(n + d - 1) / d`, which is what
222
+ * {@link withdrawalFee} reproduces.
223
+ *
224
+ * Getting this wrong fails quietly in the dangerous direction. Quote against
225
+ * the gross payout and the floor sits a whole fee above what the program
226
+ * measures, so it binds early and reverts healthy redemptions. Net it twice —
227
+ * or drop the fee from a vault that charges one — and the floor sits below the
228
+ * real payout by the fee, leaving protection weaker than the advertised
229
+ * `slippageBps` instead of visibly broken. `withdrawal_fee` is capped just
230
+ * under 10% (`set_withdrawal_fee`), which bounds that silent gap.
231
+ *
232
+ * @param input - Vault state, shares to burn, fee and tolerance.
233
+ */
234
+ function quoteRedeemFloor(input) {
235
+ const gross = assetsForRedeem(input);
236
+ const net = gross - withdrawalFee(gross, input.feePpm);
237
+ return applySlippage(net, input.slippageBps);
238
+ }
239
+ //# sourceMappingURL=pricing.js.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Remediation hints for withdrawal-queue errors.
3
+ *
4
+ * Leaf module (depends on nothing in the adapter) so both `queue.actions.ts`
5
+ * and `vault.actions.ts` can use it: `queue.actions.ts` already imports from
6
+ * `vault.actions.ts`, so defining the hints in either file and importing them
7
+ * from the other would create a circular dependency.
8
+ */
9
+ /**
10
+ * The sentence to append for a queue error the caller can act on.
11
+ *
12
+ * @param e - The error thrown by an Anchor `.rpc()` call (any value).
13
+ * @returns A sentence starting with a space, or `''` when the error is not a
14
+ * queue error with a known remedy.
15
+ */
16
+ export declare function queueHint(e: unknown): string;
17
+ /**
18
+ * The hint for a direct vault redeem refused because the vault routes exits
19
+ * through its withdrawal queue (`WithdrawalQueueRequired`, vault error 6021).
20
+ *
21
+ * Only this one queue hint applies to a direct redeem: the others (cooldown,
22
+ * claim liquidity, ...) describe the claim of a queued request, and e.g. the
23
+ * `NotEnoughLiquidity` claim hint ("the request stays pending") would be wrong
24
+ * for a direct redeem, which leaves no request behind.
25
+ *
26
+ * @param e - The error thrown by the redeem `.rpc()` call (any value).
27
+ * @returns The queue-redeem instruction sentence (leading space), or `''`.
28
+ */
29
+ export declare function redeemQueueHint(e: unknown): string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Remediation hints for withdrawal-queue errors.
4
+ *
5
+ * Leaf module (depends on nothing in the adapter) so both `queue.actions.ts`
6
+ * and `vault.actions.ts` can use it: `queue.actions.ts` already imports from
7
+ * `vault.actions.ts`, so defining the hints in either file and importing them
8
+ * from the other would create a circular dependency.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.queueHint = queueHint;
12
+ exports.redeemQueueHint = redeemQueueHint;
13
+ /**
14
+ * What to do next, for the queue errors a caller can act on. Matched by the
15
+ * error's name, not its number: both programs number their errors from 6000,
16
+ * so a bare code is ambiguous between them.
17
+ */
18
+ const QUEUE_HINTS = {
19
+ WithdrawalQueueRequired: ' This vault redeems through its withdrawal queue: request with `vaultRequestRedeem`, then claim with `vaultRedeem` and `options.request`.',
20
+ CooldownNotElapsed: ' The request is still in its cooldown; claim it once its eligibility time has passed.',
21
+ RequestExpired: ' The request is past its fulfillment window and can no longer be claimed; cancel it to get the shares back.',
22
+ FinalizerNotAllowed: ' Only the holder or the finalizer the request names may claim it.',
23
+ StaleRequestSequence: ' The request changed since it was read (it was claimed or cancelled, and possibly recreated); read it again.',
24
+ QueueNotActiveOnVault: ' The vault is no longer attached to this queue, so it takes no new requests; redeem directly instead.',
25
+ NotRequestOwner: ' Only the holder who made the request may cancel it.',
26
+ PayoutBelowFloor: ' The shares are worth less than the floor set when the request was made; claim once the price recovers, or cancel and request again with a lower `minAssetsOut` or higher `slippageBps`.',
27
+ // Raised by the vault inside the claim's CPI; only claims reach this map.
28
+ NotEnoughLiquidity: " The vault's liquid reserve cannot cover this payout yet; the request stays pending, so claim it again later.",
29
+ };
30
+ /**
31
+ * The sentence to append for a queue error the caller can act on.
32
+ *
33
+ * @param e - The error thrown by an Anchor `.rpc()` call (any value).
34
+ * @returns A sentence starting with a space, or `''` when the error is not a
35
+ * queue error with a known remedy.
36
+ */
37
+ function queueHint(e) {
38
+ const name = e
39
+ ?.error?.errorCode?.code;
40
+ return (name && QUEUE_HINTS[name]) || '';
41
+ }
42
+ /**
43
+ * The hint for a direct vault redeem refused because the vault routes exits
44
+ * through its withdrawal queue (`WithdrawalQueueRequired`, vault error 6021).
45
+ *
46
+ * Only this one queue hint applies to a direct redeem: the others (cooldown,
47
+ * claim liquidity, ...) describe the claim of a queued request, and e.g. the
48
+ * `NotEnoughLiquidity` claim hint ("the request stays pending") would be wrong
49
+ * for a direct redeem, which leaves no request behind.
50
+ *
51
+ * @param e - The error thrown by the redeem `.rpc()` call (any value).
52
+ * @returns The queue-redeem instruction sentence (leading space), or `''`.
53
+ */
54
+ function redeemQueueHint(e) {
55
+ const name = e
56
+ ?.error?.errorCode?.code;
57
+ return name === 'WithdrawalQueueRequired' ? queueHint(e) : '';
58
+ }
59
+ //# sourceMappingURL=queue-hints.js.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Write paths for the august_withdrawal_queue program: request a withdrawal,
3
+ * claim (finalize) a ready one, cancel a pending one.
4
+ *
5
+ * Built like the vault's deposit and redeem handlers (`vault.actions.ts`):
6
+ * every check the SDK can make runs before the wallet is asked to sign, every
7
+ * account the transaction needs is created inside it with an idempotent
8
+ * instruction, and failures surface as `UpshiftValidationError` (bad input or
9
+ * state the caller can fix) or `UpshiftSDKError` (the transaction failed, with
10
+ * the program's reason and the numeric code).
11
+ */
12
+ import { type AnchorProvider } from '@coral-xyz/anchor';
13
+ import { type Connection, PublicKey } from '@solana/web3.js';
14
+ import type { ISolanaCancelRedeemRequestParams, ISolanaRequestRedeemParams, ISolanaRequestRedeemResult } from './types';
15
+ export { queueHint } from './queue-hints';
16
+ /** The request PDA: `["withdrawal_request", queue, owner, request_id as u64 LE]`. */
17
+ export declare function deriveWithdrawalRequestPda(queue: PublicKey, owner: PublicKey, requestId: bigint, queueProgramId: PublicKey): PublicKey;
18
+ /**
19
+ * Escrow shares in a withdrawal request on a vault with a queue attached.
20
+ *
21
+ * Reads the vault state and queue in one call, checks the gate points at the
22
+ * queue, and submits `request_withdrawal` from the holder's share account. The
23
+ * recipient's deposit-token account is created in the same transaction when it
24
+ * has none. Unless `minAssetsOut` is given, the request's floor is the current
25
+ * net quote lowered by `slippageBps`, the floor `vaultRedeem` would use.
26
+ *
27
+ * RPC: one `getMultipleAccountsInfo` (vault state and queue), one
28
+ * `getAccountInfo` for the share mint (decimals for a UI `amount`, supply for
29
+ * the default floor) unless `amount` is raw and `minAssetsOut` is given, one
30
+ * `getParsedTokenAccountsByOwner` for the share account, and one more read for
31
+ * the payout account (the holder's, or another recipient's ATA, which may be
32
+ * off-curve), then the send.
33
+ *
34
+ * @returns The signature, the new request's address and its id.
35
+ * @throws UpshiftValidationError for bad input, a vault without an attached
36
+ * queue, a frozen account or too few shares, all before signing.
37
+ * @throws UpshiftSDKError when the transaction fails.
38
+ */
39
+ export declare function handleSolanaRequestRedeem({ provider, connection, queueProgramId, params, }: {
40
+ provider: AnchorProvider;
41
+ connection: Connection;
42
+ queueProgramId: PublicKey;
43
+ params: ISolanaRequestRedeemParams;
44
+ }): Promise<ISolanaRequestRedeemResult>;
45
+ /**
46
+ * Claim a request whose cooldown has run: `finalize_withdrawal`, which redeems
47
+ * the escrowed shares through the vault and pays the request's recipient.
48
+ *
49
+ * Anyone the request permits may claim it: the holder always, and anyone else
50
+ * unless it names a finalizer, in which case only that key. It is refused here,
51
+ * before signing, when the caller is not permitted, the cooldown has not run,
52
+ * or the window has closed; the wall clock stands in for the chain's, so at the
53
+ * boundary the program may still disagree by a slot. The vault's fee-recipient
54
+ * account is created in the same transaction when it has none, and so is the
55
+ * request's payout account when it is the holder's own ATA and has been closed
56
+ * since; any other closed or a frozen payout account is refused before
57
+ * signing, since the claim could only fail.
58
+ *
59
+ * RPC: three reads in turn, each address coming from the account before it
60
+ * (the request, its queue, then the queue's vault together with the payout
61
+ * account), then the send.
62
+ *
63
+ * @throws UpshiftValidationError for a missing request or one the caller cannot
64
+ * claim yet, before signing.
65
+ * @throws UpshiftSDKError when the transaction fails, e.g. `NotEnoughLiquidity`
66
+ * while the vault's reserve is deployed; the request stays pending.
67
+ */
68
+ export declare function handleSolanaClaimRedeem({ provider, connection, vaultProgramId, queueProgramId, wallet, request: requestAddress, nowSeconds, }: {
69
+ provider: AnchorProvider;
70
+ connection: Connection;
71
+ vaultProgramId: PublicKey;
72
+ queueProgramId: PublicKey;
73
+ wallet: PublicKey | string;
74
+ request: PublicKey | string;
75
+ /** Unix seconds to check eligibility against; defaults to now. */
76
+ nowSeconds?: number;
77
+ }): Promise<string>;
78
+ /**
79
+ * Cancel a pending request: `cancel_withdrawal` returns its shares to the
80
+ * holder's share account (created in the same transaction when they closed
81
+ * theirs) and closes the request, refunding its rent. Allowed at any time
82
+ * while the request exists, cooldown or not, expired or not, paused or not.
83
+ *
84
+ * RPC: two reads in turn (the request, then its queue), one
85
+ * `getParsedTokenAccountsByOwner`, then the send.
86
+ *
87
+ * @returns The confirmed transaction's signature.
88
+ * @throws UpshiftValidationError for a missing request or one `wallet` did not
89
+ * make, before signing.
90
+ * @throws UpshiftSDKError when the transaction fails.
91
+ */
92
+ export declare function handleSolanaCancelRedeemRequest({ provider, connection, queueProgramId, params, }: {
93
+ provider: AnchorProvider;
94
+ connection: Connection;
95
+ queueProgramId: PublicKey;
96
+ params: ISolanaCancelRedeemRequestParams;
97
+ }): Promise<string>;