@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
@@ -2,6 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformOctavfiToDebank = transformOctavfiToDebank;
4
4
  exports.transformOctavfiPortfoliosToDebank = transformOctavfiPortfoliosToDebank;
5
+ /**
6
+ * Transforms Octavfi portfolio response to DeBank-compatible format.
7
+ * This allows Solana addresses to use Octavfi data while maintaining
8
+ * compatibility with existing DeBank parsing functions.
9
+ *
10
+ * @param octavfiPortfolio - Octavfi portfolio response
11
+ * @returns DeBank-compatible response structure
12
+ */
5
13
  function transformOctavfiToDebank(octavfiPortfolio) {
6
14
  if (!octavfiPortfolio) {
7
15
  return {
@@ -13,20 +21,25 @@ function transformOctavfiToDebank(octavfiPortfolio) {
13
21
  }
14
22
  const positions = [];
15
23
  const tokens = [];
24
+ // Transform protocols (assetByProtocols) into DeBank positions format
16
25
  const assetByProtocols = octavfiPortfolio.assetByProtocols || {};
17
26
  Object.entries(assetByProtocols).forEach(([protocolKey, protocol]) => {
27
+ // Skip wallet protocol - we'll handle it separately in tokens
18
28
  if (protocolKey === 'wallet') {
19
29
  return;
20
30
  }
31
+ // Extract all assets from nested structure: chains -> protocolPositions -> assets
21
32
  const allAssets = [];
22
33
  if (protocol.chains) {
23
34
  Object.values(protocol.chains).forEach((chain) => {
24
35
  if (chain.protocolPositions) {
25
36
  Object.values(chain.protocolPositions).forEach((protocolPosition) => {
37
+ // Direct assets
26
38
  if (protocolPosition.assets &&
27
39
  Array.isArray(protocolPosition.assets)) {
28
40
  allAssets.push(...protocolPosition.assets);
29
41
  }
42
+ // Nested protocolPositions (like in Kamino)
30
43
  if (protocolPosition.protocolPositions &&
31
44
  Array.isArray(protocolPosition.protocolPositions)) {
32
45
  protocolPosition.protocolPositions.forEach((nestedPos) => {
@@ -39,33 +52,36 @@ function transformOctavfiToDebank(octavfiPortfolio) {
39
52
  }
40
53
  });
41
54
  }
55
+ // Create position structure matching DeBank format
42
56
  const position = {
43
57
  id: protocolKey,
44
58
  chain: getChainFromProtocol(protocol, octavfiPortfolio),
45
59
  name: protocol.name || protocolKey,
46
- logo_url: '',
47
- site_url: '',
60
+ logo_url: '', // Octavfi doesn't provide protocol logos
61
+ site_url: '', // Octavfi doesn't provide protocol URLs
48
62
  portfolio_item_list: [
49
63
  {
50
64
  name: protocol.name || protocolKey,
51
65
  stats: {
52
66
  asset_usd_value: parseFloat(protocol.value || '0') || 0,
53
- debt_usd_value: 0,
67
+ debt_usd_value: 0, // Octavfi doesn't distinguish debt, default to 0
54
68
  net_usd_value: parseFloat(protocol.value || '0') || 0,
55
69
  },
56
70
  detail: {
57
71
  supply_token_list: allAssets
58
72
  .map((asset) => transformAssetToDebankToken(asset, 'supply'))
59
73
  .filter((token) => token !== null),
60
- borrow_token_list: [],
74
+ borrow_token_list: [], // Octavfi doesn't provide borrow data
61
75
  },
62
76
  },
63
77
  ],
64
78
  };
65
79
  positions.push(position);
66
80
  });
81
+ // Transform wallet assets to tokens array
67
82
  const walletProtocol = assetByProtocols['wallet'];
68
83
  if (walletProtocol && walletProtocol.chains) {
84
+ // Extract assets from nested structure: chains -> protocolPositions -> assets
69
85
  Object.values(walletProtocol.chains).forEach((chain) => {
70
86
  if (chain.protocolPositions) {
71
87
  Object.values(chain.protocolPositions).forEach((protocolPosition) => {
@@ -75,7 +91,7 @@ function transformOctavfiToDebank(octavfiPortfolio) {
75
91
  tokens.push({
76
92
  ...transformAssetToDebankToken(asset, 'wallet'),
77
93
  is_wallet: true,
78
- is_core: true,
94
+ is_core: true, // Assume wallet tokens are core tokens
79
95
  });
80
96
  });
81
97
  }
@@ -83,28 +99,33 @@ function transformOctavfiToDebank(octavfiPortfolio) {
83
99
  }
84
100
  });
85
101
  }
102
+ // Also add protocol assets as tokens (non-wallet)
86
103
  Object.entries(assetByProtocols).forEach(([protocolKey, protocol]) => {
87
104
  if (protocolKey === 'wallet')
88
105
  return;
89
106
  if (!protocol || !protocol.chains)
90
107
  return;
108
+ // Extract assets from nested structure
91
109
  Object.values(protocol.chains).forEach((chain) => {
92
110
  if (chain.protocolPositions) {
93
111
  Object.values(chain.protocolPositions).forEach((protocolPosition) => {
112
+ // Direct assets
94
113
  if (protocolPosition.assets &&
95
114
  Array.isArray(protocolPosition.assets)) {
96
115
  protocolPosition.assets.forEach((asset) => {
116
+ // Check if token already exists (from wallet)
97
117
  const existingToken = tokens.find((t) => t.symbol === asset.symbol &&
98
118
  t.chain === (asset.chainKey || asset.chain));
99
119
  if (!existingToken) {
100
120
  tokens.push({
101
121
  ...transformAssetToDebankToken(asset, 'supply'),
102
122
  is_wallet: false,
103
- is_core: true,
123
+ is_core: true, // Assume protocol tokens are core
104
124
  });
105
125
  }
106
126
  });
107
127
  }
128
+ // Nested protocolPositions (like in Kamino)
108
129
  if (protocolPosition.protocolPositions &&
109
130
  Array.isArray(protocolPosition.protocolPositions)) {
110
131
  protocolPosition.protocolPositions.forEach((nestedPos) => {
@@ -134,7 +155,11 @@ function transformOctavfiToDebank(octavfiPortfolio) {
134
155
  },
135
156
  };
136
157
  }
137
- function transformAssetToDebankToken(asset, exposureType) {
158
+ /**
159
+ * Transforms Octavfi asset to DeBank token format
160
+ */
161
+ function transformAssetToDebankToken(asset, // Using any since the actual structure differs from IOctavfiAsset
162
+ exposureType) {
138
163
  if (!asset) {
139
164
  return null;
140
165
  }
@@ -145,26 +170,31 @@ function transformAssetToDebankToken(asset, exposureType) {
145
170
  const contract = asset.contract || asset.chainContract || asset.contractAddress;
146
171
  const decimals = parseInt(asset.decimal || asset.decimals || '18', 10);
147
172
  return {
148
- id: contract || asset.symbol || 'unknown',
173
+ id: contract || asset.symbol || 'unknown', // Use contract address if available, fallback to symbol
149
174
  chain: chain,
150
175
  name: asset.name || asset.symbol || 'Unknown',
151
176
  symbol: asset.symbol || 'UNKNOWN',
152
177
  optimized_symbol: asset.symbol || 'UNKNOWN',
153
178
  decimals: decimals,
154
- logo_url: '',
179
+ logo_url: '', // Octavfi doesn't provide token logos
155
180
  amount,
156
181
  price,
157
- protocol_id: '',
182
+ protocol_id: '', // Will be set by the calling context
158
183
  supplying_exposure: exposureType === 'supply' ? 'true' : undefined,
159
184
  };
160
185
  }
186
+ /**
187
+ * Determines the chain from protocol data or portfolio chains
188
+ */
161
189
  function getChainFromProtocol(protocol, portfolio) {
190
+ // Try to get chain from protocol.chains structure
162
191
  if (protocol.chains) {
163
192
  const chainKeys = Object.keys(protocol.chains);
164
193
  if (chainKeys.length > 0) {
165
194
  return chainKeys[0];
166
195
  }
167
196
  }
197
+ // Fallback to first chain in portfolio
168
198
  const chains = portfolio.chains || {};
169
199
  const chainKeys = Object.keys(chains);
170
200
  if (chainKeys.length > 0) {
@@ -172,6 +202,10 @@ function getChainFromProtocol(protocol, portfolio) {
172
202
  }
173
203
  return 'unknown';
174
204
  }
205
+ /**
206
+ * Transforms multiple Octavfi portfolios to DeBank format.
207
+ * Used when fetching multiple addresses.
208
+ */
175
209
  function transformOctavfiPortfoliosToDebank(portfolios) {
176
210
  return portfolios.map(transformOctavfiToDebank);
177
211
  }
@@ -14,7 +14,7 @@ async function fetchSubgraphWithRetry(graphUrl, query, apiKey, maxRetries = 3, b
14
14
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
15
15
  try {
16
16
  const controller = new AbortController();
17
- const timeoutId = setTimeout(() => controller.abort(), core_1.REQUEST_TIMEOUT_MS / 3);
17
+ const timeoutId = setTimeout(() => controller.abort(), core_1.REQUEST_TIMEOUT_MS / 3); // 30 second timeout
18
18
  try {
19
19
  const headers = {
20
20
  'Content-Type': 'application/json',
@@ -40,17 +40,19 @@ async function fetchSubgraphWithRetry(graphUrl, query, apiKey, maxRetries = 3, b
40
40
  }
41
41
  catch (error) {
42
42
  lastError = error;
43
+ // If it's a timeout error, abort error, or network error and we have retries left
43
44
  if (attempt < maxRetries &&
44
45
  ((error instanceof TypeError &&
45
46
  error.message.includes('fetch failed')) ||
46
47
  error.name === 'AbortError' ||
47
48
  error.message.includes('ETIMEDOUT') ||
48
49
  error.message.includes('timeout'))) {
49
- const delay = baseDelay * Math.pow(2, attempt);
50
+ const delay = baseDelay * Math.pow(2, attempt); // Exponential backoff
50
51
  core_1.Logger.log.warn(`fetchSubgraph`, `${graphUrl?.includes('/subgraphs') ? graphUrl?.split('/subgraphs/')?.[1]?.split('/')?.[0] : graphUrl}: Attempt ${attempt + 1} failed, retrying in ${delay}ms`);
51
52
  await new Promise((resolve) => setTimeout(resolve, delay));
52
53
  continue;
53
54
  }
55
+ // If it's not a retryable error or we're out of retries, throw
54
56
  throw error;
55
57
  }
56
58
  }
@@ -1,7 +1,19 @@
1
1
  import type { IAddress, IContractRunner, ISubgraphTransfer, ISubgraphUserHistoryItem, ISubgraphWithdrawProccessed, ISubgraphWithdrawRequest } from '../../types';
2
2
  export declare function isOldSubgraphSchema(vaultSymbol: string): boolean;
3
+ /**
4
+ *
5
+ * @param pool
6
+ * @param provider
7
+ * @returns
8
+ */
3
9
  export declare function getSubgraphWithdrawRequests(pool: IAddress, provider: IContractRunner, slackWebookUrl?: string): Promise<ISubgraphWithdrawRequest[]>;
4
10
  export declare function getSubgraphWithdrawProccessed(pool: IAddress, provider: IContractRunner, slackWebookUrl?: string): Promise<ISubgraphWithdrawProccessed[]>;
11
+ /**
12
+ *
13
+ * @param pool
14
+ * @param provider
15
+ * @returns
16
+ */
5
17
  export declare function getSubgraphAllWithdrawals(pool: IAddress, provider: IContractRunner, slackWebookUrl?: string): Promise<{
6
18
  withdrawalRequesteds: ISubgraphWithdrawRequest[];
7
19
  withdrawalProcesseds: ISubgraphWithdrawProccessed[];
@@ -11,11 +11,20 @@ const slack_1 = require("../../core/logger/slack");
11
11
  const fetcher_1 = require("./fetcher");
12
12
  const core_1 = require("../../core");
13
13
  const fetcher_2 = require("../../modules/vaults/fetcher");
14
+ /**
15
+ * Utils
16
+ */
14
17
  const GOLDSKY_API_KEY = 'cmd0lz6qf35lg01ty7u20aijy';
18
+ /**
19
+ * earnAUSD exists on both Ethereum and Monad, so it needs a _monad suffix
20
+ * to distinguish its Monad subgraph from the Ethereum one.
21
+ * Other Monad-native vaults (sausd, supermon, etc.) don't need this.
22
+ */
15
23
  function needsMonadSuffix(chainId, symbol) {
16
24
  return chainId === 143 && symbol.toLowerCase() === 'earnausd';
17
25
  }
18
26
  function transformUserHistory(data, chainId, decimals, poolAddress) {
27
+ //ok to return dupes even though withdraws will return dupe because we parse out duplicate txn hash on the FE
19
28
  return [
20
29
  ...(data.withdraws?.map((item) => ({
21
30
  ...item,
@@ -69,6 +78,7 @@ function sortUserHistory(data, chainId, decimals, poolAddress) {
69
78
  return [];
70
79
  return transformUserHistory(data, chainId, decimals, poolAddress).sort((a, b) => Number(a.timestamp_) - Number(b.timestamp_));
71
80
  }
81
+ // queries
72
82
  const WITHDRAWALS_REQUESTED_QUERY_PROPS = `
73
83
  id
74
84
  day
@@ -155,10 +165,15 @@ const EVM_V2_DEPOSIT_QUERY_PROPS = `
155
165
  senderAddr
156
166
  receiverAddr
157
167
  `;
168
+ // New deployment process uses a different subgraph schema (no trailing underscores).
169
+ // Vaults in SUBGRAPH_VAULT_URLS use the old schema; everything else uses the new schema.
170
+ // GraphQL aliases map new-schema fields to what the SDK expects internally.
158
171
  function isOldSubgraphSchema(vaultSymbol) {
159
172
  return (vaultSymbol?.toLowerCase() in
160
173
  core_1.SUBGRAPH_VAULT_URLS);
161
174
  }
175
+ // New schema query props (shared across evm-1 and evm-2 — the new subgraph schema
176
+ // normalized field names, so no per-version variants are needed)
162
177
  const NEW_DEPOSIT_QUERY_PROPS = `
163
178
  id
164
179
  assetIn
@@ -196,6 +211,7 @@ const NEW_WITHDRAWALS_QUERY_PROPS = `
196
211
  shares
197
212
  owner
198
213
  `;
214
+ // New schema: transfer query props
199
215
  const NEW_TRANSFER_QUERY_PROPS = `
200
216
  id
201
217
  from
@@ -215,7 +231,14 @@ const TRANSFER_QUERY_PROPS = `
215
231
  block_number
216
232
  contractId_
217
233
  `;
234
+ /**
235
+ *
236
+ * @param pool
237
+ * @param provider
238
+ * @returns
239
+ */
218
240
  async function getSubgraphWithdrawRequests(pool, provider, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
241
+ // setup
219
242
  let vaultSymbol = await (0, core_1.getVaultSymbol)(pool, provider);
220
243
  if (vaultSymbol === undefined) {
221
244
  core_1.Logger.log.warn('getSubgraphWithdrawRequests', `cannot find vault symbol for pool: ${pool}`);
@@ -226,6 +249,7 @@ async function getSubgraphWithdrawRequests(pool, provider, slackWebookUrl = slac
226
249
  if (needsMonadSuffix(network, vaultSymbol)) {
227
250
  vaultSymbol = vaultSymbol.concat('_monad');
228
251
  }
252
+ // sanitize
229
253
  if (vaultSymbol === 'testWETHTSA') {
230
254
  return [];
231
255
  }
@@ -275,6 +299,7 @@ async function getSubgraphWithdrawRequests(pool, provider, slackWebookUrl = slac
275
299
  }
276
300
  async function getSubgraphWithdrawProccessed(pool, provider, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
277
301
  try {
302
+ // setup
278
303
  let vaultSymbol = await (0, core_1.getVaultSymbol)(pool, provider);
279
304
  if (vaultSymbol === undefined) {
280
305
  core_1.Logger.log.warn('getSubgraphWithdrawProccessed', `cannot find vault symbol for pool: ${pool}`);
@@ -286,6 +311,7 @@ async function getSubgraphWithdrawProccessed(pool, provider, slackWebookUrl = sl
286
311
  vaultSymbol = vaultSymbol.concat('_monad');
287
312
  }
288
313
  const noWithdrawalProcessed = vaultSymbol === 'agETH';
314
+ // sanitize
289
315
  if (vaultSymbol === 'testWETHTSA' || noWithdrawalProcessed) {
290
316
  return [];
291
317
  }
@@ -338,9 +364,16 @@ async function getSubgraphWithdrawProccessed(pool, provider, slackWebookUrl = sl
338
364
  return [];
339
365
  }
340
366
  }
367
+ /**
368
+ *
369
+ * @param pool
370
+ * @param provider
371
+ * @returns
372
+ */
341
373
  async function getSubgraphAllWithdrawals(pool, provider, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
342
374
  let query = '';
343
375
  try {
376
+ // setup
344
377
  const errorReturnObj = {
345
378
  withdrawalRequesteds: [],
346
379
  withdrawalProcesseds: [],
@@ -356,6 +389,7 @@ async function getSubgraphAllWithdrawals(pool, provider, slackWebookUrl = slack_
356
389
  vaultSymbol = vaultSymbol.concat('_monad');
357
390
  }
358
391
  const noWithdrawalProcessed = vaultSymbol === 'agETH';
392
+ // sanitize
359
393
  if (vaultSymbol === 'testWETHTSA') {
360
394
  return errorReturnObj;
361
395
  }
@@ -431,6 +465,7 @@ async function getSubgraphAllWithdrawals(pool, provider, slackWebookUrl = slack_
431
465
  }
432
466
  async function getSubgraphUserHistory(user, provider, pool, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
433
467
  try {
468
+ // setup
434
469
  const chainId = await (0, core_1.getChainId)(provider);
435
470
  const requests = [];
436
471
  let vaultSymbol = await (0, core_1.getVaultSymbol)(pool, provider);
@@ -444,6 +479,7 @@ async function getSubgraphUserHistory(user, provider, pool, slackWebookUrl = sla
444
479
  vaultSymbol = vaultSymbol.concat('_monad');
445
480
  }
446
481
  const noWithdrawalProcessed = vaultSymbol === 'agETH';
482
+ // sanitize
447
483
  if (vaultSymbol === 'testWETHTSA') {
448
484
  return requests;
449
485
  }
@@ -541,6 +577,7 @@ async function getSubgraphUserHistory(user, provider, pool, slackWebookUrl = sla
541
577
  return requests;
542
578
  }
543
579
  const json = (await result.json());
580
+ // Format data
544
581
  const decimals = await (0, core_1.getDecimals)(provider, pool);
545
582
  const formattedRequests = sortUserHistory(json.data, chainId, decimals, pool);
546
583
  return formattedRequests;
@@ -552,6 +589,7 @@ async function getSubgraphUserHistory(user, provider, pool, slackWebookUrl = sla
552
589
  }
553
590
  async function getSubgraphVaultHistory(provider, pool, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
554
591
  try {
592
+ // setup
555
593
  const requests = [];
556
594
  let vaultSymbol = await (0, core_1.getVaultSymbol)(pool, provider);
557
595
  if (vaultSymbol === undefined) {
@@ -562,7 +600,7 @@ async function getSubgraphVaultHistory(provider, pool, slackWebookUrl = slack_1.
562
600
  const network = Number(networkValue.chainId);
563
601
  if (needsMonadSuffix(network, vaultSymbol)) {
564
602
  vaultSymbol = vaultSymbol.concat('_monad');
565
- }
603
+ } // sanitize
566
604
  if (vaultSymbol === 'testWETHTSA') {
567
605
  return requests;
568
606
  }
@@ -642,6 +680,7 @@ async function getSubgraphVaultHistory(provider, pool, slackWebookUrl = slack_1.
642
680
  return requests;
643
681
  }
644
682
  const json = (await result.json());
683
+ // Format data
645
684
  const chainId = await (0, core_1.getChainId)(provider);
646
685
  const decimals = await (0, core_1.getDecimals)(provider, pool);
647
686
  const formattedRequests = sortUserHistory(json.data, chainId, decimals, pool);
@@ -654,6 +693,7 @@ async function getSubgraphVaultHistory(provider, pool, slackWebookUrl = slack_1.
654
693
  }
655
694
  async function getSubgraphUserTransfers(user, provider, pool, slackWebookUrl = slack_1.DEFAULT_SLACK_WEBHOOK_URL) {
656
695
  try {
696
+ // setup
657
697
  let amountOfTransfers = 0;
658
698
  let userTransfers = [];
659
699
  let hasNoData = false;
@@ -669,7 +709,7 @@ async function getSubgraphUserTransfers(user, provider, pool, slackWebookUrl = s
669
709
  const network = Number(networkValue.chainId);
670
710
  if (needsMonadSuffix(network, vaultSymbol)) {
671
711
  vaultSymbol = vaultSymbol.concat('_monad');
672
- }
712
+ } // sanitize
673
713
  if (vaultSymbol === 'testWETHTSA') {
674
714
  return userTransfers;
675
715
  }
@@ -696,6 +736,7 @@ async function getSubgraphUserTransfers(user, provider, pool, slackWebookUrl = s
696
736
  ? TRANSFER_QUERY_PROPS
697
737
  : NEW_TRANSFER_QUERY_PROPS;
698
738
  do {
739
+ // get all the transfers, includes redeem requests and deposits, excludes stake and withdraw events
699
740
  const where = `
700
741
  where: {
701
742
  and: [
@@ -1,25 +1,96 @@
1
+ /** @module core/services/swap-quotes */
1
2
  import type { IAddress } from '../../types';
3
+ /** Quote-provider discriminant. Will widen as new providers are added. */
2
4
  export type ISwapQuoteProvider = 'paraswap';
5
+ /**
6
+ * Input to {@link fetchSwapQuote}.
7
+ */
3
8
  export interface ISwapQuoteRequest {
9
+ /** EVM chain ID where the swap will execute. */
4
10
  chainId: number;
11
+ /** ERC-20 the user holds. */
5
12
  srcToken: IAddress;
13
+ /** `srcToken.decimals()`. */
6
14
  srcDecimals: number;
15
+ /** ERC-20 the SwapRouter should produce — typically the vault's `referenceAsset`. */
7
16
  destToken: IAddress;
17
+ /** `destToken.decimals()`. */
8
18
  destDecimals: number;
19
+ /** Input amount in `srcToken`'s smallest unit. */
9
20
  amount: bigint;
21
+ /**
22
+ * Address that will execute the resulting calldata. For SwapRouter use,
23
+ * pass the SwapRouter's address — the aggregator's calldata is bound to
24
+ * this address, so it must hold the tokens at swap time.
25
+ */
10
26
  receiver: IAddress;
27
+ /**
28
+ * Slippage tolerance in bps (1 bp = 0.01%). Defaults to 100 (1%). Must be
29
+ * in `[0, 10_000)` — 10_000 disables protection entirely and is rejected.
30
+ */
11
31
  slippageBps?: number;
32
+ /** Aggregator partner key. Defaults to `'august'`. */
12
33
  partner?: string;
34
+ /** Aggregator partner-fee receiver. Defaults to the August partner address. */
13
35
  partnerAddress?: IAddress;
36
+ /**
37
+ * `fetch`-compatible function override. Defaults to `globalThis.fetch`.
38
+ * Exposed so callers in Node environments lacking a global `fetch` can
39
+ * inject one, and so tests can mock without touching the global.
40
+ */
14
41
  fetchImpl?: typeof fetch;
42
+ /** Optional AbortSignal to cancel the in-flight Paraswap requests. */
15
43
  signal?: AbortSignal;
16
44
  }
45
+ /**
46
+ * Output of {@link fetchSwapQuote}. The `router` + `payload` pair maps
47
+ * directly into one entry of an `ISwapParams[]` passed to
48
+ * `SwapRouter.swapAndDeposit`.
49
+ *
50
+ * Modeled as a discriminated union on `provider` so adding 1inch/0x is an
51
+ * additive change rather than a breaking widening.
52
+ */
17
53
  export type ISwapQuoteResult = {
54
+ /** Quote provider that produced this calldata. */
18
55
  provider: 'paraswap';
56
+ /** DEX router that will execute the swap (the contract `payload` is calldata for). */
19
57
  router: IAddress;
58
+ /** ABI-encoded calldata for `router`. */
20
59
  payload: `0x${string}`;
60
+ /** Expected output in `destToken` units before slippage. */
21
61
  expectedAmountOut: bigint;
62
+ /** Slippage-adjusted minimum output. Below this the on-chain call reverts. */
22
63
  minAmountOut: bigint;
64
+ /**
65
+ * Epoch ms when the quote was fetched. Callers that prefetch a quote
66
+ * before submitting should re-fetch when this is older than ~60s — DEX
67
+ * pool state moves and a stale `minAmountOut` may have been computed
68
+ * against a price that no longer holds.
69
+ */
23
70
  fetchedAt: number;
24
71
  };
72
+ /**
73
+ * Fetch a swap quote and the calldata required for the on-chain SwapRouter
74
+ * to execute it.
75
+ *
76
+ * @throws {@link AugustValidationError} on invalid input (slippage out of
77
+ * range, zero amount, src===dst).
78
+ * @throws {@link AugustNetworkError} on transport failure.
79
+ * @throws {@link AugustServerError} on aggregator-side errors.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const quote = await fetchSwapQuote({
84
+ * chainId: 1,
85
+ * srcToken: WBTC,
86
+ * srcDecimals: 8,
87
+ * destToken: USDC,
88
+ * destDecimals: 6,
89
+ * amount: 100_000_000n,
90
+ * receiver: SWAP_ROUTER_ADDRESSES[1]!,
91
+ * });
92
+ * // quote.router -> Paraswap augustor
93
+ * // quote.payload -> calldata
94
+ * ```
95
+ */
25
96
  export declare function fetchSwapQuote(request: ISwapQuoteRequest): Promise<ISwapQuoteResult>;
@@ -1,10 +1,35 @@
1
1
  "use strict";
2
+ /** @module core/services/swap-quotes */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.fetchSwapQuote = fetchSwapQuote;
4
5
  const errors_1 = require("../../core/errors");
5
6
  const paraswap_1 = require("./paraswap");
6
7
  const DEFAULT_SLIPPAGE_BPS = 100;
7
8
  const BPS_DENOMINATOR = 10000n;
9
+ /**
10
+ * Fetch a swap quote and the calldata required for the on-chain SwapRouter
11
+ * to execute it.
12
+ *
13
+ * @throws {@link AugustValidationError} on invalid input (slippage out of
14
+ * range, zero amount, src===dst).
15
+ * @throws {@link AugustNetworkError} on transport failure.
16
+ * @throws {@link AugustServerError} on aggregator-side errors.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const quote = await fetchSwapQuote({
21
+ * chainId: 1,
22
+ * srcToken: WBTC,
23
+ * srcDecimals: 8,
24
+ * destToken: USDC,
25
+ * destDecimals: 6,
26
+ * amount: 100_000_000n,
27
+ * receiver: SWAP_ROUTER_ADDRESSES[1]!,
28
+ * });
29
+ * // quote.router -> Paraswap augustor
30
+ * // quote.payload -> calldata
31
+ * ```
32
+ */
8
33
  async function fetchSwapQuote(request) {
9
34
  validateRequest(request);
10
35
  const slippageBps = request.slippageBps ?? DEFAULT_SLIPPAGE_BPS;
@@ -7,6 +7,13 @@ export interface IParaswapQuoteInput {
7
7
  destDecimals: number;
8
8
  amount: bigint;
9
9
  receiver: IAddress;
10
+ /**
11
+ * Slippage tolerance in bps (1 bp = 0.01%). Used to derive the
12
+ * `destAmount` minimum baked into the resulting Paraswap calldata, so the
13
+ * on-chain DEX leg enforces the same tolerance the SwapRouter does
14
+ * (otherwise the leg reverts at the aggregator's exact-out check before
15
+ * the SwapRouter's `minAmountOut` is ever evaluated).
16
+ */
10
17
  slippageBps: number;
11
18
  partner: string;
12
19
  partnerAddress: IAddress;
@@ -19,6 +26,16 @@ export interface IParaswapQuoteOutput {
19
26
  expectedAmountOut: bigint;
20
27
  fetchedAt: number;
21
28
  }
29
+ /**
30
+ * Fetch a Paraswap quote and the calldata to execute it on behalf of the
31
+ * SwapRouter. Throws `AugustNetworkError` on fetch-layer failure and
32
+ * `AugustServerError` on Paraswap-side error responses or malformed bodies.
33
+ *
34
+ * `fetchedAt` is the wall-clock timestamp captured *after* the calldata
35
+ * response — callers downstream can use it to decide whether the leg is
36
+ * fresh enough to broadcast (DEX pool state moves; stale calldata may
37
+ * silently revert at the on-chain slippage check).
38
+ */
22
39
  export declare function fetchParaswapQuote(input: IParaswapQuoteInput): Promise<IParaswapQuoteOutput>;
23
40
  export declare const PARASWAP_DEFAULTS: {
24
41
  readonly partner: "august";
@@ -10,6 +10,16 @@ const DEFAULT_PARTNER = 'august';
10
10
  const DEFAULT_PARTNER_ADDRESS = '0xb60ee0FA5B6bA917255A03e744967E0Bda531dD0';
11
11
  const PARASWAP_VERSION = '6.2';
12
12
  const BPS_DENOMINATOR = 10000n;
13
+ /**
14
+ * Fetch a Paraswap quote and the calldata to execute it on behalf of the
15
+ * SwapRouter. Throws `AugustNetworkError` on fetch-layer failure and
16
+ * `AugustServerError` on Paraswap-side error responses or malformed bodies.
17
+ *
18
+ * `fetchedAt` is the wall-clock timestamp captured *after* the calldata
19
+ * response — callers downstream can use it to decide whether the leg is
20
+ * fresh enough to broadcast (DEX pool state moves; stale calldata may
21
+ * silently revert at the on-chain slippage check).
22
+ */
13
23
  async function fetchParaswapQuote(input) {
14
24
  const priceRoute = await getPriceRoute(input);
15
25
  const destAmountRaw = priceRoute.destAmount;
@@ -58,6 +68,10 @@ async function getPriceRoute(input) {
58
68
  }
59
69
  async function getTransactionData(input, priceRoute) {
60
70
  const url = `${PARASWAP_TRANSACTIONS_BASE_URL}/${input.chainId}/?ignoreChecks=true&ignoreGasEstimate=true&onlyParams=false`;
71
+ // Bake slippage into the destAmount Paraswap embeds as the aggregator's
72
+ // own min-out, so the DEX leg enforces the same lower bound the
73
+ // SwapRouter will check. Without this the aggregator uses the exact
74
+ // priceRoute quote (0% tolerance) and reverts on any adverse movement.
61
75
  const expectedDestAmount = BigInt(priceRoute.destAmount);
62
76
  const minDestAmount = (expectedDestAmount * (BPS_DENOMINATOR - BigInt(input.slippageBps))) /
63
77
  BPS_DENOMINATOR;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated
3
+ */
1
4
  import { IAddress, INormalizedNumber } from './web3';
2
5
  import { IDebankProtocolExposure, IDebankTokenExposure, ITokenizedVaultStrategist, IWSSubaccountCefi } from './webserver';
3
6
  type ILabelValue = {