@augustdigital/sdk 4.0.9-alpha → 4.1.0-alpha

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 (352) hide show
  1. package/lib/abis/AddressResolver.d.ts +28 -0
  2. package/lib/abis/AddressResolver.js +23 -0
  3. package/lib/abis/AddressResolver.js.map +1 -0
  4. package/lib/abis/ChainlinkV3.d.ts +87 -0
  5. package/lib/abis/ChainlinkV3.js +117 -0
  6. package/lib/abis/ChainlinkV3.js.map +1 -0
  7. package/lib/abis/ERC20.d.ts +168 -0
  8. package/lib/abis/ERC20.js +226 -0
  9. package/lib/abis/ERC20.js.map +1 -0
  10. package/lib/abis/ERC20_Bytes32.d.ts +135 -0
  11. package/lib/abis/ERC20_Bytes32.js +192 -0
  12. package/lib/abis/ERC20_Bytes32.js.map +1 -0
  13. package/lib/abis/ERC4626.d.ts +363 -0
  14. package/lib/abis/ERC4626.js +506 -0
  15. package/lib/abis/ERC4626.js.map +1 -0
  16. package/lib/abis/ERC721.d.ts +230 -0
  17. package/lib/abis/ERC721.js +320 -0
  18. package/lib/abis/ERC721.js.map +1 -0
  19. package/lib/abis/FeeOracle.d.ts +120 -0
  20. package/lib/abis/FeeOracle.js +161 -0
  21. package/lib/abis/FeeOracle.js.map +1 -0
  22. package/lib/abis/LendingPool.d.ts +1393 -0
  23. package/lib/abis/LendingPool.js +1806 -0
  24. package/lib/abis/LendingPool.js.map +1 -0
  25. package/lib/abis/LendingPoolV2.d.ts +55 -0
  26. package/lib/abis/LendingPoolV2.js +1832 -0
  27. package/lib/abis/LendingPoolV2.js.map +1 -0
  28. package/lib/abis/LendingPoolV3.d.ts +35 -0
  29. package/lib/abis/LendingPoolV3.js +1160 -0
  30. package/lib/abis/LendingPoolV3.js.map +1 -0
  31. package/lib/abis/Loan.d.ts +837 -0
  32. package/lib/abis/Loan.js +1080 -0
  33. package/lib/abis/Loan.js.map +1 -0
  34. package/lib/abis/Multicall3.d.ts +30 -0
  35. package/lib/abis/Multicall3.js +94 -0
  36. package/lib/abis/Multicall3.js.map +1 -0
  37. package/lib/abis/PoolAdapter.d.ts +76 -0
  38. package/lib/abis/PoolAdapter.js +412 -0
  39. package/lib/abis/PoolAdapter.js.map +1 -0
  40. package/lib/abis/RewardDistributor.d.ts +46 -0
  41. package/lib/abis/RewardDistributor.js +352 -0
  42. package/lib/abis/RewardDistributor.js.map +1 -0
  43. package/lib/abis/SmartAccount.d.ts +16 -0
  44. package/lib/abis/SmartAccount.js +16 -0
  45. package/lib/abis/SmartAccount.js.map +1 -0
  46. package/lib/abis/TextResolver.d.ts +16 -0
  47. package/lib/abis/TextResolver.js +16 -0
  48. package/lib/abis/TextResolver.js.map +1 -0
  49. package/lib/abis/TokenizedVaultV2.d.ts +1354 -0
  50. package/lib/abis/TokenizedVaultV2.js +1028 -0
  51. package/lib/abis/TokenizedVaultV2.js.map +1 -0
  52. package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
  53. package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
  54. package/lib/abis/TokenizedVaultV2Receipt.js.map +1 -0
  55. package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
  56. package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
  57. package/lib/abis/TokenizedVaultV2WhitelistedAssets.js.map +1 -0
  58. package/lib/abis/UniversalResolverResolve.d.ts +69 -0
  59. package/lib/abis/UniversalResolverResolve.js +35 -0
  60. package/lib/abis/UniversalResolverResolve.js.map +1 -0
  61. package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
  62. package/lib/abis/UniversalSignatureValidator.js +27 -0
  63. package/lib/abis/UniversalSignatureValidator.js.map +1 -0
  64. package/lib/abis/WrapperAdapter.d.ts +60 -0
  65. package/lib/abis/WrapperAdapter.js +150 -0
  66. package/lib/abis/WrapperAdapter.js.map +1 -0
  67. package/lib/abis/index.d.ts +19 -0
  68. package/lib/abis/index.js +36 -0
  69. package/lib/abis/index.js.map +1 -0
  70. package/lib/adapters/evm/core.actions.d.ts +9 -0
  71. package/lib/adapters/evm/core.actions.js +51 -0
  72. package/lib/adapters/evm/core.actions.js.map +1 -0
  73. package/lib/adapters/evm/getters.d.ts +4 -0
  74. package/lib/adapters/evm/getters.js +163 -0
  75. package/lib/adapters/evm/getters.js.map +1 -0
  76. package/lib/adapters/evm/index.d.ts +19 -0
  77. package/lib/adapters/evm/index.js +55 -0
  78. package/lib/adapters/evm/index.js.map +1 -0
  79. package/lib/adapters/evm/read.actions.d.ts +3 -0
  80. package/lib/adapters/evm/read.actions.js +39 -0
  81. package/lib/adapters/evm/read.actions.js.map +1 -0
  82. package/lib/adapters/evm/utils.d.ts +28 -0
  83. package/lib/adapters/evm/utils.js +336 -0
  84. package/lib/adapters/evm/utils.js.map +1 -0
  85. package/lib/adapters/evm/vaults.actions.d.ts +10 -0
  86. package/lib/adapters/evm/vaults.actions.js +97 -0
  87. package/lib/adapters/evm/vaults.actions.js.map +1 -0
  88. package/lib/adapters/solana/actions.d.ts +20 -0
  89. package/lib/adapters/solana/actions.js +225 -0
  90. package/lib/adapters/solana/actions.js.map +1 -0
  91. package/lib/adapters/solana/class.d.ts +45 -0
  92. package/lib/adapters/solana/class.js +135 -0
  93. package/lib/adapters/solana/class.js.map +1 -0
  94. package/lib/adapters/solana/constants.d.ts +25 -0
  95. package/lib/adapters/solana/constants.js +32 -0
  96. package/lib/adapters/solana/constants.js.map +1 -0
  97. package/lib/adapters/solana/getters.d.ts +3 -0
  98. package/lib/adapters/solana/getters.js +126 -0
  99. package/lib/adapters/solana/getters.js.map +1 -0
  100. package/lib/adapters/solana/idl/vault-idl.d.ts +338 -0
  101. package/lib/adapters/solana/idl/vault-idl.js +1075 -0
  102. package/lib/adapters/solana/idl/vault-idl.js.map +1 -0
  103. package/lib/adapters/solana/index.d.ts +136 -0
  104. package/lib/adapters/solana/index.js +174 -0
  105. package/lib/adapters/solana/index.js.map +1 -0
  106. package/lib/adapters/solana/types.d.ts +58 -0
  107. package/lib/adapters/solana/types.js +3 -0
  108. package/lib/adapters/solana/types.js.map +1 -0
  109. package/lib/adapters/solana/utils.d.ts +104 -0
  110. package/lib/adapters/solana/utils.js +380 -0
  111. package/lib/adapters/solana/utils.js.map +1 -0
  112. package/lib/adapters/solana/vault-idl.d.ts +338 -0
  113. package/lib/adapters/solana/vault-idl.js +1075 -0
  114. package/lib/adapters/solana/vault-idl.js.map +1 -0
  115. package/lib/adapters/solana/vault.actions.d.ts +18 -0
  116. package/lib/adapters/solana/vault.actions.js +235 -0
  117. package/lib/adapters/solana/vault.actions.js.map +1 -0
  118. package/lib/adapters/sui/index.d.ts +0 -0
  119. package/lib/adapters/sui/index.js +1 -0
  120. package/lib/adapters/sui/index.js.map +1 -0
  121. package/lib/core/auth/index.d.ts +1 -0
  122. package/lib/core/auth/index.js +18 -0
  123. package/lib/core/auth/index.js.map +1 -0
  124. package/lib/core/auth/verify.d.ts +2 -0
  125. package/lib/core/auth/verify.js +21 -0
  126. package/lib/core/auth/verify.js.map +1 -0
  127. package/lib/core/base-class.d.ts +34 -0
  128. package/lib/core/base-class.js +55 -0
  129. package/lib/core/base-class.js.map +1 -0
  130. package/lib/core/base.class.d.ts +34 -0
  131. package/lib/core/base.class.js +61 -0
  132. package/lib/core/base.class.js.map +1 -0
  133. package/lib/core/constants.d.ts +86 -0
  134. package/lib/core/constants.js +146 -0
  135. package/lib/core/constants.js.map +1 -0
  136. package/lib/core/core.helpers.d.ts +23 -0
  137. package/lib/core/core.helpers.js +210 -0
  138. package/lib/core/core.helpers.js.map +1 -0
  139. package/lib/core/fetcher.d.ts +22 -0
  140. package/lib/core/fetcher.js +259 -0
  141. package/lib/core/fetcher.js.map +1 -0
  142. package/lib/core/helpers.core.d.ts +23 -0
  143. package/lib/core/helpers.core.js +210 -0
  144. package/lib/core/helpers.core.js.map +1 -0
  145. package/lib/core/helpers.d.ts +23 -0
  146. package/lib/core/helpers.js +210 -0
  147. package/lib/core/helpers.js.map +1 -0
  148. package/lib/core/helpers.web3.d.ts +26 -0
  149. package/lib/core/helpers.web3.js +315 -0
  150. package/lib/core/helpers.web3.js.map +1 -0
  151. package/lib/core/index.d.ts +9 -0
  152. package/lib/core/index.js +26 -0
  153. package/lib/core/index.js.map +1 -0
  154. package/lib/core/logger/index.d.ts +12 -0
  155. package/lib/core/logger/index.js +51 -0
  156. package/lib/core/logger/index.js.map +1 -0
  157. package/lib/core/logger/slack.d.ts +12 -0
  158. package/lib/core/logger/slack.js +49 -0
  159. package/lib/core/logger/slack.js.map +1 -0
  160. package/lib/core/read.actions.d.ts +3 -0
  161. package/lib/core/read.actions.js +39 -0
  162. package/lib/core/read.actions.js.map +1 -0
  163. package/lib/core/web3.helpers.d.ts +28 -0
  164. package/lib/core/web3.helpers.js +336 -0
  165. package/lib/core/web3.helpers.js.map +1 -0
  166. package/lib/core/write.actions.d.ts +9 -0
  167. package/lib/core/write.actions.js +51 -0
  168. package/lib/core/write.actions.js.map +1 -0
  169. package/lib/modules/vaults/admin-actions.d.ts +0 -0
  170. package/lib/modules/vaults/admin-actions.js +1 -0
  171. package/lib/modules/vaults/admin-actions.js.map +1 -0
  172. package/lib/modules/vaults/constants.d.ts +63 -0
  173. package/lib/modules/vaults/constants.js +190 -0
  174. package/lib/modules/vaults/constants.js.map +1 -0
  175. package/lib/modules/vaults/getters.d.ts +38 -0
  176. package/lib/modules/vaults/getters.js +636 -0
  177. package/lib/modules/vaults/getters.js.map +1 -0
  178. package/lib/modules/vaults/index.d.ts +84 -0
  179. package/lib/modules/vaults/index.js +498 -0
  180. package/lib/modules/vaults/index.js.map +1 -0
  181. package/lib/modules/vaults/main.d.ts +118 -0
  182. package/lib/modules/vaults/main.js +590 -0
  183. package/lib/modules/vaults/main.js.map +1 -0
  184. package/lib/modules/vaults/user-actions.d.ts +19 -0
  185. package/lib/modules/vaults/user-actions.js +172 -0
  186. package/lib/modules/vaults/user-actions.js.map +1 -0
  187. package/lib/modules/vaults/user.actions.d.ts +10 -0
  188. package/lib/modules/vaults/user.actions.js +95 -0
  189. package/lib/modules/vaults/user.actions.js.map +1 -0
  190. package/lib/modules/vaults/utils.d.ts +116 -0
  191. package/lib/modules/vaults/utils.js +395 -0
  192. package/lib/modules/vaults/utils.js.map +1 -0
  193. package/lib/modules/vaults/vault.actions.d.ts +10 -0
  194. package/lib/modules/vaults/vault.actions.js +95 -0
  195. package/lib/modules/vaults/vault.actions.js.map +1 -0
  196. package/lib/services/auth/index.d.ts +1 -0
  197. package/lib/services/auth/index.js +18 -0
  198. package/lib/services/auth/index.js.map +1 -0
  199. package/lib/services/auth/verify.d.ts +2 -0
  200. package/lib/services/auth/verify.js +20 -0
  201. package/lib/services/auth/verify.js.map +1 -0
  202. package/lib/services/coingecko/fetcher.d.ts +1 -0
  203. package/lib/services/coingecko/fetcher.js +36 -0
  204. package/lib/services/coingecko/fetcher.js.map +1 -0
  205. package/lib/services/coingecko/index.d.ts +2 -0
  206. package/lib/services/coingecko/index.js +19 -0
  207. package/lib/services/coingecko/index.js.map +1 -0
  208. package/lib/services/coingecko/utils.d.ts +1 -0
  209. package/lib/services/coingecko/utils.js +24 -0
  210. package/lib/services/coingecko/utils.js.map +1 -0
  211. package/lib/services/debank/fetcher.d.ts +2 -0
  212. package/lib/services/debank/fetcher.js +16 -0
  213. package/lib/services/debank/fetcher.js.map +1 -0
  214. package/lib/services/debank/index.d.ts +2 -0
  215. package/lib/services/debank/index.js +19 -0
  216. package/lib/services/debank/index.js.map +1 -0
  217. package/lib/services/debank/utils.d.ts +32 -0
  218. package/lib/services/debank/utils.js +229 -0
  219. package/lib/services/debank/utils.js.map +1 -0
  220. package/lib/services/index.d.ts +4 -0
  221. package/lib/services/index.js +21 -0
  222. package/lib/services/index.js.map +1 -0
  223. package/lib/services/logger/index.d.ts +12 -0
  224. package/lib/services/logger/index.js +51 -0
  225. package/lib/services/logger/index.js.map +1 -0
  226. package/lib/services/logger/slack.d.ts +12 -0
  227. package/lib/services/logger/slack.js +48 -0
  228. package/lib/services/logger/slack.js.map +1 -0
  229. package/lib/services/solana/actions.d.ts +20 -0
  230. package/lib/services/solana/actions.js +225 -0
  231. package/lib/services/solana/actions.js.map +1 -0
  232. package/lib/services/solana/class.d.ts +45 -0
  233. package/lib/services/solana/class.js +135 -0
  234. package/lib/services/solana/class.js.map +1 -0
  235. package/lib/services/solana/constants.d.ts +25 -0
  236. package/lib/services/solana/constants.js +32 -0
  237. package/lib/services/solana/constants.js.map +1 -0
  238. package/lib/services/solana/index.d.ts +84 -0
  239. package/lib/services/solana/index.js +50 -0
  240. package/lib/services/solana/index.js.map +1 -0
  241. package/lib/services/solana/types.d.ts +58 -0
  242. package/lib/services/solana/types.js +3 -0
  243. package/lib/services/solana/types.js.map +1 -0
  244. package/lib/services/solana/utils.d.ts +96 -0
  245. package/lib/services/solana/utils.js +355 -0
  246. package/lib/services/solana/utils.js.map +1 -0
  247. package/lib/services/solana/vault-idl.d.ts +338 -0
  248. package/lib/services/solana/vault-idl.js +1075 -0
  249. package/lib/services/solana/vault-idl.js.map +1 -0
  250. package/lib/services/subgraph/fetcher.d.ts +2 -0
  251. package/lib/services/subgraph/fetcher.js +58 -0
  252. package/lib/services/subgraph/fetcher.js.map +1 -0
  253. package/lib/services/subgraph/index.d.ts +2 -0
  254. package/lib/services/subgraph/index.js +19 -0
  255. package/lib/services/subgraph/index.js.map +1 -0
  256. package/lib/services/subgraph/vaults.d.ts +10 -0
  257. package/lib/services/subgraph/vaults.js +473 -0
  258. package/lib/services/subgraph/vaults.js.map +1 -0
  259. package/lib/types/index.d.ts +8 -0
  260. package/lib/types/index.js +24 -0
  261. package/lib/types/index.js.map +1 -0
  262. package/lib/types/pools.d.ts +141 -0
  263. package/lib/types/pools.js +3 -0
  264. package/lib/types/pools.js.map +1 -0
  265. package/lib/types/staking.d.ts +28 -0
  266. package/lib/types/staking.js +3 -0
  267. package/lib/types/staking.js.map +1 -0
  268. package/lib/types/subgraph.d.ts +45 -0
  269. package/lib/types/subgraph.js +3 -0
  270. package/lib/types/subgraph.js.map +1 -0
  271. package/lib/types/user.d.ts +1 -0
  272. package/lib/types/user.js +3 -0
  273. package/lib/types/user.js.map +1 -0
  274. package/lib/types/vaults.d.ts +164 -0
  275. package/lib/types/vaults.js +3 -0
  276. package/lib/types/vaults.js.map +1 -0
  277. package/lib/types/web3.d.ts +24 -0
  278. package/lib/types/web3.js +3 -0
  279. package/lib/types/web3.js.map +1 -0
  280. package/lib/types/webserver.d.ts +475 -0
  281. package/lib/types/webserver.js +3 -0
  282. package/lib/types/webserver.js.map +1 -0
  283. package/lib/utils/base-class.d.ts +34 -0
  284. package/lib/utils/base-class.js +55 -0
  285. package/lib/utils/base-class.js.map +1 -0
  286. package/lib/utils/constants/august.d.ts +57 -0
  287. package/lib/utils/constants/august.js +61 -0
  288. package/lib/utils/constants/august.js.map +1 -0
  289. package/lib/utils/constants/fallbacks.d.ts +3 -0
  290. package/lib/utils/constants/fallbacks.js +26 -0
  291. package/lib/utils/constants/fallbacks.js.map +1 -0
  292. package/lib/utils/constants/index.d.ts +3 -0
  293. package/lib/utils/constants/index.js +20 -0
  294. package/lib/utils/constants/index.js.map +1 -0
  295. package/lib/utils/constants/web3.d.ts +32 -0
  296. package/lib/utils/constants/web3.js +101 -0
  297. package/lib/utils/constants/web3.js.map +1 -0
  298. package/lib/utils/fetcher.d.ts +25 -0
  299. package/lib/utils/fetcher.js +334 -0
  300. package/lib/utils/fetcher.js.map +1 -0
  301. package/lib/utils/helpers/array.d.ts +6 -0
  302. package/lib/utils/helpers/array.js +40 -0
  303. package/lib/utils/helpers/array.js.map +1 -0
  304. package/lib/utils/helpers/datetime.d.ts +5 -0
  305. package/lib/utils/helpers/datetime.js +32 -0
  306. package/lib/utils/helpers/datetime.js.map +1 -0
  307. package/lib/utils/helpers/formatters.d.ts +8 -0
  308. package/lib/utils/helpers/formatters.js +113 -0
  309. package/lib/utils/helpers/formatters.js.map +1 -0
  310. package/lib/utils/helpers/index.d.ts +6 -0
  311. package/lib/utils/helpers/index.js +23 -0
  312. package/lib/utils/helpers/index.js.map +1 -0
  313. package/lib/utils/helpers/responses.d.ts +32 -0
  314. package/lib/utils/helpers/responses.js +229 -0
  315. package/lib/utils/helpers/responses.js.map +1 -0
  316. package/lib/utils/helpers/verify-keys.d.ts +2 -0
  317. package/lib/utils/helpers/verify-keys.js +21 -0
  318. package/lib/utils/helpers/verify-keys.js.map +1 -0
  319. package/lib/utils/helpers/web3.d.ts +27 -0
  320. package/lib/utils/helpers/web3.js +339 -0
  321. package/lib/utils/helpers/web3.js.map +1 -0
  322. package/lib/utils/index.d.ts +5 -0
  323. package/lib/utils/index.js +22 -0
  324. package/lib/utils/index.js.map +1 -0
  325. package/lib/utils/vaults.d.ts +53 -0
  326. package/lib/utils/vaults.js +156 -0
  327. package/lib/utils/vaults.js.map +1 -0
  328. package/lib/vaults/admin-actions.d.ts +0 -0
  329. package/lib/vaults/admin-actions.js +1 -0
  330. package/lib/vaults/admin-actions.js.map +1 -0
  331. package/lib/vaults/getters.d.ts +38 -0
  332. package/lib/vaults/getters.js +760 -0
  333. package/lib/vaults/getters.js.map +1 -0
  334. package/lib/vaults/index.d.ts +4 -0
  335. package/lib/vaults/index.js +21 -0
  336. package/lib/vaults/index.js.map +1 -0
  337. package/lib/vaults/main.d.ts +118 -0
  338. package/lib/vaults/main.js +591 -0
  339. package/lib/vaults/main.js.map +1 -0
  340. package/lib/vaults/rpc-config.d.ts +4 -0
  341. package/lib/vaults/rpc-config.js +27 -0
  342. package/lib/vaults/rpc-config.js.map +1 -0
  343. package/lib/vaults/subgraph.d.ts +10 -0
  344. package/lib/vaults/subgraph.js +470 -0
  345. package/lib/vaults/subgraph.js.map +1 -0
  346. package/lib/vaults/user-actions.d.ts +19 -0
  347. package/lib/vaults/user-actions.js +172 -0
  348. package/lib/vaults/user-actions.js.map +1 -0
  349. package/lib/vaults/utils.d.ts +121 -0
  350. package/lib/vaults/utils.js +414 -0
  351. package/lib/vaults/utils.js.map +1 -0
  352. package/package.json +7 -7
@@ -0,0 +1,760 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVault = getVault;
4
+ exports.getVaultLoans = getVaultLoans;
5
+ exports.getVaultAllocations = getVaultAllocations;
6
+ exports.getVaultAvailableRedemptions = getVaultAvailableRedemptions;
7
+ exports.getVaultRedemptionHistory = getVaultRedemptionHistory;
8
+ exports.getVaultPositions = getVaultPositions;
9
+ exports.getVaultApy = getVaultApy;
10
+ exports.getRewardsStakingPositions = getRewardsStakingPositions;
11
+ const abis_1 = require("../abis");
12
+ const utils_1 = require("../utils");
13
+ const ethers_1 = require("ethers");
14
+ const services_1 = require("../services");
15
+ const utils_2 = require("./utils");
16
+ const subgraph_1 = require("./subgraph");
17
+ async function getVault({ vault, loans = false, allocations = false, options, }) {
18
+ let returnedVault;
19
+ try {
20
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault))?.[0];
21
+ const isSolana = services_1.Solana.utils.isSolanaAddress(vault);
22
+ if (isSolana) {
23
+ const solanaRpcUrl = options.rpcUrl;
24
+ const vaultState = await services_1.Solana.utils.getVaultStateReadOnly({
25
+ idl: services_1.Solana.constants.vaultIdl,
26
+ vaultProgramId: vault,
27
+ endpoint: solanaRpcUrl,
28
+ connection: options.solanaService?.connection,
29
+ });
30
+ let depositMint = null;
31
+ if (vaultState.vaultState && vaultState.vaultState.depositMint) {
32
+ depositMint = await services_1.Solana.utils.getToken({
33
+ mintAddress: vaultState.vaultState.depositMint,
34
+ endpoint: solanaRpcUrl,
35
+ connection: options.solanaService?.connection,
36
+ });
37
+ }
38
+ const returnObj = {
39
+ address: vault,
40
+ chainId: utils_1.SPECIAL_CHAINS.solana.chainId,
41
+ name: tokenizedVault?.vault_name || 'Solana Program',
42
+ logoUrl: tokenizedVault?.vault_logo_url || '/img/strategist/august.svg',
43
+ symbol: tokenizedVault?.receipt_token_symbol || 'upSOL',
44
+ description: tokenizedVault?.description || 'Description here',
45
+ startDatetime: new Date(tokenizedVault?.start_datetime).toISOString() ||
46
+ new Date().toISOString(),
47
+ status: 'active',
48
+ internalType: tokenizedVault?.internal_type ||
49
+ 'tokenizedVault',
50
+ publicType: tokenizedVault?.public_type || 'Defi Yield',
51
+ tags: [tokenizedVault?.public_type || 'Defi Yield'],
52
+ isFeatured: tokenizedVault?.is_featured || false,
53
+ isVisible: tokenizedVault?.is_visible || true,
54
+ reserveTarget: tokenizedVault?.reserve_target || 0,
55
+ reserveTolerance: tokenizedVault?.reserve_tolerance || 0,
56
+ decimals: vaultState.depositMintDecimals || 0,
57
+ totalAssets: (0, utils_1.toNormalizedBn)(vaultState.vaultToken?.balance, vaultState.depositMintDecimals),
58
+ totalSupply: (0, utils_1.toNormalizedBn)(vaultState.vaultToken?.balance, vaultState.depositMintDecimals),
59
+ loansOperator: '0x',
60
+ maxSupply: (0, utils_1.toNormalizedBn)(1000000000000),
61
+ underlying: {
62
+ address: depositMint?.address,
63
+ symbol: depositMint?.symbol,
64
+ decimals: depositMint?.decimals || services_1.Solana.constants.fallbackDecimals,
65
+ name: depositMint?.name,
66
+ },
67
+ apy: tokenizedVault?.reported_apy?.apy || 0,
68
+ apyBreakdown: tokenizedVault?.reported_apy || {
69
+ apy: 0,
70
+ explainer: '',
71
+ liquidApy: 0,
72
+ rewardsClaimable: 0,
73
+ rewardsCompounded: 0,
74
+ underlyingApy: 0,
75
+ },
76
+ rewards: {
77
+ upshiftPoints: '0',
78
+ latestUpshiftPointMultiplier: 0,
79
+ upshiftPointsMultipliers: [],
80
+ additionalPoints: [],
81
+ },
82
+ weeklyPerformanceFee: tokenizedVault?.weekly_performance_fee_bps || 0,
83
+ platformFee: {
84
+ fee: tokenizedVault?.platform_fee_override?.management_fee || 0,
85
+ isWaived: false,
86
+ },
87
+ lagDuration: 0,
88
+ maxDailyDrawdown: tokenizedVault?.max_daily_drawdown || 0,
89
+ risk: tokenizedVault?.risk || 'low',
90
+ isWithdrawalPaused: false,
91
+ isDepositPaused: false,
92
+ idleAssets: (0, utils_1.toNormalizedBn)(0),
93
+ loans: [],
94
+ allocations: {
95
+ unfilteredTokens: [],
96
+ defi: [],
97
+ tokens: [],
98
+ cefi: [],
99
+ otc: {},
100
+ exposurePerCategory: {
101
+ borrowing: [],
102
+ supplying: [],
103
+ lending: [],
104
+ wallet: [],
105
+ cefiBalance: 0,
106
+ defiBalance: 0,
107
+ walletBalance: 0,
108
+ loanBalance: 0,
109
+ },
110
+ netValue: 0,
111
+ defiPerBorrower: {},
112
+ },
113
+ position: {
114
+ vault: vault,
115
+ status: 'active',
116
+ availableRedemptions: [],
117
+ pendingRedemptions: [],
118
+ redeemable: (0, utils_1.toNormalizedBn)(0),
119
+ walletBalance: (0, utils_1.toNormalizedBn)(0),
120
+ },
121
+ strategists: [
122
+ {
123
+ address: '0xE926502EdBcE3d56A409ef5dA352B5b522542D7c',
124
+ logo: '/img/strategist/august.svg',
125
+ name: 'August',
126
+ },
127
+ ],
128
+ };
129
+ returnedVault = returnObj;
130
+ return returnObj;
131
+ }
132
+ else if ((0, ethers_1.isAddress)(vault)) {
133
+ const provider = (0, utils_1.createProvider)(options.rpcUrl);
134
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
135
+ if (tokenizedVault.status === 'closed' &&
136
+ tokenizedVault.is_visible === false) {
137
+ console.log('#getVault::closed:', tokenizedVault.vault_name);
138
+ return null;
139
+ }
140
+ const vaultContract = (0, utils_1.createContract)({
141
+ address: vault,
142
+ abi: abis_1.ABI_LENDING_POOL_V2,
143
+ provider,
144
+ });
145
+ const vaultContractCalls = await Promise.all(utils_2.POOL_FUNCTIONS.map((f) => {
146
+ if ((f === 'totalSupply' || f === 'totalAssets') &&
147
+ utils_2.MULTI_ASSET_VAULTS.includes(vault)) {
148
+ return 0;
149
+ }
150
+ if (f === 'symbol') {
151
+ return (0, utils_1.getSymbol)(provider, vault);
152
+ }
153
+ if (f === 'decimals') {
154
+ return (0, utils_1.getDecimals)(provider, vault);
155
+ }
156
+ return vaultContract[f]();
157
+ }));
158
+ const formattedContractCalls = vaultContractCalls.reduce((acc, curr, i) => {
159
+ let val;
160
+ if (utils_2.POOL_FUNCTIONS[i] === 'totalSupply' ||
161
+ utils_2.POOL_FUNCTIONS[i] === 'totalAssets' ||
162
+ utils_2.POOL_FUNCTIONS[i] === 'globalLoansAmount' ||
163
+ utils_2.POOL_FUNCTIONS[i] === 'maxSupply') {
164
+ val = (0, utils_1.toNormalizedBn)(curr, vaultContractCalls[0]);
165
+ }
166
+ else if (utils_2.POOL_FUNCTIONS[i] === 'getTotalLoansDeployed') {
167
+ val = (0, utils_1.toNormalizedBn)(curr, 0);
168
+ }
169
+ else if (utils_2.POOL_FUNCTIONS[i] === 'withdrawalFee') {
170
+ val = (0, utils_1.toNormalizedBn)(curr, 2);
171
+ }
172
+ else if (utils_2.POOL_FUNCTIONS[i] === 'decimals') {
173
+ val = Number(curr.toString());
174
+ }
175
+ else if (utils_2.POOL_FUNCTIONS[i] === 'loansOperator') {
176
+ val = '0x4DCb388488622e47683EAd1a147947140a31e485';
177
+ }
178
+ else {
179
+ val = curr;
180
+ }
181
+ return { ...acc, [utils_2.POOL_FUNCTIONS[i]]: val };
182
+ }, {});
183
+ const returnObj = await (0, utils_2.buildFormattedVault)(provider, tokenizedVault, formattedContractCalls);
184
+ returnedVault = returnObj;
185
+ }
186
+ }
187
+ catch (err) {
188
+ console.error(`#getVault::${vault}:`, err);
189
+ throw new Error(`#getVault::${vault}:${err?.message}`);
190
+ }
191
+ if (!(0, utils_1.isBadVault)(vault)) {
192
+ if (loans) {
193
+ try {
194
+ returnedVault = {
195
+ ...returnedVault,
196
+ loans: await getVaultLoans(returnedVault, options),
197
+ };
198
+ }
199
+ catch (e) {
200
+ console.error(`getVault::${returnedVault.symbol}:`, e?.message);
201
+ }
202
+ }
203
+ if (allocations) {
204
+ try {
205
+ const vaultAllocations = await getVaultAllocations(vault, options);
206
+ returnedVault = {
207
+ ...returnedVault,
208
+ allocations: vaultAllocations,
209
+ };
210
+ }
211
+ catch (e) {
212
+ console.error(`getVault::${returnedVault.symbol}:`, e?.message);
213
+ throw new Error('Failure fetching debank res');
214
+ }
215
+ }
216
+ }
217
+ return returnedVault;
218
+ }
219
+ async function getVaultLoans(vault, options) {
220
+ const vaultAddress = typeof vault === 'string' ? vault : vault.address;
221
+ const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vaultAddress);
222
+ if (!isOldLendingPool)
223
+ return [];
224
+ try {
225
+ let poolTotalSupply;
226
+ let poolDecimals;
227
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vaultAddress, options?.headers))?.[0];
228
+ const chainId = options?.chainId || tokenizedVault?.chain;
229
+ const provider = (0, utils_1.createProvider)(options.rpcUrl);
230
+ const tokenizedVaultLoans = await (0, utils_1.fetchTokenizedVaultLoans)(vaultAddress, chainId);
231
+ if (typeof vault === 'string') {
232
+ const poolContract = (0, utils_1.createContract)({
233
+ provider,
234
+ address: vaultAddress,
235
+ abi: abis_1.ABI_LENDING_POOL_V2,
236
+ });
237
+ [poolTotalSupply, poolDecimals] = await Promise.all([
238
+ poolContract.totalSupply(),
239
+ (0, utils_1.getDecimals)(provider, vaultAddress),
240
+ ]);
241
+ poolTotalSupply = BigInt(poolTotalSupply).toString();
242
+ poolDecimals = Number(poolDecimals);
243
+ }
244
+ else {
245
+ poolTotalSupply = vault.totalSupply.raw;
246
+ poolDecimals = vault.decimals;
247
+ }
248
+ const newLoans = (await Promise.all((Array.isArray(tokenizedVaultLoans) ? tokenizedVaultLoans : [])?.map(async (l) => {
249
+ const borrower = l.borrower;
250
+ const allocation = l.principal_amount /
251
+ Number((0, ethers_1.formatUnits)(poolTotalSupply, poolDecimals));
252
+ const loanFeeRate = await (0, utils_1.getLoanOracleFeeRate)(provider, 'LOAN.REPAY.INTERESTS', l.address, chainId);
253
+ const loanApr = Number(l.apr || 0) / 100;
254
+ const loanAprAfterFees = loanApr * (1 - loanFeeRate / 100);
255
+ const isIdleCapital = utils_1.IDLE_CAPITAL_BORROWER_ADDRESS.includes(borrower);
256
+ const newLoanObj = {
257
+ vault: vaultAddress,
258
+ address: l.address,
259
+ lender: l.lender,
260
+ borrower: l.borrower,
261
+ state: l.state,
262
+ totalRepaid: l.total_repaid,
263
+ principalToken: l.principal_token,
264
+ principalAmount: l.principal_amount,
265
+ interestAmount: l.interest_amount,
266
+ upcomingPayment: {
267
+ amount: l.upcoming_payment.amount,
268
+ dueDate: l.upcoming_payment.due_date,
269
+ },
270
+ apr: loanAprAfterFees,
271
+ initialPrincipalAmount: l.initial_principal_amount,
272
+ deployedDate: l.deployed_date,
273
+ isIdleCapital,
274
+ paymentInterval: l.payment_interval,
275
+ allocation,
276
+ };
277
+ return newLoanObj;
278
+ }))).filter((l) => l !== undefined);
279
+ return newLoans;
280
+ }
281
+ catch (e) {
282
+ console.error('#getVaultLoans:', e);
283
+ throw new Error(`#getVaultLoans::${vault}:${e?.message}`);
284
+ }
285
+ }
286
+ async function getVaultAllocations(vault, options) {
287
+ let protocolExposure = [];
288
+ let tokenExposure = [];
289
+ let cefiExposure = [];
290
+ let cefiBorrowerResponses = {};
291
+ let otcPositions = {};
292
+ let defiPerBorrower = {};
293
+ let exposurePerCategory = {
294
+ supplying: [],
295
+ borrowing: [],
296
+ wallet: [],
297
+ walletBalance: 0,
298
+ cefiBalance: 0,
299
+ defiBalance: 0,
300
+ lending: [],
301
+ loanBalance: 0,
302
+ };
303
+ let netValue = { value: 0 };
304
+ let debankErr = false;
305
+ let unfilteredTokens = [];
306
+ let uniqueBorrowers;
307
+ const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vault);
308
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
309
+ try {
310
+ if (isOldLendingPool) {
311
+ const loans = await getVaultLoans(vault, options);
312
+ uniqueBorrowers = [...new Set(loans.map((l) => l.borrower))];
313
+ }
314
+ else {
315
+ uniqueBorrowers = tokenizedVault.subaccounts.map((s) => s.address);
316
+ }
317
+ }
318
+ catch (e) {
319
+ console.error('#getVaultAllocations::borrowers:', e);
320
+ }
321
+ if (vault.toLowerCase() === utils_2.VAULT_AgoraAUSD.toLowerCase()) {
322
+ const debankRes = await (0, utils_1.fetchDebankResponse)(utils_2.SUBACCOUNT_CALEB);
323
+ console.log('debankRes:', debankRes);
324
+ if (debankRes === false) {
325
+ debankErr = true;
326
+ }
327
+ (0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, utils_2.SUBACCOUNT_CALEB, exposurePerCategory, netValue);
328
+ unfilteredTokens = debankRes?.subaccount?.tokens;
329
+ const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
330
+ defiPerBorrower[utils_2.SUBACCOUNT_CALEB] = debankPerLoan;
331
+ }
332
+ else {
333
+ for (const borrower of uniqueBorrowers) {
334
+ try {
335
+ const debankRes = await (0, utils_1.fetchDebankResponse)(borrower);
336
+ if (debankRes === false) {
337
+ debankErr = true;
338
+ }
339
+ (0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue);
340
+ unfilteredTokens = debankRes?.subaccount?.tokens;
341
+ const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
342
+ defiPerBorrower[borrower] = debankPerLoan;
343
+ }
344
+ catch (e) {
345
+ console.error('#getVaultAllocations::debank:', e);
346
+ }
347
+ try {
348
+ const cefiResponse = await (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.cefi(borrower), { headers: options?.headers });
349
+ if (cefiResponse.status !== 200) {
350
+ console.error('#getVaultAllocations::cefi:', cefiResponse.status, cefiResponse.statusText);
351
+ }
352
+ if (cefiResponse.status === 200) {
353
+ const cefiRes = (await cefiResponse.json());
354
+ cefiBorrowerResponses[borrower] = cefiRes;
355
+ cefiExposure = cefiRes;
356
+ }
357
+ }
358
+ catch (e) {
359
+ console.error('#getVaultAllocations::cefi:', e);
360
+ }
361
+ try {
362
+ const otcResponse = await (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.otc_positions(borrower), { headers: options?.headers });
363
+ if (otcResponse.status !== 200) {
364
+ console.error('#getVaultAllocations::otc:', otcResponse.status, otcResponse.statusText);
365
+ }
366
+ if (otcResponse.status === 200) {
367
+ const otcRes = (await otcResponse.json());
368
+ otcPositions[borrower] = otcRes;
369
+ }
370
+ }
371
+ catch (e) {
372
+ console.error('#getVaultAllocations::otc:', e);
373
+ }
374
+ }
375
+ }
376
+ const walletBalance = exposurePerCategory.wallet.reduce((sum, item) => sum + item.amount, 0);
377
+ const defiBalance = protocolExposure.reduce((sum, item) => sum + item.netUsdValue, 0);
378
+ const cefiBalance = cefiExposure.reduce((sum, item) => sum + item.value, 0);
379
+ exposurePerCategory.walletBalance = walletBalance;
380
+ exposurePerCategory.defiBalance = defiBalance;
381
+ exposurePerCategory.cefiBalance = cefiBalance;
382
+ netValue.value += cefiBalance;
383
+ if (debankErr) {
384
+ throw Error('failure to fetch debank response');
385
+ }
386
+ if (vault === '0x828BC5895b78b2fb591018Ca5bDC2064742D6D0f') {
387
+ console.log('protocolExposure:', {
388
+ defi: protocolExposure,
389
+ cefi: cefiExposure,
390
+ otc: otcPositions,
391
+ tokens: tokenExposure,
392
+ defiPerBorrower,
393
+ exposurePerCategory,
394
+ netValue: netValue.value,
395
+ });
396
+ }
397
+ return {
398
+ defi: protocolExposure,
399
+ cefi: cefiExposure,
400
+ otc: otcPositions,
401
+ tokens: tokenExposure,
402
+ defiPerBorrower,
403
+ exposurePerCategory,
404
+ netValue: netValue.value,
405
+ unfilteredTokens: unfilteredTokens,
406
+ };
407
+ }
408
+ async function getVaultAvailableRedemptions({ vault, wallet, options, }) {
409
+ try {
410
+ const provider = (0, utils_1.createProvider)(options.rpcUrl);
411
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
412
+ if (!tokenizedVault) {
413
+ return { availableRedemptions: [], pendingRedemptions: [] };
414
+ }
415
+ const poolContract = (0, utils_1.createContract)({
416
+ address: vault,
417
+ abi: abis_1.ABI_LENDING_POOL_V2,
418
+ provider,
419
+ });
420
+ const { withdrawalRequesteds, withdrawalProcesseds } = await (0, subgraph_1.getSubgraphAllWithdrawals)(vault, provider);
421
+ const decimals = await (0, utils_1.getDecimals)(provider, vault);
422
+ const availableRedemptions = [];
423
+ const pendingRedemptions = [];
424
+ for (const ev of withdrawalRequesteds) {
425
+ if (!ev || typeof ev !== 'object') {
426
+ console.warn('#getVaultAvailableRedemptions: Skipping invalid event:', ev);
427
+ continue;
428
+ }
429
+ if (!ev.year || !ev.month || !ev.day || !ev.receiverAddr) {
430
+ console.warn('#getVaultAvailableRedemptions: Skipping event with missing required properties:', ev);
431
+ continue;
432
+ }
433
+ const fullDate = new Date(Number(ev.year), Number(ev.month) - 1, Number(ev.day));
434
+ const foundRedemptionAgainstClaim = withdrawalProcesseds.find((h) => new Date(h.processedOn).toDateString() === fullDate.toDateString() &&
435
+ h.receiverAddr === ev.receiverAddr);
436
+ if (wallet) {
437
+ if (ev?.receiverAddr?.toLowerCase() === wallet.toLowerCase()) {
438
+ const alreadyRedeemed = availableRedemptions.find((red) => BigInt(red.day.raw) === BigInt(ev.day) &&
439
+ BigInt(red.month.raw) === BigInt(ev.month) &&
440
+ BigInt(red.year.raw) === BigInt(ev.year));
441
+ if (!(foundRedemptionAgainstClaim && alreadyRedeemed)) {
442
+ try {
443
+ const trueClaimableAmount = await poolContract?.getClaimableAmountByReceiver?.(BigInt(ev.year), BigInt(ev.month), BigInt(ev.day), (0, ethers_1.getAddress)(wallet));
444
+ if (trueClaimableAmount > BigInt(0)) {
445
+ availableRedemptions.push({
446
+ id: ev.transactionHash_ || ev.id,
447
+ hash: ev.transactionHash_ || ev.id,
448
+ timestamp: Number(ev.timestamp_),
449
+ receiver: ev.receiverAddr,
450
+ day: (0, utils_1.toNormalizedBn)(ev.day, 0),
451
+ month: (0, utils_1.toNormalizedBn)(ev.month, 0),
452
+ year: (0, utils_1.toNormalizedBn)(ev.year, 0),
453
+ amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount, decimals),
454
+ date: fullDate,
455
+ vault,
456
+ });
457
+ }
458
+ pendingRedemptions.push({
459
+ id: ev.transactionHash_ || ev.id,
460
+ hash: ev.transactionHash_ || ev.id,
461
+ timestamp: Number(ev.timestamp_),
462
+ receiver: ev.receiverAddr,
463
+ day: (0, utils_1.toNormalizedBn)(ev.day, 0),
464
+ month: (0, utils_1.toNormalizedBn)(ev.month, 0),
465
+ year: (0, utils_1.toNormalizedBn)(ev.year, 0),
466
+ amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount || BigInt(0), decimals),
467
+ date: fullDate,
468
+ vault,
469
+ });
470
+ }
471
+ catch (contractError) {
472
+ console.error('#getVaultAvailableRedemptions: Contract call failed:', contractError);
473
+ pendingRedemptions.push({
474
+ id: ev.transactionHash_ || ev.id,
475
+ hash: ev.transactionHash_ || ev.id,
476
+ timestamp: Number(ev.timestamp_),
477
+ receiver: ev.receiverAddr,
478
+ day: (0, utils_1.toNormalizedBn)(ev.day, 0),
479
+ month: (0, utils_1.toNormalizedBn)(ev.month, 0),
480
+ year: (0, utils_1.toNormalizedBn)(ev.year, 0),
481
+ amount: (0, utils_1.toNormalizedBn)(BigInt(0), decimals),
482
+ date: fullDate,
483
+ vault,
484
+ });
485
+ }
486
+ }
487
+ }
488
+ }
489
+ else {
490
+ if (!!foundRedemptionAgainstClaim) {
491
+ availableRedemptions.push({
492
+ id: ev.transactionHash_ || ev.id,
493
+ hash: ev.transactionHash_ || ev.id,
494
+ timestamp: Number(ev.timestamp_),
495
+ receiver: ev.receiverAddr,
496
+ day: (0, utils_1.toNormalizedBn)(ev.day, 0),
497
+ month: (0, utils_1.toNormalizedBn)(ev.month, 0),
498
+ year: (0, utils_1.toNormalizedBn)(ev.year, 0),
499
+ amount: (0, utils_1.toNormalizedBn)(ev.assets || BigInt(0), decimals),
500
+ date: fullDate,
501
+ vault,
502
+ });
503
+ }
504
+ }
505
+ }
506
+ return { availableRedemptions, pendingRedemptions };
507
+ }
508
+ catch (e) {
509
+ console.error('#getVaultAvailableRedemptions:', e);
510
+ return { availableRedemptions: [], pendingRedemptions: [] };
511
+ }
512
+ }
513
+ async function getVaultRedemptionHistory({ vault, wallet, options, }) {
514
+ try {
515
+ const provider = (0, utils_1.createProvider)(options.rpcUrl);
516
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
517
+ if (!tokenizedVault) {
518
+ return [];
519
+ }
520
+ const chainId = tokenizedVault.chain;
521
+ const poolContract = (0, utils_1.createContract)({
522
+ address: vault,
523
+ abi: abis_1.ABI_LENDING_POOL_V2,
524
+ provider,
525
+ });
526
+ let logPromises = [];
527
+ const currentBlock = await provider.getBlockNumber();
528
+ let startingBlock = currentBlock - (0, utils_2.determineBlockSkipInternal)(chainId);
529
+ let endBlock = currentBlock;
530
+ const cutoffBlock = currentBlock - (0, utils_2.determineBlockCutoff)(chainId);
531
+ while (endBlock >= cutoffBlock) {
532
+ const logBloomsPromises = poolContract.queryFilter('WithdrawalProcessed', BigInt(startingBlock), BigInt(endBlock));
533
+ logPromises.push(logBloomsPromises);
534
+ startingBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
535
+ endBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
536
+ }
537
+ const logs = (await Promise.all(logPromises.flat())).flat();
538
+ const iface = new ethers_1.ethers.Interface([
539
+ 'event WithdrawalProcessed (uint256 assetsAmount, uint256 processedOn, address receiverAddr, uint256 requestedOn)',
540
+ ]);
541
+ const events = logs.map((log) => iface.parseLog(log));
542
+ const decimals = await (0, utils_1.getDecimals)(provider, vault);
543
+ const redemptions = [];
544
+ events?.forEach((ev) => {
545
+ if (!ev?.args)
546
+ return;
547
+ const [assetsAmount, processedOn, receiverAddr, requestedOn] = ev.args;
548
+ if (wallet) {
549
+ if (String(receiverAddr)?.toLowerCase() === wallet.toLowerCase()) {
550
+ redemptions.push({
551
+ receiver: receiverAddr,
552
+ amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
553
+ processed: new Date(Number(processedOn) * 1000),
554
+ requested: new Date(Number(requestedOn) * 1000),
555
+ vault,
556
+ });
557
+ }
558
+ }
559
+ else {
560
+ redemptions.push({
561
+ receiver: receiverAddr,
562
+ amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
563
+ processed: new Date(Number(processedOn) * 1000),
564
+ requested: new Date(Number(requestedOn) * 1000),
565
+ vault,
566
+ });
567
+ }
568
+ });
569
+ if (options.env === 'DEV')
570
+ console.log('#getVaultRedemptionHistory:', redemptions.slice(0, 1));
571
+ return redemptions;
572
+ }
573
+ catch (e) {
574
+ console.error('#getVaultRedemptionHistory:', e);
575
+ return [];
576
+ }
577
+ }
578
+ async function getVaultPositions({ vault, wallet, solanaWallet, options, }) {
579
+ try {
580
+ const tokenizedVaults = await (0, utils_1.fetchTokenizedVaults)(vault ? vault : undefined, options?.headers);
581
+ if (!tokenizedVaults || tokenizedVaults.length === 0) {
582
+ return [];
583
+ }
584
+ function renderStatus(_redemptions, _balance) {
585
+ if (_redemptions?.length)
586
+ return 'REDEEM';
587
+ if (BigInt(_balance.raw) > BigInt(0))
588
+ return 'STAKED';
589
+ return 'PENDING';
590
+ }
591
+ const promises = await Promise.all(tokenizedVaults.map(async (v) => {
592
+ try {
593
+ if (services_1.Solana.utils.isSolanaAddress(v.address)) {
594
+ let balance = (0, utils_1.toNormalizedBn)(0);
595
+ if (services_1.Solana.utils.isSolanaAddress(solanaWallet)) {
596
+ const vaultStateRes = await options.solanaService.getVaultState(String(v.address), services_1.Solana.constants.vaultIdl);
597
+ if (vaultStateRes &&
598
+ vaultStateRes?.vaultState?.shareMint) {
599
+ balance = (0, utils_1.toNormalizedBn)(await options.solanaService.fetchUserShareBalance(solanaWallet, vaultStateRes?.vaultState?.shareMint));
600
+ }
601
+ }
602
+ return {
603
+ vault,
604
+ status: renderStatus([], balance),
605
+ availableRedemptions: [],
606
+ pendingRedemptions: [],
607
+ redeemable: balance,
608
+ walletBalance: balance,
609
+ };
610
+ }
611
+ const provider = (0, utils_1.createProvider)(options.rpcUrl);
612
+ const decimals = await (0, utils_1.getDecimals)(provider, vault);
613
+ const poolContract = (0, utils_1.createContract)({
614
+ provider,
615
+ abi: abis_1.ABI_LENDING_POOL_V2,
616
+ address: v.address,
617
+ });
618
+ const bal = await poolContract.balanceOf(wallet);
619
+ const balance = (0, utils_1.toNormalizedBn)(bal || 0, decimals);
620
+ const { availableRedemptions, pendingRedemptions } = await getVaultAvailableRedemptions({
621
+ vault: v.address,
622
+ wallet,
623
+ options,
624
+ });
625
+ const aggregateAvailableRedemptions = availableRedemptions?.reduce((acc, curr) => acc + BigInt(curr.amount.raw), BigInt(0));
626
+ return {
627
+ vault,
628
+ status: renderStatus(availableRedemptions, balance),
629
+ availableRedemptions,
630
+ pendingRedemptions,
631
+ redeemable: (0, utils_1.toNormalizedBn)(aggregateAvailableRedemptions, decimals),
632
+ walletBalance: balance,
633
+ };
634
+ }
635
+ catch (vaultError) {
636
+ console.error(`#getVaultPositions: Error processing vault ${v.address}:`, vaultError);
637
+ return {
638
+ vault,
639
+ status: 'PENDING',
640
+ availableRedemptions: [],
641
+ pendingRedemptions: [],
642
+ redeemable: (0, utils_1.toNormalizedBn)(0),
643
+ walletBalance: (0, utils_1.toNormalizedBn)(0),
644
+ };
645
+ }
646
+ }));
647
+ return promises.flat();
648
+ }
649
+ catch (e) {
650
+ console.error('#getVaultPositions:', e);
651
+ throw new Error(`#getVaultPositions::${vault}:${e?.message}`);
652
+ }
653
+ }
654
+ async function getVaultApy({ vault, options, }) {
655
+ try {
656
+ const tokenizedVault = (await (0, utils_1.fetchTokenizedVaults)(vault, options?.headers))?.[0];
657
+ return tokenizedVault?.reported_apy?.apy || 0;
658
+ }
659
+ catch (e) {
660
+ console.error('#getVaultApy:', e);
661
+ throw new Error(`#getVaultApy::${vault}:${e?.message}`);
662
+ }
663
+ }
664
+ async function getRewardsStakingPositions({ rpcUrl, wallet, coinGeckoKey, }) {
665
+ const REWARDS_CHAIN = 43114;
666
+ const REWARDS_SYMBOL = 'AVAX';
667
+ const REWARDS_DECIMALS = 18;
668
+ const REWARDS_NAME = 'Avalanche';
669
+ const APR_MULTIPLIER = 31536000;
670
+ const UP_AUSD_SYMBOL = 'upAUSD';
671
+ try {
672
+ const provider = (0, utils_1.createProvider)(rpcUrl);
673
+ const chainId = await (0, utils_1.getChainId)(provider);
674
+ if (chainId !== REWARDS_CHAIN) {
675
+ console.warn('#getStakingPositions: no rewards distributor on chain_id', chainId);
676
+ return [];
677
+ }
678
+ if (wallet && !(0, ethers_1.isAddress)(wallet)) {
679
+ console.warn('#getStakingPositions: wallet passed is not a valid address', wallet);
680
+ return [];
681
+ }
682
+ const rewardDistributorAddresses = (0, utils_1.REWARD_DISTRIBUTOR_ADDRESS)(chainId);
683
+ const positions = await Promise.all(rewardDistributorAddresses.map(async (contract, i) => {
684
+ const rewardContract = (0, utils_1.createContract)({
685
+ address: contract,
686
+ provider: provider,
687
+ abi: abis_1.ABI_REWARD_DISTRIBUTOR,
688
+ });
689
+ const totalStaked = await rewardContract.totalStaked();
690
+ const rewardsPerSecond = await rewardContract.rewardsPerSecond();
691
+ const stakingTokenCalls = ['decimals', 'symbol', 'name', 'totalSupply'];
692
+ const stakingTokenAddress = (await rewardContract.stakingToken());
693
+ const stakingTokenContract = (0, utils_1.createContract)({
694
+ address: stakingTokenAddress,
695
+ provider: provider,
696
+ abi: abis_1.ABI_ERC20,
697
+ });
698
+ const [decimals, symbol, name, totalSupply] = await Promise.all(stakingTokenCalls.map((staking) => stakingTokenContract[staking]()));
699
+ let balance;
700
+ let earned;
701
+ if (wallet) {
702
+ const formattedWallet = (0, ethers_1.getAddress)(wallet);
703
+ balance = await rewardContract.balanceOf(formattedWallet);
704
+ earned = await rewardContract.earned(formattedWallet);
705
+ }
706
+ const rewardTokenPriceInUsd = await (0, utils_1.fetchTokenPrice)(REWARDS_SYMBOL, null, coinGeckoKey);
707
+ const normalizedRewardTokenPrice = (0, utils_1.toNormalizedBn)(rewardTokenPriceInUsd);
708
+ const normalizedTotalStakedInPool = (0, utils_1.toNormalizedBn)(totalStaked, decimals);
709
+ const normalizedRedeemable = (0, utils_1.toNormalizedBn)(earned, REWARDS_DECIMALS);
710
+ const normalizedRewardsPerSecond = (0, utils_1.toNormalizedBn)(rewardsPerSecond, REWARDS_DECIMALS);
711
+ const normalizedTotalStakedBalance = (0, utils_1.toNormalizedBn)(balance, decimals);
712
+ const rewardTokenPriceToMultiply = symbol === UP_AUSD_SYMBOL
713
+ ? Number(normalizedRewardTokenPrice?.normalized)
714
+ : 1;
715
+ const STAKED_APR = ((Number(normalizedRewardsPerSecond?.normalized) *
716
+ APR_MULTIPLIER *
717
+ rewardTokenPriceToMultiply) /
718
+ (Number(normalizedTotalStakedInPool?.normalized) * Number(1))) *
719
+ 100;
720
+ const MAX_APR = ((Number(normalizedRewardsPerSecond?.normalized) *
721
+ APR_MULTIPLIER *
722
+ rewardTokenPriceToMultiply) /
723
+ (Number(normalizedTotalStakedInPool?.normalized) * Number(1))) *
724
+ 100;
725
+ const activePosition = {
726
+ id: String(i),
727
+ rewardToken: {
728
+ decimals: REWARDS_DECIMALS,
729
+ symbol: REWARDS_SYMBOL,
730
+ address: ethers_1.ZeroAddress,
731
+ chain: REWARDS_CHAIN,
732
+ redeemable: normalizedRedeemable,
733
+ usd: normalizedRewardTokenPrice,
734
+ name: REWARDS_NAME,
735
+ },
736
+ stakingToken: {
737
+ decimals: Number(decimals),
738
+ symbol: symbol,
739
+ address: stakingTokenAddress,
740
+ chain: REWARDS_CHAIN,
741
+ totalStaked: normalizedTotalStakedBalance,
742
+ usd: normalizedRewardTokenPrice,
743
+ totalSupply: normalizedTotalStakedInPool,
744
+ name: name,
745
+ },
746
+ rewardDistributor: contract,
747
+ rewardPerSecond: (0, utils_1.toNormalizedBn)(rewardsPerSecond),
748
+ apy: STAKED_APR,
749
+ maxApy: MAX_APR,
750
+ chainId: REWARDS_CHAIN,
751
+ };
752
+ return activePosition;
753
+ }));
754
+ return positions;
755
+ }
756
+ catch (e) {
757
+ console.error('#getStakingPositions:', e);
758
+ }
759
+ }
760
+ //# sourceMappingURL=getters.js.map