@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
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchSubaccountSummary = exports.fetchSubaccountOtcPositions = exports.fetchSubaccountCefiPositions = exports.fetchSubaccountLoans = exports.fetchSubaccountHeathFactor = void 0;
4
4
  const core_1 = require("../../core");
5
+ /**
6
+ * Fetch subaccount health factor for a given subaccount address
7
+ */
5
8
  const fetchSubaccountHeathFactor = async (address, augustKey, headers) => {
6
9
  const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.health_factor(address), {
7
10
  headers,
@@ -12,6 +15,9 @@ const fetchSubaccountHeathFactor = async (address, augustKey, headers) => {
12
15
  return response.json();
13
16
  };
14
17
  exports.fetchSubaccountHeathFactor = fetchSubaccountHeathFactor;
18
+ /**
19
+ * Fetch subaccount loans details
20
+ */
15
21
  const fetchSubaccountLoans = async (payload, augustKey, headers) => {
16
22
  const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.loans(payload.address, payload.side, payload.active), {
17
23
  headers,
@@ -22,6 +28,9 @@ const fetchSubaccountLoans = async (payload, augustKey, headers) => {
22
28
  return response.json();
23
29
  };
24
30
  exports.fetchSubaccountLoans = fetchSubaccountLoans;
31
+ /**
32
+ * Fetch the subaccount CeFi positions
33
+ */
25
34
  const fetchSubaccountCefiPositions = async (address, augustKey, headers) => {
26
35
  const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.cefi(address), {
27
36
  headers,
@@ -32,6 +41,9 @@ const fetchSubaccountCefiPositions = async (address, augustKey, headers) => {
32
41
  return response.json();
33
42
  };
34
43
  exports.fetchSubaccountCefiPositions = fetchSubaccountCefiPositions;
44
+ /**
45
+ * Fetch the subaccount OTC positions
46
+ */
35
47
  const fetchSubaccountOtcPositions = async (address, augustKey, headers) => {
36
48
  const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.otc_positions(address), {
37
49
  headers,
@@ -42,6 +54,9 @@ const fetchSubaccountOtcPositions = async (address, augustKey, headers) => {
42
54
  return response.json();
43
55
  };
44
56
  exports.fetchSubaccountOtcPositions = fetchSubaccountOtcPositions;
57
+ /**
58
+ * Fetch the subaccount summary view
59
+ */
45
60
  const fetchSubaccountSummary = async (address, augustKey, headers) => {
46
61
  const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.summary(address), {
47
62
  headers,
@@ -1,8 +1,19 @@
1
- import { AugustBase, IAugustBase } from '../../core';
2
- import { IAddress } from '../../types';
1
+ import { AugustBase, type IAugustBase } from '../../core';
2
+ import type { IAddress } from '../../types';
3
+ /**
4
+ * Subaccount operation class interacting with August Subaccounts
5
+ * Subaccount is a smart contract wallet that serves as the fundamental infrastructure for August's platform.
6
+ * It functions as a cross-margin account designed for optimal capital efficiency.
7
+ * Most of the operations require a August API key to perform
8
+ */
3
9
  export declare class AugustSubAccounts extends AugustBase {
4
10
  private headers;
5
11
  constructor(baseConfig: IAugustBase);
12
+ /**
13
+ * Retrieves the health factor for a subaccount.
14
+ * @param subaccountAddress - The address of the subaccount to query
15
+ * @returns The health factor data including collateral value, loan value, and health factor ratio
16
+ */
6
17
  getSubaccountHealthFactor(subaccountAddress: IAddress): Promise<{
7
18
  id: `0x${string}`;
8
19
  dateTime: string;
@@ -10,9 +21,31 @@ export declare class AugustSubAccounts extends AugustBase {
10
21
  totalCollateral: number;
11
22
  totalLoan: number;
12
23
  }>;
24
+ /**
25
+ * Retrieves loan positions for a subaccount.
26
+ * @param subaccountAddress - The address of the subaccount to query
27
+ * @param side - Filter by loan side: 'BOTH' for all loans, 'LENDER' for lent positions, 'BORROWER' for borrowed positions
28
+ * @param active - When true, returns only active loans; when false, returns all loans including closed ones
29
+ * @returns List of loan positions matching the specified filters
30
+ */
13
31
  getSubaccountLoans(subaccountAddress: IAddress, side: 'BOTH' | 'LENDER' | 'BORROWER', active: boolean): Promise<import("../../types").IWSSubaccountLoan[]>;
32
+ /**
33
+ * Retrieves CeFi (Centralized Finance) positions for a subaccount.
34
+ * @param subaccountAddress - The address of the subaccount to query
35
+ * @returns List of CeFi positions held by the subaccount
36
+ */
14
37
  getSubaccountCefiPositions(subaccountAddress: IAddress): Promise<import("../../types").IWSSubaccountCefi[]>;
38
+ /**
39
+ * Retrieves OTC (Over-The-Counter) positions for a subaccount.
40
+ * @param subaccountAddress - The address of the subaccount to query
41
+ * @returns List of OTC positions held by the subaccount
42
+ */
15
43
  getSubaccountOtcPositions(subaccountAddress: IAddress): Promise<import("../../types").IOTCPosition[]>;
44
+ /**
45
+ * Retrieves the summary view for a subaccount or EOA operator.
46
+ * @param subaccountAddress - The address of the subaccount to query
47
+ * @returns The full summary including portfolio, loanbook, tokens, and account values
48
+ */
16
49
  getSubaccountSummary(subaccountAddress: IAddress): Promise<{
17
50
  address: `0x${string}`;
18
51
  name: string;
@@ -1,18 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AugustSubAccounts = void 0;
4
+ /**
5
+ * The August Sub Accounts Module.
6
+ *
7
+ * @module AugustSubAccounts
8
+ */
4
9
  const fetcher_1 = require("./fetcher");
5
10
  const utils_1 = require("./utils");
6
11
  const core_1 = require("../../core");
12
+ /**
13
+ * Subaccount operation class interacting with August Subaccounts
14
+ * Subaccount is a smart contract wallet that serves as the fundamental infrastructure for August's platform.
15
+ * It functions as a cross-margin account designed for optimal capital efficiency.
16
+ * Most of the operations require a August API key to perform
17
+ */
7
18
  class AugustSubAccounts extends core_1.AugustBase {
19
+ headers = null;
8
20
  constructor(baseConfig) {
9
21
  super(baseConfig);
10
- this.headers = null;
11
22
  this.headers = {
12
23
  'x-environment': this.monitoring?.['x-environment'],
13
24
  'x-user-id': this.monitoring?.['x-user-id'],
14
25
  };
15
26
  }
27
+ /**
28
+ * Retrieves the health factor for a subaccount.
29
+ * @param subaccountAddress - The address of the subaccount to query
30
+ * @returns The health factor data including collateral value, loan value, and health factor ratio
31
+ */
16
32
  async getSubaccountHealthFactor(subaccountAddress) {
17
33
  const response = await (0, fetcher_1.fetchSubaccountHeathFactor)(subaccountAddress, this.keys.august, this.headers);
18
34
  return {
@@ -23,18 +39,40 @@ class AugustSubAccounts extends core_1.AugustBase {
23
39
  totalLoan: response.total_loan_value,
24
40
  };
25
41
  }
42
+ /**
43
+ * Retrieves loan positions for a subaccount.
44
+ * @param subaccountAddress - The address of the subaccount to query
45
+ * @param side - Filter by loan side: 'BOTH' for all loans, 'LENDER' for lent positions, 'BORROWER' for borrowed positions
46
+ * @param active - When true, returns only active loans; when false, returns all loans including closed ones
47
+ * @returns List of loan positions matching the specified filters
48
+ */
26
49
  async getSubaccountLoans(subaccountAddress, side, active) {
27
50
  const response = await (0, fetcher_1.fetchSubaccountLoans)({ address: subaccountAddress, active, side }, this.keys.august, this.headers);
28
51
  return response;
29
52
  }
53
+ /**
54
+ * Retrieves CeFi (Centralized Finance) positions for a subaccount.
55
+ * @param subaccountAddress - The address of the subaccount to query
56
+ * @returns List of CeFi positions held by the subaccount
57
+ */
30
58
  async getSubaccountCefiPositions(subaccountAddress) {
31
59
  const response = await (0, fetcher_1.fetchSubaccountCefiPositions)(subaccountAddress, this.keys.august, this.headers);
32
60
  return response;
33
61
  }
62
+ /**
63
+ * Retrieves OTC (Over-The-Counter) positions for a subaccount.
64
+ * @param subaccountAddress - The address of the subaccount to query
65
+ * @returns List of OTC positions held by the subaccount
66
+ */
34
67
  async getSubaccountOtcPositions(subaccountAddress) {
35
68
  const response = await (0, fetcher_1.fetchSubaccountOtcPositions)(subaccountAddress, this.keys.august, this.headers);
36
69
  return response;
37
70
  }
71
+ /**
72
+ * Retrieves the summary view for a subaccount or EOA operator.
73
+ * @param subaccountAddress - The address of the subaccount to query
74
+ * @returns The full summary including portfolio, loanbook, tokens, and account values
75
+ */
38
76
  async getSubaccountSummary(subaccountAddress) {
39
77
  const response = await (0, fetcher_1.fetchSubaccountSummary)(subaccountAddress, this.keys.august, this.headers);
40
78
  return (0, utils_1.transformSubaccountSummary)(response);
@@ -1,4 +1,7 @@
1
- import { IWSSubaccountSummary } from '../../types';
1
+ import type { IWSSubaccountSummary } from '../../types';
2
+ /**
3
+ * Transform the raw API response to camelCase
4
+ */
2
5
  export declare const transformSubaccountSummary: (response: IWSSubaccountSummary) => {
3
6
  address: `0x${string}`;
4
7
  name: string;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformSubaccountSummary = void 0;
4
+ /**
5
+ * Transform the raw API response to camelCase
6
+ */
4
7
  const transformSubaccountSummary = (response) => {
5
8
  return {
6
9
  address: response.address,
@@ -1,6 +1,15 @@
1
- import { BaseContract, Signer, Wallet } from 'ethers';
2
- import { IAddress } from '../../types';
3
- import { IVaultAdapterConfig } from '../../types/vaults';
1
+ /**
2
+ * Adapter Helper Functions
3
+ *
4
+ * Functions to support deposits with alternative tokens through swap adapters,
5
+ * wrapper contracts, and Paraswap integration.
6
+ */
7
+ import type { BaseContract, Signer, Wallet } from 'ethers';
8
+ import type { IAddress } from '../../types';
9
+ import type { IVaultAdapterConfig } from '../../types/vaults';
10
+ /**
11
+ * Get quote from Paraswap for token swap
12
+ */
4
13
  export declare function getParaswapQuote({ srcToken, destToken, amount, network, srcDecimals, destDecimals, }: {
5
14
  srcToken: string;
6
15
  destToken: string;
@@ -9,6 +18,9 @@ export declare function getParaswapQuote({ srcToken, destToken, amount, network,
9
18
  srcDecimals: number;
10
19
  destDecimals: number;
11
20
  }): Promise<any>;
21
+ /**
22
+ * Build swap and deposit transaction for Paraswap bridge
23
+ */
12
24
  export declare function buildSwapAndDepositTransaction({ signer, srcToken, srcDecimals, destToken, destDecimals, amount, network, adapterConfig, userAddress, }: {
13
25
  signer: Signer | Wallet;
14
26
  srcToken: IAddress;
@@ -20,6 +32,9 @@ export declare function buildSwapAndDepositTransaction({ signer, srcToken, srcDe
20
32
  adapterConfig: IVaultAdapterConfig;
21
33
  userAddress: IAddress;
22
34
  }): Promise<BaseContract>;
35
+ /**
36
+ * Build native/wrapped token deposit transaction
37
+ */
23
38
  export declare function buildNativeDepositTransaction({ signer, srcToken, amount, poolName, adapterConfig, userAddress, }: {
24
39
  signer: Signer | Wallet;
25
40
  srcToken: IAddress;
@@ -33,6 +48,9 @@ export declare function buildNativeDepositTransaction({ signer, srcToken, amount
33
48
  args: any[];
34
49
  value?: bigint;
35
50
  }>;
51
+ /**
52
+ * Preview adapter deposit output
53
+ */
36
54
  export declare function previewAdapterDeposit({ signer, vaultAddress, srcToken, srcAmount, srcDecimals, destToken, destDecimals, adapterConfig, chainId, }: {
37
55
  signer: Signer | Wallet;
38
56
  vaultAddress: IAddress;
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Adapter Helper Functions
4
+ *
5
+ * Functions to support deposits with alternative tokens through swap adapters,
6
+ * wrapper contracts, and Paraswap integration.
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.getParaswapQuote = getParaswapQuote;
4
10
  exports.buildSwapAndDepositTransaction = buildSwapAndDepositTransaction;
@@ -7,10 +13,19 @@ exports.previewAdapterDeposit = previewAdapterDeposit;
7
13
  const adapters_1 = require("../../core/constants/adapters");
8
14
  const abis_1 = require("../../abis");
9
15
  const core_1 = require("../../core");
16
+ /**
17
+ * Paraswap API endpoints
18
+ */
10
19
  const PARASWAP_PRICES_API = 'https://api.paraswap.io/prices';
20
+ /**
21
+ * Paraswap partner configuration
22
+ */
11
23
  const PARASWAP_PARTNER = 'august';
12
24
  const PARASWAP_PARTNER_ADDRESS = '0xb60ee0FA5B6bA917255A03e744967E0Bda531dD0';
13
25
  const PARASWAP_VERSION = '6.2';
26
+ /**
27
+ * Get quote from Paraswap for token swap
28
+ */
14
29
  async function getParaswapQuote({ srcToken, destToken, amount, network, srcDecimals, destDecimals, }) {
15
30
  const params = new URLSearchParams();
16
31
  params.append('network', network);
@@ -32,7 +47,13 @@ async function getParaswapQuote({ srcToken, destToken, amount, network, srcDecim
32
47
  const data = await response.json();
33
48
  return data?.priceRoute || {};
34
49
  }
50
+ // Note: buildParaswapTransaction is kept for potential future use
51
+ // Currently transaction building is handled directly in buildSwapAndDepositTransaction
52
+ /**
53
+ * Build swap and deposit transaction for Paraswap bridge
54
+ */
35
55
  async function buildSwapAndDepositTransaction({ signer, srcToken, srcDecimals, destToken, destDecimals, amount, network, adapterConfig, userAddress, }) {
56
+ // Get price quote from Paraswap
36
57
  const priceRoute = await getParaswapQuote({
37
58
  srcToken,
38
59
  destToken,
@@ -44,6 +65,8 @@ async function buildSwapAndDepositTransaction({ signer, srcToken, srcDecimals, d
44
65
  if (!priceRoute || !priceRoute.destAmount) {
45
66
  throw new Error('No price route found from Paraswap');
46
67
  }
68
+ // Create adapter contract
69
+ // Note: Transaction data will be built in the calling code
47
70
  const adapterContract = (0, core_1.createContract)({
48
71
  address: adapterConfig.wrapperAddress,
49
72
  provider: signer,
@@ -51,6 +74,9 @@ async function buildSwapAndDepositTransaction({ signer, srcToken, srcDecimals, d
51
74
  });
52
75
  return adapterContract;
53
76
  }
77
+ /**
78
+ * Build native/wrapped token deposit transaction
79
+ */
54
80
  async function buildNativeDepositTransaction({ signer, srcToken, amount, poolName, adapterConfig, userAddress, }) {
55
81
  const isNative = srcToken === '0x0000000000000000000000000000000000000000';
56
82
  const wrapperContract = (0, core_1.createContract)({
@@ -59,6 +85,7 @@ async function buildNativeDepositTransaction({ signer, srcToken, amount, poolNam
59
85
  abi: (adapterConfig.abi ||
60
86
  abis_1.ABI_WRAPPER_ADAPTER),
61
87
  });
88
+ // Handle different pool types
62
89
  if (poolName === adapters_1.POOL_NAMES.ETH_TREEHOUSE_GROWTH) {
63
90
  if (isNative) {
64
91
  return {
@@ -101,6 +128,7 @@ async function buildNativeDepositTransaction({ signer, srcToken, amount, poolNam
101
128
  ],
102
129
  };
103
130
  }
131
+ // Default native deposit
104
132
  if (isNative && adapterConfig.isNativeTokenDeposit) {
105
133
  return {
106
134
  contract: wrapperContract,
@@ -111,7 +139,11 @@ async function buildNativeDepositTransaction({ signer, srcToken, amount, poolNam
111
139
  }
112
140
  throw new Error('Unsupported deposit configuration');
113
141
  }
142
+ /**
143
+ * Preview adapter deposit output
144
+ */
114
145
  async function previewAdapterDeposit({ signer, vaultAddress, srcToken, srcAmount, srcDecimals, destToken, destDecimals, adapterConfig, chainId, }) {
146
+ // If using Paraswap bridge, get quote
115
147
  if (adapterConfig.bridgeId === 2) {
116
148
  const quote = await getParaswapQuote({
117
149
  srcToken,
@@ -123,6 +155,7 @@ async function previewAdapterDeposit({ signer, vaultAddress, srcToken, srcAmount
123
155
  });
124
156
  return BigInt(quote.destAmount || 0);
125
157
  }
158
+ // If view adapter is available, use it
126
159
  if (adapterConfig.viewAdapter) {
127
160
  const viewContract = (0, core_1.createContract)({
128
161
  address: adapterConfig.viewAdapter,
@@ -145,6 +178,7 @@ async function previewAdapterDeposit({ signer, vaultAddress, srcToken, srcAmount
145
178
  const output = await viewContract.getRsETHAmountToMint(srcToken, BigInt(srcAmount));
146
179
  return BigInt(output);
147
180
  }
181
+ // Default: assume 1:1 ratio
148
182
  return BigInt(srcAmount);
149
183
  }
150
184
  //# sourceMappingURL=adapter.helpers.js.map
@@ -1,3 +1,37 @@
1
+ import type { IAddress } from '../../types';
2
+ /**
3
+ * Fetch the set of vaults whose deposit/withdraw history is served from the
4
+ * backend Mongo snapshot (`/upshift/vault_history`) rather than their (retired)
5
+ * Goldsky subgraph.
6
+ *
7
+ * This is the routing source of truth: a vault appears here only once its
8
+ * history has been backfilled, so the SDK can never reroute a vault to empty
9
+ * snapshot data ahead of its backfill. Result is cached for 10 minutes.
10
+ *
11
+ * Side effects: one HTTP GET to the public API (cached).
12
+ *
13
+ * @returns A set of lowercased vault addresses. Empty on any error — callers
14
+ * then fall back to the subgraph path, which is the safe default while
15
+ * subgraphs still exist.
16
+ */
17
+ export declare function fetchArchivedVaults(): Promise<Set<string>>;
18
+ /**
19
+ * Whether a vault's history should be served from the backend snapshot rather
20
+ * than its subgraph. Backed by {@link fetchArchivedVaults} (cached).
21
+ *
22
+ * @param vaultAddress - The vault contract address (any casing).
23
+ * @returns `true` if the vault has a backfilled history snapshot.
24
+ */
25
+ export declare function isArchivedVault(vaultAddress: IAddress): Promise<boolean>;
26
+ /**
27
+ * Specialized vault fetching with enhanced retry logic and fallback strategies
28
+ * This function attempts to fetch vault data with multiple fallback approaches
29
+ *
30
+ * The return shape is "success flag wins": when `success === true`, `data` is
31
+ * the resolved value (which may legitimately be falsy — `0`, `''`, `0n`,
32
+ * `null`); when `success === false`, `error` is populated. Callers must branch
33
+ * on `success`, not on the truthiness of `data`.
34
+ */
1
35
  export declare function fetchVaultWithFallback<T>(vaultAddress: string, fetchFn: () => Promise<T>, options?: {
2
36
  maxRetries?: number;
3
37
  baseDelay?: number;
@@ -9,6 +43,10 @@ export declare function fetchVaultWithFallback<T>(vaultAddress: string, fetchFn:
9
43
  error?: Error;
10
44
  strategy: string;
11
45
  }>;
46
+ /**
47
+ * Batch vault fetching with intelligent retry and fallback
48
+ * Ensures maximum vault coverage by trying multiple strategies
49
+ */
12
50
  export declare function fetchVaultsBatch<T>(vaults: Array<{
13
51
  address: string;
14
52
  fetchFn: () => Promise<T>;
@@ -31,6 +69,10 @@ export declare function fetchVaultsBatch<T>(vaults: Array<{
31
69
  totalAttempted: number;
32
70
  successRate: number;
33
71
  }>;
72
+ /**
73
+ * Comprehensive vault fetching that handles all failure points
74
+ * This function ensures maximum vault coverage by implementing multiple strategies
75
+ */
34
76
  export declare function fetchVaultsComprehensive<T>(vaults: Array<{
35
77
  address: string;
36
78
  chain: number;
@@ -73,6 +115,9 @@ export declare function fetchVaultsComprehensive<T>(vaults: Array<{
73
115
  rpcFailures: Record<number, number>;
74
116
  };
75
117
  }>;
118
+ /**
119
+ * Enhanced vault filtering that preserves more vaults while maintaining quality
120
+ */
76
121
  export declare function filterVaultsIntelligently<T extends {
77
122
  status?: string;
78
123
  isVisible?: boolean;
@@ -1,11 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchVaultMetadata = void 0;
4
+ exports.fetchArchivedVaults = fetchArchivedVaults;
5
+ exports.isArchivedVault = isArchivedVault;
4
6
  exports.fetchVaultWithFallback = fetchVaultWithFallback;
5
7
  exports.fetchVaultsBatch = fetchVaultsBatch;
6
8
  exports.fetchVaultsComprehensive = fetchVaultsComprehensive;
7
9
  exports.filterVaultsIntelligently = filterVaultsIntelligently;
8
10
  const core_1 = require("../../core");
11
+ const ARCHIVED_VAULTS_CACHE_KEY = 'archived_vaults';
12
+ const ARCHIVED_VAULTS_TTL_MS = 10 * 60 * 1000;
13
+ /**
14
+ * Fetch the set of vaults whose deposit/withdraw history is served from the
15
+ * backend Mongo snapshot (`/upshift/vault_history`) rather than their (retired)
16
+ * Goldsky subgraph.
17
+ *
18
+ * This is the routing source of truth: a vault appears here only once its
19
+ * history has been backfilled, so the SDK can never reroute a vault to empty
20
+ * snapshot data ahead of its backfill. Result is cached for 10 minutes.
21
+ *
22
+ * Side effects: one HTTP GET to the public API (cached).
23
+ *
24
+ * @returns A set of lowercased vault addresses. Empty on any error — callers
25
+ * then fall back to the subgraph path, which is the safe default while
26
+ * subgraphs still exist.
27
+ */
28
+ async function fetchArchivedVaults() {
29
+ const cached = core_1.CACHE.get(ARCHIVED_VAULTS_CACHE_KEY);
30
+ if (cached)
31
+ return cached;
32
+ try {
33
+ const response = await (0, core_1.fetchAugustPublic)(core_1.WEBSERVER_ENDPOINTS.public.tokenizedVault.archivedVaults);
34
+ if (response.status !== 200) {
35
+ core_1.Logger.log.error('fetchArchivedVaults', `non-200 from archived endpoint: ${response.status}`);
36
+ return new Set();
37
+ }
38
+ const addresses = (await response.json());
39
+ const set = new Set(addresses.map((a) => a.toLowerCase()));
40
+ core_1.CACHE.set(ARCHIVED_VAULTS_CACHE_KEY, set, { ttl: ARCHIVED_VAULTS_TTL_MS });
41
+ return set;
42
+ }
43
+ catch (e) {
44
+ core_1.Logger.log.error('fetchArchivedVaults', e);
45
+ return new Set();
46
+ }
47
+ }
48
+ /**
49
+ * Whether a vault's history should be served from the backend snapshot rather
50
+ * than its subgraph. Backed by {@link fetchArchivedVaults} (cached).
51
+ *
52
+ * @param vaultAddress - The vault contract address (any casing).
53
+ * @returns `true` if the vault has a backfilled history snapshot.
54
+ */
55
+ async function isArchivedVault(vaultAddress) {
56
+ const archived = await fetchArchivedVaults();
57
+ return archived.has(vaultAddress.toLowerCase());
58
+ }
59
+ /** @internal */
9
60
  async function runWithConcurrency(tasks, limit) {
10
61
  if (!Number.isFinite(limit) || limit <= 0) {
11
62
  throw new Error(`runWithConcurrency: limit must be a positive finite number, got ${limit}`);
@@ -13,6 +64,8 @@ async function runWithConcurrency(tasks, limit) {
13
64
  const results = new Array(tasks.length);
14
65
  let nextIndex = 0;
15
66
  const workerCount = Math.min(Math.floor(limit), tasks.length);
67
+ // `nextIndex++` is safe across workers — JS is single-threaded and the
68
+ // increment runs to completion before any worker yields at `await`.
16
69
  const workers = Array.from({ length: workerCount }, async () => {
17
70
  while (true) {
18
71
  const i = nextIndex++;
@@ -24,6 +77,15 @@ async function runWithConcurrency(tasks, limit) {
24
77
  await Promise.all(workers);
25
78
  return results;
26
79
  }
80
+ /**
81
+ * Specialized vault fetching with enhanced retry logic and fallback strategies
82
+ * This function attempts to fetch vault data with multiple fallback approaches
83
+ *
84
+ * The return shape is "success flag wins": when `success === true`, `data` is
85
+ * the resolved value (which may legitimately be falsy — `0`, `''`, `0n`,
86
+ * `null`); when `success === false`, `error` is populated. Callers must branch
87
+ * on `success`, not on the truthiness of `data`.
88
+ */
27
89
  async function fetchVaultWithFallback(vaultAddress, fetchFn, options = {}) {
28
90
  const { maxRetries = 3, baseDelay = 1000 } = options;
29
91
  try {
@@ -42,6 +104,10 @@ async function fetchVaultWithFallback(vaultAddress, fetchFn, options = {}) {
42
104
  strategy: 'all-failed',
43
105
  };
44
106
  }
107
+ /**
108
+ * Batch vault fetching with intelligent retry and fallback
109
+ * Ensures maximum vault coverage by trying multiple strategies
110
+ */
45
111
  async function fetchVaultsBatch(vaults, options = {}) {
46
112
  const { maxRetries = 3, baseDelay = 1000, batchSize = 10, parallelLimit = batchSize, } = options;
47
113
  const successful = [];
@@ -57,6 +123,10 @@ async function fetchVaultsBatch(vaults, options = {}) {
57
123
  maxRetries,
58
124
  baseDelay,
59
125
  });
126
+ // Branch on `result.success` only — not on truthiness of `result.data`.
127
+ // A successful fetch can legitimately resolve to a falsy value
128
+ // (`0`, `''`, `0n`, `null`); the cast respects the function's
129
+ // documented contract that `data` is present on the success branch.
60
130
  if (result.success) {
61
131
  successful.push({
62
132
  index: globalIndex,
@@ -81,6 +151,7 @@ async function fetchVaultsBatch(vaults, options = {}) {
81
151
  }
82
152
  });
83
153
  await runWithConcurrency(batchTasks, parallelLimit);
154
+ // Small delay between batches to be respectful to RPC endpoints
84
155
  if (i + batchSize < vaults.length) {
85
156
  await new Promise((resolve) => setTimeout(resolve, 100));
86
157
  }
@@ -93,8 +164,14 @@ async function fetchVaultsBatch(vaults, options = {}) {
93
164
  successRate,
94
165
  };
95
166
  }
167
+ /**
168
+ * Comprehensive vault fetching that handles all failure points
169
+ * This function ensures maximum vault coverage by implementing multiple strategies
170
+ */
96
171
  async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
97
- const { maxRetries = 5, baseDelay = 2000, batchSize = 10, parallelLimit = batchSize, includeClosed: _includeClosed = false, includeInvisible: _includeInvisible = false, fallbackRpcUrls = {}, timeout = 60000, } = options;
172
+ const { maxRetries = 5, baseDelay = 2000, batchSize = 10, parallelLimit = batchSize, includeClosed: _includeClosed = false, // Reserved for future filtering
173
+ includeInvisible: _includeInvisible = false, // Reserved for future filtering
174
+ fallbackRpcUrls = {}, timeout = 60000, } = options;
98
175
  const successful = [];
99
176
  const failed = [];
100
177
  const rpcFailures = {};
@@ -106,6 +183,7 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
106
183
  totalAttempted++;
107
184
  let attempts = 0;
108
185
  let lastError;
186
+ // Strategy 1: Primary fetch with retry
109
187
  for (attempts = 1; attempts <= maxRetries; attempts++) {
110
188
  try {
111
189
  const data = await Promise.race([
@@ -123,12 +201,13 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
123
201
  catch (error) {
124
202
  lastError = error;
125
203
  if (attempts < maxRetries) {
126
- const delay = baseDelay * Math.pow(2, attempts - 1);
204
+ const delay = baseDelay * 2 ** (attempts - 1);
127
205
  core_1.Logger.log.warn('fetchVaultsComprehensive', `Vault ${vault.address} attempt ${attempts} failed, retrying in ${delay}ms: ${error.message}`);
128
206
  await new Promise((resolve) => setTimeout(resolve, delay));
129
207
  }
130
208
  }
131
209
  }
210
+ // Strategy 2: Try with fallback RPC endpoints
132
211
  if (fallbackRpcUrls[vault.chain] &&
133
212
  fallbackRpcUrls[vault.chain].length > 0) {
134
213
  for (const fallbackRpc of fallbackRpcUrls[vault.chain]) {
@@ -154,6 +233,7 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
154
233
  }
155
234
  }
156
235
  }
236
+ // Strategy 3: Try with minimal data fetching (if fetchFn supports it)
157
237
  try {
158
238
  const data = await Promise.race([
159
239
  fetchFn({ ...vault, minimal: true }),
@@ -173,6 +253,7 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
173
253
  error: error instanceof Error ? error.message : String(error),
174
254
  });
175
255
  }
256
+ // Strategy 4: Extended retry with longer delays
176
257
  try {
177
258
  const extendedDelay = baseDelay * 3;
178
259
  await new Promise((resolve) => setTimeout(resolve, extendedDelay));
@@ -194,6 +275,7 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
194
275
  error: error instanceof Error ? error.message : String(error),
195
276
  });
196
277
  }
278
+ // All strategies failed
197
279
  failed.push({
198
280
  index: globalIndex,
199
281
  error: lastError || new Error('All strategies failed'),
@@ -201,9 +283,11 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
201
283
  chain: vault.chain,
202
284
  attempts: attempts + 2,
203
285
  });
286
+ // Track RPC failures by chain
204
287
  rpcFailures[vault.chain] = (rpcFailures[vault.chain] || 0) + 1;
205
288
  });
206
289
  await runWithConcurrency(batchTasks, parallelLimit);
290
+ // Small delay between batches to be respectful to RPC endpoints
207
291
  if (i + batchSize < vaults.length) {
208
292
  await new Promise((resolve) => setTimeout(resolve, 200));
209
293
  }
@@ -218,12 +302,15 @@ async function fetchVaultsComprehensive(vaults, fetchFn, options = {}) {
218
302
  totalVaults: vaults.length,
219
303
  successfulVaults: successful.length,
220
304
  failedVaults: failed.length,
221
- closedVaults: 0,
222
- invisibleVaults: 0,
305
+ closedVaults: 0, // Will be calculated by the calling code
306
+ invisibleVaults: 0, // Will be calculated by the calling code
223
307
  rpcFailures,
224
308
  },
225
309
  };
226
310
  }
311
+ /**
312
+ * Enhanced vault filtering that preserves more vaults while maintaining quality
313
+ */
227
314
  function filterVaultsIntelligently(vaults, options = {}) {
228
315
  const { includeClosed = true, includeInvisible = true, includeNull = false, minStatus = ['active', 'closed'], } = options;
229
316
  const active = [];