@upshiftfinance/sdk 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (344) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +408 -2
  3. package/lib/abis/AddressResolver.d.ts +28 -0
  4. package/lib/abis/AddressResolver.js +23 -0
  5. package/lib/abis/ChainlinkV3.d.ts +87 -0
  6. package/lib/abis/ChainlinkV3.js +117 -0
  7. package/lib/abis/ERC20.d.ts +168 -0
  8. package/lib/abis/ERC20.js +226 -0
  9. package/lib/abis/ERC20_Bytes32.d.ts +139 -0
  10. package/lib/abis/ERC20_Bytes32.js +196 -0
  11. package/lib/abis/ERC4626.d.ts +364 -0
  12. package/lib/abis/ERC4626.js +507 -0
  13. package/lib/abis/ERC721.d.ts +231 -0
  14. package/lib/abis/ERC721.js +321 -0
  15. package/lib/abis/FeeOracle.d.ts +120 -0
  16. package/lib/abis/FeeOracle.js +162 -0
  17. package/lib/abis/LendingPool.d.ts +1393 -0
  18. package/lib/abis/LendingPool.js +1807 -0
  19. package/lib/abis/LendingPoolV2.d.ts +1413 -0
  20. package/lib/abis/LendingPoolV2.js +1833 -0
  21. package/lib/abis/LendingPoolV3.d.ts +1677 -0
  22. package/lib/abis/LendingPoolV3.js +1160 -0
  23. package/lib/abis/Loan.d.ts +837 -0
  24. package/lib/abis/Loan.js +1080 -0
  25. package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
  26. package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
  27. package/lib/abis/Multicall3.d.ts +30 -0
  28. package/lib/abis/Multicall3.js +97 -0
  29. package/lib/abis/OFT.d.ts +116 -0
  30. package/lib/abis/OFT.js +85 -0
  31. package/lib/abis/PoolAdapter.d.ts +36 -0
  32. package/lib/abis/PoolAdapter.js +51 -0
  33. package/lib/abis/RewardDistributor.d.ts +267 -0
  34. package/lib/abis/RewardDistributor.js +352 -0
  35. package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
  36. package/lib/abis/RwaRedeemSubaccount.js +548 -0
  37. package/lib/abis/SmartAccount.d.ts +17 -0
  38. package/lib/abis/SmartAccount.js +19 -0
  39. package/lib/abis/SwapRouter.d.ts +953 -0
  40. package/lib/abis/SwapRouter.js +1228 -0
  41. package/lib/abis/TextResolver.d.ts +16 -0
  42. package/lib/abis/TextResolver.js +16 -0
  43. package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
  44. package/lib/abis/TokenizedVaultV2.js +1041 -0
  45. package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
  46. package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
  47. package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
  48. package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
  49. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
  50. package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
  51. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
  52. package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
  53. package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
  54. package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
  55. package/lib/abis/UniversalResolverResolve.d.ts +69 -0
  56. package/lib/abis/UniversalResolverResolve.js +35 -0
  57. package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
  58. package/lib/abis/UniversalSignatureValidator.js +30 -0
  59. package/lib/abis/WrapperAdapter.d.ts +71 -0
  60. package/lib/abis/WrapperAdapter.js +77 -0
  61. package/lib/abis/index.d.ts +34 -0
  62. package/lib/abis/index.js +51 -0
  63. package/lib/adapters/evm/getters.d.ts +19 -0
  64. package/lib/adapters/evm/getters.js +249 -0
  65. package/lib/adapters/evm/index.d.ts +539 -0
  66. package/lib/adapters/evm/index.js +656 -0
  67. package/lib/adapters/evm/utils.d.ts +8 -0
  68. package/lib/adapters/evm/utils.js +51 -0
  69. package/lib/adapters/solana/confirm.d.ts +88 -0
  70. package/lib/adapters/solana/confirm.js +291 -0
  71. package/lib/adapters/solana/constants.d.ts +42 -0
  72. package/lib/adapters/solana/constants.js +59 -0
  73. package/lib/adapters/solana/getters.d.ts +42 -0
  74. package/lib/adapters/solana/getters.js +275 -0
  75. package/lib/adapters/solana/idl/vault-idl.d.ts +700 -0
  76. package/lib/adapters/solana/idl/vault-idl.js +2101 -0
  77. package/lib/adapters/solana/idl/withdrawal-queue-idl.d.ts +795 -0
  78. package/lib/adapters/solana/idl/withdrawal-queue-idl.js +1864 -0
  79. package/lib/adapters/solana/index.d.ts +372 -0
  80. package/lib/adapters/solana/index.js +459 -0
  81. package/lib/adapters/solana/pricing.d.ts +184 -0
  82. package/lib/adapters/solana/pricing.js +239 -0
  83. package/lib/adapters/solana/queue-hints.d.ts +29 -0
  84. package/lib/adapters/solana/queue-hints.js +59 -0
  85. package/lib/adapters/solana/queue.actions.d.ts +97 -0
  86. package/lib/adapters/solana/queue.actions.js +468 -0
  87. package/lib/adapters/solana/token-reads.d.ts +108 -0
  88. package/lib/adapters/solana/token-reads.js +145 -0
  89. package/lib/adapters/solana/types.d.ts +325 -0
  90. package/lib/adapters/solana/types.js +3 -0
  91. package/lib/adapters/solana/utils.d.ts +229 -0
  92. package/lib/adapters/solana/utils.js +773 -0
  93. package/lib/adapters/solana/vault.actions.d.ts +140 -0
  94. package/lib/adapters/solana/vault.actions.js +657 -0
  95. package/lib/adapters/solana/withdrawal-queue.d.ts +125 -0
  96. package/lib/adapters/solana/withdrawal-queue.js +301 -0
  97. package/lib/adapters/stellar/actions.d.ts +41 -0
  98. package/lib/adapters/stellar/actions.js +126 -0
  99. package/lib/adapters/stellar/constants.d.ts +43 -0
  100. package/lib/adapters/stellar/constants.js +53 -0
  101. package/lib/adapters/stellar/getters.d.ts +68 -0
  102. package/lib/adapters/stellar/getters.js +290 -0
  103. package/lib/adapters/stellar/index.d.ts +126 -0
  104. package/lib/adapters/stellar/index.js +187 -0
  105. package/lib/adapters/stellar/invocation.d.ts +55 -0
  106. package/lib/adapters/stellar/invocation.js +92 -0
  107. package/lib/adapters/stellar/soroban.d.ts +131 -0
  108. package/lib/adapters/stellar/soroban.js +617 -0
  109. package/lib/adapters/stellar/submit.d.ts +42 -0
  110. package/lib/adapters/stellar/submit.js +195 -0
  111. package/lib/adapters/stellar/types.d.ts +57 -0
  112. package/lib/adapters/stellar/types.js +6 -0
  113. package/lib/adapters/stellar/utils.d.ts +24 -0
  114. package/lib/adapters/stellar/utils.js +34 -0
  115. package/lib/adapters/sui/client.d.ts +83 -0
  116. package/lib/adapters/sui/client.js +216 -0
  117. package/lib/adapters/sui/constants.d.ts +33 -0
  118. package/lib/adapters/sui/constants.js +31 -0
  119. package/lib/adapters/sui/index.d.ts +57 -0
  120. package/lib/adapters/sui/index.js +100 -0
  121. package/lib/adapters/sui/targets.d.ts +171 -0
  122. package/lib/adapters/sui/targets.js +225 -0
  123. package/lib/adapters/sui/utils.d.ts +8 -0
  124. package/lib/adapters/sui/utils.js +17 -0
  125. package/lib/core/analytics/app-name.d.ts +27 -0
  126. package/lib/core/analytics/app-name.js +48 -0
  127. package/lib/core/analytics/chain-name.d.ts +9 -0
  128. package/lib/core/analytics/chain-name.js +34 -0
  129. package/lib/core/analytics/constants.d.ts +15 -0
  130. package/lib/core/analytics/constants.js +28 -0
  131. package/lib/core/analytics/env.d.ts +46 -0
  132. package/lib/core/analytics/env.js +147 -0
  133. package/lib/core/analytics/index.d.ts +39 -0
  134. package/lib/core/analytics/index.js +83 -0
  135. package/lib/core/analytics/instrumentation.d.ts +29 -0
  136. package/lib/core/analytics/instrumentation.js +292 -0
  137. package/lib/core/analytics/method-taxonomy.d.ts +19 -0
  138. package/lib/core/analytics/method-taxonomy.js +156 -0
  139. package/lib/core/analytics/metrics.d.ts +48 -0
  140. package/lib/core/analytics/metrics.js +142 -0
  141. package/lib/core/analytics/sanitize.d.ts +57 -0
  142. package/lib/core/analytics/sanitize.js +272 -0
  143. package/lib/core/analytics/sentry-runtime.d.ts +15 -0
  144. package/lib/core/analytics/sentry-runtime.js +131 -0
  145. package/lib/core/analytics/sentry.d.ts +100 -0
  146. package/lib/core/analytics/sentry.js +696 -0
  147. package/lib/core/analytics/types.d.ts +55 -0
  148. package/lib/core/analytics/types.js +3 -0
  149. package/lib/core/analytics/user-identity.d.ts +55 -0
  150. package/lib/core/analytics/user-identity.js +218 -0
  151. package/lib/core/analytics/version.d.ts +6 -0
  152. package/lib/core/analytics/version.js +10 -0
  153. package/lib/core/attribution.d.ts +159 -0
  154. package/lib/core/attribution.js +194 -0
  155. package/lib/core/auth/index.d.ts +1 -0
  156. package/lib/core/auth/index.js +18 -0
  157. package/lib/core/auth/verify.d.ts +2 -0
  158. package/lib/core/auth/verify.js +35 -0
  159. package/lib/core/base.class.d.ts +193 -0
  160. package/lib/core/base.class.js +163 -0
  161. package/lib/core/cache.d.ts +9 -0
  162. package/lib/core/cache.js +31 -0
  163. package/lib/core/constants/adapters.d.ts +103 -0
  164. package/lib/core/constants/adapters.js +180 -0
  165. package/lib/core/constants/core.d.ts +162 -0
  166. package/lib/core/constants/core.js +281 -0
  167. package/lib/core/constants/swap-router.d.ts +180 -0
  168. package/lib/core/constants/swap-router.js +203 -0
  169. package/lib/core/constants/vaults.d.ts +93 -0
  170. package/lib/core/constants/vaults.js +277 -0
  171. package/lib/core/constants/web3.d.ts +106 -0
  172. package/lib/core/constants/web3.js +251 -0
  173. package/lib/core/errors/index.d.ts +177 -0
  174. package/lib/core/errors/index.js +257 -0
  175. package/lib/core/fetcher.d.ts +237 -0
  176. package/lib/core/fetcher.js +1103 -0
  177. package/lib/core/helpers/adapters.d.ts +13 -0
  178. package/lib/core/helpers/adapters.js +39 -0
  179. package/lib/core/helpers/chain-address.d.ts +13 -0
  180. package/lib/core/helpers/chain-address.js +47 -0
  181. package/lib/core/helpers/chain-error.d.ts +207 -0
  182. package/lib/core/helpers/chain-error.js +697 -0
  183. package/lib/core/helpers/chain-support.d.ts +98 -0
  184. package/lib/core/helpers/chain-support.js +139 -0
  185. package/lib/core/helpers/concurrency.d.ts +51 -0
  186. package/lib/core/helpers/concurrency.js +79 -0
  187. package/lib/core/helpers/core.d.ts +92 -0
  188. package/lib/core/helpers/core.js +368 -0
  189. package/lib/core/helpers/explorer-link.d.ts +16 -0
  190. package/lib/core/helpers/explorer-link.js +26 -0
  191. package/lib/core/helpers/multicall.d.ts +68 -0
  192. package/lib/core/helpers/multicall.js +103 -0
  193. package/lib/core/helpers/revert-decode.d.ts +248 -0
  194. package/lib/core/helpers/revert-decode.js +515 -0
  195. package/lib/core/helpers/signer.d.ts +61 -0
  196. package/lib/core/helpers/signer.js +184 -0
  197. package/lib/core/helpers/swap-router.d.ts +269 -0
  198. package/lib/core/helpers/swap-router.js +542 -0
  199. package/lib/core/helpers/vault-version.d.ts +24 -0
  200. package/lib/core/helpers/vault-version.js +83 -0
  201. package/lib/core/helpers/vaults.d.ts +89 -0
  202. package/lib/core/helpers/vaults.js +241 -0
  203. package/lib/core/helpers/web3.d.ts +366 -0
  204. package/lib/core/helpers/web3.js +1034 -0
  205. package/lib/core/index.d.ts +23 -0
  206. package/lib/core/index.js +40 -0
  207. package/lib/core/logger/curator-alert.d.ts +217 -0
  208. package/lib/core/logger/curator-alert.js +276 -0
  209. package/lib/core/logger/index.d.ts +99 -0
  210. package/lib/core/logger/index.js +163 -0
  211. package/lib/core/logger/slack.d.ts +49 -0
  212. package/lib/core/logger/slack.js +111 -0
  213. package/lib/core/vault-metadata.d.ts +12 -0
  214. package/lib/core/vault-metadata.js +42 -0
  215. package/lib/core/version-check.d.ts +58 -0
  216. package/lib/core/version-check.js +182 -0
  217. package/lib/evm/index.d.ts +2 -0
  218. package/lib/evm/index.js +19 -0
  219. package/lib/evm/methods/crossChainVault.d.ts +132 -0
  220. package/lib/evm/methods/crossChainVault.js +857 -0
  221. package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
  222. package/lib/evm/methods/crossChainVaultRegistry.js +239 -0
  223. package/lib/evm/methods/index.d.ts +2 -0
  224. package/lib/evm/methods/index.js +19 -0
  225. package/lib/evm/types/crossChain.d.ts +363 -0
  226. package/lib/evm/types/crossChain.js +20 -0
  227. package/lib/evm/types/index.d.ts +1 -0
  228. package/lib/evm/types/index.js +18 -0
  229. package/lib/index.d.ts +30 -0
  230. package/lib/index.js +52 -0
  231. package/lib/main.d.ts +596 -0
  232. package/lib/main.js +681 -0
  233. package/lib/modules/api/fetcher.d.ts +108 -0
  234. package/lib/modules/api/fetcher.js +187 -0
  235. package/lib/modules/api/index.d.ts +1 -0
  236. package/lib/modules/api/index.js +6 -0
  237. package/lib/modules/api/main.d.ts +587 -0
  238. package/lib/modules/api/main.js +911 -0
  239. package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
  240. package/lib/modules/sub-accounts/fetcher.js +96 -0
  241. package/lib/modules/sub-accounts/index.d.ts +2 -0
  242. package/lib/modules/sub-accounts/index.js +19 -0
  243. package/lib/modules/sub-accounts/main.d.ts +249 -0
  244. package/lib/modules/sub-accounts/main.js +211 -0
  245. package/lib/modules/sub-accounts/utils.d.ts +106 -0
  246. package/lib/modules/sub-accounts/utils.js +112 -0
  247. package/lib/modules/vaults/adapter.helpers.d.ts +84 -0
  248. package/lib/modules/vaults/adapter.helpers.js +202 -0
  249. package/lib/modules/vaults/fetcher.d.ts +147 -0
  250. package/lib/modules/vaults/fetcher.js +357 -0
  251. package/lib/modules/vaults/getters.d.ts +1060 -0
  252. package/lib/modules/vaults/getters.js +4079 -0
  253. package/lib/modules/vaults/index.d.ts +20 -0
  254. package/lib/modules/vaults/index.js +44 -0
  255. package/lib/modules/vaults/main.d.ts +607 -0
  256. package/lib/modules/vaults/main.js +1687 -0
  257. package/lib/modules/vaults/prefetch.d.ts +65 -0
  258. package/lib/modules/vaults/prefetch.js +120 -0
  259. package/lib/modules/vaults/read.actions.d.ts +406 -0
  260. package/lib/modules/vaults/read.actions.js +891 -0
  261. package/lib/modules/vaults/types.d.ts +149 -0
  262. package/lib/modules/vaults/types.js +3 -0
  263. package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
  264. package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
  265. package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
  266. package/lib/modules/vaults/utils/date-utils.js +84 -0
  267. package/lib/modules/vaults/utils.d.ts +153 -0
  268. package/lib/modules/vaults/utils.js +818 -0
  269. package/lib/modules/vaults/write.actions.d.ts +812 -0
  270. package/lib/modules/vaults/write.actions.js +2377 -0
  271. package/lib/polyfills.d.ts +1 -0
  272. package/lib/polyfills.js +12 -0
  273. package/lib/sdk.d.ts +30173 -0
  274. package/lib/services/coingecko/fetcher.d.ts +15 -0
  275. package/lib/services/coingecko/fetcher.js +67 -0
  276. package/lib/services/coingecko/index.d.ts +2 -0
  277. package/lib/services/coingecko/index.js +19 -0
  278. package/lib/services/coingecko/utils.d.ts +1 -0
  279. package/lib/services/coingecko/utils.js +24 -0
  280. package/lib/services/debank/fetcher.d.ts +126 -0
  281. package/lib/services/debank/fetcher.js +47 -0
  282. package/lib/services/debank/index.d.ts +2 -0
  283. package/lib/services/debank/index.js +19 -0
  284. package/lib/services/debank/utils.d.ts +50 -0
  285. package/lib/services/debank/utils.js +325 -0
  286. package/lib/services/layerzero/deposits.d.ts +55 -0
  287. package/lib/services/layerzero/deposits.js +174 -0
  288. package/lib/services/layerzero/redeems.d.ts +20 -0
  289. package/lib/services/layerzero/redeems.js +92 -0
  290. package/lib/services/layerzero/utils.d.ts +9 -0
  291. package/lib/services/layerzero/utils.js +22 -0
  292. package/lib/services/octavfi/fetcher.d.ts +33 -0
  293. package/lib/services/octavfi/fetcher.js +39 -0
  294. package/lib/services/octavfi/index.d.ts +3 -0
  295. package/lib/services/octavfi/index.js +20 -0
  296. package/lib/services/octavfi/types.d.ts +34 -0
  297. package/lib/services/octavfi/types.js +3 -0
  298. package/lib/services/octavfi/utils.d.ts +16 -0
  299. package/lib/services/octavfi/utils.js +244 -0
  300. package/lib/services/subgraph/fetcher.d.ts +2 -0
  301. package/lib/services/subgraph/fetcher.js +66 -0
  302. package/lib/services/subgraph/index.d.ts +2 -0
  303. package/lib/services/subgraph/index.js +19 -0
  304. package/lib/services/subgraph/schema.d.ts +48 -0
  305. package/lib/services/subgraph/schema.js +87 -0
  306. package/lib/services/subgraph/vaults.d.ts +83 -0
  307. package/lib/services/subgraph/vaults.js +1282 -0
  308. package/lib/services/swap-quotes/index.d.ts +105 -0
  309. package/lib/services/swap-quotes/index.js +77 -0
  310. package/lib/services/swap-quotes/paraswap.d.ts +51 -0
  311. package/lib/services/swap-quotes/paraswap.js +138 -0
  312. package/lib/services/untangled/fetcher.d.ts +40 -0
  313. package/lib/services/untangled/fetcher.js +110 -0
  314. package/lib/services/untangled/index.d.ts +3 -0
  315. package/lib/services/untangled/index.js +20 -0
  316. package/lib/services/untangled/types.d.ts +83 -0
  317. package/lib/services/untangled/types.js +10 -0
  318. package/lib/services/untangled/utils.d.ts +91 -0
  319. package/lib/services/untangled/utils.js +339 -0
  320. package/lib/types/api.d.ts +498 -0
  321. package/lib/types/api.js +3 -0
  322. package/lib/types/index.d.ts +12 -0
  323. package/lib/types/index.js +28 -0
  324. package/lib/types/points.d.ts +28 -0
  325. package/lib/types/points.js +3 -0
  326. package/lib/types/pools.d.ts +144 -0
  327. package/lib/types/pools.js +3 -0
  328. package/lib/types/staking.d.ts +28 -0
  329. package/lib/types/staking.js +3 -0
  330. package/lib/types/sub-accounts.d.ts +150 -0
  331. package/lib/types/sub-accounts.js +3 -0
  332. package/lib/types/subgraph.d.ts +84 -0
  333. package/lib/types/subgraph.js +3 -0
  334. package/lib/types/typed-contract.d.ts +102 -0
  335. package/lib/types/typed-contract.js +3 -0
  336. package/lib/types/user.d.ts +1 -0
  337. package/lib/types/user.js +3 -0
  338. package/lib/types/vaults.d.ts +886 -0
  339. package/lib/types/vaults.js +30 -0
  340. package/lib/types/web3.d.ts +100 -0
  341. package/lib/types/web3.js +14 -0
  342. package/lib/types/webserver.d.ts +730 -0
  343. package/lib/types/webserver.js +3 -0
  344. package/package.json +79 -3
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseVaultLevelDebank = parseVaultLevelDebank;
4
+ exports.getVaultExposure = getVaultExposure;
5
+ exports.parseLoanLevelDebank = parseLoanLevelDebank;
6
+ const core_1 = require("../../core");
7
+ const core_2 = require("../../core/helpers/core");
8
+ function addToTokenExposure(token, tokenExposure, exposureType, protocol, exposurePerCategory, netValue, borrower, poolId) {
9
+ const usdAmount = Number(token?.price || 0) * Number(token?.amount);
10
+ // Dust filter applies uniformly to every exposure type.
11
+ if (!(0, core_2.filterOutBySize)(usdAmount))
12
+ return;
13
+ if (exposureType === 'borrow') {
14
+ netValue.value -= usdAmount;
15
+ }
16
+ else {
17
+ netValue.value += usdAmount;
18
+ }
19
+ // Merge into an existing row only when the symbol, the exposure type AND
20
+ // the protocol all match: the same token supplied in one protocol and
21
+ // borrowed in another must stay as two rows (different
22
+ // `exposurePerCategory` buckets), and the same token supplied in two
23
+ // protocols must stay as two rows (allocations are reported per protocol).
24
+ // Repeat sightings of the same symbol/type/protocol triple accumulate.
25
+ //
26
+ // The lookup key must be the exact expression stored on the row below
27
+ // (`optimized_symbol` first), otherwise a token whose optimized symbol differs
28
+ // from its raw symbol never finds its own row and is emitted again.
29
+ const rowSymbol = token?.optimized_symbol || token?.symbol;
30
+ const foundTokenExposure = tokenExposure.find((t) => t.symbol === rowSymbol &&
31
+ t.exposureType === exposureType &&
32
+ t.protocol === protocol);
33
+ if (foundTokenExposure) {
34
+ foundTokenExposure.amount += usdAmount;
35
+ }
36
+ else {
37
+ const protoReturnObj = {
38
+ id: token?.id,
39
+ chain: token?.chain,
40
+ name: token?.name,
41
+ symbol: rowSymbol,
42
+ decimals: token?.decimals,
43
+ logoUrl: token?.logo_url,
44
+ amount: usdAmount,
45
+ protocol: protocol,
46
+ exposureType: exposureType,
47
+ poolId: poolId,
48
+ };
49
+ if (exposureType === 'wallet') {
50
+ exposurePerCategory.wallet.push(protoReturnObj);
51
+ }
52
+ else if (exposureType === 'borrow') {
53
+ exposurePerCategory.borrowing.push(protoReturnObj);
54
+ }
55
+ else if (exposureType === 'supply') {
56
+ exposurePerCategory.supplying.push(protoReturnObj);
57
+ }
58
+ tokenExposure.push(protoReturnObj);
59
+ }
60
+ }
61
+ function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue) {
62
+ // new mapping to grab vault-level token and protocol exposure per
63
+ const tokenMap = {};
64
+ const protocolTokenMap = {};
65
+ const protocolExposures = debankRes?.subaccount?.positions || [];
66
+ const appProtocolExposures = debankRes?.subaccount?.app_positions || [];
67
+ const tokenExposures = debankRes?.subaccount?.tokens || [];
68
+ protocolExposures.forEach((pos) => {
69
+ // protocol-level data fetching
70
+ const protoReturnObj = {
71
+ id: pos?.id,
72
+ chain: pos?.chain,
73
+ protocol: pos?.name,
74
+ logoUrl: pos?.logo_url,
75
+ siteUrl: pos?.site_url,
76
+ assetUsdValue: 0,
77
+ debtUsdValue: 0,
78
+ netUsdValue: 0,
79
+ label: pos?.portfolio_item_list?.[0]?.name,
80
+ tokenExposure: tokenMap,
81
+ protocolExposure: protocolTokenMap,
82
+ address: borrower,
83
+ };
84
+ pos?.portfolio_item_list?.forEach((item) => {
85
+ // initialize protocol exposure
86
+ protoReturnObj.assetUsdValue += item?.stats?.asset_usd_value || 0;
87
+ protoReturnObj.debtUsdValue += item?.stats?.debt_usd_value || 0;
88
+ protoReturnObj.netUsdValue += item?.stats?.net_usd_value || 0;
89
+ });
90
+ const foundExistingProtocolExposure = protocolExposure.find((exp) => exp.id === pos.id);
91
+ if (!foundExistingProtocolExposure &&
92
+ (0, core_2.filterOutBySize)(protoReturnObj.netUsdValue)) {
93
+ protocolExposure.push(protoReturnObj);
94
+ }
95
+ else if (foundExistingProtocolExposure) {
96
+ foundExistingProtocolExposure.netUsdValue += protoReturnObj.netUsdValue;
97
+ foundExistingProtocolExposure.debtUsdValue += protoReturnObj.debtUsdValue;
98
+ foundExistingProtocolExposure.assetUsdValue +=
99
+ protoReturnObj.assetUsdValue;
100
+ }
101
+ // go through the debank portfolio
102
+ pos.portfolio_item_list.forEach((item) => {
103
+ item.detail.supply_token_list.forEach((sup) => {
104
+ // add protocol id for vault-level "protocol exposure"
105
+ if (sup?.protocol_id) {
106
+ const existingArray = protocolTokenMap[sup.protocol_id] || [];
107
+ if (!existingArray.includes(sup.symbol))
108
+ existingArray.push(sup.symbol);
109
+ }
110
+ // add token to vault "token exposure"
111
+ addToTokenExposure(sup, tokenExposure, 'supply', pos.id, exposurePerCategory, netValue, borrower, item?.pool?.id);
112
+ // add token image url to token mapping for display
113
+ if (sup?.symbol && sup?.logo_url) {
114
+ tokenMap[sup.symbol] = sup.logo_url;
115
+ }
116
+ // `supplying_exposure` is not a DeBank token field (always undefined
117
+ // at runtime); kept as-is to preserve existing `tokenMap` output.
118
+ tokenMap[sup.supplying_exposure] =
119
+ 'true';
120
+ });
121
+ item.detail.borrow_token_list.forEach((bor) => {
122
+ // add token to vault "token exposure"
123
+ addToTokenExposure(bor, tokenExposure, 'borrow', pos.id, exposurePerCategory, netValue, borrower, item?.pool?.id);
124
+ // add token image url to token mapping for display
125
+ if (bor?.symbol && bor?.logo_url) {
126
+ tokenMap[bor.symbol] = bor.logo_url;
127
+ }
128
+ // `supplying_exposure` is not a DeBank token field (always undefined
129
+ // at runtime); kept as-is to preserve existing `tokenMap` output.
130
+ tokenMap[bor.supplying_exposure] =
131
+ 'true';
132
+ });
133
+ });
134
+ });
135
+ // Process non-EVM app protocols (e.g. Hyperliquid, Lighter).
136
+ // These lack chain and protocol_id fields unlike EVM-based positions.
137
+ appProtocolExposures.forEach((pos) => {
138
+ const protoReturnObj = {
139
+ id: pos?.id,
140
+ chain: null,
141
+ protocol: pos?.name,
142
+ logoUrl: pos?.logo_url,
143
+ siteUrl: pos?.site_url,
144
+ assetUsdValue: 0,
145
+ debtUsdValue: 0,
146
+ netUsdValue: 0,
147
+ label: pos?.portfolio_item_list?.[0]?.name,
148
+ tokenExposure: tokenMap,
149
+ protocolExposure: protocolTokenMap,
150
+ address: borrower,
151
+ };
152
+ pos?.portfolio_item_list?.forEach((item) => {
153
+ protoReturnObj.assetUsdValue += item?.stats?.asset_usd_value || 0;
154
+ protoReturnObj.debtUsdValue += item?.stats?.debt_usd_value || 0;
155
+ protoReturnObj.netUsdValue += item?.stats?.net_usd_value || 0;
156
+ });
157
+ const foundExistingProtocolExposure = protocolExposure.find((exp) => exp.id === pos.id);
158
+ if (!foundExistingProtocolExposure &&
159
+ (0, core_2.filterOutBySize)(protoReturnObj.netUsdValue)) {
160
+ protocolExposure.push(protoReturnObj);
161
+ }
162
+ else if (foundExistingProtocolExposure) {
163
+ foundExistingProtocolExposure.netUsdValue += protoReturnObj.netUsdValue;
164
+ foundExistingProtocolExposure.debtUsdValue += protoReturnObj.debtUsdValue;
165
+ foundExistingProtocolExposure.assetUsdValue +=
166
+ protoReturnObj.assetUsdValue;
167
+ }
168
+ pos?.portfolio_item_list?.forEach((item) => {
169
+ (item?.detail?.supply_token_list || []).forEach((sup) => {
170
+ addToTokenExposure(sup, tokenExposure, 'supply', pos.id, exposurePerCategory, netValue, borrower,
171
+ // App portfolio items carry `pool` only as an untyped extra field.
172
+ item?.pool?.id);
173
+ if (sup?.symbol && sup?.logo_url) {
174
+ tokenMap[sup.symbol] = sup.logo_url;
175
+ }
176
+ });
177
+ (item?.detail?.borrow_token_list || []).forEach((bor) => {
178
+ addToTokenExposure(bor, tokenExposure, 'borrow', pos.id, exposurePerCategory, netValue, borrower,
179
+ // App portfolio items carry `pool` only as an untyped extra field.
180
+ item?.pool?.id);
181
+ if (bor?.symbol && bor?.logo_url) {
182
+ tokenMap[bor.symbol] = bor.logo_url;
183
+ }
184
+ });
185
+ });
186
+ });
187
+ tokenExposures?.forEach((token) => {
188
+ if (token?.is_wallet) {
189
+ addToTokenExposure(token, tokenExposure, 'wallet', null, exposurePerCategory, netValue, borrower);
190
+ }
191
+ });
192
+ const loanLevelExposure = parseLoanLevelDebank(debankRes);
193
+ return {
194
+ tokenMap,
195
+ protocolTokenMap,
196
+ protocolExposures,
197
+ tokenExposures,
198
+ loansExposure: loanLevelExposure,
199
+ };
200
+ }
201
+ function getVaultExposure(debankResponse) {
202
+ const borrowing_exposure = [];
203
+ const supplying_exposure = [];
204
+ const wallet_exposure = [];
205
+ const positions = debankResponse?.subaccount?.positions ?? [];
206
+ const tokens = debankResponse?.subaccount?.tokens ?? [];
207
+ // Wallet (idle) tokens belong to the subaccount, not to any position, so
208
+ // they are counted exactly once — not once per portfolio item.
209
+ for (const token of tokens) {
210
+ if (token?.symbol && token?.is_core) {
211
+ wallet_exposure.push({
212
+ symbol: token.symbol,
213
+ chain: token.chain,
214
+ amount: token.amount * token.price,
215
+ });
216
+ }
217
+ }
218
+ for (const position of positions) {
219
+ const portfolioItems = position?.portfolio_item_list ?? [];
220
+ for (const item of portfolioItems) {
221
+ const borrowTokens = item?.detail?.borrow_token_list ?? [];
222
+ const supplyTokens = item?.detail?.supply_token_list ?? [];
223
+ for (const token of borrowTokens) {
224
+ if (token?.symbol &&
225
+ !token.is_suspicious &&
226
+ !token.is_scam &&
227
+ token?.is_core) {
228
+ borrowing_exposure.push({
229
+ symbol: token.symbol,
230
+ chain: token.chain,
231
+ amount: token.amount * token.price,
232
+ });
233
+ }
234
+ }
235
+ for (const token of supplyTokens) {
236
+ if (token?.symbol &&
237
+ !token.is_suspicious &&
238
+ !token.is_scam &&
239
+ token?.is_core) {
240
+ // Not sure what isWallet is, but I'm guessing is that this field means that it should be in wallet exposure...
241
+ // fwiw I have seen this double counted in supplyTokens AND tokens
242
+ if (!token.is_wallet) {
243
+ supplying_exposure.push({
244
+ symbol: token.symbol,
245
+ chain: token.chain,
246
+ amount: token.amount * token.price,
247
+ });
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ return { borrowing_exposure, supplying_exposure, wallet_exposure };
254
+ }
255
+ function parseLoanLevelDebank(debankRes) {
256
+ let positions = [];
257
+ let exposure = [];
258
+ try {
259
+ // new mapping to grab token and protocol exposure
260
+ const protocolExposures = [
261
+ ...(debankRes?.subaccount?.positions || []),
262
+ ...(debankRes?.subaccount?.app_positions || []),
263
+ ];
264
+ // Old mapping to grab token and protocol exposure
265
+ positions = protocolExposures?.map((p) => ({
266
+ value: p.logo_url,
267
+ label: p.name,
268
+ }));
269
+ exposure = protocolExposures?.map((p) => p.portfolio_item_list?.map((li) => {
270
+ const extra = {
271
+ value: li.pool?.controller,
272
+ label: li.pool?.adapter_id,
273
+ usd: li?.stats?.asset_usd_value,
274
+ };
275
+ if (li.detail?.supply_token_list?.length) {
276
+ const returnArr = li.detail?.supply_token_list?.map((t) => ({
277
+ value: t?.id,
278
+ label: t?.symbol,
279
+ usd: t?.amount * t?.price,
280
+ }));
281
+ return [...returnArr, extra];
282
+ }
283
+ return extra;
284
+ }));
285
+ // this is a request where if there is no protocol exposure then show any spots
286
+ // over 10k in collateral exposure
287
+ if (protocolExposures.length === 0) {
288
+ if (debankRes?.subaccount?.tokens) {
289
+ debankRes.subaccount.tokens.forEach((t) => {
290
+ if (t?.amount && t?.price && t.amount * t.price >= 10_000) {
291
+ exposure.push({
292
+ value: t?.id,
293
+ label: t?.symbol,
294
+ usd: t?.amount && t?.price ? t.amount * t.price : '',
295
+ });
296
+ }
297
+ });
298
+ }
299
+ }
300
+ exposure = exposure?.flat()?.flat();
301
+ // De-duplicate by `value` (token id / pool controller), summing `usd`
302
+ // across sightings. The accumulator row starts at `usd: 0` so the `+=`
303
+ // below counts the first sighting exactly once — seeding it with `a.usd`
304
+ // and then adding `a.usd` again doubled every unique exposure.
305
+ const uniqueExposure = [];
306
+ exposure?.forEach(function (a) {
307
+ if (!this[a.value]) {
308
+ if (a?.value === '0xa1290d69c65a6fe4df752f95823fae25cb99e5a7') {
309
+ this[a.value] = { ...a, label: 'rsETH', usd: 0 };
310
+ }
311
+ else {
312
+ this[a.value] = { ...a, usd: 0 };
313
+ }
314
+ uniqueExposure.push(this[a.value]);
315
+ }
316
+ this[a.value].usd += a.usd;
317
+ }, Object.create(null));
318
+ exposure = uniqueExposure;
319
+ }
320
+ catch (err) {
321
+ core_1.Logger.log.error('getPoolLoansData.strategies', err);
322
+ }
323
+ return { exposure, positions };
324
+ }
325
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,55 @@
1
+ /**
2
+ * LayerZero Deposits Service
3
+ * Handles querying LayerZero USDC deposits from subgraphs
4
+ */
5
+ import type { IAddress } from '../../types';
6
+ export declare const LAYERZERO_VAULTS: {
7
+ coreUSDC: {
8
+ address: IAddress;
9
+ receiptToken: "coreusdc";
10
+ decimals: number;
11
+ hubChainId: number;
12
+ hubComposer: IAddress;
13
+ hubShareOFT: IAddress;
14
+ spokeChains: Record<number, IAddress>;
15
+ subgraphEndpoints: string[];
16
+ };
17
+ upUSDC: {
18
+ address: IAddress;
19
+ receiptToken: "upusdc";
20
+ decimals: number;
21
+ hubChainId: number;
22
+ hubComposer: IAddress;
23
+ hubShareOFT: IAddress;
24
+ spokeChains: Record<number, IAddress>;
25
+ subgraphEndpoints: string[];
26
+ };
27
+ earnAUSD: {
28
+ address: IAddress;
29
+ receiptToken: "earnausd";
30
+ decimals: number;
31
+ hubChainId: number;
32
+ hubComposer: IAddress;
33
+ hubShareOFT: IAddress;
34
+ spokeChains: Record<number, IAddress>;
35
+ subgraphEndpoints: string[];
36
+ };
37
+ };
38
+ export interface ILayerZeroDeposit {
39
+ assetAmt: string;
40
+ dstEid: string;
41
+ sender: string;
42
+ recipient: string;
43
+ shareAmt: string;
44
+ transactionHash_: string;
45
+ timestamp_: string;
46
+ }
47
+ /**
48
+ * Check if a vault address or symbol is a LayerZero vault
49
+ */
50
+ export declare function isLayerZeroVault(vaultAddressOrSymbol: string): keyof typeof LAYERZERO_VAULTS | null;
51
+ /**
52
+ * Query LayerZero deposits from the appropriate subgraph
53
+ * @throws Error if the GraphQL request fails or returns invalid data
54
+ */
55
+ export declare function queryLayerZeroDeposits(vaultKey: keyof typeof LAYERZERO_VAULTS, wallet?: IAddress): Promise<ILayerZeroDeposit[]>;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ /**
3
+ * LayerZero Deposits Service
4
+ * Handles querying LayerZero USDC deposits from subgraphs
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LAYERZERO_VAULTS = void 0;
8
+ exports.isLayerZeroVault = isLayerZeroVault;
9
+ exports.queryLayerZeroDeposits = queryLayerZeroDeposits;
10
+ const fetcher_1 = require("../subgraph/fetcher");
11
+ const utils_1 = require("./utils");
12
+ // LayerZero vault addresses and their corresponding receipt tokens
13
+ // spokeChains maps chainId -> shareOFT address (receipt token on that chain)
14
+ // hubComposer / hubShareOFT: the hub-chain OVault composer (VAULT() is the
15
+ // vault) and its SHARE_OFT(), verified on-chain 2026-10-01
16
+ exports.LAYERZERO_VAULTS = {
17
+ coreUSDC: {
18
+ address: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
19
+ receiptToken: 'coreusdc',
20
+ decimals: 6, // USDC decimals
21
+ hubChainId: 1,
22
+ hubComposer: '0xc2637d7721791cc9cb196628d1e5e06887b1d4b9',
23
+ hubShareOFT: '0x4A21dcbA38c3816C78144f33bb42D8fa17F38067',
24
+ spokeChains: {
25
+ 42161: '0x50a31ff4d57841681011837c17aa201c6a34203c', // Arbitrum
26
+ 43114: '0x1FA931Bf85248aD2eDf0004DD9A284698358e708', // Avalanche
27
+ 8453: '0x1fa931bf85248ad2edf0004dd9a284698358e708', // Base
28
+ 146: '0x4bdd224fe59a3ae0b249125ad4c5b3126074c71b', // Sonic
29
+ },
30
+ subgraphEndpoints: [
31
+ 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-coreusdc/1.0.0/gn',
32
+ ],
33
+ },
34
+ upUSDC: {
35
+ address: '0x80E1048eDE66ec4c364b4F22C8768fc657FF6A42',
36
+ receiptToken: 'upusdc',
37
+ decimals: 6, // USDC decimals
38
+ hubChainId: 1,
39
+ hubComposer: '0xbe82134b95a8e9370e6759f3c8f44087cd9a52be',
40
+ hubShareOFT: '0x81971A3C359cFE74259CfF1b46FB5f2112ddDE34',
41
+ spokeChains: {
42
+ 42161: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Arbitrum
43
+ 43114: '0x81971A3C359cFE74259CfF1b46FB5f2112ddDE34', // Avalanche
44
+ 8453: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Base
45
+ 146: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Sonic
46
+ },
47
+ subgraphEndpoints: [
48
+ 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-upusdc/1.0.0/gn',
49
+ ],
50
+ },
51
+ earnAUSD: {
52
+ address: '0x36eDbF0C834591BFdfCaC0Ef9605528c75c406aA',
53
+ receiptToken: 'earnausd',
54
+ decimals: 6,
55
+ hubChainId: 143,
56
+ hubComposer: '0xd1b1b12533e12badb8ea6d63aedd11922cae5580',
57
+ hubShareOFT: '0x9549Fa3DF579Cca9F3e328695382675F7f1f0F34',
58
+ spokeChains: {
59
+ 1: '0xa6916b65c5e3fEdf46c0a2F59bff776e872C8992', // Ethereum
60
+ },
61
+ subgraphEndpoints: [
62
+ 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-earnAUSD/1.0.0/gn',
63
+ 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-earnausd/1.0.0/gn',
64
+ ],
65
+ },
66
+ };
67
+ /**
68
+ * Check if a vault address or symbol is a LayerZero vault
69
+ */
70
+ function isLayerZeroVault(vaultAddressOrSymbol) {
71
+ const normalized = vaultAddressOrSymbol.toLowerCase();
72
+ // Check by address
73
+ if (normalized === exports.LAYERZERO_VAULTS.coreUSDC.address.toLowerCase() ||
74
+ normalized === 'coreusdc') {
75
+ return 'coreUSDC';
76
+ }
77
+ if (normalized === exports.LAYERZERO_VAULTS.upUSDC.address.toLowerCase() ||
78
+ normalized === 'upusdc') {
79
+ return 'upUSDC';
80
+ }
81
+ if (normalized === exports.LAYERZERO_VAULTS.earnAUSD.address.toLowerCase() ||
82
+ normalized === 'earnausd') {
83
+ return 'earnAUSD';
84
+ }
85
+ return null;
86
+ }
87
+ /**
88
+ * Validate GraphQL response structure
89
+ */
90
+ function validateDepositResponse(result) {
91
+ if (!result || typeof result !== 'object') {
92
+ return false;
93
+ }
94
+ const r = result;
95
+ if (!r.data || typeof r.data !== 'object') {
96
+ return false;
97
+ }
98
+ const data = r.data;
99
+ if (!Array.isArray(data.depositeds)) {
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ /**
105
+ * Query LayerZero deposits from the appropriate subgraph
106
+ * @throws Error if the GraphQL request fails or returns invalid data
107
+ */
108
+ async function queryLayerZeroDeposits(vaultKey, wallet) {
109
+ const vaultConfig = exports.LAYERZERO_VAULTS[vaultKey];
110
+ // Build GraphQL query (fetchSubgraph prepends "query " automatically)
111
+ let query = `GetDeposits {
112
+ depositeds(first: 1000) {
113
+ assetAmt
114
+ dstEid
115
+ sender
116
+ recipient
117
+ shareAmt
118
+ transactionHash_
119
+ timestamp_
120
+ }
121
+ }`;
122
+ // If wallet is provided, filter by sender
123
+ if (wallet) {
124
+ const senderBytes32 = (0, utils_1.addressToBytes32)(wallet);
125
+ query = `GetDeposits {
126
+ depositeds(first: 1000, where: { sender: "${senderBytes32}" }) {
127
+ assetAmt
128
+ dstEid
129
+ sender
130
+ recipient
131
+ shareAmt
132
+ transactionHash_
133
+ timestamp_
134
+ }
135
+ }`;
136
+ }
137
+ const endpoints = vaultConfig.subgraphEndpoints;
138
+ let lastError;
139
+ for (let i = 0; i < endpoints.length; i++) {
140
+ try {
141
+ const response = await (0, fetcher_1.fetchSubgraph)(endpoints[i], query);
142
+ // Only fall through to next endpoint on 404 (wrong URL casing)
143
+ if (response.status === 404 && i < endpoints.length - 1) {
144
+ continue;
145
+ }
146
+ if (!response.ok) {
147
+ throw new Error(`GraphQL request failed with status ${response.status}: ${response.statusText}`);
148
+ }
149
+ const result = await response.json();
150
+ if (result.errors) {
151
+ throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`);
152
+ }
153
+ // Validate response structure
154
+ if (!validateDepositResponse(result)) {
155
+ throw new Error(`Invalid response structure from LayerZero subgraph. Expected data.depositeds array, got: ${JSON.stringify(result)}`);
156
+ }
157
+ return result.data.depositeds;
158
+ }
159
+ catch (error) {
160
+ lastError = error;
161
+ // Only continue to next endpoint on network-level failures; re-throw application errors immediately
162
+ if (i >= endpoints.length - 1)
163
+ break;
164
+ }
165
+ }
166
+ // All endpoints failed — throw the last error with context
167
+ if (lastError instanceof Error) {
168
+ const enhancedError = new Error(`Failed to fetch LayerZero deposits for ${vaultKey}: ${lastError.message}`);
169
+ enhancedError.stack = lastError.stack;
170
+ throw enhancedError;
171
+ }
172
+ throw new Error(`Failed to fetch LayerZero deposits for ${vaultKey}: ${String(lastError)}`);
173
+ }
174
+ //# sourceMappingURL=deposits.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * LayerZero Redeems Service
3
+ * Handles querying LayerZero earnAUSD redeems from subgraphs
4
+ */
5
+ import type { IAddress } from '../../types';
6
+ export interface ILayerZeroRedeem {
7
+ id: string;
8
+ recipient: string;
9
+ sender: string;
10
+ shareAmt: string;
11
+ transactionHash_: string;
12
+ timestamp_: string;
13
+ }
14
+ /**
15
+ * Query LayerZero redeems for earnAUSD from the subgraph.
16
+ * Uses the same earnAUSD subgraph endpoints as deposits — the subgraph indexes
17
+ * both Deposited and Redeemed events from the same contract.
18
+ * @throws Error if the GraphQL request fails or returns invalid data
19
+ */
20
+ export declare function queryLayerZeroRedeems(wallet?: IAddress): Promise<ILayerZeroRedeem[]>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ /**
3
+ * LayerZero Redeems Service
4
+ * Handles querying LayerZero earnAUSD redeems from subgraphs
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.queryLayerZeroRedeems = queryLayerZeroRedeems;
8
+ const fetcher_1 = require("../subgraph/fetcher");
9
+ const deposits_1 = require("./deposits");
10
+ const utils_1 = require("./utils");
11
+ /**
12
+ * Validate GraphQL response structure for redeems
13
+ */
14
+ function validateRedeemResponse(result) {
15
+ if (!result || typeof result !== 'object') {
16
+ return false;
17
+ }
18
+ const r = result;
19
+ if (!r.data || typeof r.data !== 'object') {
20
+ return false;
21
+ }
22
+ const data = r.data;
23
+ if (!Array.isArray(data.redeemeds)) {
24
+ return false;
25
+ }
26
+ return true;
27
+ }
28
+ /**
29
+ * Query LayerZero redeems for earnAUSD from the subgraph.
30
+ * Uses the same earnAUSD subgraph endpoints as deposits — the subgraph indexes
31
+ * both Deposited and Redeemed events from the same contract.
32
+ * @throws Error if the GraphQL request fails or returns invalid data
33
+ */
34
+ async function queryLayerZeroRedeems(wallet) {
35
+ const vaultConfig = deposits_1.LAYERZERO_VAULTS.earnAUSD;
36
+ let query = `GetRedeems {
37
+ redeemeds(first: 1000) {
38
+ id
39
+ recipient
40
+ sender
41
+ shareAmt
42
+ transactionHash_
43
+ timestamp_
44
+ }
45
+ }`;
46
+ if (wallet) {
47
+ const senderBytes32 = (0, utils_1.addressToBytes32)(wallet);
48
+ query = `GetRedeems {
49
+ redeemeds(first: 1000, where: { sender: "${senderBytes32}" }) {
50
+ id
51
+ recipient
52
+ sender
53
+ shareAmt
54
+ transactionHash_
55
+ timestamp_
56
+ }
57
+ }`;
58
+ }
59
+ const endpoints = vaultConfig.subgraphEndpoints;
60
+ let lastError;
61
+ for (let i = 0; i < endpoints.length; i++) {
62
+ try {
63
+ const response = await (0, fetcher_1.fetchSubgraph)(endpoints[i], query);
64
+ if (response.status === 404 && i < endpoints.length - 1) {
65
+ continue;
66
+ }
67
+ if (!response.ok) {
68
+ throw new Error(`GraphQL request failed with status ${response.status}: ${response.statusText}`);
69
+ }
70
+ const result = await response.json();
71
+ if (result.errors) {
72
+ throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`);
73
+ }
74
+ if (!validateRedeemResponse(result)) {
75
+ throw new Error(`Invalid response structure from LayerZero subgraph. Expected data.redeemeds array, got: ${JSON.stringify(result)}`);
76
+ }
77
+ return result.data.redeemeds;
78
+ }
79
+ catch (error) {
80
+ lastError = error;
81
+ if (i >= endpoints.length - 1)
82
+ break;
83
+ }
84
+ }
85
+ if (lastError instanceof Error) {
86
+ const enhancedError = new Error(`Failed to fetch LayerZero redeems for earnAUSD: ${lastError.message}`);
87
+ enhancedError.stack = lastError.stack;
88
+ throw enhancedError;
89
+ }
90
+ throw new Error(`Failed to fetch LayerZero redeems for earnAUSD: ${String(lastError)}`);
91
+ }
92
+ //# sourceMappingURL=redeems.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared LayerZero utilities
3
+ */
4
+ /**
5
+ * Convert Ethereum address to bytes32 format (left-padded with zeros)
6
+ * Used by LayerZero subgraph queries where addresses are stored in bytes32 format.
7
+ * @throws {Error} If address format is invalid
8
+ */
9
+ export declare function addressToBytes32(address: string): string;