@augustdigital/sdk 8.3.2 → 8.6.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 (213) hide show
  1. package/README.md +207 -117
  2. package/lib/abis/ERC20_Bytes32.d.ts +4 -0
  3. package/lib/abis/ERC20_Bytes32.js +4 -0
  4. package/lib/abis/ERC4626.d.ts +1 -0
  5. package/lib/abis/ERC4626.js +1 -0
  6. package/lib/abis/ERC721.d.ts +1 -0
  7. package/lib/abis/ERC721.js +1 -0
  8. package/lib/abis/FeeOracle.js +1 -0
  9. package/lib/abis/LendingPool.js +1 -0
  10. package/lib/abis/LendingPoolV2.js +1 -0
  11. package/lib/abis/Multicall3.js +3 -0
  12. package/lib/abis/OFT.d.ts +20 -0
  13. package/lib/abis/OFT.js +20 -0
  14. package/lib/abis/SmartAccount.d.ts +1 -0
  15. package/lib/abis/SmartAccount.js +3 -0
  16. package/lib/abis/SwapRouter.d.ts +1 -0
  17. package/lib/abis/SwapRouter.js +1 -0
  18. package/lib/abis/UniversalSignatureValidator.js +3 -0
  19. package/lib/abis/index.d.ts +5 -0
  20. package/lib/abis/index.js +5 -0
  21. package/lib/adapters/evm/getters.d.ts +17 -2
  22. package/lib/adapters/evm/getters.js +35 -3
  23. package/lib/adapters/evm/index.d.ts +266 -4
  24. package/lib/adapters/evm/index.js +270 -1
  25. package/lib/adapters/evm/utils.d.ts +6 -0
  26. package/lib/adapters/evm/utils.js +7 -0
  27. package/lib/adapters/solana/constants.d.ts +1 -1
  28. package/lib/adapters/solana/constants.js +4 -1
  29. package/lib/adapters/solana/getters.d.ts +9 -1
  30. package/lib/adapters/solana/getters.js +21 -0
  31. package/lib/adapters/solana/idl/vault-idl.js +9 -0
  32. package/lib/adapters/solana/index.d.ts +59 -4
  33. package/lib/adapters/solana/index.js +61 -0
  34. package/lib/adapters/solana/types.d.ts +1 -1
  35. package/lib/adapters/solana/utils.d.ts +31 -3
  36. package/lib/adapters/solana/utils.js +79 -4
  37. package/lib/adapters/solana/vault.actions.d.ts +23 -4
  38. package/lib/adapters/solana/vault.actions.js +47 -3
  39. package/lib/adapters/stellar/actions.d.ts +26 -1
  40. package/lib/adapters/stellar/actions.js +33 -0
  41. package/lib/adapters/stellar/constants.d.ts +26 -0
  42. package/lib/adapters/stellar/constants.js +29 -0
  43. package/lib/adapters/stellar/getters.d.ts +56 -0
  44. package/lib/adapters/stellar/getters.js +81 -0
  45. package/lib/adapters/stellar/index.d.ts +70 -0
  46. package/lib/adapters/stellar/index.js +71 -0
  47. package/lib/adapters/stellar/soroban.d.ts +21 -1
  48. package/lib/adapters/stellar/soroban.js +47 -1
  49. package/lib/adapters/stellar/submit.d.ts +29 -0
  50. package/lib/adapters/stellar/submit.js +90 -5
  51. package/lib/adapters/stellar/types.d.ts +27 -0
  52. package/lib/adapters/stellar/types.js +3 -0
  53. package/lib/adapters/stellar/utils.d.ts +10 -0
  54. package/lib/adapters/stellar/utils.js +10 -0
  55. package/lib/adapters/sui/getters.d.ts +7 -1
  56. package/lib/adapters/sui/getters.js +6 -0
  57. package/lib/adapters/sui/index.d.ts +16 -1
  58. package/lib/adapters/sui/index.js +17 -0
  59. package/lib/adapters/sui/transformer.d.ts +8 -2
  60. package/lib/adapters/sui/transformer.js +7 -0
  61. package/lib/adapters/sui/types.d.ts +1 -1
  62. package/lib/adapters/sui/utils.d.ts +6 -0
  63. package/lib/adapters/sui/utils.js +6 -0
  64. package/lib/core/analytics/chain-name.d.ts +8 -0
  65. package/lib/core/analytics/chain-name.js +8 -0
  66. package/lib/core/analytics/constants.d.ts +4 -0
  67. package/lib/core/analytics/constants.js +4 -0
  68. package/lib/core/analytics/env.d.ts +25 -0
  69. package/lib/core/analytics/env.js +26 -0
  70. package/lib/core/analytics/index.d.ts +26 -0
  71. package/lib/core/analytics/index.js +35 -0
  72. package/lib/core/analytics/instrumentation.d.ts +26 -0
  73. package/lib/core/analytics/instrumentation.js +66 -2
  74. package/lib/core/analytics/method-taxonomy.d.ts +16 -0
  75. package/lib/core/analytics/method-taxonomy.js +18 -0
  76. package/lib/core/analytics/metrics.d.ts +23 -0
  77. package/lib/core/analytics/metrics.js +40 -0
  78. package/lib/core/analytics/sanitize.d.ts +38 -0
  79. package/lib/core/analytics/sanitize.js +46 -0
  80. package/lib/core/analytics/sentry-runtime.d.ts +11 -0
  81. package/lib/core/analytics/sentry-runtime.js +20 -1
  82. package/lib/core/analytics/sentry.d.ts +47 -2
  83. package/lib/core/analytics/sentry.js +115 -2
  84. package/lib/core/analytics/types.d.ts +28 -1
  85. package/lib/core/analytics/user-identity.d.ts +36 -2
  86. package/lib/core/analytics/user-identity.js +43 -1
  87. package/lib/core/analytics/version.d.ts +6 -1
  88. package/lib/core/analytics/version.js +6 -1
  89. package/lib/core/auth/verify.js +5 -0
  90. package/lib/core/base.class.d.ts +78 -3
  91. package/lib/core/base.class.js +66 -4
  92. package/lib/core/cache.d.ts +5 -0
  93. package/lib/core/cache.js +6 -0
  94. package/lib/core/constants/adapters.d.ts +16 -1
  95. package/lib/core/constants/adapters.js +28 -8
  96. package/lib/core/constants/core.d.ts +14 -1
  97. package/lib/core/constants/core.js +18 -0
  98. package/lib/core/constants/swap-router.d.ts +83 -1
  99. package/lib/core/constants/swap-router.js +91 -1
  100. package/lib/core/constants/vaults.d.ts +57 -1
  101. package/lib/core/constants/vaults.js +66 -1
  102. package/lib/core/constants/web3.d.ts +4 -1
  103. package/lib/core/constants/web3.js +15 -5
  104. package/lib/core/errors/index.d.ts +38 -2
  105. package/lib/core/errors/index.js +38 -0
  106. package/lib/core/fetcher.d.ts +136 -2
  107. package/lib/core/fetcher.js +229 -25
  108. package/lib/core/helpers/adapters.d.ts +10 -1
  109. package/lib/core/helpers/adapters.js +11 -0
  110. package/lib/core/helpers/chain-address.d.ts +10 -0
  111. package/lib/core/helpers/chain-address.js +11 -0
  112. package/lib/core/helpers/core.d.ts +49 -4
  113. package/lib/core/helpers/core.js +74 -7
  114. package/lib/core/helpers/explorer-link.d.ts +15 -1
  115. package/lib/core/helpers/explorer-link.js +14 -0
  116. package/lib/core/helpers/signer.d.ts +27 -1
  117. package/lib/core/helpers/signer.js +39 -0
  118. package/lib/core/helpers/swap-router.d.ts +33 -1
  119. package/lib/core/helpers/swap-router.js +32 -0
  120. package/lib/core/helpers/vault-version.d.ts +2 -1
  121. package/lib/core/helpers/vault-version.js +2 -0
  122. package/lib/core/helpers/vaults.d.ts +9 -1
  123. package/lib/core/helpers/vaults.js +22 -8
  124. package/lib/core/helpers/web3.d.ts +154 -2
  125. package/lib/core/helpers/web3.js +192 -15
  126. package/lib/core/logger/index.d.ts +55 -0
  127. package/lib/core/logger/index.js +19 -0
  128. package/lib/core/logger/slack.d.ts +3 -0
  129. package/lib/core/logger/slack.js +3 -0
  130. package/lib/core/vault-metadata.d.ts +7 -1
  131. package/lib/core/vault-metadata.js +6 -0
  132. package/lib/core/version-check.d.ts +52 -0
  133. package/lib/core/version-check.js +82 -1
  134. package/lib/evm/methods/crossChainVault.d.ts +90 -0
  135. package/lib/evm/methods/crossChainVault.js +187 -2
  136. package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
  137. package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
  138. package/lib/evm/methods/index.d.ts +1 -0
  139. package/lib/evm/methods/index.js +1 -0
  140. package/lib/evm/types/crossChain.d.ts +202 -0
  141. package/lib/evm/types/crossChain.js +12 -1
  142. package/lib/index.d.ts +16 -0
  143. package/lib/index.js +19 -0
  144. package/lib/main.d.ts +289 -6
  145. package/lib/main.js +312 -0
  146. package/lib/modules/api/index.d.ts +1 -0
  147. package/lib/modules/api/index.js +6 -0
  148. package/lib/modules/api/main.d.ts +52 -0
  149. package/lib/modules/api/main.js +130 -0
  150. package/lib/modules/sub-accounts/fetcher.d.ts +17 -2
  151. package/lib/modules/sub-accounts/fetcher.js +15 -0
  152. package/lib/modules/sub-accounts/main.d.ts +35 -2
  153. package/lib/modules/sub-accounts/main.js +39 -1
  154. package/lib/modules/sub-accounts/utils.d.ts +4 -1
  155. package/lib/modules/sub-accounts/utils.js +3 -0
  156. package/lib/modules/vaults/adapter.helpers.d.ts +21 -3
  157. package/lib/modules/vaults/adapter.helpers.js +34 -0
  158. package/lib/modules/vaults/fetcher.d.ts +45 -0
  159. package/lib/modules/vaults/fetcher.js +91 -4
  160. package/lib/modules/vaults/getters.d.ts +295 -0
  161. package/lib/modules/vaults/getters.js +567 -26
  162. package/lib/modules/vaults/index.d.ts +12 -0
  163. package/lib/modules/vaults/index.js +12 -0
  164. package/lib/modules/vaults/main.d.ts +292 -4
  165. package/lib/modules/vaults/main.js +382 -8
  166. package/lib/modules/vaults/read.actions.d.ts +170 -2
  167. package/lib/modules/vaults/read.actions.js +143 -0
  168. package/lib/modules/vaults/types.d.ts +34 -0
  169. package/lib/modules/vaults/utils/call-data-decoder.d.ts +48 -1
  170. package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
  171. package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
  172. package/lib/modules/vaults/utils/date-utils.js +47 -1
  173. package/lib/modules/vaults/utils.d.ts +85 -0
  174. package/lib/modules/vaults/utils.js +139 -7
  175. package/lib/modules/vaults/write.actions.d.ts +363 -3
  176. package/lib/modules/vaults/write.actions.js +399 -3
  177. package/lib/polyfills.js +4 -2
  178. package/lib/sdk.d.ts +23847 -0
  179. package/lib/services/coingecko/fetcher.d.ts +15 -1
  180. package/lib/services/coingecko/fetcher.js +30 -9
  181. package/lib/services/debank/fetcher.d.ts +15 -1
  182. package/lib/services/debank/fetcher.js +12 -0
  183. package/lib/services/debank/utils.d.ts +1 -1
  184. package/lib/services/debank/utils.js +18 -1
  185. package/lib/services/layerzero/deposits.d.ts +12 -1
  186. package/lib/services/layerzero/deposits.js +34 -11
  187. package/lib/services/layerzero/redeems.d.ts +11 -1
  188. package/lib/services/layerzero/redeems.js +13 -0
  189. package/lib/services/layerzero/utils.d.ts +8 -0
  190. package/lib/services/layerzero/utils.js +11 -0
  191. package/lib/services/octavfi/fetcher.d.ts +8 -1
  192. package/lib/services/octavfi/fetcher.js +25 -0
  193. package/lib/services/octavfi/types.d.ts +1 -1
  194. package/lib/services/octavfi/utils.d.ts +14 -2
  195. package/lib/services/octavfi/utils.js +44 -10
  196. package/lib/services/subgraph/fetcher.js +4 -2
  197. package/lib/services/subgraph/vaults.d.ts +12 -0
  198. package/lib/services/subgraph/vaults.js +119 -2
  199. package/lib/services/swap-quotes/index.d.ts +80 -0
  200. package/lib/services/swap-quotes/index.js +27 -1
  201. package/lib/services/swap-quotes/paraswap.d.ts +25 -0
  202. package/lib/services/swap-quotes/paraswap.js +22 -0
  203. package/lib/types/pools.d.ts +5 -2
  204. package/lib/types/staking.d.ts +1 -1
  205. package/lib/types/sub-accounts.d.ts +1 -1
  206. package/lib/types/subgraph.d.ts +10 -1
  207. package/lib/types/typed-contract.d.ts +64 -0
  208. package/lib/types/vaults.d.ts +163 -2
  209. package/lib/types/vaults.js +10 -0
  210. package/lib/types/web3.d.ts +9 -1
  211. package/lib/types/web3.js +1 -0
  212. package/lib/types/webserver.d.ts +47 -2
  213. package/package.json +6 -5
@@ -17,6 +17,10 @@ const abis_1 = require("../../abis");
17
17
  const core_1 = require("../../core");
18
18
  const vaults_1 = require("../../core/helpers/vaults");
19
19
  const ethers_1 = require("ethers");
20
+ /**
21
+ * @param walletClient a wagmi-derived client (from useWalletClient)
22
+ * @returns An ethers JsonRpcSigner object used in sdk.evm.setSigner
23
+ */
20
24
  async function walletClientToSigner(walletClient) {
21
25
  const { account, chain, transport } = walletClient;
22
26
  const network = {
@@ -24,14 +28,23 @@ async function walletClientToSigner(walletClient) {
24
28
  name: chain.name,
25
29
  ensAddress: chain.contracts?.ensRegistry?.address,
26
30
  };
31
+ //@ts-expect-error
27
32
  const provider = new ethers_1.BrowserProvider(transport, network);
28
33
  const signer = await provider.getSigner(account.address);
29
34
  return signer;
30
35
  }
36
+ /**
37
+ * Calculates the reward multiplier based on the vault and optional timestamp.
38
+ * Returns the applicable multiplier for a given vault at a specific timestamp,
39
+ * or the latest multiplier if no timestamp is provided.
40
+ * @param foundPool The vault to get the multiplier for
41
+ * @param timestamp Optional timestamp to get historical multiplier
42
+ * @returns The reward multiplier value
43
+ */
31
44
  const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
32
45
  const multipliers = foundPool.rewards?.multipliers;
33
46
  if (!multipliers?.length) {
34
- return 1;
47
+ return 1; // default multiplier if multipliers are not found
35
48
  }
36
49
  const multipliersByTimestamp = multipliers.reduce((acc, curr) => {
37
50
  return {
@@ -40,8 +53,9 @@ const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
40
53
  };
41
54
  }, {});
42
55
  if (!multipliersByTimestamp) {
43
- return 1;
56
+ return 1; // default multiplier if pool is not found
44
57
  }
58
+ // return the latest if timestamp not provided
45
59
  if (!timestamp) {
46
60
  const latest = Object.keys(multipliersByTimestamp)
47
61
  .map(Number)
@@ -50,13 +64,43 @@ const getRewardMultiplierByTimestamp = (foundPool, timestamp) => {
50
64
  }
51
65
  const applicableTimestamp = Object.keys(multipliersByTimestamp)
52
66
  .map(Number)
53
- .filter((ts) => ts <= timestamp)
54
- .sort((a, b) => b - a)[0];
67
+ .filter((ts) => ts <= timestamp) // filter only timestamps before or equal to the given timestamp
68
+ .sort((a, b) => b - a)[0]; // get the latest applicable timestamp
55
69
  return applicableTimestamp !== undefined
56
70
  ? (multipliersByTimestamp[applicableTimestamp] ?? 1)
57
71
  : 1;
58
72
  };
59
73
  exports.getRewardMultiplierByTimestamp = getRewardMultiplierByTimestamp;
74
+ /**
75
+ * Build the human-readable display label for a single reward.
76
+ *
77
+ * The format is `"{multiplier}x {text}"`, with the multiplier prefix omitted
78
+ * when it equals 1 (e.g. `"2x Cores"`, `" Cores"` when multiplier is 1 — the
79
+ * leading space is preserved to keep `additionalPoints` and the
80
+ * `additionalPointsDetailed` label in lockstep). This is a display string only;
81
+ * consumers that need a stable key should join on the reward's `id`
82
+ * (see {@link IVaultRewardDetail}), not on this label.
83
+ *
84
+ * @param reward - The raw tokenized-vault reward.
85
+ * @returns The display label string.
86
+ */
87
+ function getRewardLabel(reward) {
88
+ return `${reward.multiplier !== 1 ? `${reward.multiplier}x` : ''} ${reward.text}`;
89
+ }
90
+ /**
91
+ * Get the rewards for the vault.
92
+ *
93
+ * Builds the display-facing rewards summary from the raw tokenized-vault
94
+ * rewards array. In addition to the legacy `additionalPoints` string list, it
95
+ * emits `additionalPointsDetailed`, which pairs each label with its
96
+ * backend-provided `img_url`. Consumers (e.g. the Upshift app) resolve a
97
+ * reward's logo from this `imgUrl` first, falling back to a bundled asset only
98
+ * when it is absent — so a newly-added reward with a backend logo (e.g.
99
+ * "Cores") renders its icon without any client-side keyword mapping.
100
+ *
101
+ * @param tokenizedVault - The tokenized vault.
102
+ * @returns The rewards summary, including `additionalPointsDetailed`.
103
+ */
60
104
  function getVaultRewards(tokenizedVault) {
61
105
  const upshiftPointRewards = tokenizedVault.rewards?.filter((r) => r.text === 'Upshift Points');
62
106
  const sortedPointsMultipliers = upshiftPointRewards?.sort((a, b) => new Date(b.start_datetime).getTime() -
@@ -72,16 +116,31 @@ function getVaultRewards(tokenizedVault) {
72
116
  : '',
73
117
  multiplier: latestUpshiftPointMultiplier,
74
118
  multipliers: upshiftPointsMultipliers,
75
- additionalPoints: tokenizedVault.rewards.map((r) => `${r.multiplier !== 1 ? `${r.multiplier}x` : ''} ${r.text}`),
119
+ additionalPoints: tokenizedVault.rewards.map(getRewardLabel),
120
+ additionalPointsDetailed: tokenizedVault.rewards.map((r) => ({
121
+ id: r.id,
122
+ label: getRewardLabel(r),
123
+ text: r.text,
124
+ imgUrl: r.img_url || null,
125
+ multiplier: r.multiplier,
126
+ })),
76
127
  };
77
128
  return rewards;
78
129
  }
130
+ /**
131
+ * Get the idle assets for the vault
132
+ * @param provider - The provider
133
+ * @param vaultAddress - The vault address
134
+ * @param totalAssets - The total assets of the vault
135
+ * @returns The idle assets
136
+ */
79
137
  async function getIdleAssets(provider, vaultAddress, underlying, totalAssets) {
80
138
  const tokenizedVault = (await (0, core_1.fetchTokenizedVault)(vaultAddress))?.[0];
81
139
  const version = (0, vaults_1.getVaultVersionV2)(tokenizedVault);
82
140
  let idleAssets;
83
141
  switch (version) {
84
142
  case 'evm-0': {
143
+ // old lending pool
85
144
  const globalLoansAmount = await (0, core_1.createContract)({
86
145
  provider,
87
146
  address: vaultAddress,
@@ -105,6 +164,7 @@ async function getIdleAssets(provider, vaultAddress, underlying, totalAssets) {
105
164
  break;
106
165
  }
107
166
  default: {
167
+ // tokenized vault
108
168
  idleAssets = await (0, core_1.createContract)({
109
169
  provider,
110
170
  address: underlying,
@@ -146,6 +206,7 @@ async function getYieldLastRealizedOn(provider, vaultAddress) {
146
206
  return 0;
147
207
  }
148
208
  default: {
209
+ // Default to V3 ABI which has assetsUpdatedOn
149
210
  const contract = (0, core_1.createContract)({
150
211
  provider,
151
212
  address: vaultAddress,
@@ -157,6 +218,10 @@ async function getYieldLastRealizedOn(provider, vaultAddress) {
157
218
  }
158
219
  return Number(assetsUpdatedOn);
159
220
  }
221
+ /**
222
+ * Format APY data from backend tokenized vault into the unified IVaultApy shape.
223
+ * Shared across all chain adapters (EVM, Solana, Stellar).
224
+ */
160
225
  function formatVaultApy(tokenizedVault) {
161
226
  const { reported_apy, campaign_apy } = tokenizedVault;
162
227
  return {
@@ -170,6 +235,10 @@ function formatVaultApy(tokenizedVault) {
170
235
  underlyingApy: (reported_apy?.underlying_apy ?? 0) * 100,
171
236
  };
172
237
  }
238
+ /**
239
+ * Map strategists from backend subaccounts or hardcoded list.
240
+ * Shared across all chain adapters.
241
+ */
173
242
  function mapStrategists(tokenizedVault) {
174
243
  const hasValidStrategists = tokenizedVault.subaccounts?.length > 0 &&
175
244
  tokenizedVault.subaccounts.some((s) => s.strategist !== null);
@@ -191,6 +260,10 @@ function mapStrategists(tokenizedVault) {
191
260
  website_url: s.website_url ?? null,
192
261
  }));
193
262
  }
263
+ /**
264
+ * Map composability integrations from backend format to vault format.
265
+ * Shared across all chain adapters.
266
+ */
194
267
  function mapComposabilityIntegrations(tokenizedVault) {
195
268
  return (tokenizedVault.composability_integrations?.map((integration) => ({
196
269
  name: integration.name,
@@ -202,6 +275,11 @@ function mapComposabilityIntegrations(tokenizedVault) {
202
275
  id: integration.id,
203
276
  })) || []);
204
277
  }
278
+ /**
279
+ * Convert a backend-reported TVL (whole token units) to a NormalizedBn.
280
+ * Handles null, undefined, and non-finite values (NaN, Infinity) safely, defaulting to 0.
281
+ * Shared between non-EVM adapters (Solana, Stellar) and the module-level getVaultTvl handler.
282
+ */
205
283
  function backendTvlToNormalizedBn(tvl, decimals) {
206
284
  if (tvl == null) {
207
285
  core_1.Logger.log.warn('backendTvlToNormalizedBn', 'TVL is null/undefined, defaulting to 0 — check backend data pipeline', { decimals });
@@ -217,6 +295,10 @@ function backendTvlToNormalizedBn(tvl, decimals) {
217
295
  const tvlWhole = BigInt(Math.round(tvl));
218
296
  return (0, core_1.toNormalizedBn)(tvlWhole * scaleFactor, decimals);
219
297
  }
298
+ /**
299
+ * Map daily PnL per share from backend Record format to array format.
300
+ * Shared across non-EVM adapters.
301
+ */
220
302
  function mapDailyPnlPerShare(dailyPnl) {
221
303
  if (!dailyPnl)
222
304
  return [];
@@ -225,6 +307,11 @@ function mapDailyPnlPerShare(dailyPnl) {
225
307
  value,
226
308
  }));
227
309
  }
310
+ /**
311
+ * Build a base IVault from backend data, shared across non-EVM adapters (Solana, Stellar).
312
+ * Chain-specific fields (chainId, version, name, totalAssets, totalSupply, depositAssets, receipt)
313
+ * must be provided via the overrides parameter.
314
+ */
228
315
  function buildBackendVault(tokenizedVault, overrides) {
229
316
  const apy = formatVaultApy(tokenizedVault);
230
317
  const rewards = tokenizedVault.rewards?.length
@@ -234,6 +321,7 @@ function buildBackendVault(tokenizedVault, overrides) {
234
321
  multiplier: 0,
235
322
  multipliers: [],
236
323
  additionalPoints: [],
324
+ additionalPointsDetailed: [],
237
325
  };
238
326
  return {
239
327
  operator: '0x',
@@ -256,8 +344,9 @@ function buildBackendVault(tokenizedVault, overrides) {
256
344
  isVisible: tokenizedVault.is_visible || false,
257
345
  reserveTarget: tokenizedVault.reserve_target || 0,
258
346
  reserveTolerance: tokenizedVault.reserve_tolerance || 0,
347
+ // Vault decimals are derived from the receipt token decimals for non-EVM vaults
259
348
  decimals: overrides.receipt.decimals,
260
- maxSupply: (0, core_1.toNormalizedBn)(1000000000),
349
+ maxSupply: (0, core_1.toNormalizedBn)(1_000_000_000),
261
350
  depositCap: null,
262
351
  apy,
263
352
  rewards,
@@ -331,13 +420,22 @@ function buildBackendVault(tokenizedVault, overrides) {
331
420
  : {}),
332
421
  showCapFilled: tokenizedVault?.show_cap_filled ?? null,
333
422
  apyOverride: tokenizedVault.apy_override ?? null,
423
+ // Spread chain-specific overrides last so they take precedence
334
424
  ...overrides,
335
425
  };
336
426
  }
427
+ /**
428
+ * Build the formatted vault
429
+ * @param provider - The provider
430
+ * @param tokenizedVault - The tokenized vault
431
+ * @param contractCalls - The contract calls
432
+ * @returns The formatted vault
433
+ */
337
434
  async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
338
435
  const strategists = mapStrategists(tokenizedVault);
339
436
  const operators = tokenizedVault?.operators || [];
340
437
  const eoa_operators = tokenizedVault?.eoa_operators || [];
438
+ // Load offchain props
341
439
  const baseProps = {
342
440
  chainId: tokenizedVault.chain,
343
441
  maxDailyDrawdown: tokenizedVault.max_daily_drawdown || 0,
@@ -392,6 +490,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
392
490
  isWithdrawalPaused: contractCalls.withdrawalsPaused,
393
491
  idleAssets: (0, core_1.toNormalizedBn)(await getIdleAssets(provider, tokenizedVault.address, contractCalls.asset, contractCalls.totalAssets), Number(contractCalls.decimals)),
394
492
  };
493
+ // Version specific logic
395
494
  const version = (0, vaults_1.getVaultVersionV2)(tokenizedVault);
396
495
  let operator = '0x';
397
496
  let depositAssets = [];
@@ -407,6 +506,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
407
506
  };
408
507
  switch (version) {
409
508
  case 'sol-0': {
509
+ // @todo
410
510
  break;
411
511
  }
412
512
  case 'evm-2': {
@@ -431,15 +531,18 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
431
531
  depositAssets = [...depositAssets, ...extraAssets];
432
532
  totalSupply = contractCalls.totalSupply;
433
533
  (maxSupply =
434
- (0, core_1.toNormalizedBn)(1000000000000)),
534
+ (0, core_1.toNormalizedBn)(1_000_000_000_000)), // @hardcoded: no maxSupply on here
435
535
  (receipt = {
436
536
  symbol: tokenizedVault.receipt_token_symbol,
437
537
  address: contractCalls.lpTokenAddress,
438
538
  decimals: contractCalls.decimals,
439
539
  });
540
+ // @todo: get operator
541
+ // operator = contractCalls.loansOperator as IAddress;
440
542
  break;
441
543
  }
442
544
  default: {
545
+ // get idle assets
443
546
  depositAssets = [
444
547
  {
445
548
  address: contractCalls.asset,
@@ -462,10 +565,13 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
462
565
  break;
463
566
  }
464
567
  }
568
+ // Check for adapter configuration and add adapter deposit tokens
465
569
  const adapterConfig = (0, core_1.getVaultAdapterConfig)(tokenizedVault.address);
466
570
  if (adapterConfig) {
467
571
  const allDepositTokens = (0, core_1.getVaultDepositTokens)(tokenizedVault.address, contractCalls.asset);
572
+ // Build deposit assets array including adapter tokens
468
573
  const depositAssetsWithAdapters = await Promise.all(allDepositTokens.map(async (tokenAddress) => {
574
+ // Skip if already in depositAssets
469
575
  if (depositAssets.find((a) => a.address.toLowerCase() === tokenAddress.toLowerCase())) {
470
576
  return null;
471
577
  }
@@ -477,6 +583,7 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
477
583
  decimals,
478
584
  };
479
585
  }));
586
+ // Add adapter tokens to depositAssets
480
587
  depositAssets = [
481
588
  ...depositAssets,
482
589
  ...depositAssetsWithAdapters.filter((a) => a !== null),
@@ -527,6 +634,17 @@ async function buildFormattedVault(provider, tokenizedVault, contractCalls) {
527
634
  return result;
528
635
  }
529
636
  exports.ERC_20_PERMIT_HASH = '0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9';
637
+ /**
638
+ * Generate an ERC2612 permit signature
639
+ * @param token - The ERC20 token contract address
640
+ * @param owner - The token owner's address (signer)
641
+ * @param spender - The address that will be approved to spend (your pool contract)
642
+ * @param value - The amount to approve
643
+ * @param deadline - Unix timestamp for when the permit expires
644
+ * @param signer - The ethers.js Signer (wallet)
645
+ * @param provider - The ethers.js Provider
646
+ * @returns The signature components (v, r, s) and deadline
647
+ */
530
648
  async function generatePermitSignature(token, owner, spender, value, deadline, signer, chainId) {
531
649
  const tokenContract = (0, core_1.createContract)({
532
650
  address: token,
@@ -564,10 +682,14 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
564
682
  }
565
683
  if (!matchingDomain) {
566
684
  const name = (await tokenContract.name());
685
+ // Try different domain configurations to find which matches
567
686
  const domainConfigs = [
687
+ // Standard EIP-2612
568
688
  { name, version: '1', chainId, verifyingContract: token },
569
689
  { name, version: '2', chainId, verifyingContract: token },
690
+ // Without version
570
691
  { name, chainId, verifyingContract: token },
692
+ // With different salt values (some contracts use this)
571
693
  {
572
694
  name,
573
695
  version: '1',
@@ -584,6 +706,8 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
584
706
  }
585
707
  }
586
708
  if (!matchingDomain) {
709
+ // If no match, try to get the version from the contract
710
+ // Some token contracts have a version() method for EIP-2612 domain
587
711
  try {
588
712
  const version = await tokenContract.version();
589
713
  matchingDomain = { name, version, chainId, verifyingContract: token };
@@ -600,6 +724,7 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
600
724
  ttl: 60 * 60 * 1000,
601
725
  });
602
726
  }
727
+ // EIP-2612 Permit type
603
728
  const types = {
604
729
  Permit: [
605
730
  { name: 'owner', type: 'address' },
@@ -616,7 +741,9 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
616
741
  nonce: Number(nonce),
617
742
  deadline: deadline,
618
743
  };
744
+ // Sign the typed data
619
745
  const signature = await signer.signTypedData(matchingDomain, types, message);
746
+ // Split signature into r, s, v
620
747
  const sig = ethers_1.ethers.Signature.from(signature);
621
748
  return {
622
749
  r: sig.r,
@@ -625,6 +752,11 @@ async function generatePermitSignature(token, owner, spender, value, deadline, s
625
752
  deadline: deadline,
626
753
  };
627
754
  }
755
+ /**
756
+ * Helper to create a deadline (current time + offset in seconds)
757
+ * @param offsetSeconds - Number of seconds from now (default: 20 minutes)
758
+ * @returns Unix timestamp
759
+ */
628
760
  function createDeadline(offsetSeconds = 1200) {
629
761
  return Math.floor(Date.now() / 1000) + offsetSeconds;
630
762
  }