@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
@@ -1,23 +1,68 @@
1
1
  import type { INormalizedNumber } from '../../types';
2
+ /**
3
+ * Table of Contents
4
+ * - Formatters
5
+ * - Datetime
6
+ * - Arrays
7
+ * - Caching
8
+ */
2
9
  export declare function toNormalizedBn(value: string | bigint | number, decimals?: number | bigint): INormalizedNumber;
10
+ /**
11
+ * Get fallback RPC URLs for a specific chain
12
+ */
3
13
  export declare function getFallbackRpcUrls(chainId: number): string[];
4
14
  export declare const filterOutBySize: (usdAmount: number) => boolean;
15
+ /**
16
+ * Formatters
17
+ */
5
18
  export declare function toTitleCase(str: string, type?: 'camel'): string;
6
19
  export declare function truncate(s: string, amount?: number): string;
20
+ /**
21
+ * Formats any numeric value (number, string, or bigint) to a standardized string.
22
+ *
23
+ * @param value - amount to be formatted
24
+ * @param options - formatting options:
25
+ * `showing` is the number of decimals to cut off at (or `'all'`);
26
+ * `usd` toggles USD-value display;
27
+ * `decimals` is how many decimals to parse to when `value` is a bigint.
28
+ *
29
+ * @returns standardized string type value
30
+ */
7
31
  export declare function round(value: number | string | bigint, options?: {
8
32
  showing?: number | 'all';
9
33
  usd?: boolean;
10
34
  decimals?: number;
11
35
  }): string;
12
36
  export declare function loanStateToReadable(loanState: number | bigint): "PREAPPROVED" | "FUNDING_REQUIRED" | "FUNDED" | "ACTIVE" | "CANCELLED" | "MATURED" | "CLOSED";
37
+ /**
38
+ * Datetime
39
+ */
13
40
  export declare function dateToUnix(date: Date): number;
14
41
  export declare function unixToDate(epoch: number): Date;
15
42
  export declare function isEarlierThanNow(startTime: Date): boolean;
16
43
  export declare function daysAgo(days: number): Date;
17
44
  export declare function prepareDateForDb(date: string | Date): string;
18
- export declare function orderObjArrByDate(objectArray: any[], options?: {
45
+ /**
46
+ * Arrays
47
+ */
48
+ export declare function orderObjArrByDate<T extends Record<string, unknown>>(objectArray: T[], options?: {
19
49
  key?: string;
20
50
  order?: 'asc' | 'desc';
21
- }): any[];
22
- export declare function calculateWeights(data?: Array<any>, weightProperty?: string): any[];
23
- export declare function calculateWeightedAverage(data?: Array<any>, valueProperty?: string, weightProperty?: string): any;
51
+ }): T[];
52
+ /**
53
+ * Calculate weights based on a specific property in array of objects.
54
+ * @param data - Array of objects to calculate weights for
55
+ * @param weightProperty - Property name to base weights on
56
+ * @returns Original data with each item's `weight` added
57
+ */
58
+ export declare function calculateWeights<T extends Record<string, unknown>>(data?: T[], weightProperty?: string): Array<T & {
59
+ weight: number;
60
+ }>;
61
+ /**
62
+ * Calculate weighted average for array of objects.
63
+ * @param data - Array of objects with values
64
+ * @param valueProperty - Property name containing the value to average
65
+ * @param weightProperty - Optional property to base weights on
66
+ * @returns Weighted average
67
+ */
68
+ export declare function calculateWeightedAverage<T extends Record<string, unknown>>(data?: T[], valueProperty?: string, weightProperty?: string): number;
@@ -17,23 +17,36 @@ exports.calculateWeights = calculateWeights;
17
17
  exports.calculateWeightedAverage = calculateWeightedAverage;
18
18
  const web3_1 = require("../constants/web3");
19
19
  const ethers_1 = require("ethers");
20
+ /**
21
+ * Table of Contents
22
+ * - Formatters
23
+ * - Datetime
24
+ * - Arrays
25
+ * - Caching
26
+ */
20
27
  function toNormalizedBn(value, decimals = 18) {
21
28
  if (!value)
22
29
  return { normalized: '0', raw: BigInt(0).toString() };
23
30
  const sanitize = (val, decimals) => {
24
31
  const [whole, frac = ''] = val.split('.');
25
- const trimmedFrac = frac.slice(0, decimals);
32
+ const trimmedFrac = frac.slice(0, decimals); // trim to allowed precision
26
33
  return trimmedFrac ? `${whole}.${trimmedFrac}` : whole;
27
34
  };
35
+ // Convert number or exponential string to fixed decimal string
28
36
  const toFixedDecimalString = (val) => {
29
37
  const strRep = typeof val === 'number' ? String(val) : val;
38
+ // Check if the string representation contains exponential notation
30
39
  if (strRep.includes('e') || strRep.includes('E')) {
40
+ // Parse as number and use toFixed with high precision to convert exponential to fixed decimal
41
+ // 100 decimals should handle even extremely small numbers like 1e-20
31
42
  const num = typeof val === 'number' ? val : parseFloat(strRep);
32
43
  return num.toFixed(100).replace(/\.?0+$/, '');
33
44
  }
45
+ // For regular numbers/strings, return as is
34
46
  return strRep;
35
47
  };
36
48
  if (typeof value === 'string' || typeof value === 'number') {
49
+ // Convert to fixed decimal string to avoid exponential notation
37
50
  const strVal = toFixedDecimalString(value);
38
51
  const safeVal = sanitize(strVal, Number(decimals));
39
52
  return {
@@ -48,11 +61,17 @@ function toNormalizedBn(value, decimals = 18) {
48
61
  };
49
62
  }
50
63
  }
64
+ /**
65
+ * Get fallback RPC URLs for a specific chain
66
+ */
51
67
  function getFallbackRpcUrls(chainId) {
52
68
  return web3_1.FALLBACK_RPC_URLS[chainId] || [];
53
69
  }
54
- const filterOutBySize = (usdAmount) => usdAmount > 3000;
70
+ const filterOutBySize = (usdAmount) => usdAmount > 3_000;
55
71
  exports.filterOutBySize = filterOutBySize;
72
+ /**
73
+ * Formatters
74
+ */
56
75
  function toTitleCase(str, type) {
57
76
  if (!str)
58
77
  return;
@@ -60,9 +79,11 @@ function toTitleCase(str, type) {
60
79
  case 'camel': {
61
80
  const words = Array.from(str)
62
81
  .map((letter) => {
82
+ // letter is uppercase
63
83
  if (letter === letter.toUpperCase()) {
64
84
  return ` ${letter}`;
65
85
  }
86
+ // else
66
87
  return letter;
67
88
  })
68
89
  .join('');
@@ -83,6 +104,11 @@ function toTitleCase(str, type) {
83
104
  }
84
105
  function truncate(s, amount) {
85
106
  if (typeof s !== 'string') {
107
+ // Leaf string util: importing Logger here would create an import cycle
108
+ // (helpers/core → logger/index → slack → helpers/core) that the madge CI
109
+ // check forbids (CLAUDE.md §9). Keep a direct console.error for this
110
+ // defensive type-guard diagnostic.
111
+ // biome-ignore lint/suspicious/noConsole: leaf util cannot import Logger without a cycle (CLAUDE.md §9); keep a direct console.error for this defensive type-guard diagnostic.
86
112
  if (s !== undefined)
87
113
  console.error('#truncate: not a string', s);
88
114
  return '';
@@ -93,16 +119,30 @@ function truncate(s, amount) {
93
119
  return s;
94
120
  return `${s.slice(0, amount ? amount : 4)}...${s.slice(amount ? amount * -1 : -4)}`;
95
121
  }
122
+ /**
123
+ * Formats any numeric value (number, string, or bigint) to a standardized string.
124
+ *
125
+ * @param value - amount to be formatted
126
+ * @param options - formatting options:
127
+ * `showing` is the number of decimals to cut off at (or `'all'`);
128
+ * `usd` toggles USD-value display;
129
+ * `decimals` is how many decimals to parse to when `value` is a bigint.
130
+ *
131
+ * @returns standardized string type value
132
+ */
96
133
  function round(value, options) {
134
+ // standardize to string
97
135
  let _value;
98
136
  if (typeof value === 'bigint') {
99
- _value = toNormalizedBn(value, options.decimals ?? web3_1.FALLBACK_DECIMALS).normalized;
137
+ _value = toNormalizedBn(value, options?.decimals ?? web3_1.FALLBACK_DECIMALS).normalized;
100
138
  }
101
139
  else {
102
140
  _value = String(value);
141
+ // if string passed includes something like a symbol (i.e. 0.1 ETH --> 0.1)
103
142
  if (_value.includes(' '))
104
143
  _value = _value.split(' ')[0];
105
144
  }
145
+ // if wanting USD value
106
146
  if (options?.usd) {
107
147
  const usdFormatter = new Intl.NumberFormat('en-US', {
108
148
  style: 'currency',
@@ -113,6 +153,7 @@ function round(value, options) {
113
153
  ? usdFormatter.format(valueNumber)
114
154
  : '0';
115
155
  }
156
+ // else slice if decimal places is more than 6 and display
116
157
  if (_value === '0' || _value === '0.0')
117
158
  return '0.000';
118
159
  if (options?.showing === 'all') {
@@ -157,9 +198,12 @@ function loanStateToReadable(loanState) {
157
198
  return 'CLOSED';
158
199
  }
159
200
  }
201
+ /**
202
+ * Datetime
203
+ */
160
204
  function dateToUnix(date) {
161
205
  if (!date)
162
- return Math.floor(new Date().getTime());
206
+ return Math.floor(Date.now());
163
207
  return Math.floor(new Date(date).getTime());
164
208
  }
165
209
  function unixToDate(epoch) {
@@ -181,28 +225,50 @@ function daysAgo(days) {
181
225
  function prepareDateForDb(date) {
182
226
  return new Date(date).toISOString();
183
227
  }
228
+ /**
229
+ * Arrays
230
+ */
184
231
  function orderObjArrByDate(objectArray, options) {
185
232
  const selectedOrder = options?.order ?? 'desc';
186
233
  const selectedKey = options?.key ?? 'date';
234
+ const toTime = (item) => new Date(item[selectedKey]).valueOf();
187
235
  return objectArray.sort((a, b) => {
236
+ // Turn your strings into dates, and then subtract them
237
+ // to get a value that is either negative, positive, or zero.
188
238
  if (selectedOrder === 'asc')
189
- return (new Date(a[selectedKey]).valueOf() - new Date(b[selectedKey]).valueOf());
190
- return (new Date(b[selectedKey]).valueOf() - new Date(a[selectedKey]).valueOf());
239
+ return toTime(a) - toTime(b);
240
+ return toTime(b) - toTime(a);
191
241
  });
192
242
  }
243
+ /**
244
+ * Calculate weights based on a specific property in array of objects.
245
+ * @param data - Array of objects to calculate weights for
246
+ * @param weightProperty - Property name to base weights on
247
+ * @returns Original data with each item's `weight` added
248
+ */
193
249
  function calculateWeights(data, weightProperty) {
194
250
  if (!data || data.length === 0 || !weightProperty)
195
251
  return [];
252
+ // Get total of the property we're using for weight calculation
196
253
  const total = data.reduce((sum, item) => sum + item[weightProperty], 0);
254
+ // Add weight property to each item
197
255
  return data.map((item) => ({
198
256
  ...item,
199
257
  weight: item[weightProperty] / total,
200
258
  }));
201
259
  }
260
+ /**
261
+ * Calculate weighted average for array of objects.
262
+ * @param data - Array of objects with values
263
+ * @param valueProperty - Property name containing the value to average
264
+ * @param weightProperty - Optional property to base weights on
265
+ * @returns Weighted average
266
+ */
202
267
  function calculateWeightedAverage(data, valueProperty, weightProperty) {
203
268
  if (!data || data.length === 0 || !valueProperty)
204
269
  return 0;
205
- let weightedData = data;
270
+ let weightedData;
271
+ // If no weightProperty specified, use equal weights
206
272
  if (!weightProperty) {
207
273
  weightedData = data.map((item) => ({
208
274
  ...item,
@@ -212,6 +278,7 @@ function calculateWeightedAverage(data, valueProperty, weightProperty) {
212
278
  else {
213
279
  weightedData = calculateWeights(data, weightProperty);
214
280
  }
281
+ // Calculate weighted average
215
282
  const weightedAverage = weightedData.reduce((acc, item) => acc + item[valueProperty] * item.weight, 0);
216
283
  return weightedAverage;
217
284
  }
@@ -1,2 +1,16 @@
1
- import { IAddress, IChainId, IExplorerType } from '../../types';
1
+ import type { IAddress, IChainId, IExplorerType } from '../../types';
2
+ /**
3
+ * Generate a block-explorer URL for an address or transaction hash.
4
+ *
5
+ * Returns an empty string when `chain` is falsy or unknown so the return
6
+ * type stays assignable to `string` — preserves the historical public
7
+ * shape from before the file split out of `web3.ts`, where the SDK's
8
+ * `strictNullChecks: false` masked the implicit `undefined` branch and
9
+ * consumers pinned to `string` via the emitted `.d.ts`.
10
+ *
11
+ * @param hex Address or transaction hash
12
+ * @param chain Chain ID
13
+ * @param type Explorer view type (`address`, `tx`, `block`)
14
+ * @returns Full explorer URL, or `''` when `chain` is falsy / unknown.
15
+ */
2
16
  export declare const explorerLink: (hex: IAddress, chain: IChainId, type: IExplorerType) => string;
@@ -2,6 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.explorerLink = void 0;
4
4
  const web3_1 = require("../constants/web3");
5
+ /**
6
+ * Generate a block-explorer URL for an address or transaction hash.
7
+ *
8
+ * Returns an empty string when `chain` is falsy or unknown so the return
9
+ * type stays assignable to `string` — preserves the historical public
10
+ * shape from before the file split out of `web3.ts`, where the SDK's
11
+ * `strictNullChecks: false` masked the implicit `undefined` branch and
12
+ * consumers pinned to `string` via the emitted `.d.ts`.
13
+ *
14
+ * @param hex Address or transaction hash
15
+ * @param chain Chain ID
16
+ * @param type Explorer view type (`address`, `tx`, `block`)
17
+ * @returns Full explorer URL, or `''` when `chain` is falsy / unknown.
18
+ */
5
19
  const explorerLink = (hex, chain, type) => {
6
20
  const network = chain ? web3_1.NETWORKS[chain] : undefined;
7
21
  if (!network)
@@ -1,5 +1,31 @@
1
- import { Signer, Wallet } from 'ethers';
1
+ import { type Signer, type Wallet } from 'ethers';
2
+ /**
3
+ * Signer Compatibility Helpers
4
+ *
5
+ * Utilities for supporting both ethers and viem/wagmi signers.
6
+ * Provides conversion layer from viem WalletClient to ethers Signer.
7
+ */
8
+ /**
9
+ * Type guard to check if a signer is from viem/wagmi
10
+ * @param signer The signer to check
11
+ * @returns True if the signer is a viem WalletClient
12
+ */
2
13
  export declare function isViemWalletClient(signer: any): boolean;
14
+ /**
15
+ * Convert a viem WalletClient to an ethers-compatible Signer
16
+ * Uses the walletClient as a provider and wraps it for ethers compatibility
17
+ * @param walletClient Viem WalletClient from wagmi or viem
18
+ * @returns Ethers Signer that can be used with the SDK
19
+ */
3
20
  export declare function viemToEthersSigner(walletClient: any): Promise<Signer | Wallet>;
21
+ /**
22
+ * Normalize a signer to ensure it's ethers-compatible
23
+ * Accepts both ethers Signer and viem WalletClient
24
+ * @param signer Either an ethers Signer or viem WalletClient
25
+ * @returns Ethers-compatible Signer
26
+ */
4
27
  export declare function normalizeSigner(signer: Signer | Wallet | any): Promise<Signer | Wallet>;
28
+ /**
29
+ * Type that represents either an ethers signer or a viem wallet client
30
+ */
5
31
  export type CompatibleSigner = Signer | Wallet | any;
@@ -4,7 +4,19 @@ exports.isViemWalletClient = isViemWalletClient;
4
4
  exports.viemToEthersSigner = viemToEthersSigner;
5
5
  exports.normalizeSigner = normalizeSigner;
6
6
  const ethers_1 = require("ethers");
7
+ /**
8
+ * Signer Compatibility Helpers
9
+ *
10
+ * Utilities for supporting both ethers and viem/wagmi signers.
11
+ * Provides conversion layer from viem WalletClient to ethers Signer.
12
+ */
13
+ /**
14
+ * Type guard to check if a signer is from viem/wagmi
15
+ * @param signer The signer to check
16
+ * @returns True if the signer is a viem WalletClient
17
+ */
7
18
  function isViemWalletClient(signer) {
19
+ // Viem WalletClient has specific properties that ethers Signer doesn't
8
20
  return !!(signer &&
9
21
  typeof signer === 'object' &&
10
22
  'account' in signer &&
@@ -12,17 +24,27 @@ function isViemWalletClient(signer) {
12
24
  'transport' in signer &&
13
25
  typeof signer.writeContract === 'function');
14
26
  }
27
+ /**
28
+ * Convert a viem WalletClient to an ethers-compatible Signer
29
+ * Uses the walletClient as a provider and wraps it for ethers compatibility
30
+ * @param walletClient Viem WalletClient from wagmi or viem
31
+ * @returns Ethers Signer that can be used with the SDK
32
+ */
15
33
  async function viemToEthersSigner(walletClient) {
16
34
  if (!walletClient) {
17
35
  throw new Error('WalletClient is required');
18
36
  }
37
+ // Create an EIP-1193 provider from the wallet client
19
38
  const { account, chain, transport } = walletClient;
20
39
  if (!account) {
21
40
  throw new Error('WalletClient must have an account');
22
41
  }
42
+ // Create a custom transport that uses the walletClient
23
43
  const provider = new ethers_1.BrowserProvider({
24
44
  request: async ({ method, params }) => {
45
+ // Use the wallet client's transport for all requests
25
46
  if (method === 'eth_sendTransaction') {
47
+ // For transactions, use writeContract or sendTransaction
26
48
  const [tx] = params;
27
49
  return walletClient.sendTransaction({
28
50
  ...tx,
@@ -30,25 +52,42 @@ async function viemToEthersSigner(walletClient) {
30
52
  chain,
31
53
  });
32
54
  }
55
+ // For all other requests, use the transport directly
33
56
  return transport({ chain }).request({ method, params });
34
57
  },
35
58
  }, chain?.id);
59
+ // Get the signer from the provider
36
60
  return provider.getSigner(account.address);
37
61
  }
62
+ /**
63
+ * Type guard to check if a signer is from ethers
64
+ * @param signer The signer to check
65
+ * @returns True if the signer is an ethers Signer or Wallet
66
+ */
38
67
  function isEthersSigner(signer) {
68
+ // Check for ethers Signer/Wallet properties
39
69
  return (signer &&
40
70
  typeof signer === 'object' &&
41
71
  typeof signer.signMessage === 'function' &&
42
72
  typeof signer.signTransaction === 'function' &&
43
73
  (signer.provider !== undefined || signer._isSigner === true));
44
74
  }
75
+ /**
76
+ * Normalize a signer to ensure it's ethers-compatible
77
+ * Accepts both ethers Signer and viem WalletClient
78
+ * @param signer Either an ethers Signer or viem WalletClient
79
+ * @returns Ethers-compatible Signer
80
+ */
45
81
  async function normalizeSigner(signer) {
82
+ // If it's already an ethers signer, return as-is
46
83
  if (isEthersSigner(signer)) {
47
84
  return signer;
48
85
  }
86
+ // If it's a viem wallet client, convert it
49
87
  if (isViemWalletClient(signer)) {
50
88
  return viemToEthersSigner(signer);
51
89
  }
90
+ // If we can't determine the type, throw an error
52
91
  throw new Error('Invalid signer type. Expected ethers Signer, ethers Wallet, or viem WalletClient');
53
92
  }
54
93
  //# sourceMappingURL=signer.js.map
@@ -1,4 +1,36 @@
1
- import { IAddress } from '../../types';
1
+ import type { IAddress } from '../../types';
2
+ /**
3
+ * Resolve the `SwapRouter` address for a chain.
4
+ *
5
+ * @param chainId - EVM chain ID.
6
+ * @returns The router address, or `undefined` if no SwapRouter is deployed.
7
+ * @example
8
+ * ```ts
9
+ * const router = getSwapRouterAddress(1);
10
+ * // '0xAC771209FF2b71EECfF6E85a9AD01db8Ff2618B0'
11
+ * ```
12
+ */
2
13
  export declare function getSwapRouterAddress(chainId: number): IAddress | undefined;
14
+ /**
15
+ * Whether a vault has been registered on a `SwapRouter` and should route
16
+ * its deposits through it. Address comparison is case-insensitive.
17
+ *
18
+ * @param vaultAddress - August vault address.
19
+ * @returns `true` when the vault is in {@link VAULTS_USING_SWAP_ROUTER}.
20
+ */
3
21
  export declare function vaultUsesSwapRouter(vaultAddress: IAddress): boolean;
22
+ /**
23
+ * Normalize an optional origin code to the value to send on-chain.
24
+ *
25
+ * Returns the caller-supplied code when present, otherwise the default
26
+ * (all-zero) sentinel from {@link ORIGIN_CODES}. Validates that any
27
+ * supplied code is exactly 32 bytes (66 chars including the `0x` prefix);
28
+ * the on-chain SwapRouter reverts with `InvalidOrigin` otherwise, but
29
+ * surfacing the failure here as a typed SDK error gives partners a
30
+ * grepable Sentry event instead of a generic `execution reverted`.
31
+ *
32
+ * @param provided - Optional caller-supplied origin code.
33
+ * @returns The 32-byte origin code to pass to the router.
34
+ * @throws {@link AugustValidationError} when `provided` is not a 32-byte hex string.
35
+ */
4
36
  export declare function resolveOriginCode(provided?: `0x${string}`): `0x${string}`;
@@ -5,12 +5,44 @@ exports.vaultUsesSwapRouter = vaultUsesSwapRouter;
5
5
  exports.resolveOriginCode = resolveOriginCode;
6
6
  const swap_router_1 = require("../constants/swap-router");
7
7
  const errors_1 = require("../errors");
8
+ /**
9
+ * Resolve the `SwapRouter` address for a chain.
10
+ *
11
+ * @param chainId - EVM chain ID.
12
+ * @returns The router address, or `undefined` if no SwapRouter is deployed.
13
+ * @example
14
+ * ```ts
15
+ * const router = getSwapRouterAddress(1);
16
+ * // '0xAC771209FF2b71EECfF6E85a9AD01db8Ff2618B0'
17
+ * ```
18
+ */
8
19
  function getSwapRouterAddress(chainId) {
9
20
  return swap_router_1.SWAP_ROUTER_ADDRESSES[chainId];
10
21
  }
22
+ /**
23
+ * Whether a vault has been registered on a `SwapRouter` and should route
24
+ * its deposits through it. Address comparison is case-insensitive.
25
+ *
26
+ * @param vaultAddress - August vault address.
27
+ * @returns `true` when the vault is in {@link VAULTS_USING_SWAP_ROUTER}.
28
+ */
11
29
  function vaultUsesSwapRouter(vaultAddress) {
12
30
  return swap_router_1.VAULTS_USING_SWAP_ROUTER.has(vaultAddress.toLowerCase());
13
31
  }
32
+ /**
33
+ * Normalize an optional origin code to the value to send on-chain.
34
+ *
35
+ * Returns the caller-supplied code when present, otherwise the default
36
+ * (all-zero) sentinel from {@link ORIGIN_CODES}. Validates that any
37
+ * supplied code is exactly 32 bytes (66 chars including the `0x` prefix);
38
+ * the on-chain SwapRouter reverts with `InvalidOrigin` otherwise, but
39
+ * surfacing the failure here as a typed SDK error gives partners a
40
+ * grepable Sentry event instead of a generic `execution reverted`.
41
+ *
42
+ * @param provided - Optional caller-supplied origin code.
43
+ * @returns The 32-byte origin code to pass to the router.
44
+ * @throws {@link AugustValidationError} when `provided` is not a 32-byte hex string.
45
+ */
14
46
  function resolveOriginCode(provided) {
15
47
  if (provided === undefined)
16
48
  return swap_router_1.ORIGIN_CODES.default;
@@ -1,4 +1,5 @@
1
- import { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
1
+ import type { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
2
+ /** Classify an address by chain family (evm / solana / stellar / sui). */
2
3
  export declare function getAddressChainType(address: string): ChainType;
3
4
  export declare function getVaultVersion(vault: string): IVaultVersion | undefined;
4
5
  export declare function getVaultVersionV2(vault: ITokenizedVault): IVaultVersion | undefined;
@@ -6,6 +6,7 @@ exports.getVaultVersionV2 = getVaultVersionV2;
6
6
  const ethers_1 = require("ethers");
7
7
  const vaults_1 = require("../constants/vaults");
8
8
  const chain_address_1 = require("./chain-address");
9
+ /** Classify an address by chain family (evm / solana / stellar / sui). */
9
10
  function getAddressChainType(address) {
10
11
  if ((0, chain_address_1.isStellarAddress)(address))
11
12
  return 'stellar';
@@ -15,6 +16,7 @@ function getAddressChainType(address) {
15
16
  return 'sui';
16
17
  return 'evm';
17
18
  }
19
+ // @todo: move to backend
18
20
  function getVaultVersion(vault) {
19
21
  if (!vault)
20
22
  return;
@@ -1,4 +1,8 @@
1
- import { IAddress, IContractRunner } from '../../types';
1
+ import type { IAddress, IContractRunner } from '../../types';
2
+ /**
3
+ * Bad transactions that should be ignored
4
+ * these transactions are usually from tests and can skew data
5
+ */
2
6
  export declare const isBadTransaction: (hash: string, chainId: number) => boolean;
3
7
  export declare const isBadVault: (address?: string) => boolean;
4
8
  import { getAddressChainType, getVaultVersion, getVaultVersionV2 } from './vault-version';
@@ -6,6 +10,10 @@ export { getAddressChainType, getVaultVersion, getVaultVersionV2 };
6
10
  export declare const REWARD_DISTRIBUTOR_ADDRESS: (chainId: number) => string[];
7
11
  export declare const AVAX_PRICE_FEED_ADDRESS: (chainId: number) => "0xFF3EEb22B5E3dE6e705b44749C2559d704923FD7" | "0x";
8
12
  export declare function getVaultSymbol(vault: IAddress, provider: IContractRunner): Promise<string | undefined>;
13
+ /**
14
+ * @deprecated
15
+ * Replaced by SUBGRAPH_VAULT_URLS which are subgraphs deployed on Goldsky.
16
+ */
9
17
  export declare const SUBGRAPH_POOL_URLS: (apiKey: string, chainId?: number, pool?: IAddress) => {
10
18
  1: string;
11
19
  8453: string;
@@ -8,10 +8,16 @@ const web3_1 = require("./web3");
8
8
  const chain_address_1 = require("./chain-address");
9
9
  const vault_metadata_1 = require("../vault-metadata");
10
10
  const logger_1 = require("../logger");
11
+ /** @internal */
11
12
  const VAULT_SYMBOLS_LOWERCASE = Object.fromEntries(Object.entries(vaults_1.VAULT_SYMBOLS).map(([k, v]) => [k.toLowerCase(), v]));
13
+ /**
14
+ * Bad transactions that should be ignored
15
+ * these transactions are usually from tests and can skew data
16
+ */
12
17
  const isBadTransaction = (hash, chainId) => {
13
18
  const badTxs = {
14
19
  1: [
20
+ // farmBOLD deposit test tx due to a decimal error
15
21
  '0xaba75b16e74a7a2457bfdcded853edd2bb4d3b305919baf84fb1f6b54b864889',
16
22
  '0xc4c30185198672cbc91a95520d1bf91634ece37c199b2f1f15d29e8290c7ed4b',
17
23
  '0x8e319576413897d1750f16bb93c7f59759b5bbafcb5bd9ef956f6bc0b0314aef',
@@ -36,21 +42,21 @@ const isBadVault = (address) => {
36
42
  case (0, ethers_1.getAddress)('0x706162790b601A8514c18718d0c63C9D1268e89C'):
37
43
  return true;
38
44
  case (0, ethers_1.getAddress)('0xd684AF965b1c17D628ee0d77cae94259c41260F4'):
39
- return true;
45
+ return true; // ETH: sUSDe
40
46
  case (0, ethers_1.getAddress)('0xB78dAf3fD674B81ebeaaa88d711506fa069E1C5E'):
41
- return true;
47
+ return true; // ETH: ETH Optimizer
42
48
  case (0, ethers_1.getAddress)('0x4e2D90f0307A93b54ACA31dc606F93FE6b9132d2'):
43
- return true;
49
+ return true; // Base: LBTC
44
50
  case (0, ethers_1.getAddress)('0x18a5a3D575F34e5eBa92ac99B0976dBe26f9F869'):
45
- return true;
51
+ return true; // ETH: LBTC
46
52
  case (0, ethers_1.getAddress)('0xD0b717ef23817b1a127139830Cf0FcD449ef74F0'):
47
- return true;
53
+ return true; // BNB: Sienna USDT Tulipa
48
54
  case (0, ethers_1.getAddress)('0xeb402fc96C7ed2f889d837C9976D6d821c1B5f01'):
49
- return true;
55
+ return true; // ETH: Kelp TAC Vault
50
56
  case (0, ethers_1.getAddress)('0xEBac5e50003d4B17Be422ff9775043cD61002f7f'):
51
- return true;
57
+ return true; // ETH: Upshift BTC
52
58
  case (0, ethers_1.getAddress)('0x419386E3Ef42368e602720CC458e00c0B28c47A7'):
53
- return true;
59
+ return true; // ETH: Kelp TAC Vault
54
60
  default:
55
61
  return false;
56
62
  }
@@ -60,6 +66,7 @@ const vault_version_1 = require("./vault-version");
60
66
  Object.defineProperty(exports, "getAddressChainType", { enumerable: true, get: function () { return vault_version_1.getAddressChainType; } });
61
67
  Object.defineProperty(exports, "getVaultVersion", { enumerable: true, get: function () { return vault_version_1.getVaultVersion; } });
62
68
  Object.defineProperty(exports, "getVaultVersionV2", { enumerable: true, get: function () { return vault_version_1.getVaultVersionV2; } });
69
+ // Used for Upshift
63
70
  const REWARD_DISTRIBUTOR_ADDRESS = (chainId) => {
64
71
  switch (chainId) {
65
72
  case 43114:
@@ -72,6 +79,7 @@ const REWARD_DISTRIBUTOR_ADDRESS = (chainId) => {
72
79
  }
73
80
  };
74
81
  exports.REWARD_DISTRIBUTOR_ADDRESS = REWARD_DISTRIBUTOR_ADDRESS;
82
+ // Used for Upshift
75
83
  const AVAX_PRICE_FEED_ADDRESS = (chainId) => {
76
84
  switch (chainId) {
77
85
  case 1:
@@ -108,16 +116,22 @@ async function getVaultSymbol(vault, provider) {
108
116
  const symbol = await (0, web3_1.getSymbol)(provider, vault);
109
117
  return symbol;
110
118
  }
119
+ /**
120
+ * @deprecated
121
+ * Replaced by SUBGRAPH_VAULT_URLS which are subgraphs deployed on Goldsky.
122
+ */
111
123
  const SUBGRAPH_POOL_URLS = (apiKey, chainId, pool) => {
112
124
  if (chainId === 999) {
113
125
  if (!pool) {
114
126
  throw new Error(`Pool address is required for chainId ${chainId}`);
115
127
  }
116
128
  switch (pool) {
129
+ // hbHYPE
117
130
  case '0x96C6cBB6251Ee1c257b2162ca0f39AA5Fa44B1FB':
118
131
  return {
119
132
  999: 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-hyperevm-hyperbeat/1.0.0/gn',
120
133
  };
134
+ // hbBTC
121
135
  case '0xc061d38903b99aC12713B550C2CB44B221674F94':
122
136
  return {
123
137
  999: 'https://api.goldsky.com/api/public/project_cm9g0xy3o4j6v01vd34r3hvv9/subgraphs/august-hyperevm-hbBTC/1.0.0/gn',