@augustdigital/sdk 8.3.2 → 8.5.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 (204) hide show
  1. package/lib/abis/ERC20_Bytes32.d.ts +4 -0
  2. package/lib/abis/ERC20_Bytes32.js +4 -0
  3. package/lib/abis/ERC4626.d.ts +1 -0
  4. package/lib/abis/ERC4626.js +1 -0
  5. package/lib/abis/ERC721.d.ts +1 -0
  6. package/lib/abis/ERC721.js +1 -0
  7. package/lib/abis/FeeOracle.js +1 -0
  8. package/lib/abis/LendingPool.js +1 -0
  9. package/lib/abis/LendingPoolV2.js +1 -0
  10. package/lib/abis/Multicall3.js +3 -0
  11. package/lib/abis/OFT.d.ts +20 -0
  12. package/lib/abis/OFT.js +20 -0
  13. package/lib/abis/SmartAccount.d.ts +1 -0
  14. package/lib/abis/SmartAccount.js +3 -0
  15. package/lib/abis/SwapRouter.d.ts +1 -0
  16. package/lib/abis/SwapRouter.js +1 -0
  17. package/lib/abis/UniversalSignatureValidator.js +3 -0
  18. package/lib/abis/index.d.ts +5 -0
  19. package/lib/abis/index.js +5 -0
  20. package/lib/adapters/evm/getters.d.ts +17 -2
  21. package/lib/adapters/evm/getters.js +35 -3
  22. package/lib/adapters/evm/index.d.ts +262 -0
  23. package/lib/adapters/evm/index.js +268 -1
  24. package/lib/adapters/evm/utils.d.ts +6 -0
  25. package/lib/adapters/evm/utils.js +7 -0
  26. package/lib/adapters/solana/constants.js +4 -1
  27. package/lib/adapters/solana/getters.d.ts +8 -0
  28. package/lib/adapters/solana/getters.js +21 -0
  29. package/lib/adapters/solana/idl/vault-idl.js +9 -0
  30. package/lib/adapters/solana/index.d.ts +55 -0
  31. package/lib/adapters/solana/index.js +57 -0
  32. package/lib/adapters/solana/utils.d.ts +28 -0
  33. package/lib/adapters/solana/utils.js +79 -4
  34. package/lib/adapters/solana/vault.actions.d.ts +19 -0
  35. package/lib/adapters/solana/vault.actions.js +47 -3
  36. package/lib/adapters/stellar/actions.d.ts +25 -0
  37. package/lib/adapters/stellar/actions.js +33 -0
  38. package/lib/adapters/stellar/constants.d.ts +26 -0
  39. package/lib/adapters/stellar/constants.js +29 -0
  40. package/lib/adapters/stellar/getters.d.ts +56 -0
  41. package/lib/adapters/stellar/getters.js +81 -0
  42. package/lib/adapters/stellar/index.d.ts +48 -0
  43. package/lib/adapters/stellar/index.js +48 -0
  44. package/lib/adapters/stellar/soroban.d.ts +20 -0
  45. package/lib/adapters/stellar/soroban.js +46 -0
  46. package/lib/adapters/stellar/submit.d.ts +12 -0
  47. package/lib/adapters/stellar/submit.js +19 -0
  48. package/lib/adapters/stellar/types.d.ts +27 -0
  49. package/lib/adapters/stellar/types.js +3 -0
  50. package/lib/adapters/stellar/utils.d.ts +10 -0
  51. package/lib/adapters/stellar/utils.js +10 -0
  52. package/lib/adapters/sui/getters.d.ts +6 -0
  53. package/lib/adapters/sui/getters.js +6 -0
  54. package/lib/adapters/sui/index.d.ts +15 -0
  55. package/lib/adapters/sui/index.js +15 -0
  56. package/lib/adapters/sui/transformer.d.ts +6 -0
  57. package/lib/adapters/sui/transformer.js +6 -0
  58. package/lib/adapters/sui/utils.d.ts +6 -0
  59. package/lib/adapters/sui/utils.js +6 -0
  60. package/lib/core/analytics/chain-name.d.ts +8 -0
  61. package/lib/core/analytics/chain-name.js +8 -0
  62. package/lib/core/analytics/constants.d.ts +4 -0
  63. package/lib/core/analytics/constants.js +4 -0
  64. package/lib/core/analytics/env.d.ts +25 -0
  65. package/lib/core/analytics/env.js +26 -0
  66. package/lib/core/analytics/index.d.ts +26 -0
  67. package/lib/core/analytics/index.js +35 -0
  68. package/lib/core/analytics/instrumentation.d.ts +26 -0
  69. package/lib/core/analytics/instrumentation.js +66 -2
  70. package/lib/core/analytics/method-taxonomy.d.ts +16 -0
  71. package/lib/core/analytics/method-taxonomy.js +18 -0
  72. package/lib/core/analytics/metrics.d.ts +23 -0
  73. package/lib/core/analytics/metrics.js +40 -0
  74. package/lib/core/analytics/sanitize.d.ts +38 -0
  75. package/lib/core/analytics/sanitize.js +46 -0
  76. package/lib/core/analytics/sentry-runtime.d.ts +11 -0
  77. package/lib/core/analytics/sentry-runtime.js +19 -0
  78. package/lib/core/analytics/sentry.d.ts +45 -0
  79. package/lib/core/analytics/sentry.js +115 -2
  80. package/lib/core/analytics/types.d.ts +27 -0
  81. package/lib/core/analytics/user-identity.d.ts +34 -0
  82. package/lib/core/analytics/user-identity.js +42 -0
  83. package/lib/core/analytics/version.d.ts +6 -1
  84. package/lib/core/analytics/version.js +6 -1
  85. package/lib/core/auth/verify.js +5 -0
  86. package/lib/core/base.class.d.ts +75 -0
  87. package/lib/core/base.class.js +56 -0
  88. package/lib/core/cache.d.ts +5 -0
  89. package/lib/core/cache.js +6 -0
  90. package/lib/core/constants/adapters.d.ts +15 -0
  91. package/lib/core/constants/adapters.js +28 -8
  92. package/lib/core/constants/core.d.ts +12 -1
  93. package/lib/core/constants/core.js +12 -0
  94. package/lib/core/constants/swap-router.d.ts +46 -0
  95. package/lib/core/constants/swap-router.js +50 -0
  96. package/lib/core/constants/vaults.d.ts +56 -0
  97. package/lib/core/constants/vaults.js +66 -1
  98. package/lib/core/constants/web3.d.ts +3 -0
  99. package/lib/core/constants/web3.js +18 -5
  100. package/lib/core/errors/index.d.ts +36 -0
  101. package/lib/core/errors/index.js +29 -0
  102. package/lib/core/fetcher.d.ts +134 -0
  103. package/lib/core/fetcher.js +191 -5
  104. package/lib/core/helpers/adapters.d.ts +9 -0
  105. package/lib/core/helpers/adapters.js +11 -0
  106. package/lib/core/helpers/chain-address.d.ts +10 -0
  107. package/lib/core/helpers/chain-address.js +11 -0
  108. package/lib/core/helpers/core.d.ts +42 -0
  109. package/lib/core/helpers/core.js +66 -1
  110. package/lib/core/helpers/explorer-link.d.ts +14 -0
  111. package/lib/core/helpers/explorer-link.js +14 -0
  112. package/lib/core/helpers/signer.d.ts +26 -0
  113. package/lib/core/helpers/signer.js +39 -0
  114. package/lib/core/helpers/swap-router.d.ts +32 -0
  115. package/lib/core/helpers/swap-router.js +32 -0
  116. package/lib/core/helpers/vault-version.d.ts +1 -0
  117. package/lib/core/helpers/vault-version.js +2 -0
  118. package/lib/core/helpers/vaults.d.ts +8 -0
  119. package/lib/core/helpers/vaults.js +22 -8
  120. package/lib/core/helpers/web3.d.ts +152 -0
  121. package/lib/core/helpers/web3.js +183 -6
  122. package/lib/core/logger/index.d.ts +55 -0
  123. package/lib/core/logger/index.js +19 -0
  124. package/lib/core/logger/slack.d.ts +3 -0
  125. package/lib/core/logger/slack.js +3 -0
  126. package/lib/core/vault-metadata.d.ts +6 -0
  127. package/lib/core/vault-metadata.js +6 -0
  128. package/lib/core/version-check.d.ts +52 -0
  129. package/lib/core/version-check.js +81 -0
  130. package/lib/evm/methods/crossChainVault.d.ts +90 -0
  131. package/lib/evm/methods/crossChainVault.js +186 -1
  132. package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
  133. package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
  134. package/lib/evm/methods/index.d.ts +1 -0
  135. package/lib/evm/methods/index.js +1 -0
  136. package/lib/evm/types/crossChain.d.ts +202 -0
  137. package/lib/evm/types/crossChain.js +11 -0
  138. package/lib/index.d.ts +16 -0
  139. package/lib/index.js +19 -0
  140. package/lib/main.d.ts +288 -5
  141. package/lib/main.js +305 -0
  142. package/lib/modules/api/index.d.ts +1 -0
  143. package/lib/modules/api/index.js +6 -0
  144. package/lib/modules/api/main.d.ts +52 -0
  145. package/lib/modules/api/main.js +130 -0
  146. package/lib/modules/sub-accounts/fetcher.d.ts +15 -0
  147. package/lib/modules/sub-accounts/fetcher.js +15 -0
  148. package/lib/modules/sub-accounts/main.d.ts +33 -0
  149. package/lib/modules/sub-accounts/main.js +38 -0
  150. package/lib/modules/sub-accounts/utils.d.ts +3 -0
  151. package/lib/modules/sub-accounts/utils.js +3 -0
  152. package/lib/modules/vaults/adapter.helpers.d.ts +18 -0
  153. package/lib/modules/vaults/adapter.helpers.js +34 -0
  154. package/lib/modules/vaults/fetcher.d.ts +20 -0
  155. package/lib/modules/vaults/fetcher.js +40 -3
  156. package/lib/modules/vaults/getters.d.ts +295 -0
  157. package/lib/modules/vaults/getters.js +552 -12
  158. package/lib/modules/vaults/index.d.ts +12 -0
  159. package/lib/modules/vaults/index.js +12 -0
  160. package/lib/modules/vaults/main.d.ts +292 -4
  161. package/lib/modules/vaults/main.js +379 -7
  162. package/lib/modules/vaults/read.actions.d.ts +168 -0
  163. package/lib/modules/vaults/read.actions.js +143 -0
  164. package/lib/modules/vaults/types.d.ts +34 -0
  165. package/lib/modules/vaults/utils/call-data-decoder.d.ts +47 -0
  166. package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
  167. package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
  168. package/lib/modules/vaults/utils/date-utils.js +47 -1
  169. package/lib/modules/vaults/utils.d.ts +69 -0
  170. package/lib/modules/vaults/utils.js +104 -5
  171. package/lib/modules/vaults/write.actions.d.ts +363 -3
  172. package/lib/modules/vaults/write.actions.js +364 -2
  173. package/lib/polyfills.js +2 -0
  174. package/lib/sdk.d.ts +23705 -0
  175. package/lib/services/coingecko/fetcher.d.ts +13 -0
  176. package/lib/services/coingecko/fetcher.js +17 -0
  177. package/lib/services/debank/fetcher.d.ts +14 -0
  178. package/lib/services/debank/fetcher.js +12 -0
  179. package/lib/services/debank/utils.js +17 -0
  180. package/lib/services/layerzero/deposits.d.ts +11 -0
  181. package/lib/services/layerzero/deposits.js +34 -11
  182. package/lib/services/layerzero/redeems.d.ts +10 -0
  183. package/lib/services/layerzero/redeems.js +13 -0
  184. package/lib/services/layerzero/utils.d.ts +8 -0
  185. package/lib/services/layerzero/utils.js +11 -0
  186. package/lib/services/octavfi/fetcher.d.ts +7 -0
  187. package/lib/services/octavfi/fetcher.js +25 -0
  188. package/lib/services/octavfi/utils.d.ts +12 -0
  189. package/lib/services/octavfi/utils.js +44 -10
  190. package/lib/services/subgraph/fetcher.js +4 -2
  191. package/lib/services/subgraph/vaults.d.ts +12 -0
  192. package/lib/services/subgraph/vaults.js +43 -2
  193. package/lib/services/swap-quotes/index.d.ts +71 -0
  194. package/lib/services/swap-quotes/index.js +25 -0
  195. package/lib/services/swap-quotes/paraswap.d.ts +17 -0
  196. package/lib/services/swap-quotes/paraswap.js +14 -0
  197. package/lib/types/pools.d.ts +3 -0
  198. package/lib/types/typed-contract.d.ts +64 -0
  199. package/lib/types/vaults.d.ts +137 -2
  200. package/lib/types/vaults.js +10 -0
  201. package/lib/types/web3.d.ts +8 -0
  202. package/lib/types/web3.js +1 -0
  203. package/lib/types/webserver.d.ts +45 -0
  204. package/package.json +6 -5
@@ -1 +1,14 @@
1
+ /**
2
+ * Fetch the latest USD price for a token symbol from CoinGecko's
3
+ * `/market_chart/range` endpoint, mapped through `COINGECKO_COIN_ID_MAP`.
4
+ *
5
+ * @param symbol Token symbol (case-insensitive). Must be present in
6
+ * `COINGECKO_COIN_ID_MAP`; unmapped symbols still hit the network and
7
+ * 404 today (see todo/32-coingecko-fetcher-defects.md).
8
+ * @param coinGeckoKey CoinGecko Pro API key passed as `x-cg-pro-api-key`.
9
+ * @returns The latest price in USD on success; `null` on any failure
10
+ * (non-2xx response, network error, JSON parse error, or missing
11
+ * `prices` array). The `musd` short-circuit returns a tuple literal
12
+ * for back-compat — see todo/32 for the cleanup.
13
+ */
1
14
  export declare function fetchTokenPricesFromCoinGecko(symbol: string, coinGeckoKey: string): Promise<any>;
@@ -3,11 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchTokenPricesFromCoinGecko = fetchTokenPricesFromCoinGecko;
4
4
  const logger_1 = require("../../core/logger");
5
5
  const utils_1 = require("./utils");
6
+ /**
7
+ * Fetch the latest USD price for a token symbol from CoinGecko's
8
+ * `/market_chart/range` endpoint, mapped through `COINGECKO_COIN_ID_MAP`.
9
+ *
10
+ * @param symbol Token symbol (case-insensitive). Must be present in
11
+ * `COINGECKO_COIN_ID_MAP`; unmapped symbols still hit the network and
12
+ * 404 today (see todo/32-coingecko-fetcher-defects.md).
13
+ * @param coinGeckoKey CoinGecko Pro API key passed as `x-cg-pro-api-key`.
14
+ * @returns The latest price in USD on success; `null` on any failure
15
+ * (non-2xx response, network error, JSON parse error, or missing
16
+ * `prices` array). The `musd` short-circuit returns a tuple literal
17
+ * for back-compat — see todo/32 for the cleanup.
18
+ */
6
19
  async function fetchTokenPricesFromCoinGecko(symbol, coinGeckoKey) {
7
20
  const coinId = utils_1.COINGECKO_COIN_ID_MAP[symbol.toLowerCase()];
8
21
  if (coinId === 'mezo-usd') {
9
22
  return [['175394880000', 1]];
10
23
  }
24
+ // this is what we do in FE - not sure if we really need 7d worth of data since we just want something but it'll do for now
11
25
  const sevendDaysInS = 7 * 24 * 60 * 60;
12
26
  const from = Date.now() / 1000 - sevendDaysInS;
13
27
  const url = `https://pro-api.coingecko.com/api/v3/coins/${coinId}/market_chart/range?vs_currency=usd&from=${from}&to=${Math.floor(Date.now() / 1000)}&interval=daily`;
@@ -30,6 +44,9 @@ async function fetchTokenPricesFromCoinGecko(symbol, coinGeckoKey) {
30
44
  throw err;
31
45
  }
32
46
  const data = (await response.json());
47
+ // `/market_chart/range` returns `{ prices, market_caps, total_volumes }` —
48
+ // an object. The previous `data.length` check was always falsy on the
49
+ // success path and silently collapsed every valid response to `null`.
33
50
  if (data?.prices?.length) {
34
51
  return data.prices[data.prices.length - 1][1];
35
52
  }
@@ -107,6 +107,20 @@ export interface IDebankAccountData {
107
107
  export interface IDebankAccountDataError {
108
108
  error: string;
109
109
  }
110
+ /**
111
+ * Response type for vault-level DeBank data.
112
+ * Keys are subaccount addresses, values are either DeBank data or error objects.
113
+ */
110
114
  export type IVaultDebankResponse = Record<string, IDebankAccountData | IDebankAccountDataError>;
115
+ /**
116
+ * Fetch DeBank data for all subaccounts of a vault in a single request.
117
+ * @param vaultAddress The vault contract address
118
+ * @param headers Optional monitoring headers
119
+ * @returns Dictionary of subaccount addresses to DeBank data, or false on error
120
+ */
111
121
  export declare function fetchVaultDebankResponse(vaultAddress: IAddress, headers?: IWSMonitorHeaders): Promise<IVaultDebankResponse | false>;
122
+ /**
123
+ * @deprecated Use fetchVaultDebankResponse for vault-level queries.
124
+ * Fetch DeBank data for a single subaccount address.
125
+ */
112
126
  export declare function fetchDebankResponse(address: IAddress, headers?: IWSMonitorHeaders): Promise<any>;
@@ -3,9 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchVaultDebankResponse = fetchVaultDebankResponse;
4
4
  exports.fetchDebankResponse = fetchDebankResponse;
5
5
  const core_1 = require("../../core");
6
+ /**
7
+ * Fetch DeBank data for all subaccounts of a vault in a single request.
8
+ * @param vaultAddress The vault contract address
9
+ * @param headers Optional monitoring headers
10
+ * @returns Dictionary of subaccount addresses to DeBank data, or false on error
11
+ */
6
12
  async function fetchVaultDebankResponse(vaultAddress, headers) {
7
13
  try {
8
14
  const response = await (0, core_1.fetchAugustPublic)(core_1.WEBSERVER_ENDPOINTS.public.tokenizedVault.debank(vaultAddress), { headers: headers });
15
+ // 200 = success, 207 = partial success (some subaccounts failed)
9
16
  if (response.status === 200 || response.status === 207) {
10
17
  const data = (await response.json());
11
18
  return data;
@@ -18,7 +25,12 @@ async function fetchVaultDebankResponse(vaultAddress, headers) {
18
25
  return false;
19
26
  }
20
27
  }
28
+ /**
29
+ * @deprecated Use fetchVaultDebankResponse for vault-level queries.
30
+ * Fetch DeBank data for a single subaccount address.
31
+ */
21
32
  async function fetchDebankResponse(address, headers) {
33
+ // filter out hyperevm since debank does not yet support hyperevm
22
34
  const debankResponse = await (0, core_1.fetchAugustWithKey)(undefined, core_1.WEBSERVER_ENDPOINTS.subaccount.debank(address), { override: true, headers: headers });
23
35
  if (debankResponse.status !== 200) {
24
36
  core_1.Logger.log.error('fetchDebankResponse', new Error(`HTTP ${debankResponse.status} ${debankResponse.statusText}`), {
@@ -47,12 +47,14 @@ function addToTokenExposure(token, tokenExposure, exposureType, protocol, exposu
47
47
  }
48
48
  }
49
49
  function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue) {
50
+ // new mapping to grab vault-level token and protocol exposure per
50
51
  const tokenMap = {};
51
52
  const protocolTokenMap = {};
52
53
  const protocolExposures = debankRes?.subaccount?.positions || [];
53
54
  const appProtocolExposures = debankRes?.subaccount?.app_positions || [];
54
55
  const tokenExposures = debankRes?.subaccount?.tokens || [];
55
56
  protocolExposures.forEach((pos) => {
57
+ // protocol-level data fetching
56
58
  const protoReturnObj = {
57
59
  id: pos?.id,
58
60
  chain: pos?.chain,
@@ -68,6 +70,7 @@ function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borro
68
70
  address: borrower,
69
71
  };
70
72
  pos?.portfolio_item_list?.forEach((item) => {
73
+ // initialize protocol exposure
71
74
  protoReturnObj.assetUsdValue += item?.stats?.asset_usd_value || 0;
72
75
  protoReturnObj.debtUsdValue += item?.stats?.debt_usd_value || 0;
73
76
  protoReturnObj.netUsdValue += item?.stats?.net_usd_value || 0;
@@ -83,21 +86,27 @@ function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borro
83
86
  foundExistingProtocolExposure.assetUsdValue +=
84
87
  protoReturnObj.assetUsdValue;
85
88
  }
89
+ // go through the debank portfolio
86
90
  pos.portfolio_item_list.forEach((item) => {
87
91
  item.detail.supply_token_list.forEach((sup) => {
92
+ // add protocol id for vault-level "protocol exposure"
88
93
  if (sup?.protocol_id) {
89
94
  const existingArray = protocolTokenMap[sup.protocol_id] || [];
90
95
  if (!existingArray.includes(sup.symbol))
91
96
  existingArray.push(sup.symbol);
92
97
  }
98
+ // add token to vault "token exposure"
93
99
  addToTokenExposure(sup, tokenExposure, 'supply', pos.id, exposurePerCategory, netValue, borrower);
100
+ // add token image url to token mapping for display
94
101
  if (sup?.symbol && sup?.logo_url) {
95
102
  tokenMap[sup.symbol] = sup.logo_url;
96
103
  }
97
104
  tokenMap[sup.supplying_exposure] = 'true';
98
105
  });
99
106
  item.detail.borrow_token_list.forEach((bor) => {
107
+ // add token to vault "token exposure"
100
108
  addToTokenExposure(bor, tokenExposure, 'borrow', pos.id, exposurePerCategory, netValue, borrower);
109
+ // add token image url to token mapping for display
101
110
  if (bor?.symbol && bor?.logo_url) {
102
111
  tokenMap[bor.symbol] = bor.logo_url;
103
112
  }
@@ -105,6 +114,8 @@ function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure, borro
105
114
  });
106
115
  });
107
116
  });
117
+ // Process non-EVM app protocols (e.g. Hyperliquid, Lighter).
118
+ // These lack chain and protocol_id fields unlike EVM-based positions.
108
119
  appProtocolExposures.forEach((pos) => {
109
120
  const protoReturnObj = {
110
121
  id: pos?.id,
@@ -202,6 +213,8 @@ function getVaultExposure(debankResponse) {
202
213
  !token.is_suspicious &&
203
214
  !token.is_scam &&
204
215
  token?.is_core) {
216
+ // Not sure what isWallet is, but I'm guessing is that this field means that it should be in wallet exposure...
217
+ // fwiw I have seen this double counted in supplyTokens AND tokens
205
218
  if (!token.is_wallet) {
206
219
  supplying_exposure.push({
207
220
  symbol: token.symbol,
@@ -219,10 +232,12 @@ function parseLoanLevelDebank(debankRes) {
219
232
  let positions = [];
220
233
  let exposure = [];
221
234
  try {
235
+ // new mapping to grab token and protocol exposure
222
236
  const protocolExposures = [
223
237
  ...(debankRes?.subaccount?.positions || []),
224
238
  ...(debankRes?.subaccount?.app_positions || []),
225
239
  ];
240
+ // Old mapping to grab token and protocol exposure
226
241
  positions = protocolExposures?.map((p) => ({
227
242
  value: p.logo_url,
228
243
  label: p.name,
@@ -243,6 +258,8 @@ function parseLoanLevelDebank(debankRes) {
243
258
  }
244
259
  return extra;
245
260
  }));
261
+ // this is a request where if there is no protocol exposure then show any spots
262
+ // over 10k in collateral exposure
246
263
  if (protocolExposures.length === 0) {
247
264
  if (debankRes?.subaccount?.tokens) {
248
265
  debankRes.subaccount.tokens.forEach((t) => {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * LayerZero Deposits Service
3
+ * Handles querying LayerZero USDC deposits from subgraphs
4
+ */
1
5
  import { IAddress } from '../../types';
2
6
  export declare const LAYERZERO_VAULTS: {
3
7
  coreUSDC: {
@@ -34,5 +38,12 @@ export interface ILayerZeroDeposit {
34
38
  transactionHash_: string;
35
39
  timestamp_: string;
36
40
  }
41
+ /**
42
+ * Check if a vault address or symbol is a LayerZero vault
43
+ */
37
44
  export declare function isLayerZeroVault(vaultAddressOrSymbol: string): keyof typeof LAYERZERO_VAULTS | null;
45
+ /**
46
+ * Query LayerZero deposits from the appropriate subgraph
47
+ * @throws Error if the GraphQL request fails or returns invalid data
48
+ */
38
49
  export declare function queryLayerZeroDeposits(vaultKey: keyof typeof LAYERZERO_VAULTS, wallet?: IAddress): Promise<ILayerZeroDeposit[]>;
@@ -1,21 +1,27 @@
1
1
  "use strict";
2
+ /**
3
+ * LayerZero Deposits Service
4
+ * Handles querying LayerZero USDC deposits from subgraphs
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.LAYERZERO_VAULTS = void 0;
4
8
  exports.isLayerZeroVault = isLayerZeroVault;
5
9
  exports.queryLayerZeroDeposits = queryLayerZeroDeposits;
6
10
  const fetcher_1 = require("../subgraph/fetcher");
7
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)
8
14
  exports.LAYERZERO_VAULTS = {
9
15
  coreUSDC: {
10
16
  address: '0xE9B725010A9E419412ed67d0fA5f3A5f40159D32',
11
17
  receiptToken: 'coreusdc',
12
- decimals: 6,
18
+ decimals: 6, // USDC decimals
13
19
  hubChainId: 1,
14
20
  spokeChains: {
15
- 42161: '0x50a31ff4d57841681011837c17aa201c6a34203c',
16
- 43114: '0x1FA931Bf85248aD2eDf0004DD9A284698358e708',
17
- 8453: '0x1fa931bf85248ad2edf0004dd9a284698358e708',
18
- 146: '0x4bdd224fe59a3ae0b249125ad4c5b3126074c71b',
21
+ 42161: '0x50a31ff4d57841681011837c17aa201c6a34203c', // Arbitrum
22
+ 43114: '0x1FA931Bf85248aD2eDf0004DD9A284698358e708', // Avalanche
23
+ 8453: '0x1fa931bf85248ad2edf0004dd9a284698358e708', // Base
24
+ 146: '0x4bdd224fe59a3ae0b249125ad4c5b3126074c71b', // Sonic
19
25
  },
20
26
  subgraphEndpoints: [
21
27
  'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-coreusdc/1.0.0/gn',
@@ -24,13 +30,13 @@ exports.LAYERZERO_VAULTS = {
24
30
  upUSDC: {
25
31
  address: '0x80E1048eDE66ec4c364b4F22C8768fc657FF6A42',
26
32
  receiptToken: 'upusdc',
27
- decimals: 6,
33
+ decimals: 6, // USDC decimals
28
34
  hubChainId: 1,
29
35
  spokeChains: {
30
- 42161: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34',
31
- 43114: '0x81971A3C359cFE74259CfF1b46FB5f2112ddDE34',
32
- 8453: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34',
33
- 146: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34',
36
+ 42161: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Arbitrum
37
+ 43114: '0x81971A3C359cFE74259CfF1b46FB5f2112ddDE34', // Avalanche
38
+ 8453: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Base
39
+ 146: '0x81971a3c359cfe74259cff1b46fb5f2112ddde34', // Sonic
34
40
  },
35
41
  subgraphEndpoints: [
36
42
  'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-upusdc/1.0.0/gn',
@@ -42,7 +48,7 @@ exports.LAYERZERO_VAULTS = {
42
48
  decimals: 6,
43
49
  hubChainId: 143,
44
50
  spokeChains: {
45
- 1: '0xa6916b65c5e3fEdf46c0a2F59bff776e872C8992',
51
+ 1: '0xa6916b65c5e3fEdf46c0a2F59bff776e872C8992', // Ethereum
46
52
  },
47
53
  subgraphEndpoints: [
48
54
  'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-layerzero-earnAUSD/1.0.0/gn',
@@ -50,8 +56,12 @@ exports.LAYERZERO_VAULTS = {
50
56
  ],
51
57
  },
52
58
  };
59
+ /**
60
+ * Check if a vault address or symbol is a LayerZero vault
61
+ */
53
62
  function isLayerZeroVault(vaultAddressOrSymbol) {
54
63
  const normalized = vaultAddressOrSymbol.toLowerCase();
64
+ // Check by address
55
65
  if (normalized === exports.LAYERZERO_VAULTS.coreUSDC.address.toLowerCase() ||
56
66
  normalized === 'coreusdc') {
57
67
  return 'coreUSDC';
@@ -66,6 +76,9 @@ function isLayerZeroVault(vaultAddressOrSymbol) {
66
76
  }
67
77
  return null;
68
78
  }
79
+ /**
80
+ * Validate GraphQL response structure
81
+ */
69
82
  function validateDepositResponse(result) {
70
83
  if (!result || typeof result !== 'object') {
71
84
  return false;
@@ -80,8 +93,13 @@ function validateDepositResponse(result) {
80
93
  }
81
94
  return true;
82
95
  }
96
+ /**
97
+ * Query LayerZero deposits from the appropriate subgraph
98
+ * @throws Error if the GraphQL request fails or returns invalid data
99
+ */
83
100
  async function queryLayerZeroDeposits(vaultKey, wallet) {
84
101
  const vaultConfig = exports.LAYERZERO_VAULTS[vaultKey];
102
+ // Build GraphQL query (fetchSubgraph prepends "query " automatically)
85
103
  let query = `GetDeposits {
86
104
  depositeds(first: 1000) {
87
105
  assetAmt
@@ -93,6 +111,7 @@ async function queryLayerZeroDeposits(vaultKey, wallet) {
93
111
  timestamp_
94
112
  }
95
113
  }`;
114
+ // If wallet is provided, filter by sender
96
115
  if (wallet) {
97
116
  const senderBytes32 = (0, utils_1.addressToBytes32)(wallet);
98
117
  query = `GetDeposits {
@@ -112,6 +131,7 @@ async function queryLayerZeroDeposits(vaultKey, wallet) {
112
131
  for (let i = 0; i < endpoints.length; i++) {
113
132
  try {
114
133
  const response = await (0, fetcher_1.fetchSubgraph)(endpoints[i], query);
134
+ // Only fall through to next endpoint on 404 (wrong URL casing)
115
135
  if (response.status === 404 && i < endpoints.length - 1) {
116
136
  continue;
117
137
  }
@@ -122,6 +142,7 @@ async function queryLayerZeroDeposits(vaultKey, wallet) {
122
142
  if (result.errors) {
123
143
  throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`);
124
144
  }
145
+ // Validate response structure
125
146
  if (!validateDepositResponse(result)) {
126
147
  throw new Error(`Invalid response structure from LayerZero subgraph. Expected data.depositeds array, got: ${JSON.stringify(result)}`);
127
148
  }
@@ -129,10 +150,12 @@ async function queryLayerZeroDeposits(vaultKey, wallet) {
129
150
  }
130
151
  catch (error) {
131
152
  lastError = error;
153
+ // Only continue to next endpoint on network-level failures; re-throw application errors immediately
132
154
  if (i >= endpoints.length - 1)
133
155
  break;
134
156
  }
135
157
  }
158
+ // All endpoints failed — throw the last error with context
136
159
  if (lastError instanceof Error) {
137
160
  const enhancedError = new Error(`Failed to fetch LayerZero deposits for ${vaultKey}: ${lastError.message}`);
138
161
  enhancedError.stack = lastError.stack;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * LayerZero Redeems Service
3
+ * Handles querying LayerZero earnAUSD redeems from subgraphs
4
+ */
1
5
  import { IAddress } from '../../types';
2
6
  export interface ILayerZeroRedeem {
3
7
  id: string;
@@ -7,4 +11,10 @@ export interface ILayerZeroRedeem {
7
11
  transactionHash_: string;
8
12
  timestamp_: string;
9
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
+ */
10
20
  export declare function queryLayerZeroRedeems(wallet?: IAddress): Promise<ILayerZeroRedeem[]>;
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
+ /**
3
+ * LayerZero Redeems Service
4
+ * Handles querying LayerZero earnAUSD redeems from subgraphs
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.queryLayerZeroRedeems = queryLayerZeroRedeems;
4
8
  const fetcher_1 = require("../subgraph/fetcher");
5
9
  const deposits_1 = require("./deposits");
6
10
  const utils_1 = require("./utils");
11
+ /**
12
+ * Validate GraphQL response structure for redeems
13
+ */
7
14
  function validateRedeemResponse(result) {
8
15
  if (!result || typeof result !== 'object') {
9
16
  return false;
@@ -18,6 +25,12 @@ function validateRedeemResponse(result) {
18
25
  }
19
26
  return true;
20
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
+ */
21
34
  async function queryLayerZeroRedeems(wallet) {
22
35
  const vaultConfig = deposits_1.LAYERZERO_VAULTS.earnAUSD;
23
36
  let query = `GetRedeems {
@@ -1 +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
+ */
1
9
  export declare function addressToBytes32(address: string): string;
@@ -1,11 +1,22 @@
1
1
  "use strict";
2
+ /**
3
+ * Shared LayerZero utilities
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.addressToBytes32 = addressToBytes32;
7
+ /**
8
+ * Convert Ethereum address to bytes32 format (left-padded with zeros)
9
+ * Used by LayerZero subgraph queries where addresses are stored in bytes32 format.
10
+ * @throws {Error} If address format is invalid
11
+ */
4
12
  function addressToBytes32(address) {
13
+ // Validate address format
5
14
  if (!address.match(/^0x[a-fA-F0-9]{40}$/)) {
6
15
  throw new Error(`Invalid Ethereum address format: ${address}. Expected format: 0x followed by 40 hexadecimal characters.`);
7
16
  }
17
+ // Remove 0x prefix and convert to lowercase
8
18
  const cleanAddress = address.replace(/^0x/i, '').toLowerCase();
19
+ // Pad with 24 zeros (12 bytes) to make it 32 bytes total
9
20
  return '0x' + '0'.repeat(24) + cleanAddress;
10
21
  }
11
22
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,9 @@
1
1
  import { IOctavfiPortfolio } from './types';
2
+ /**
3
+ * Fetches portfolio data from Octavfi API.
4
+ * Note: The API currently doesn't support multiple addresses in a single request,
5
+ * so individual requests are made for each address.
6
+ * @param addresses - Array of addresses to fetch data for.
7
+ * @returns Array of portfolio data (may be empty if all requests fail).
8
+ */
2
9
  export declare function fetchOctavfiPortfolios(addresses: string[]): Promise<IOctavfiPortfolio[]>;
@@ -6,6 +6,13 @@ const utils_1 = require("../../adapters/solana/utils");
6
6
  const core_1 = require("../../core");
7
7
  const BASE_URL = 'https://api.octav.fi';
8
8
  const OCTAVFI_API_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImF1Z3VzdDEyMjM0In19.zaMUtrtdC82uaDh6XSZrsneEcKO3PFOE6FyX3G-MR6c';
9
+ /**
10
+ * Filters addresses to only include EVM and Solana wallet addresses.
11
+ * Excludes Sui addresses and other non-supported address formats.
12
+ *
13
+ * @param addresses - Array of addresses to filter
14
+ * @returns Array containing only EVM and Solana addresses
15
+ */
9
16
  function filterEvmAndSolanaAddresses(addresses) {
10
17
  return addresses.filter((address) => {
11
18
  if (!address || typeof address !== 'string')
@@ -20,6 +27,11 @@ function filterEvmAndSolanaAddresses(addresses) {
20
27
  return false;
21
28
  });
22
29
  }
30
+ /**
31
+ * Fetches portfolio data for a single address from Octavfi API.
32
+ * @param address - Single address to fetch data for.
33
+ * @returns Portfolio data or null if request fails.
34
+ */
23
35
  async function fetchSinglePortfolio(address) {
24
36
  try {
25
37
  const response = await fetch(`${BASE_URL}/v1/portfolio?addresses=${address}`, {
@@ -47,18 +59,22 @@ async function fetchSinglePortfolio(address) {
47
59
  core_1.Logger.log.error('fetchSinglePortfolio.api-error', new Error(String(data.error)), { address });
48
60
  return null;
49
61
  }
62
+ // Handle nested array response: [[portfolio]] or [portfolio] or portfolio
50
63
  let portfolio = data;
51
64
  if (Array.isArray(data)) {
52
65
  if (data.length > 0 && Array.isArray(data[0])) {
66
+ // Nested array: [[portfolio]]
53
67
  portfolio = data[0][0];
54
68
  }
55
69
  else if (data.length > 0) {
70
+ // Single array: [portfolio]
56
71
  portfolio = data[0];
57
72
  }
58
73
  else {
59
74
  return null;
60
75
  }
61
76
  }
77
+ // Return raw Octavfi data (transformation should happen separately when needed)
62
78
  return portfolio;
63
79
  }
64
80
  catch (error) {
@@ -66,13 +82,22 @@ async function fetchSinglePortfolio(address) {
66
82
  return null;
67
83
  }
68
84
  }
85
+ /**
86
+ * Fetches portfolio data from Octavfi API.
87
+ * Note: The API currently doesn't support multiple addresses in a single request,
88
+ * so individual requests are made for each address.
89
+ * @param addresses - Array of addresses to fetch data for.
90
+ * @returns Array of portfolio data (may be empty if all requests fail).
91
+ */
69
92
  async function fetchOctavfiPortfolios(addresses) {
70
93
  const filteredAddresses = filterEvmAndSolanaAddresses(addresses);
71
94
  if (filteredAddresses.length === 0) {
72
95
  return [];
73
96
  }
97
+ // Fetch portfolios for each address in parallel
74
98
  const portfolioPromises = filteredAddresses.map((address) => fetchSinglePortfolio(address));
75
99
  const portfolios = await Promise.all(portfolioPromises);
100
+ // Filter out null results (failed requests)
76
101
  return portfolios.filter((portfolio) => portfolio !== null);
77
102
  }
78
103
  //# sourceMappingURL=fetcher.js.map
@@ -1,4 +1,16 @@
1
1
  import { IOctavfiPortfolio } from './types';
2
2
  import { IDebankNormalizedResponse } from '../debank/utils';
3
+ /**
4
+ * Transforms Octavfi portfolio response to DeBank-compatible format.
5
+ * This allows Solana addresses to use Octavfi data while maintaining
6
+ * compatibility with existing DeBank parsing functions.
7
+ *
8
+ * @param octavfiPortfolio - Octavfi portfolio response
9
+ * @returns DeBank-compatible response structure
10
+ */
3
11
  export declare function transformOctavfiToDebank(octavfiPortfolio: IOctavfiPortfolio | null | undefined): IDebankNormalizedResponse;
12
+ /**
13
+ * Transforms multiple Octavfi portfolios to DeBank format.
14
+ * Used when fetching multiple addresses.
15
+ */
4
16
  export declare function transformOctavfiPortfoliosToDebank(portfolios: IOctavfiPortfolio[]): any[];