augustdigital-sdk 8.20.1

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 (316) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  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 +1043 -0
  40. package/lib/abis/SwapRouter.js +740 -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 +209 -0
  65. package/lib/adapters/evm/index.d.ts +353 -0
  66. package/lib/adapters/evm/index.js +434 -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/constants.d.ts +33 -0
  70. package/lib/adapters/solana/constants.js +52 -0
  71. package/lib/adapters/solana/getters.d.ts +11 -0
  72. package/lib/adapters/solana/getters.js +165 -0
  73. package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
  74. package/lib/adapters/solana/idl/vault-idl.js +1084 -0
  75. package/lib/adapters/solana/index.d.ts +233 -0
  76. package/lib/adapters/solana/index.js +291 -0
  77. package/lib/adapters/solana/types.d.ts +67 -0
  78. package/lib/adapters/solana/types.js +3 -0
  79. package/lib/adapters/solana/utils.d.ts +141 -0
  80. package/lib/adapters/solana/utils.js +595 -0
  81. package/lib/adapters/solana/vault.actions.d.ts +57 -0
  82. package/lib/adapters/solana/vault.actions.js +379 -0
  83. package/lib/adapters/stellar/actions.d.ts +28 -0
  84. package/lib/adapters/stellar/actions.js +77 -0
  85. package/lib/adapters/stellar/constants.d.ts +43 -0
  86. package/lib/adapters/stellar/constants.js +53 -0
  87. package/lib/adapters/stellar/getters.d.ts +68 -0
  88. package/lib/adapters/stellar/getters.js +290 -0
  89. package/lib/adapters/stellar/index.d.ts +114 -0
  90. package/lib/adapters/stellar/index.js +175 -0
  91. package/lib/adapters/stellar/soroban.d.ts +123 -0
  92. package/lib/adapters/stellar/soroban.js +613 -0
  93. package/lib/adapters/stellar/submit.d.ts +34 -0
  94. package/lib/adapters/stellar/submit.js +149 -0
  95. package/lib/adapters/stellar/types.d.ts +58 -0
  96. package/lib/adapters/stellar/types.js +6 -0
  97. package/lib/adapters/stellar/utils.d.ts +24 -0
  98. package/lib/adapters/stellar/utils.js +34 -0
  99. package/lib/adapters/sui/constants.d.ts +14 -0
  100. package/lib/adapters/sui/constants.js +29 -0
  101. package/lib/adapters/sui/getters.d.ts +9 -0
  102. package/lib/adapters/sui/getters.js +60 -0
  103. package/lib/adapters/sui/index.d.ts +45 -0
  104. package/lib/adapters/sui/index.js +101 -0
  105. package/lib/adapters/sui/transformer.d.ts +10 -0
  106. package/lib/adapters/sui/transformer.js +107 -0
  107. package/lib/adapters/sui/types.d.ts +66 -0
  108. package/lib/adapters/sui/types.js +3 -0
  109. package/lib/adapters/sui/utils.d.ts +10 -0
  110. package/lib/adapters/sui/utils.js +29 -0
  111. package/lib/core/analytics/chain-name.d.ts +9 -0
  112. package/lib/core/analytics/chain-name.js +34 -0
  113. package/lib/core/analytics/constants.d.ts +5 -0
  114. package/lib/core/analytics/constants.js +9 -0
  115. package/lib/core/analytics/env.d.ts +29 -0
  116. package/lib/core/analytics/env.js +59 -0
  117. package/lib/core/analytics/index.d.ts +36 -0
  118. package/lib/core/analytics/index.js +79 -0
  119. package/lib/core/analytics/instrumentation.d.ts +29 -0
  120. package/lib/core/analytics/instrumentation.js +277 -0
  121. package/lib/core/analytics/method-taxonomy.d.ts +19 -0
  122. package/lib/core/analytics/method-taxonomy.js +128 -0
  123. package/lib/core/analytics/metrics.d.ts +33 -0
  124. package/lib/core/analytics/metrics.js +116 -0
  125. package/lib/core/analytics/sanitize.d.ts +44 -0
  126. package/lib/core/analytics/sanitize.js +260 -0
  127. package/lib/core/analytics/sentry-runtime.d.ts +15 -0
  128. package/lib/core/analytics/sentry-runtime.js +97 -0
  129. package/lib/core/analytics/sentry.d.ts +67 -0
  130. package/lib/core/analytics/sentry.js +613 -0
  131. package/lib/core/analytics/types.d.ts +48 -0
  132. package/lib/core/analytics/types.js +3 -0
  133. package/lib/core/analytics/user-identity.d.ts +41 -0
  134. package/lib/core/analytics/user-identity.js +141 -0
  135. package/lib/core/analytics/version.d.ts +6 -0
  136. package/lib/core/analytics/version.js +10 -0
  137. package/lib/core/attribution.d.ts +111 -0
  138. package/lib/core/attribution.js +142 -0
  139. package/lib/core/auth/index.d.ts +1 -0
  140. package/lib/core/auth/index.js +18 -0
  141. package/lib/core/auth/verify.d.ts +2 -0
  142. package/lib/core/auth/verify.js +31 -0
  143. package/lib/core/base.class.d.ts +152 -0
  144. package/lib/core/base.class.js +172 -0
  145. package/lib/core/cache.d.ts +9 -0
  146. package/lib/core/cache.js +31 -0
  147. package/lib/core/constants/adapters.d.ts +103 -0
  148. package/lib/core/constants/adapters.js +180 -0
  149. package/lib/core/constants/core.d.ts +133 -0
  150. package/lib/core/constants/core.js +209 -0
  151. package/lib/core/constants/swap-router.d.ts +150 -0
  152. package/lib/core/constants/swap-router.js +169 -0
  153. package/lib/core/constants/vaults.d.ts +93 -0
  154. package/lib/core/constants/vaults.js +273 -0
  155. package/lib/core/constants/web3.d.ts +91 -0
  156. package/lib/core/constants/web3.js +229 -0
  157. package/lib/core/errors/index.d.ts +114 -0
  158. package/lib/core/errors/index.js +183 -0
  159. package/lib/core/fetcher.d.ts +198 -0
  160. package/lib/core/fetcher.js +903 -0
  161. package/lib/core/helpers/adapters.d.ts +13 -0
  162. package/lib/core/helpers/adapters.js +39 -0
  163. package/lib/core/helpers/chain-address.d.ts +13 -0
  164. package/lib/core/helpers/chain-address.js +47 -0
  165. package/lib/core/helpers/chain-error.d.ts +207 -0
  166. package/lib/core/helpers/chain-error.js +682 -0
  167. package/lib/core/helpers/chain-support.d.ts +80 -0
  168. package/lib/core/helpers/chain-support.js +115 -0
  169. package/lib/core/helpers/core.d.ts +68 -0
  170. package/lib/core/helpers/core.js +285 -0
  171. package/lib/core/helpers/explorer-link.d.ts +16 -0
  172. package/lib/core/helpers/explorer-link.js +26 -0
  173. package/lib/core/helpers/multicall.d.ts +68 -0
  174. package/lib/core/helpers/multicall.js +103 -0
  175. package/lib/core/helpers/revert-decode.d.ts +248 -0
  176. package/lib/core/helpers/revert-decode.js +515 -0
  177. package/lib/core/helpers/signer.d.ts +52 -0
  178. package/lib/core/helpers/signer.js +145 -0
  179. package/lib/core/helpers/swap-router.d.ts +211 -0
  180. package/lib/core/helpers/swap-router.js +480 -0
  181. package/lib/core/helpers/vault-version.d.ts +23 -0
  182. package/lib/core/helpers/vault-version.js +75 -0
  183. package/lib/core/helpers/vaults.d.ts +89 -0
  184. package/lib/core/helpers/vaults.js +235 -0
  185. package/lib/core/helpers/web3.d.ts +353 -0
  186. package/lib/core/helpers/web3.js +992 -0
  187. package/lib/core/index.d.ts +23 -0
  188. package/lib/core/index.js +40 -0
  189. package/lib/core/logger/index.d.ts +98 -0
  190. package/lib/core/logger/index.js +144 -0
  191. package/lib/core/logger/slack.d.ts +16 -0
  192. package/lib/core/logger/slack.js +57 -0
  193. package/lib/core/vault-metadata.d.ts +12 -0
  194. package/lib/core/vault-metadata.js +42 -0
  195. package/lib/core/version-check.d.ts +58 -0
  196. package/lib/core/version-check.js +182 -0
  197. package/lib/evm/index.d.ts +2 -0
  198. package/lib/evm/index.js +19 -0
  199. package/lib/evm/methods/crossChainVault.d.ts +128 -0
  200. package/lib/evm/methods/crossChainVault.js +853 -0
  201. package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
  202. package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
  203. package/lib/evm/methods/index.d.ts +2 -0
  204. package/lib/evm/methods/index.js +19 -0
  205. package/lib/evm/types/crossChain.d.ts +363 -0
  206. package/lib/evm/types/crossChain.js +20 -0
  207. package/lib/evm/types/index.d.ts +1 -0
  208. package/lib/evm/types/index.js +18 -0
  209. package/lib/index.d.ts +30 -0
  210. package/lib/index.js +52 -0
  211. package/lib/main.d.ts +527 -0
  212. package/lib/main.js +601 -0
  213. package/lib/modules/api/fetcher.d.ts +82 -0
  214. package/lib/modules/api/fetcher.js +150 -0
  215. package/lib/modules/api/index.d.ts +1 -0
  216. package/lib/modules/api/index.js +6 -0
  217. package/lib/modules/api/main.d.ts +313 -0
  218. package/lib/modules/api/main.js +479 -0
  219. package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
  220. package/lib/modules/sub-accounts/fetcher.js +120 -0
  221. package/lib/modules/sub-accounts/index.d.ts +2 -0
  222. package/lib/modules/sub-accounts/index.js +19 -0
  223. package/lib/modules/sub-accounts/main.d.ts +243 -0
  224. package/lib/modules/sub-accounts/main.js +205 -0
  225. package/lib/modules/sub-accounts/utils.d.ts +106 -0
  226. package/lib/modules/sub-accounts/utils.js +112 -0
  227. package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
  228. package/lib/modules/vaults/adapter.helpers.js +184 -0
  229. package/lib/modules/vaults/fetcher.d.ts +147 -0
  230. package/lib/modules/vaults/fetcher.js +368 -0
  231. package/lib/modules/vaults/getters.d.ts +570 -0
  232. package/lib/modules/vaults/getters.js +3051 -0
  233. package/lib/modules/vaults/index.d.ts +20 -0
  234. package/lib/modules/vaults/index.js +44 -0
  235. package/lib/modules/vaults/main.d.ts +601 -0
  236. package/lib/modules/vaults/main.js +1623 -0
  237. package/lib/modules/vaults/prefetch.d.ts +65 -0
  238. package/lib/modules/vaults/prefetch.js +120 -0
  239. package/lib/modules/vaults/read.actions.d.ts +225 -0
  240. package/lib/modules/vaults/read.actions.js +596 -0
  241. package/lib/modules/vaults/types.d.ts +71 -0
  242. package/lib/modules/vaults/types.js +3 -0
  243. package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
  244. package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
  245. package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
  246. package/lib/modules/vaults/utils/date-utils.js +84 -0
  247. package/lib/modules/vaults/utils.d.ts +140 -0
  248. package/lib/modules/vaults/utils.js +799 -0
  249. package/lib/modules/vaults/write.actions.d.ts +529 -0
  250. package/lib/modules/vaults/write.actions.js +1749 -0
  251. package/lib/polyfills.d.ts +1 -0
  252. package/lib/polyfills.js +12 -0
  253. package/lib/sdk.d.ts +26721 -0
  254. package/lib/services/coingecko/fetcher.d.ts +15 -0
  255. package/lib/services/coingecko/fetcher.js +67 -0
  256. package/lib/services/coingecko/index.d.ts +2 -0
  257. package/lib/services/coingecko/index.js +19 -0
  258. package/lib/services/coingecko/utils.d.ts +1 -0
  259. package/lib/services/coingecko/utils.js +24 -0
  260. package/lib/services/debank/fetcher.d.ts +126 -0
  261. package/lib/services/debank/fetcher.js +47 -0
  262. package/lib/services/debank/index.d.ts +2 -0
  263. package/lib/services/debank/index.js +19 -0
  264. package/lib/services/debank/utils.d.ts +38 -0
  265. package/lib/services/debank/utils.js +297 -0
  266. package/lib/services/layerzero/deposits.d.ts +49 -0
  267. package/lib/services/layerzero/deposits.js +166 -0
  268. package/lib/services/layerzero/redeems.d.ts +20 -0
  269. package/lib/services/layerzero/redeems.js +92 -0
  270. package/lib/services/layerzero/utils.d.ts +9 -0
  271. package/lib/services/layerzero/utils.js +22 -0
  272. package/lib/services/octavfi/fetcher.d.ts +9 -0
  273. package/lib/services/octavfi/fetcher.js +103 -0
  274. package/lib/services/octavfi/index.d.ts +3 -0
  275. package/lib/services/octavfi/index.js +20 -0
  276. package/lib/services/octavfi/types.d.ts +34 -0
  277. package/lib/services/octavfi/types.js +3 -0
  278. package/lib/services/octavfi/utils.d.ts +16 -0
  279. package/lib/services/octavfi/utils.js +212 -0
  280. package/lib/services/subgraph/fetcher.d.ts +2 -0
  281. package/lib/services/subgraph/fetcher.js +61 -0
  282. package/lib/services/subgraph/index.d.ts +2 -0
  283. package/lib/services/subgraph/index.js +19 -0
  284. package/lib/services/subgraph/schema.d.ts +45 -0
  285. package/lib/services/subgraph/schema.js +75 -0
  286. package/lib/services/subgraph/vaults.d.ts +25 -0
  287. package/lib/services/subgraph/vaults.js +1106 -0
  288. package/lib/services/swap-quotes/index.d.ts +105 -0
  289. package/lib/services/swap-quotes/index.js +77 -0
  290. package/lib/services/swap-quotes/paraswap.d.ts +51 -0
  291. package/lib/services/swap-quotes/paraswap.js +138 -0
  292. package/lib/types/api.d.ts +280 -0
  293. package/lib/types/api.js +3 -0
  294. package/lib/types/index.d.ts +12 -0
  295. package/lib/types/index.js +28 -0
  296. package/lib/types/points.d.ts +28 -0
  297. package/lib/types/points.js +3 -0
  298. package/lib/types/pools.d.ts +144 -0
  299. package/lib/types/pools.js +3 -0
  300. package/lib/types/staking.d.ts +28 -0
  301. package/lib/types/staking.js +3 -0
  302. package/lib/types/sub-accounts.d.ts +140 -0
  303. package/lib/types/sub-accounts.js +3 -0
  304. package/lib/types/subgraph.d.ts +74 -0
  305. package/lib/types/subgraph.js +3 -0
  306. package/lib/types/typed-contract.d.ts +102 -0
  307. package/lib/types/typed-contract.js +3 -0
  308. package/lib/types/user.d.ts +1 -0
  309. package/lib/types/user.js +3 -0
  310. package/lib/types/vaults.d.ts +714 -0
  311. package/lib/types/vaults.js +24 -0
  312. package/lib/types/web3.d.ts +51 -0
  313. package/lib/types/web3.js +14 -0
  314. package/lib/types/webserver.d.ts +698 -0
  315. package/lib/types/webserver.js +3 -0
  316. package/package.json +78 -0
@@ -0,0 +1,1623 @@
1
+ "use strict";
2
+ /**
3
+ * The August Vaults Module.
4
+ *
5
+ * @module AugustVaults
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
25
+ };
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ var __importDefault = (this && this.__importDefault) || function (mod) {
44
+ return (mod && mod.__esModule) ? mod : { "default": mod };
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.AugustVaults = void 0;
48
+ /**
49
+ * Export getters
50
+ */
51
+ __exportStar(require("./getters"), exports);
52
+ /**
53
+ * AugustVaults class
54
+ */
55
+ const fetcher_1 = require("./fetcher");
56
+ const ethers_1 = require("ethers");
57
+ const getters_1 = require("./getters");
58
+ const vaults_1 = require("../../services/subgraph/vaults");
59
+ const deposits_1 = require("../../services/layerzero/deposits");
60
+ const redeems_1 = require("../../services/layerzero/redeems");
61
+ const core_1 = require("../../core");
62
+ const utils_1 = require("../../adapters/solana/utils");
63
+ const utils_2 = require("../../adapters/stellar/utils");
64
+ const sui_1 = __importDefault(require("../../adapters/sui"));
65
+ const constants_1 = require("../../adapters/sui/constants");
66
+ const vaults_2 = require("../../core/constants/vaults");
67
+ const write_actions_1 = require("./write.actions");
68
+ const read_actions_1 = require("./read.actions");
69
+ const prefetch_1 = require("./prefetch");
70
+ /**
71
+ * Vault operations class handling multi-chain vault queries and user positions.
72
+ * Supports both EVM and Solana vaults with unified interface.
73
+ */
74
+ class AugustVaults extends core_1.AugustBase {
75
+ solanaService;
76
+ suiService;
77
+ headers = null;
78
+ /**
79
+ * Consumer-supplied Soroban RPC override for Stellar vault reads, with the
80
+ * network it was configured for so it's only applied to matching-network
81
+ * vaults (see `IVaultBaseOptions.stellarRpc`).
82
+ */
83
+ _stellarRpc;
84
+ constructor(baseConfig, solana, sui) {
85
+ super(baseConfig);
86
+ this.solanaService = solana;
87
+ this.suiService = sui || new sui_1.default();
88
+ // Network defaults to mainnet, matching the StellarAdapter constructor.
89
+ this._stellarRpc = baseConfig.stellar?.rpcUrl
90
+ ? {
91
+ rpcUrl: baseConfig.stellar.rpcUrl,
92
+ network: baseConfig.stellar.network ?? 'mainnet',
93
+ }
94
+ : undefined;
95
+ this.headers = {
96
+ 'x-environment': this.monitoring?.['x-environment'],
97
+ 'x-user-id': this.monitoring?.['x-user-id'],
98
+ };
99
+ }
100
+ /**
101
+ * @description deposit underlying token into the specified pool with adapter support. This is for when we cannot pass in a signer in sdk and need to do so as an arg
102
+ * @param signer signer / wallet object
103
+ * @param options object including pool contract address, user wallet address, string amount, and optional depositAsset
104
+ * @returns deposit tx hash
105
+ */
106
+ async vaultDeposit(signer, options) {
107
+ return (0, write_actions_1.vaultDeposit)(signer, options);
108
+ }
109
+ /**
110
+ * @description deposit native token (ETH/AVAX/etc) into a vault using MultiAssetNativeDepositWrapper
111
+ * @param signer signer / wallet object
112
+ * @param options object including wrapper contract address, receiver address (optional), and amount
113
+ * @returns deposit tx hash
114
+ */
115
+ async depositNative(signer, options) {
116
+ return (0, write_actions_1.depositNative)(signer, options);
117
+ }
118
+ /**
119
+ * Fetch all vaults across configured networks with optional enrichment.
120
+ * Automatically filters by available providers and optionally by chain IDs.
121
+ * Includes closed vaults that are still visible (`status: 'closed'`,
122
+ * `is_visible: true`) so consumers can render positions held in closed
123
+ * vaults; closed vaults with `is_visible: false` are excluded.
124
+ *
125
+ * RPC volume (worst case, wallet enrichment path): the per-vault
126
+ * `balanceOf`/`lagDuration` reads are aggregated into chunked Multicall3
127
+ * `aggregate3` batches per chain (10 calls per chunk) on chains where the
128
+ * canonical Multicall3 deployment is verified; other chains (e.g. Citrea
129
+ * 4114) keep one `eth_call` per read. Measured with
130
+ * `benchmarks/request-counter.js` on a cold cache for a wallet with 62
131
+ * vaults across Ethereum + Avalanche: 83 RPC HTTP requests before batching,
132
+ * 54 after (~35% fewer; 124 per-vault `eth_call`s collapse into ~13
133
+ * `aggregate3` calls — the remaining requests are the per-vault cached
134
+ * decimals/receipt-token reads on a cold cache).
135
+ * @param options Filtering and enrichment configuration
136
+ * @returns Array of vault objects with optional loans/allocations/positions
137
+ */
138
+ async getVaults(options) {
139
+ // if (!(this.authorized && this.augustKey)) // @todo: commented out for integrators
140
+ const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, options?.loadSubaccounts, options?.loadSnapshots);
141
+ const vaultsPerAvailableProviders = allVaults.filter((v) =>
142
+ // Stellar vaults are backend-only (no RPC provider required)
143
+ v?.chain_type === 'stellar' ||
144
+ // Solana vaults use this.solanaService (not this.providers). Without
145
+ // an explicit pass-through here they get silently dropped on any
146
+ // instance whose ACTIVE_RPC_URLS() doesn't register chainId -1.
147
+ // Gate on solanaService presence so we don't let a vault through that
148
+ // we have no adapter to fetch — that would crash the inner getter and
149
+ // turn into a PENDING entry that the final filter drops anyway.
150
+ (v?.chain_type === 'solana' && !!this.solanaService) ||
151
+ (this.providers?.[v?.chain] ? true : false));
152
+ const vaultsPerChainId = options?.chainIds
153
+ ? vaultsPerAvailableProviders.filter((v) => options.chainIds.includes(v.chain))
154
+ : vaultsPerAvailableProviders;
155
+ // Fetch and transform (filter for active status)
156
+ const emberVaults = await this.suiService.getEmberVaults({
157
+ status: 'active',
158
+ });
159
+ const activeEmberVaults = Array.isArray(emberVaults)
160
+ ? emberVaults.filter((v) => v?.status === 'active')
161
+ : [];
162
+ const whitelistedEmberVaults = activeEmberVaults.filter((v) => {
163
+ if (!v?.address)
164
+ return false;
165
+ const normalizedAddress = v.address.toLowerCase().trim();
166
+ return constants_1.ALLOWED_SUI_VAULT_ADDRESSES.includes(normalizedAddress);
167
+ });
168
+ const transformedVaults = this.suiService.transformEmberVaultsToIVaults(whitelistedEmberVaults);
169
+ // Use comprehensive vault fetching for maximum coverage
170
+ const vaultFetchResult = await (0, fetcher_1.fetchVaultsComprehensive)(vaultsPerChainId, async (vault) => {
171
+ // Handle fallback RPC if provided
172
+ const rpcUrl = vault.fallbackRpc || this.providers?.[vault.chain];
173
+ // Closed vaults have no live loans/allocations. In portfolio mode,
174
+ // skip that enrichment so a closed vault is never dropped just because
175
+ // getVaultAllocations re-throws (no debank data / no subaccounts).
176
+ const isClosedVault = vault.status === 'closed';
177
+ const skipClosedEnrichment = !!options?.includeClosed && isClosedVault;
178
+ // Handle minimal data fetching
179
+ const shouldFetchLoans = !skipClosedEnrichment &&
180
+ !vault.minimal &&
181
+ (typeof options?.loans !== 'undefined' ? options?.loans : true);
182
+ const shouldFetchAllocations = !skipClosedEnrichment &&
183
+ !vault.minimal &&
184
+ (typeof options?.allocations !== 'undefined'
185
+ ? options?.allocations
186
+ : true);
187
+ const v = await (0, getters_1.getVault)({
188
+ vault: vault.address,
189
+ loans: shouldFetchLoans,
190
+ allocations: shouldFetchAllocations,
191
+ options: {
192
+ rpcUrl,
193
+ solanaService: this.solanaService,
194
+ stellarRpc: this._stellarRpc,
195
+ env: this.monitoring?.env,
196
+ augustKey: this.keys?.august,
197
+ subgraphKey: this.keys?.graph,
198
+ // Portfolio mode: let the EVM getter resolve closed + invisible
199
+ // vaults instead of null-ing them, so the closed vault survives.
200
+ includeClosed: options?.includeClosed,
201
+ },
202
+ loadSubaccounts: options?.loadSubaccounts,
203
+ loadSnapshots: options?.loadSnapshots,
204
+ });
205
+ return v;
206
+ }, {
207
+ maxRetries: 5,
208
+ baseDelay: 2000,
209
+ batchSize: 15,
210
+ parallelLimit: 8,
211
+ includeClosed: true,
212
+ includeInvisible: false,
213
+ timeout: 60000,
214
+ fallbackRpcUrls: {
215
+ // Use configured fallback RPC endpoints for each chain
216
+ 1: (0, core_1.getFallbackRpcUrls)(1),
217
+ 56: (0, core_1.getFallbackRpcUrls)(56),
218
+ 43114: (0, core_1.getFallbackRpcUrls)(43114),
219
+ 8453: (0, core_1.getFallbackRpcUrls)(8453),
220
+ 42161: (0, core_1.getFallbackRpcUrls)(42161),
221
+ 137: (0, core_1.getFallbackRpcUrls)(137),
222
+ // [SPECIAL_CHAINS.solana.chainId]: getFallbackRpcUrls(SPECIAL_CHAINS.solana.chainId),
223
+ },
224
+ });
225
+ // Log vault fetching results in DEV mode
226
+ core_1.Logger.log.info('getVaults', `Total: ${vaultFetchResult.coverageReport.totalVaults}, ` +
227
+ `Success: ${vaultFetchResult.coverageReport.successfulVaults}, ` +
228
+ `Failed: ${vaultFetchResult.coverageReport.failedVaults}, ` +
229
+ `Rate: ${vaultFetchResult.successRate.toFixed(2)}%`);
230
+ if (vaultFetchResult.coverageReport.failedVaults > 0) {
231
+ core_1.Logger.log.warn('getVaults:failed', vaultFetchResult.failed.map((f) => ({
232
+ address: f.address,
233
+ chain: f.chain,
234
+ error: f.error.message,
235
+ attempts: f.attempts,
236
+ })));
237
+ }
238
+ // Use intelligent filtering to preserve more vaults
239
+ const vaultResponses = vaultFetchResult.successful
240
+ .sort((a, b) => a.index - b.index)
241
+ .map((item) => item.data);
242
+ const filteredResults = (0, fetcher_1.filterVaultsIntelligently)(vaultResponses, {
243
+ includeClosed: true,
244
+ includeInvisible: true,
245
+ minStatus: ['active', 'closed'],
246
+ });
247
+ // Closed vaults are included in the result ONLY when the caller opts in via
248
+ // `includeClosed` (portfolio mode). By default they are dropped, so the
249
+ // marketplace / discovery callers never receive a closed vault and don't
250
+ // have to filter `status === 'closed'` themselves. The portfolio passes
251
+ // `includeClosed: true` so a user's position in a closed vault can be
252
+ // joined against this list. Note: closed + invisible vaults land in the
253
+ // `closed` bucket (the status check precedes the visibility check in
254
+ // filterVaultsIntelligently), so this single gate covers them too.
255
+ const filteredResponses = [
256
+ ...filteredResults.active,
257
+ ...(options?.includeClosed ? filteredResults.closed : []),
258
+ ...filteredResults.invisible,
259
+ ];
260
+ if ((options.wallet && (0, ethers_1.isAddress)(options.wallet)) ||
261
+ (options.solanaWallet &&
262
+ utils_1.SolanaUtils.isSolanaAddress(options.solanaWallet))) {
263
+ // Batch the per-vault balanceOf/lagDuration reads (Multicall3, grouped
264
+ // by chain) before fanning out — vaults the batch couldn't serve fall
265
+ // back to their own reads inside getVaultPositions.
266
+ const prefetchedReads = await (0, prefetch_1.prefetchVaultPositionReads)({
267
+ vaults: vaultsPerAvailableProviders,
268
+ wallet: options.wallet,
269
+ providers: this.providers,
270
+ });
271
+ // fetch all positions for user wallet
272
+ const vaultResponses = await (0, core_1.promiseSettle)(vaultsPerAvailableProviders.map((v) => (0, getters_1.getVaultPositions)({
273
+ vault: v.address,
274
+ wallet: options.wallet,
275
+ solanaWallet: options.solanaWallet,
276
+ stellarWallet: options.stellarWallet,
277
+ options: {
278
+ rpcUrl: this.providers?.[v.chain],
279
+ solanaService: this.solanaService,
280
+ stellarRpc: this._stellarRpc,
281
+ env: this.monitoring?.env,
282
+ augustKey: this.keys?.august,
283
+ subgraphKey: this.keys?.graph,
284
+ },
285
+ prefetchedReads: prefetchedReads.get(String(v.address).toLowerCase()),
286
+ })), 5, // 5 retries
287
+ 2000);
288
+ // return vault object with position property
289
+ const positions = vaultResponses
290
+ .flat()
291
+ .filter((v) => v.status !== 'PENDING');
292
+ return filteredResponses.map((r) => ({
293
+ ...r,
294
+ position: positions?.find((pos) => pos.vault?.toLowerCase() === r.address?.toLowerCase()) || null,
295
+ }));
296
+ }
297
+ if (options.wallet && !(0, ethers_1.isAddress)(options.wallet)) {
298
+ core_1.Logger.log.warn('getVaults:invalid_wallet', options.wallet);
299
+ }
300
+ // console.log(`#getVaults:`, filteredResponses);
301
+ return [...filteredResponses, ...transformedVaults];
302
+ }
303
+ /**
304
+ * Calculate total deposited across all tokenized vaults by summing latest_reported_tvl.
305
+ * Uses the /tokenized_vault endpoint which returns latest_reported_tvl in USD.
306
+ * @param options Optional configuration for loading vaults
307
+ * @returns Total deposited amount in USD (sum of all latest_reported_tvl values)
308
+ */
309
+ async getTotalDeposited(options) {
310
+ const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, options?.loadSubaccounts, options?.loadSnapshots);
311
+ let total = 0;
312
+ allVaults.forEach((vault) => {
313
+ if (vaults_2.TVL_EXCLUDED_VAULTS.has(vault.address?.toLowerCase()))
314
+ return;
315
+ if (vault.latest_reported_tvl !== null &&
316
+ vault.latest_reported_tvl !== undefined) {
317
+ total += vault.latest_reported_tvl;
318
+ }
319
+ });
320
+ return total;
321
+ }
322
+ /**
323
+ * Fetch detailed data for a single vault with optional enrichment.
324
+ * Automatically includes loans and allocations unless explicitly disabled.
325
+ * @param vault Vault contract address
326
+ * @param chainId Optional chain ID (uses active network if not provided)
327
+ * @param options Enrichment and wallet options
328
+ * @returns Single vault object with optional position data
329
+ * @throws {@link AugustValidationError} (`INVALID_CHAIN`) when `chainId` is
330
+ * not a chain the SDK recognises, or is a supported EVM chain with no RPC
331
+ * URL configured on this SDK instance.
332
+ */
333
+ async getVault({ vault, chainId, options, loadSubaccounts, loadSnapshots, }) {
334
+ if (!vault)
335
+ throw new Error('Vault input parameter is undefined.');
336
+ // if (!isAddress(vault))
337
+ // throw new Error(
338
+ // `Vault input parameter is not an address: ${String(vault)}`,
339
+ // );
340
+ (0, core_1.assertKnownChainId)(chainId, this.providers, 'getVault');
341
+ (0, core_1.assertEvmProviderConfigured)(chainId, this.providers, 'getVault');
342
+ // get vault data
343
+ const vaultResponse = await (0, getters_1.getVault)({
344
+ vault: vault,
345
+ loans: typeof options?.loans !== 'undefined' ? options?.loans : true,
346
+ allocations: typeof options?.allocations !== 'undefined'
347
+ ? options?.allocations
348
+ : true,
349
+ options: {
350
+ rpcUrl: chainId
351
+ ? this.providers?.[chainId]
352
+ : this.activeNetwork?.rpcUrl,
353
+ solanaService: this.solanaService,
354
+ stellarRpc: this._stellarRpc,
355
+ env: this.monitoring?.env,
356
+ augustKey: this.keys?.august,
357
+ subgraphKey: this.keys?.graph,
358
+ headers: this.headers,
359
+ },
360
+ loadSubaccounts,
361
+ loadSnapshots,
362
+ });
363
+ if (((0, ethers_1.isAddress)(vault) || (0, utils_2.isStellarAddress)(vault)) &&
364
+ ((options?.wallet && (0, ethers_1.isAddress)(options?.wallet)) ||
365
+ (options?.solanaWallet &&
366
+ utils_1.SolanaUtils.isSolanaAddress(options?.solanaWallet)) ||
367
+ (options?.stellarWallet && (0, utils_2.isStellarAddress)(options?.stellarWallet)))) {
368
+ // fetch all positions for user wallet
369
+ const vaultResponses = await (0, getters_1.getVaultPositions)({
370
+ vault: vault,
371
+ solanaWallet: options?.solanaWallet,
372
+ stellarWallet: options?.stellarWallet,
373
+ wallet: options?.wallet,
374
+ options: {
375
+ rpcUrl: chainId
376
+ ? this.providers?.[chainId]
377
+ : this.activeNetwork?.rpcUrl,
378
+ solanaService: this.solanaService,
379
+ stellarRpc: this._stellarRpc,
380
+ env: this.monitoring?.env,
381
+ augustKey: this.keys?.august,
382
+ subgraphKey: this.keys?.graph,
383
+ headers: this.headers,
384
+ },
385
+ });
386
+ // return vault object with position property
387
+ const positions = vaultResponses.filter((v) => v.status !== 'PENDING');
388
+ return {
389
+ ...vaultResponse,
390
+ position: positions?.find((pos) => pos.vault?.toLowerCase() === vault?.toLowerCase()) || null,
391
+ };
392
+ }
393
+ if (options?.wallet && !(0, ethers_1.isAddress)(options?.wallet)) {
394
+ core_1.Logger.log.warn('getVault:invalid_wallet', options?.wallet);
395
+ }
396
+ // console.log(`#getVault::${vaultResponse.symbol}:`, vaultResponse);
397
+ return vaultResponse;
398
+ }
399
+ /**
400
+ * Fetch the active loans issued by a vault.
401
+ * @param vault Vault contract address
402
+ * @param chainId Optional chain ID (uses active network if not provided)
403
+ * @returns Loan data for the vault
404
+ * @throws {@link AugustValidationError} (`INVALID_CHAIN`) when `chainId` is
405
+ * not a chain the SDK recognises, or is a supported EVM chain with no RPC
406
+ * URL configured on this SDK instance.
407
+ */
408
+ async getVaultLoans({ vault, chainId, }) {
409
+ // Sanitize
410
+ // if (!this.authorized) throw new Error('Not authorized.');
411
+ if (!vault)
412
+ throw new Error('Vault input parameter is undefined.');
413
+ if (!(0, ethers_1.isAddress)(vault))
414
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
415
+ (0, core_1.assertKnownChainId)(chainId, this.providers, 'getVaultLoans');
416
+ (0, core_1.assertEvmProviderConfigured)(chainId, this.providers, 'getVaultLoans');
417
+ // get vault loans data
418
+ const vaultResponse = await (0, getters_1.getVaultLoans)(vault, {
419
+ rpcUrl: chainId
420
+ ? this.providers?.[chainId]
421
+ : this.requireActiveNetwork().rpcUrl,
422
+ env: this.monitoring?.env,
423
+ augustKey: this.keys?.august,
424
+ subgraphKey: this.keys?.graph,
425
+ chainId: chainId,
426
+ solanaService: this.solanaService,
427
+ stellarRpc: this._stellarRpc,
428
+ headers: this.headers,
429
+ });
430
+ return vaultResponse;
431
+ }
432
+ /**
433
+ * Fetch a vault's loans broken down by sub-account.
434
+ * @param vault Vault contract address
435
+ * @param chainId Optional chain ID (uses active network if not provided)
436
+ * @returns Sub-account loan data for the vault
437
+ * @throws {@link AugustValidationError} (`INVALID_CHAIN`) when `chainId` is
438
+ * not a chain the SDK recognises, or is a supported EVM chain with no RPC
439
+ * URL configured on this SDK instance.
440
+ */
441
+ async getVaultSubaccountLoans({ vault, chainId, }) {
442
+ // Sanitize
443
+ if (!vault)
444
+ throw new Error('Vault input parameter is undefined.');
445
+ if (!(0, ethers_1.isAddress)(vault))
446
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
447
+ (0, core_1.assertKnownChainId)(chainId, this.providers, 'getVaultSubaccountLoans');
448
+ (0, core_1.assertEvmProviderConfigured)(chainId, this.providers, 'getVaultSubaccountLoans');
449
+ // get vault subaccount loans data
450
+ const vaultResponse = await (0, getters_1.getVaultSubaccountLoans)(vault, {
451
+ rpcUrl: chainId
452
+ ? this.providers?.[chainId]
453
+ : this.requireActiveNetwork().rpcUrl,
454
+ env: this.monitoring?.env,
455
+ augustKey: this.keys?.august,
456
+ subgraphKey: this.keys?.graph,
457
+ chainId: chainId,
458
+ solanaService: this.solanaService,
459
+ stellarRpc: this._stellarRpc,
460
+ headers: this.headers,
461
+ });
462
+ return vaultResponse;
463
+ }
464
+ /**
465
+ * Fetch a vault's DeFi / CeFi / OTC allocation breakdown.
466
+ * @param vault Vault contract address
467
+ * @param chainId Optional chain ID (uses active network if not provided)
468
+ * @returns Allocation data for the vault
469
+ * @throws {@link AugustValidationError} (`INVALID_CHAIN`) when `chainId` is
470
+ * not a chain the SDK recognises, or is a supported EVM chain with no RPC
471
+ * URL configured on this SDK instance.
472
+ */
473
+ async getVaultAllocations({ vault, chainId, }) {
474
+ // Sanitize
475
+ // if (!this.authorized) throw new Error('Not authorized.');
476
+ if (!vault)
477
+ throw new Error('Vault input parameter is undefined.');
478
+ if (!(0, ethers_1.isAddress)(vault) &&
479
+ !utils_1.SolanaUtils.isSolanaAddress(vault) &&
480
+ !(0, utils_2.isStellarAddress)(vault))
481
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
482
+ (0, core_1.assertKnownChainId)(chainId, this.providers, 'getVaultAllocations');
483
+ (0, core_1.assertEvmProviderConfigured)(chainId, this.providers, 'getVaultAllocations');
484
+ // get vault allocations data
485
+ try {
486
+ const vaultResponse = await (0, getters_1.getVaultAllocations)(vault, {
487
+ rpcUrl: chainId
488
+ ? this.providers?.[chainId]
489
+ : this.activeNetwork?.rpcUrl,
490
+ solanaService: this.solanaService,
491
+ stellarRpc: this._stellarRpc,
492
+ env: this.monitoring?.env,
493
+ augustKey: this.keys?.august,
494
+ subgraphKey: this.keys?.graph,
495
+ headers: this.headers,
496
+ });
497
+ return vaultResponse;
498
+ }
499
+ catch (e) {
500
+ const err = e;
501
+ if (err.message.includes('debank')) {
502
+ return {
503
+ status: 400,
504
+ message: 'There was an error fetching from debank',
505
+ };
506
+ }
507
+ return {
508
+ status: 400,
509
+ message: 'There was an error fetching vaults',
510
+ };
511
+ }
512
+ }
513
+ /**
514
+ * @deprecated use getVaultHistoricalTimeseries instead
515
+ * @function getVaultApy gets the vault/pool APR, both current and historical
516
+ * @param vault pool/vault contract address
517
+ * @param historical (optional) When passed, returns the historical records of the pool/vault APR
518
+ * @returns a value or array of objects containing the APR and timestamp
519
+ */
520
+ async getVaultApy({ vault, historical, }) {
521
+ // if (!this.authorized) throw new Error('Not authorized.');
522
+ if (!vault)
523
+ throw new Error('Vault input parameter is undefined.');
524
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault))
525
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
526
+ return await (0, getters_1.getVaultApy)({
527
+ vault,
528
+ historical,
529
+ options: {
530
+ rpcUrl: this.activeNetwork?.rpcUrl,
531
+ subgraphKey: this.keys?.graph,
532
+ headers: this.headers,
533
+ },
534
+ });
535
+ }
536
+ /**
537
+ * @function getVaultHistoricalTimeseries gets historical timeseries data for a vault
538
+ * @param vault Vault contract address
539
+ * @param nDays Number of days of historical data (default 30, min 1)
540
+ * @returns Historical timeseries data with TVL, APY, PnL, share price, and other metrics
541
+ */
542
+ async getVaultHistoricalTimeseries({ vault, nDays, }) {
543
+ if (!vault)
544
+ throw new Error('Vault input parameter is undefined.');
545
+ return await (0, getters_1.getVaultHistoricalTimeseries)({
546
+ vault,
547
+ nDays,
548
+ options: {
549
+ rpcUrl: this.activeNetwork?.rpcUrl,
550
+ headers: this.headers,
551
+ },
552
+ });
553
+ }
554
+ /**
555
+ *
556
+ */
557
+ async getVaultAvailableRedemptions({ vault, chainId, wallet, verbose, }) {
558
+ if (!this.authorized)
559
+ throw new Error('Not authorized.');
560
+ if (!vault)
561
+ throw new Error('Vault input parameter is undefined.');
562
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault))
563
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
564
+ return await (0, getters_1.getVaultAvailableRedemptions)({
565
+ vault,
566
+ wallet,
567
+ options: {
568
+ rpcUrl: chainId
569
+ ? this.providers?.[chainId]
570
+ : this.activeNetwork?.rpcUrl,
571
+ solanaService: this.solanaService,
572
+ stellarRpc: this._stellarRpc,
573
+ env: this.monitoring?.env,
574
+ augustKey: this.keys?.august,
575
+ subgraphKey: this.keys?.graph,
576
+ headers: this.headers,
577
+ verbose: verbose,
578
+ },
579
+ });
580
+ }
581
+ /**
582
+ * Historical redemption requests for a vault (settled, cancelled, and
583
+ * pending-but-out-of-window). Filterable by wallet.
584
+ *
585
+ * Stellar vaults return `[]` — on-chain redemption history is not yet
586
+ * indexed for that adapter.
587
+ *
588
+ * @param vault - Vault address (EVM or Stellar). Stellar input is
589
+ * accepted but always resolves to an empty array for now.
590
+ * @param chainId - Chain id to resolve the RPC URL against. Falls
591
+ * back to the active network.
592
+ * @param wallet - Optional EVM wallet filter; when omitted the
593
+ * response includes every wallet that has ever redeemed against
594
+ * the vault.
595
+ * @param lookbackBlocks - How far back to scan for redemption logs.
596
+ * Defaults to the SDK's internal lookback when omitted.
597
+ * @returns The same array shape `getVaultRedemptionHistory` returns
598
+ * at the module level — historical redemption records, newest
599
+ * first.
600
+ *
601
+ * @example
602
+ * ```ts
603
+ * const history = await sdk.vaultsModule.getVaultRedemptionHistory({
604
+ * vault: '0xVault',
605
+ * chainId: 8453,
606
+ * wallet: '0xWallet',
607
+ * });
608
+ * ```
609
+ */
610
+ async getVaultRedemptionHistory({ vault, chainId, wallet, lookbackBlocks, }) {
611
+ if (!this.authorized)
612
+ throw new Error('Not authorized.');
613
+ if (!vault)
614
+ throw new Error('Vault input parameter is undefined.');
615
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault)) {
616
+ throw new Error(`Vault input parameter is not an address: ${String(vault)}`);
617
+ }
618
+ return await (0, getters_1.getVaultRedemptionHistory)({
619
+ vault,
620
+ wallet,
621
+ lookbackBlocks,
622
+ options: {
623
+ rpcUrl: chainId
624
+ ? this.providers?.[chainId]
625
+ : this.activeNetwork?.rpcUrl,
626
+ env: this.monitoring?.env,
627
+ augustKey: this.keys?.august,
628
+ subgraphKey: this.keys?.graph,
629
+ headers: this.headers,
630
+ },
631
+ });
632
+ }
633
+ /**
634
+ * Fetch the wallet's positions across vaults — a single vault, one chain,
635
+ * or every chain with a configured provider.
636
+ *
637
+ * RPC volume (worst case, multi-vault paths): the two non-cacheable
638
+ * per-vault reads (`balanceOf`, `lagDuration`) are aggregated into chunked
639
+ * Multicall3 `aggregate3` batches per chain (10 calls per chunk) on chains
640
+ * where the canonical deployment is verified; unverified chains (e.g.
641
+ * Citrea 4114) and non-EVM vaults keep one `eth_call` per read. Measured
642
+ * with `benchmarks/request-counter.js` on a cold cache for a wallet with 62
643
+ * vaults across Ethereum + Avalanche: 83 RPC HTTP requests before batching,
644
+ * 54 after (~35% fewer). A vault whose batched read fails (e.g. paused)
645
+ * falls back to its own per-vault reads — never to a zeroed balance.
646
+ */
647
+ async getVaultPositions({ vault, wallet, chainId, showAllVaults, solanaWallet, stellarWallet, options, }) {
648
+ // if (!this.authorized) throw new Error('Not authorized.');
649
+ // Validate that at least one wallet type is provided
650
+ if (solanaWallet && !utils_1.SolanaUtils.isSolanaAddress(solanaWallet)) {
651
+ throw new Error('Solana wallet parameter must be provided and be a valid Solana address');
652
+ }
653
+ // Validate EVM wallet if provided
654
+ if (wallet && !(0, ethers_1.isAddress)(wallet)) {
655
+ throw new Error(`Wallet parameter is not a valid address: ${String(wallet)}`);
656
+ }
657
+ if (vault) {
658
+ const positions = await (0, getters_1.getVaultPositions)({
659
+ vault,
660
+ wallet,
661
+ solanaWallet,
662
+ stellarWallet,
663
+ options: {
664
+ rpcUrl: chainId
665
+ ? this.providers?.[chainId]
666
+ : this.activeNetwork?.rpcUrl,
667
+ solanaService: this.solanaService,
668
+ stellarRpc: this._stellarRpc,
669
+ env: this.monitoring?.env,
670
+ augustKey: this.keys?.august,
671
+ subgraphKey: this.keys?.graph,
672
+ headers: this.headers,
673
+ },
674
+ });
675
+ if (showAllVaults)
676
+ return positions;
677
+ return positions.filter((v) => v?.status !== 'PENDING');
678
+ }
679
+ const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, false, false);
680
+ if (chainId) {
681
+ const vaultsPerChain = allVaults.filter((v) => v.chain === chainId);
682
+ // Batch balanceOf/lagDuration via Multicall3 before the per-vault
683
+ // fan-out; un-batched vaults fall back to their own reads.
684
+ const prefetchedReads = await (0, prefetch_1.prefetchVaultPositionReads)({
685
+ vaults: vaultsPerChain,
686
+ wallet,
687
+ providers: this.providers,
688
+ });
689
+ const vaultResponses = await Promise.all(vaultsPerChain.map((v) => (0, getters_1.getVaultPositions)({
690
+ vault: v.address,
691
+ solanaWallet,
692
+ stellarWallet,
693
+ wallet,
694
+ options: {
695
+ rpcUrl: this.providers?.[v.chain],
696
+ solanaService: this.solanaService,
697
+ stellarRpc: this._stellarRpc,
698
+ env: this.monitoring?.env,
699
+ augustKey: this.keys?.august,
700
+ subgraphKey: this.keys?.graph,
701
+ headers: this.headers,
702
+ },
703
+ prefetchedReads: prefetchedReads.get(String(v.address).toLowerCase()),
704
+ })));
705
+ const flattened = vaultResponses.flat();
706
+ let final;
707
+ if (showAllVaults)
708
+ final = flattened;
709
+ else
710
+ final = flattened.filter((v) => v?.status !== 'PENDING');
711
+ core_1.Logger.log.info(`getPositions::${chainId || 'all'}:`, final.map((v) => v.vault));
712
+ return final;
713
+ }
714
+ const vaultsPerAvailableProviders = allVaults.filter((v) =>
715
+ // Stellar vaults are backend-only (no RPC provider required)
716
+ v?.chain_type === 'stellar' ||
717
+ // Solana vaults use this.solanaService (not this.providers). Without
718
+ // this clause every Solana position is dropped on any instance where
719
+ // ACTIVE_RPC_URLS() doesn't register chainId -1 — which is exactly
720
+ // how the jitoSOL "missing position" regression manifested. Gate on
721
+ // solanaService presence so we don't pass Solana vaults through with
722
+ // no adapter to read them — the inner getter would crash, hit the
723
+ // outer catch, and silently return PENDING (then get filtered out).
724
+ (v?.chain_type === 'solana' && !!this.solanaService) ||
725
+ (this.providers?.[v?.chain] ? true : false));
726
+ // Batch balanceOf/lagDuration via Multicall3, grouped by chain, before
727
+ // the per-vault fan-out; un-batched vaults fall back to their own reads.
728
+ const prefetchedReads = await (0, prefetch_1.prefetchVaultPositionReads)({
729
+ vaults: vaultsPerAvailableProviders,
730
+ wallet,
731
+ providers: this.providers,
732
+ });
733
+ const vaultResponses = await Promise.all(vaultsPerAvailableProviders.map((v) => (0, getters_1.getVaultPositions)({
734
+ vault: v.address,
735
+ solanaWallet,
736
+ stellarWallet,
737
+ wallet,
738
+ options: {
739
+ rpcUrl: this.providers?.[v.chain],
740
+ solanaService: this.solanaService,
741
+ stellarRpc: this._stellarRpc,
742
+ env: this.monitoring?.env,
743
+ augustKey: this.keys?.august,
744
+ subgraphKey: this.keys?.graph,
745
+ headers: this.headers,
746
+ },
747
+ prefetchedReads: prefetchedReads.get(String(v.address).toLowerCase()),
748
+ })));
749
+ const flattened = vaultResponses.flat();
750
+ let final;
751
+ if (showAllVaults)
752
+ final = flattened;
753
+ else
754
+ final = flattened.filter((v) => v?.status !== 'PENDING');
755
+ // console.log(`#getPositions::${chainId || 'all'}:`, final);
756
+ return final;
757
+ }
758
+ /**
759
+ *
760
+ */
761
+ async getUserHistory({ wallet, chainId, vault, }) {
762
+ // Santize
763
+ // if (!this.authorized) throw new Error('Not authorized.');
764
+ if (!(0, ethers_1.isAddress)(wallet))
765
+ throw new Error(`Wallet parameter is not an address: ${String(wallet)}`);
766
+ // Get Chain ID — required for subgraph queries
767
+ const _chainId = chainId || this.activeNetwork?.chainId;
768
+ if (!_chainId) {
769
+ throw new Error('Chain ID is required for getUserHistory. Pass chainId explicitly or configure an active network.');
770
+ }
771
+ // Format history initialization
772
+ let finalArray = [];
773
+ function formatHistory(history) {
774
+ return history.map((h) => ({
775
+ timestamp: Number(h.timestamp_),
776
+ address: h.address,
777
+ amount: (0, core_1.toNormalizedBn)(BigInt(h.amount), h.decimals),
778
+ pool: h.contractId_,
779
+ chainId: _chainId,
780
+ type: h.type,
781
+ transactionHash: h.transactionHash_,
782
+ // Deposit rows on multi-asset (pre-deposit) vaults carry the actual
783
+ // deposited token address; propagate it so consumers render the right
784
+ // asset symbol instead of guessing the vault's first deposit asset.
785
+ assetIn: h.assetIn,
786
+ // withdraw-request rows carry the burned share amount. Normalize with
787
+ // the vault decimals (the share token's own decimals) so UIs can show
788
+ // the receipt-token quantity that was actually burned.
789
+ shares: h.shares
790
+ ? (0, core_1.toNormalizedBn)(BigInt(h.shares), h.decimals)
791
+ : undefined,
792
+ }));
793
+ }
794
+ // Helper function to fetch history for a vault
795
+ // For LayerZero-enabled vaults (coreUSDC, upUSDC), queries BOTH the standard
796
+ // subgraph and the LayerZero subgraph, since deposits can be either same-chain
797
+ // or cross-chain via LayerZero
798
+ const fetchVaultHistory = async (vaultAddress, vaultChainId) => {
799
+ // Always query the standard subgraph
800
+ const provider = (0, core_1.createProvider)(this.providers?.[vaultChainId]);
801
+ const standardHistory = await (0, vaults_1.getSubgraphUserHistory)(wallet, provider, vaultAddress);
802
+ const formattedStandard = formatHistory(standardHistory);
803
+ // If this vault also supports LayerZero cross-chain deposits,
804
+ // query the LayerZero subgraph and merge results
805
+ const layerZeroVaultKey = (0, deposits_1.isLayerZeroVault)(vaultAddress);
806
+ if (layerZeroVaultKey) {
807
+ try {
808
+ const layerZeroDeposits = await (0, deposits_1.queryLayerZeroDeposits)(layerZeroVaultKey, wallet);
809
+ const formattedLayerZero = layerZeroDeposits.map((deposit) => ({
810
+ timestamp: Number(deposit.timestamp_) || 0,
811
+ address: wallet,
812
+ amount: (0, core_1.toNormalizedBn)(BigInt(deposit.assetAmt), deposits_1.LAYERZERO_VAULTS[layerZeroVaultKey].decimals),
813
+ pool: deposits_1.LAYERZERO_VAULTS[layerZeroVaultKey].address,
814
+ chainId: vaultChainId || _chainId,
815
+ type: 'deposit',
816
+ transactionHash: deposit.transactionHash_,
817
+ }));
818
+ // For earnAUSD, also query LayerZero redeems
819
+ let formattedLayerZeroRedeems = [];
820
+ if (layerZeroVaultKey === 'earnAUSD') {
821
+ try {
822
+ const layerZeroRedeems = await (0, redeems_1.queryLayerZeroRedeems)(wallet);
823
+ formattedLayerZeroRedeems = layerZeroRedeems.map((redeem) => ({
824
+ timestamp: Number(redeem.timestamp_) || 0,
825
+ address: wallet,
826
+ amount: (0, core_1.toNormalizedBn)(BigInt(redeem.shareAmt), deposits_1.LAYERZERO_VAULTS[layerZeroVaultKey].decimals),
827
+ pool: deposits_1.LAYERZERO_VAULTS[layerZeroVaultKey].address,
828
+ chainId: vaultChainId || _chainId,
829
+ type: 'redeem',
830
+ transactionHash: redeem.transactionHash_,
831
+ }));
832
+ }
833
+ catch (redeemError) {
834
+ core_1.Logger.log.warn('getUserHistory:layerzero:redeems', `Failed to fetch LayerZero redeems for earnAUSD: ${redeemError.message}`);
835
+ }
836
+ }
837
+ // Deduplicate against standard subgraph history only — LZ deposits and
838
+ // LZ redeems are not deduped against each other because a single tx can
839
+ // legitimately emit both a Deposited and a Redeemed event.
840
+ const seenTxHashes = new Set(formattedStandard.map((h) => h.transactionHash?.toLowerCase()));
841
+ const uniqueLayerZero = formattedLayerZero.filter((h) => !seenTxHashes.has(h.transactionHash?.toLowerCase()));
842
+ const uniqueLayerZeroRedeems = formattedLayerZeroRedeems.filter((h) => !seenTxHashes.has(h.transactionHash?.toLowerCase()));
843
+ return [
844
+ ...formattedStandard,
845
+ ...uniqueLayerZero,
846
+ ...uniqueLayerZeroRedeems,
847
+ ];
848
+ }
849
+ catch (error) {
850
+ // If LayerZero query fails, still return standard history
851
+ core_1.Logger.log.warn('getUserHistory:layerzero', `Failed to fetch LayerZero deposits for ${layerZeroVaultKey}: ${error.message}`);
852
+ return formattedStandard;
853
+ }
854
+ }
855
+ return formattedStandard;
856
+ };
857
+ // If vault is provided, return history for that vault. This path is
858
+ // EVM-only (see fetchVaultHistory → getSubgraphUserHistory); a non-EVM
859
+ // vault address would drive eth_chainId against a Solana/Stellar RPC.
860
+ if (vault) {
861
+ finalArray = (0, ethers_1.isAddress)(vault)
862
+ ? await fetchVaultHistory(vault, chainId)
863
+ : [];
864
+ }
865
+ else {
866
+ // Fetch all vaults
867
+ const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, false, false);
868
+ // If chainId is provided, return history for all vaults on that chain.
869
+ // EVM-only: skip non-EVM (Solana/Stellar) vault addresses.
870
+ if (chainId) {
871
+ const vaultsPerChain = allVaults.filter((v) => v.chain === chainId && (0, ethers_1.isAddress)(v.address));
872
+ const vaultResponses = await Promise.all(vaultsPerChain.map((v) => fetchVaultHistory(v.address, v.chain)));
873
+ const flattened = vaultResponses.flat();
874
+ finalArray = flattened;
875
+ }
876
+ else {
877
+ // Else, fetch all history for all vaults across all initialized chains.
878
+ // Gate on isAddress(v.address): the Solana provider is registered under
879
+ // chainId -1, so without this a Solana vault passes `providers?.[v.chain]`
880
+ // and gets routed into the EVM subgraph path, throwing
881
+ // "eth_chainId is not available on SOLANA_MAINNET" on every fetch.
882
+ // LayerZero vaults query subgraphs directly and don't need a provider.
883
+ const vaultsPerAvailableProviders = allVaults.filter((v) => (0, ethers_1.isAddress)(v.address) &&
884
+ (this.providers?.[v?.chain] || (0, deposits_1.isLayerZeroVault)(v.address)));
885
+ const vaultResponses = await Promise.all(vaultsPerAvailableProviders.map((v) => fetchVaultHistory(v.address, v.chain)));
886
+ const flattened = vaultResponses.flat();
887
+ finalArray = flattened;
888
+ }
889
+ }
890
+ core_1.Logger.log.info('getUserHistory', `${wallet}::${finalArray.length}`);
891
+ return finalArray;
892
+ }
893
+ /**
894
+ * Get lifetime PnL for a user in a specific vault.
895
+ * @param props Vault address, wallet address, and optional chain ID
896
+ * @returns Lifetime PnL data including realized and unrealized PnL
897
+ */
898
+ async getVaultUserLifetimePnl({ vault, wallet, chainId, }) {
899
+ if (!(0, ethers_1.isAddress)(wallet))
900
+ throw new Error(`Wallet parameter is not an address: ${String(wallet)}`);
901
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault))
902
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
903
+ const { getVaultUserLifetimePnl } = await Promise.resolve().then(() => __importStar(require('./getters')));
904
+ return await getVaultUserLifetimePnl({
905
+ vault,
906
+ wallet,
907
+ options: {
908
+ rpcUrl: chainId
909
+ ? this.providers?.[chainId]
910
+ : this.requireActiveNetwork().rpcUrl,
911
+ solanaService: this.solanaService,
912
+ stellarRpc: this._stellarRpc,
913
+ env: this.monitoring?.env,
914
+ augustKey: this.keys?.august,
915
+ subgraphKey: this.keys?.graph,
916
+ headers: this.headers,
917
+ },
918
+ coingeckoKey: this.keys?.coingecko,
919
+ });
920
+ }
921
+ /**
922
+ * Get PnL for a vault (vault-level, not user-specific).
923
+ * Returns the vault's overall profit and loss across all users.
924
+ * @param props Vault address and optional chain ID
925
+ * @returns Vault PnL in USD and notional value
926
+ */
927
+ async getVaultPnl({ vault, chainId, }) {
928
+ if (!(0, ethers_1.isAddress)(vault))
929
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
930
+ const { getVaultPnl } = await Promise.resolve().then(() => __importStar(require('./getters')));
931
+ return await getVaultPnl({
932
+ vault,
933
+ options: {
934
+ rpcUrl: chainId
935
+ ? this.providers?.[chainId]
936
+ : this.requireActiveNetwork().rpcUrl,
937
+ solanaService: this.solanaService,
938
+ stellarRpc: this._stellarRpc,
939
+ env: this.monitoring?.env,
940
+ augustKey: this.keys?.august,
941
+ subgraphKey: this.keys?.graph,
942
+ headers: this.headers,
943
+ },
944
+ });
945
+ }
946
+ /**
947
+ *
948
+ */
949
+ async getUserTransfers({ wallet, chainId, vault, options, }) {
950
+ // Santize
951
+ // if (!this.authorized) throw new Error('Not authorized.');
952
+ if (!(0, ethers_1.isAddress)(wallet))
953
+ throw new Error(`Wallet parameter is not an address: ${String(wallet)}`);
954
+ // Format history initialization
955
+ let finalArray = [];
956
+ function formatTransfers(transfers) {
957
+ return transfers.map((t) => ({
958
+ id: t.id,
959
+ value: t.value,
960
+ to: t.to,
961
+ from: t.from,
962
+ pool: t.contractId_,
963
+ block: Number(t.block_number),
964
+ timestamp: Number(t.timestamp_),
965
+ transactionHash: t.transactionHash_,
966
+ }));
967
+ }
968
+ // If vault is provided, return history for that vault
969
+ if (vault) {
970
+ const provider = (0, core_1.createProvider)(this.providers?.[chainId]);
971
+ const userHistory = await (0, vaults_1.getSubgraphUserTransfers)(wallet, provider, vault);
972
+ finalArray = formatTransfers(userHistory);
973
+ }
974
+ else {
975
+ // Fetch all vaults
976
+ const allVaults = await (0, core_1.fetchTokenizedVaults)(undefined, this.headers, false, false);
977
+ // If chainId is provided, return history for all vaults on that chain
978
+ if (chainId) {
979
+ const vaultsPerChain = allVaults.filter((v) => v.chain === chainId);
980
+ const vaultResponses = await Promise.all(vaultsPerChain.map(async (v) => {
981
+ const provider = (0, core_1.createProvider)(this.providers?.[v.chain]);
982
+ const userHistory = await (0, vaults_1.getSubgraphUserTransfers)(wallet, provider, v.address);
983
+ return userHistory;
984
+ }));
985
+ const flattened = vaultResponses.flat();
986
+ finalArray = formatTransfers(flattened);
987
+ }
988
+ else {
989
+ // Else, fetch all history for all vaults across all initialized chains
990
+ const vaultsPerAvailableProviders = allVaults.filter((v) => this.providers?.[v?.chain] ? true : false);
991
+ const vaultResponses = await Promise.all(vaultsPerAvailableProviders.map(async (v) => {
992
+ const provider = (0, core_1.createProvider)(this.providers?.[v.chain]);
993
+ const userHistory = await (0, vaults_1.getSubgraphUserTransfers)(wallet, provider, v.address);
994
+ return userHistory;
995
+ }));
996
+ const flattened = vaultResponses.flat();
997
+ finalArray = formatTransfers(flattened);
998
+ }
999
+ }
1000
+ core_1.Logger.log.info('getUserTransfers', `${wallet}::${finalArray.length}`);
1001
+ return finalArray;
1002
+ }
1003
+ /**
1004
+ * Fetch a vault's deposit/withdrawal activity across every participant.
1005
+ *
1006
+ * This is the vault-wide counterpart to {@link getUserHistory}: instead of
1007
+ * filtering the subgraph to one wallet, it returns every deposit,
1008
+ * withdrawal-request, and processed-withdrawal event for the pool. Use it to
1009
+ * answer flow questions ("how many deposits in the last 7 days", "net flow
1010
+ * this week") that point-in-time TVL cannot.
1011
+ *
1012
+ * Rows are read from the Goldsky subgraph, paginated internally so busy
1013
+ * vaults are not truncated at the 1000-row page cap. When `sinceTs` is
1014
+ * supplied the reader stops paging once it passes the window boundary, so a
1015
+ * short lookback stays cheap even on high-volume vaults.
1016
+ *
1017
+ * @param params - Query parameters.
1018
+ * @param params.vault - Vault (pool) address to read activity for.
1019
+ * @param params.chainId - Chain id of the vault; falls back to the active
1020
+ * network when omitted. Required for the subgraph lookup.
1021
+ * @param params.sinceTs - Lower bound (inclusive) as a Unix timestamp in
1022
+ * seconds. Events at or after this time are returned.
1023
+ * @param params.untilTs - Upper bound (inclusive) as a Unix timestamp in
1024
+ * seconds. Events at or before this time are returned.
1025
+ * @param params.types - Restrict to a subset of event types (e.g.
1026
+ * `['deposit']`). Returns all types when omitted.
1027
+ * @returns Activity items sorted oldest-first, each with a normalized
1028
+ * `amount`, actor `address`, `type`, and `transactionHash`.
1029
+ * @throws If `vault` is not a valid address, or no chain id can be resolved.
1030
+ * @example
1031
+ * ```ts
1032
+ * const weekAgo = Math.floor(Date.now() / 1000) - 7 * 86_400;
1033
+ * const deposits = await sdk.getVaultActivity({
1034
+ * vault: '0x36eDbF0C834591BFdfCaC0Ef9605528c75c406aA',
1035
+ * chainId: 143,
1036
+ * sinceTs: weekAgo,
1037
+ * types: ['deposit'],
1038
+ * });
1039
+ * console.log(`${deposits.length} deposits in the last 7 days`);
1040
+ * ```
1041
+ */
1042
+ async getVaultActivity({ vault, chainId, sinceTs, untilTs, types, }) {
1043
+ if (!(0, ethers_1.isAddress)(vault))
1044
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1045
+ const _chainId = chainId || this.activeNetwork?.chainId;
1046
+ if (!_chainId) {
1047
+ throw new Error('Chain ID is required for getVaultActivity. Pass chainId explicitly or configure an active network.');
1048
+ }
1049
+ const provider = (0, core_1.createProvider)(this.providers?.[_chainId]);
1050
+ const raw = await (0, vaults_1.getSubgraphVaultHistory)(provider, vault, undefined, {
1051
+ sinceTs,
1052
+ });
1053
+ const typeFilter = types?.length ? new Set(types) : undefined;
1054
+ return raw
1055
+ .map((h) => ({
1056
+ timestamp: Number(h.timestamp_),
1057
+ address: h.address,
1058
+ amount: (0, core_1.toNormalizedBn)(BigInt(h.amount), h.decimals),
1059
+ pool: h.contractId_,
1060
+ chainId: _chainId,
1061
+ type: h.type,
1062
+ transactionHash: h.transactionHash_,
1063
+ }))
1064
+ .filter((h) => {
1065
+ if (sinceTs !== undefined && h.timestamp < sinceTs)
1066
+ return false;
1067
+ if (untilTs !== undefined && h.timestamp > untilTs)
1068
+ return false;
1069
+ if (typeFilter && !typeFilter.has(h.type))
1070
+ return false;
1071
+ return true;
1072
+ });
1073
+ }
1074
+ /**
1075
+ * Resolve the ERC-20 tokens currently whitelisted for the `SwapRouter` on a
1076
+ * chain — the any-token set a deposit UI can offer as swap-and-deposit inputs,
1077
+ * each verified `true` against the router's on-chain allowlist.
1078
+ *
1079
+ * Reconstructs the set from the router's `TokenEnabled` event history and
1080
+ * re-checks `whitelistedTokens(token)` for each (the mapping is not
1081
+ * enumerable). See {@link getSwapRouterWhitelistedTokens} for the full
1082
+ * two-stage behavior and RPC cost. Uses this instance's configured provider
1083
+ * for `chainId`; returns `[]` (no RPC) when no router is deployed there or no
1084
+ * provider is configured.
1085
+ *
1086
+ * @param chainId - EVM chain ID to resolve the allowlist for.
1087
+ * @param options - Optional `fromBlock` to override the deploy-block scan floor.
1088
+ * @returns Checksummed whitelisted token addresses; `[]` when unavailable.
1089
+ * Callers still exclude a target vault's natively-accepted assets (those
1090
+ * deposit without a swap).
1091
+ * @throws AugustSDKError when an `eth_getLogs` scan chunk fails.
1092
+ * @example
1093
+ * ```ts
1094
+ * const tokens = await augustSdk.getSwapRouterWhitelistedTokens(1);
1095
+ * ```
1096
+ */
1097
+ async getSwapRouterWhitelistedTokens(chainId, options) {
1098
+ if (!(0, core_1.getSwapRouterAddress)(chainId))
1099
+ return [];
1100
+ const rpcUrl = this.providers?.[chainId];
1101
+ if (!rpcUrl) {
1102
+ core_1.Logger.log.warn('getSwapRouterWhitelistedTokens', `no provider configured for chain ${chainId}`);
1103
+ return [];
1104
+ }
1105
+ return (0, core_1.getSwapRouterWhitelistedTokens)(chainId, {
1106
+ rpcUrl,
1107
+ fromBlock: options?.fromBlock,
1108
+ });
1109
+ }
1110
+ /**
1111
+ * Resolve the vaults currently eligible for the any-token `SwapRouter`
1112
+ * deposit surface on a chain — every vault the router has `enableVault`-ed
1113
+ * whose on-chain registration is still live.
1114
+ *
1115
+ * Reconstructs the set from the router's `VaultEnabled` event history and
1116
+ * re-checks `vaultInfo(vault).referenceAsset != 0` for each (the mapping is
1117
+ * not enumerable). See {@link getSwapRouterEligibleVaults} for the full
1118
+ * two-stage behavior and RPC cost. Uses this instance's configured provider
1119
+ * for `chainId`; returns `[]` (no RPC) when no router is deployed there or no
1120
+ * provider is configured.
1121
+ *
1122
+ * On-chain eligibility only — app-level policy (e.g. excluding vaults with
1123
+ * their own OVault deposit flow) remains the caller's responsibility.
1124
+ *
1125
+ * @param chainId - EVM chain ID to resolve eligible vaults for.
1126
+ * @param options - Optional `fromBlock` to override the deploy-block scan floor.
1127
+ * @returns Checksummed eligible vault addresses; `[]` when unavailable.
1128
+ * @throws AugustSDKError when an `eth_getLogs` scan chunk fails.
1129
+ * @example
1130
+ * ```ts
1131
+ * const vaults = await augustSdk.getSwapRouterEligibleVaults(1);
1132
+ * ```
1133
+ */
1134
+ async getSwapRouterEligibleVaults(chainId, options) {
1135
+ if (!(0, core_1.getSwapRouterAddress)(chainId))
1136
+ return [];
1137
+ const rpcUrl = this.providers?.[chainId];
1138
+ if (!rpcUrl) {
1139
+ core_1.Logger.log.warn('getSwapRouterEligibleVaults', `no provider configured for chain ${chainId}`);
1140
+ return [];
1141
+ }
1142
+ return (0, core_1.getSwapRouterEligibleVaults)(chainId, {
1143
+ rpcUrl,
1144
+ fromBlock: options?.fromBlock,
1145
+ });
1146
+ }
1147
+ /**
1148
+ * @function getStakingPositions gets all available reward staking positions
1149
+ * @param wallet optionally passed user wallet address
1150
+ * @param chainId optionally passed chainId
1151
+ * @returns all available staking positions for connected or passed network(s)
1152
+ */
1153
+ async getStakingPositions(wallet, chainId) {
1154
+ if (chainId) {
1155
+ const positions = await (0, getters_1.getRewardsStakingPositions)({
1156
+ rpcUrl: this.providers?.[chainId] || this.requireActiveNetwork().rpcUrl,
1157
+ wallet,
1158
+ });
1159
+ return positions;
1160
+ }
1161
+ const positions = await Promise.all(Object.values(this.providers).map((rpcUrl) => {
1162
+ return (0, getters_1.getRewardsStakingPositions)({
1163
+ rpcUrl: chainId
1164
+ ? this.providers?.[chainId]
1165
+ : rpcUrl || this.requireActiveNetwork().rpcUrl,
1166
+ wallet,
1167
+ });
1168
+ }));
1169
+ return positions.flat();
1170
+ }
1171
+ /**
1172
+ * @function getVaultTvl gets the vault/pool TVL, both current and historical
1173
+ * @param vault pool/vault contract address
1174
+ * @param historical (optional) When passed, returns the historical records of the pool/vault TVL
1175
+ * @returns an object or array of objects containing the TVL and timestamp
1176
+ */
1177
+ async getVaultTvl({ vault, chainId, historical, }) {
1178
+ if (!this.authorized)
1179
+ throw new Error('Not authorized.');
1180
+ if (!vault)
1181
+ throw new Error('Pool input parameter is undefined.');
1182
+ if (!(0, ethers_1.isAddress)(vault) && !(0, utils_2.isStellarAddress)(vault))
1183
+ throw new Error(`Pool input parameter is not an address: ${String(vault)}`);
1184
+ const resolvedChainId = chainId ?? this.activeNetwork?.chainId;
1185
+ const rpcUrl = chainId
1186
+ ? this.providers?.[chainId]
1187
+ : this.activeNetwork?.rpcUrl;
1188
+ return await (0, getters_1.getVaultTvl)({
1189
+ vault,
1190
+ options: {
1191
+ rpcUrl: rpcUrl,
1192
+ chainId: resolvedChainId,
1193
+ solanaService: this.solanaService,
1194
+ stellarRpc: this._stellarRpc,
1195
+ env: this.monitoring?.env,
1196
+ augustKey: this.keys?.august,
1197
+ subgraphKey: this.keys?.graph,
1198
+ headers: this.headers,
1199
+ },
1200
+ historical: historical,
1201
+ });
1202
+ }
1203
+ /**
1204
+ * @function getYieldLastRealizedOn gets the timestamp when yield was last realized for a vault
1205
+ * @param vault Vault contract address
1206
+ * @param chainId Optional chain ID (uses active network if not provided)
1207
+ * @returns Timestamp (Unix timestamp in seconds) when yield was last realized
1208
+ */
1209
+ async getYieldLastRealizedOn({ vault, chainId, }) {
1210
+ const rpcUrl = chainId
1211
+ ? this.providers?.[chainId]
1212
+ : this.activeNetwork?.rpcUrl;
1213
+ return await (0, getters_1.getYieldLastRealizedOn)({
1214
+ vault,
1215
+ options: {
1216
+ rpcUrl: rpcUrl,
1217
+ solanaService: this.solanaService,
1218
+ stellarRpc: this._stellarRpc,
1219
+ env: this.monitoring?.env,
1220
+ augustKey: this.keys?.august,
1221
+ subgraphKey: this.keys?.graph,
1222
+ headers: this.headers,
1223
+ },
1224
+ });
1225
+ }
1226
+ /**
1227
+ * Gets borrower health-factor data for vaults on a chain, optionally
1228
+ * scoped to a single vault.
1229
+ *
1230
+ * Pass `vault` whenever the caller knows which pool it cares about —
1231
+ * this skips the all-vaults cross-chain fanout and only reads the loans
1232
+ * for that one pool. The response map is keyed by **lowercased** vault
1233
+ * address; look entries up with `address.toLowerCase()`.
1234
+ *
1235
+ * Individual loan failures (bad/test loan contracts, unrecognized
1236
+ * borrowers) are isolated and logged rather than rejecting the batch.
1237
+ *
1238
+ * @param chainId Optional chain to scope the read to. When omitted,
1239
+ * iterates the SDK's configured providers and returns the flattened
1240
+ * list (legacy shape — prefer passing a chain).
1241
+ * @param vault Optional vault address. When provided alongside
1242
+ * `chainId`, only that vault's data is fetched.
1243
+ * @returns When `chainId` is set, an object map of lowercased vault
1244
+ * address → array of borrower-health-factor rows. When `chainId` is
1245
+ * omitted, a flat array (legacy behavior, kept for backward compat).
1246
+ */
1247
+ async getVaultBorrowerHealthFactor(chainId, vault) {
1248
+ if (chainId) {
1249
+ const health_factors = await (0, getters_1.getHealthFactorOfBorrowersByVault)({
1250
+ options: {
1251
+ rpcUrl: this.providers?.[chainId] || this.requireActiveNetwork().rpcUrl,
1252
+ env: this.monitoring?.env,
1253
+ augustKey: this.keys?.august,
1254
+ },
1255
+ vault,
1256
+ });
1257
+ return health_factors;
1258
+ }
1259
+ const health_factors = await Promise.all(Object.values(this.providers).map((rpcUrl) => {
1260
+ return (0, getters_1.getHealthFactorOfBorrowersByVault)({
1261
+ options: {
1262
+ rpcUrl: chainId
1263
+ ? this.providers?.[chainId]
1264
+ : rpcUrl || this.requireActiveNetwork().rpcUrl,
1265
+ solanaService: this.solanaService,
1266
+ stellarRpc: this._stellarRpc,
1267
+ env: this.monitoring?.env,
1268
+ augustKey: this.keys?.august,
1269
+ subgraphKey: this.keys?.graph,
1270
+ headers: this.headers,
1271
+ },
1272
+ vault,
1273
+ });
1274
+ }));
1275
+ return health_factors.flat();
1276
+ }
1277
+ /**
1278
+ * @function getUserPoints fetches user points from the backend API
1279
+ * @param userAddress User wallet address
1280
+ * @returns Points data from the backend API
1281
+ */
1282
+ async getUserPoints(userAddress) {
1283
+ const { getUserPoints } = await Promise.resolve().then(() => __importStar(require('./getters')));
1284
+ return await getUserPoints({
1285
+ userAddress,
1286
+ options: {
1287
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1288
+ env: this.monitoring?.env,
1289
+ augustKey: this.keys?.august,
1290
+ subgraphKey: this.keys?.graph,
1291
+ headers: this.headers,
1292
+ },
1293
+ });
1294
+ }
1295
+ /**
1296
+ * Register a user for the points program, authenticated by a wallet signature.
1297
+ *
1298
+ * The caller produces a personal_sign signature over a canonical message
1299
+ * built from these primitives — see `registerUserForPoints` in
1300
+ * `./getters` for the exact template and a worked example.
1301
+ *
1302
+ * @param userAddress EVM wallet address being registered.
1303
+ * @param referrerAddress Optional referrer EVM address.
1304
+ * @param chainId Chain on which the wallet signed; powers the EIP-1271
1305
+ * fallback for smart-contract wallets and pins the signature cross-chain.
1306
+ * @param signature 0x-prefixed hex personal_sign signature over the canonical message.
1307
+ * @param nonce Single-use random string (8–128 chars).
1308
+ * @param expiry Unix seconds; must be in the future, within the backend's TTL.
1309
+ * @returns Raw `Response` from the backend.
1310
+ */
1311
+ async registerUserForPoints(userAddress, referrerAddress, chainId, signature, nonce, expiry) {
1312
+ const { registerUserForPoints } = await Promise.resolve().then(() => __importStar(require('./getters')));
1313
+ return await registerUserForPoints({
1314
+ userAddress,
1315
+ referrerAddress,
1316
+ chainId,
1317
+ signature,
1318
+ nonce,
1319
+ expiry,
1320
+ options: {
1321
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1322
+ env: this.monitoring?.env,
1323
+ augustKey: this.keys?.august,
1324
+ subgraphKey: this.keys?.graph,
1325
+ headers: this.headers,
1326
+ },
1327
+ });
1328
+ }
1329
+ /**
1330
+ * @function fetchPointsLeaderboard fetches the points leaderboard data
1331
+ * @param params Optional parameters for pagination and sorting
1332
+ * @returns Leaderboard response data
1333
+ */
1334
+ async fetchPointsLeaderboard(params) {
1335
+ const { fetchPointsLeaderboard } = await Promise.resolve().then(() => __importStar(require('./getters')));
1336
+ return await fetchPointsLeaderboard({
1337
+ params,
1338
+ options: {
1339
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1340
+ env: this.monitoring?.env,
1341
+ augustKey: this.keys?.august,
1342
+ subgraphKey: this.keys?.graph,
1343
+ headers: this.headers,
1344
+ },
1345
+ });
1346
+ }
1347
+ /**
1348
+ * Get annualized APY metrics for a vault.
1349
+ *
1350
+ * Supported Vaults: cUSDO, tETH, wstETH, rsETH
1351
+ *
1352
+ * @deprecated The `hgETH30dLiquidAPY` and `hgETH7dLiquidAPY` response fields are deprecated.
1353
+ * These fields will be removed on 2026-01-01.
1354
+ * Use `liquidAPY30Day` and `liquidAPY7Day` fields instead.
1355
+ *
1356
+ * @param vault Vault address
1357
+ * @returns Annualized APY data including liquidity APY
1358
+ */
1359
+ async getVaultAnnualizedApy(vault) {
1360
+ if (!vault)
1361
+ throw new Error('Vault address parameter is undefined.');
1362
+ if (!(0, ethers_1.isAddress)(vault)) {
1363
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1364
+ }
1365
+ const { getVaultAnnualizedApy } = await Promise.resolve().then(() => __importStar(require('./getters')));
1366
+ return await getVaultAnnualizedApy({
1367
+ vault,
1368
+ options: {
1369
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1370
+ env: this.monitoring?.env,
1371
+ augustKey: this.keys?.august,
1372
+ subgraphKey: this.keys?.graph,
1373
+ headers: this.headers,
1374
+ },
1375
+ });
1376
+ }
1377
+ /**
1378
+ * Get summary data for a vault (name, type, chain, recent returns).
1379
+ * @param vault Vault address
1380
+ * @returns Vault summary data
1381
+ */
1382
+ async getVaultSummary(vault) {
1383
+ if (!vault)
1384
+ throw new Error('Vault address parameter is undefined.');
1385
+ if (!(0, ethers_1.isAddress)(vault)) {
1386
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1387
+ }
1388
+ const { getVaultSummary } = await Promise.resolve().then(() => __importStar(require('./getters')));
1389
+ return await getVaultSummary({
1390
+ vault,
1391
+ options: {
1392
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1393
+ env: this.monitoring?.env,
1394
+ augustKey: this.keys?.august,
1395
+ subgraphKey: this.keys?.graph,
1396
+ headers: this.headers,
1397
+ },
1398
+ });
1399
+ }
1400
+ /**
1401
+ * Get withdrawal summary and pending queue for a vault.
1402
+ * @param vault Vault address
1403
+ * @param chainId Chain ID (will be converted to chain name)
1404
+ * @returns Withdrawal summary and pending queue
1405
+ */
1406
+ async getVaultWithdrawals(vault, chainId) {
1407
+ if (!vault)
1408
+ throw new Error('Vault address parameter is undefined.');
1409
+ if (!(0, ethers_1.isAddress)(vault)) {
1410
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1411
+ }
1412
+ const chain = chainId?.toString() || this.requireActiveNetwork().chainId.toString();
1413
+ const { getVaultWithdrawals } = await Promise.resolve().then(() => __importStar(require('./getters')));
1414
+ return await getVaultWithdrawals({
1415
+ vault,
1416
+ chain,
1417
+ options: {
1418
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1419
+ env: this.monitoring?.env,
1420
+ augustKey: this.keys?.august,
1421
+ subgraphKey: this.keys?.graph,
1422
+ headers: this.headers,
1423
+ },
1424
+ });
1425
+ }
1426
+ /**
1427
+ * Fetch pending redemptions for a vault with liquidity analysis.
1428
+ * @param vault - Vault contract address
1429
+ * @param pastDays - Number of past days to include (default 7, min 1, max 30)
1430
+ * @param futureDays - Number of future days to include (default 14, min 1, max 30)
1431
+ * @returns Pending redemptions grouped by date with liquidity summary
1432
+ */
1433
+ async getVaultPendingRedemptions({ vault, pastDays, futureDays, }) {
1434
+ if (!vault)
1435
+ throw new Error('Vault address parameter is undefined.');
1436
+ if (!(0, ethers_1.isAddress)(vault))
1437
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1438
+ const { getVaultPendingRedemptions } = await Promise.resolve().then(() => __importStar(require('./getters')));
1439
+ return await getVaultPendingRedemptions({
1440
+ vault,
1441
+ pastDays,
1442
+ futureDays,
1443
+ options: {
1444
+ rpcUrl: this.requireActiveNetwork().rpcUrl,
1445
+ env: this.monitoring?.env,
1446
+ augustKey: this.keys?.august,
1447
+ subgraphKey: this.keys?.graph,
1448
+ headers: this.headers,
1449
+ },
1450
+ });
1451
+ }
1452
+ /**
1453
+ * Preview the amount of assets that would be received for redeeming shares (queued redemption).
1454
+ * @param vault Vault contract address
1455
+ * @param sharesAmount Amount of shares to redeem (human-readable, raw bigint, or string)
1456
+ * @param chainId Optional chain ID (uses active network if not provided)
1457
+ * @returns The amount of assets as INormalizedNumber { normalized, raw }
1458
+ */
1459
+ async previewRedemption({ vault, sharesAmount, chainId, }) {
1460
+ const rpcUrl = chainId
1461
+ ? this.providers?.[chainId]
1462
+ : this.requireActiveNetwork().rpcUrl;
1463
+ return await (0, getters_1.getPreviewRedemption)({
1464
+ vault,
1465
+ sharesAmount,
1466
+ options: {
1467
+ rpcUrl,
1468
+ headers: this.headers,
1469
+ },
1470
+ });
1471
+ }
1472
+ /**
1473
+ * Get all withdrawal requests for a vault with deterministic status tracking.
1474
+ *
1475
+ * Matches requests to processed events by `(receiver, claimableDate)` tuple.
1476
+ *
1477
+ * **Status values:**
1478
+ * - `'processed'` — Matching `WithdrawalProcessed` event found on-chain.
1479
+ * - `'ready_to_claim'` — Claimable date has passed, no processed event found yet.
1480
+ * - `'pending'` — Claimable date is still in the future.
1481
+ *
1482
+ * **Lookback window:** Processed events are fetched from on-chain logs, which
1483
+ * only cover a finite block range. Requests whose claimable date is older than
1484
+ * this window with no matching processed event are excluded (assumed already
1485
+ * processed). Use `lookbackBlocks` to widen or narrow the scan range.
1486
+ *
1487
+ * @param vault - Vault contract address
1488
+ * @param receiver - Optional receiver address to filter by
1489
+ * @param lookbackBlocks - Optional on-chain log lookback window in blocks.
1490
+ * Defaults to chain-specific value (e.g. 150,000 for Ethereum, 3,456,000 for Monad).
1491
+ * @param chainId - Optional chain id for the vault address
1492
+ * @returns Array of withdrawal requests with status and claimable dates
1493
+ */
1494
+ async getWithdrawalRequestsWithStatus(vault, receiver, lookbackBlocks, chainId) {
1495
+ if (!vault)
1496
+ throw new Error('Vault address parameter is undefined.');
1497
+ if (!(0, ethers_1.isAddress)(vault)) {
1498
+ throw new Error(`Vault parameter is not an address: ${String(vault)}`);
1499
+ }
1500
+ const rpcUrl = (chainId && this.providers?.[chainId]) ||
1501
+ this.requireActiveNetwork().rpcUrl;
1502
+ const { getWithdrawalRequestsWithStatus } = await Promise.resolve().then(() => __importStar(require('./getters')));
1503
+ return await getWithdrawalRequestsWithStatus({
1504
+ vault,
1505
+ receiver,
1506
+ lookbackBlocks,
1507
+ options: {
1508
+ rpcUrl,
1509
+ env: this.monitoring?.env,
1510
+ augustKey: this.keys?.august,
1511
+ subgraphKey: this.keys?.graph,
1512
+ headers: this.headers,
1513
+ },
1514
+ });
1515
+ }
1516
+ /**
1517
+ * Redeem vault shares for an underlying asset via instant redemption (RWA subaccount).
1518
+ * Resolves the vault address to the RwaRedeemSubaccount internally.
1519
+ * Handles vault share approval automatically.
1520
+ * @param signer - Signer / wallet object
1521
+ * @param vault - Vault contract address
1522
+ * @param asset - Redeemable asset address (e.g. USDC, USDT)
1523
+ * @param amount - Amount of vault shares to redeem
1524
+ * @param minOut - Minimum output amount in output asset units (slippage protection)
1525
+ * @param chainId - Optional chain ID (uses active network if not provided)
1526
+ * @param wait - Wait for transaction confirmation
1527
+ * @returns transaction hash
1528
+ */
1529
+ async rwaRedeemAsset(signer, { vault, asset, amount, minOut, chainId, wait, }) {
1530
+ if (!vault)
1531
+ throw new Error('Vault address parameter is undefined.');
1532
+ // Fetch vault data to resolve subaccount address and decimals
1533
+ const vaultData = await (0, getters_1.getVault)({
1534
+ vault,
1535
+ loans: false,
1536
+ allocations: false,
1537
+ options: {
1538
+ rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl,
1539
+ solanaService: this.solanaService,
1540
+ stellarRpc: this._stellarRpc,
1541
+ env: this.monitoring?.env,
1542
+ augustKey: this.keys?.august,
1543
+ subgraphKey: this.keys?.graph,
1544
+ headers: this.headers,
1545
+ },
1546
+ loadSnapshots: false,
1547
+ loadSubaccounts: false,
1548
+ });
1549
+ if (!vaultData?.instant_redeem_config) {
1550
+ throw new Error(`Vault ${vault} does not support instant redemption.`);
1551
+ }
1552
+ const { subaccountAddress, redeemableAssets } = vaultData.instant_redeem_config;
1553
+ // Resolve output asset decimals from config
1554
+ const redeemableAsset = redeemableAssets.find((a) => a.address.toLowerCase() === asset.toLowerCase());
1555
+ if (!redeemableAsset) {
1556
+ throw new Error(`Asset ${asset} is not redeemable for vault ${vault}.`);
1557
+ }
1558
+ const walletAddress = (await signer.getAddress());
1559
+ return (0, write_actions_1.rwaRedeemAsset)(signer, {
1560
+ target: subaccountAddress,
1561
+ wallet: walletAddress,
1562
+ asset,
1563
+ amount,
1564
+ minOut,
1565
+ decimals: vaultData.decimals,
1566
+ outputDecimals: redeemableAsset.decimals,
1567
+ wait,
1568
+ });
1569
+ }
1570
+ /**
1571
+ * Preview the output amount for an RWA instant redemption.
1572
+ * Resolves the vault address to the RwaRedeemSubaccount internally.
1573
+ * @param vault - Vault contract address
1574
+ * @param asset - Redeemable asset address (e.g. USDC, USDT)
1575
+ * @param amount - Amount of vault shares to preview
1576
+ * @param chainId - Optional chain ID (uses active network if not provided)
1577
+ * @returns normalized number of the expected output amount (in output asset decimals)
1578
+ */
1579
+ async previewRwaRedemption({ vault, asset, amount, chainId, }) {
1580
+ if (!vault)
1581
+ throw new Error('Vault address parameter is undefined.');
1582
+ const rpcUrl = chainId
1583
+ ? this.providers?.[chainId]
1584
+ : this.activeNetwork.rpcUrl;
1585
+ // Fetch vault data to resolve subaccount address and decimals
1586
+ const vaultData = await (0, getters_1.getVault)({
1587
+ vault,
1588
+ loans: false,
1589
+ allocations: false,
1590
+ options: {
1591
+ rpcUrl,
1592
+ solanaService: this.solanaService,
1593
+ stellarRpc: this._stellarRpc,
1594
+ env: this.monitoring?.env,
1595
+ augustKey: this.keys?.august,
1596
+ subgraphKey: this.keys?.graph,
1597
+ headers: this.headers,
1598
+ },
1599
+ loadSnapshots: false,
1600
+ loadSubaccounts: false,
1601
+ });
1602
+ if (!vaultData?.instant_redeem_config) {
1603
+ throw new Error(`Vault ${vault} does not support instant redemption.`);
1604
+ }
1605
+ const { subaccountAddress, redeemableAssets } = vaultData.instant_redeem_config;
1606
+ // Resolve output asset decimals from config
1607
+ const redeemableAsset = redeemableAssets.find((a) => a.address.toLowerCase() === asset.toLowerCase());
1608
+ if (!redeemableAsset) {
1609
+ throw new Error(`Asset ${asset} is not redeemable for vault ${vault}.`);
1610
+ }
1611
+ const provider = (0, core_1.createProvider)(rpcUrl);
1612
+ return (0, read_actions_1.previewRwaRedemption)(provider, {
1613
+ target: subaccountAddress,
1614
+ asset,
1615
+ amount,
1616
+ decimals: vaultData.decimals,
1617
+ outputDecimals: redeemableAsset.decimals,
1618
+ });
1619
+ }
1620
+ }
1621
+ exports.AugustVaults = AugustVaults;
1622
+ exports.default = AugustVaults;
1623
+ //# sourceMappingURL=main.js.map