@elizaos/plugin-wallet 2.0.0-beta.1

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 (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/auto-enable.ts +76 -0
  4. package/dist/LpManagementService-BWrQ5-cO.mjs +353 -0
  5. package/dist/MockLpService-D_Apn4Fd.mjs +99 -0
  6. package/dist/aerodrome-CfnESC32.mjs +890 -0
  7. package/dist/chunk-hT5z_Zn9.mjs +35 -0
  8. package/dist/index.d.mts +34727 -0
  9. package/dist/index.mjs +21590 -0
  10. package/dist/lib/server-wallet-trade.d.mts +34 -0
  11. package/dist/lib/server-wallet-trade.mjs +306 -0
  12. package/dist/meteora-BPX39hZo.mjs +22640 -0
  13. package/dist/orca-Bybp1HXO.mjs +249 -0
  14. package/dist/pancakeswp-CkEXlXti.mjs +604 -0
  15. package/dist/plugin-ZO_MTyd0.mjs +529 -0
  16. package/dist/raydium-rfaM9yEf.mjs +539 -0
  17. package/dist/sdk/index.d.mts +32492 -0
  18. package/dist/sdk/index.mjs +6415 -0
  19. package/dist/types-D5252NZk.mjs +487 -0
  20. package/dist/uniswap-CReXgXVN.mjs +573 -0
  21. package/dist/wallet-action.d.mts +6 -0
  22. package/dist/wallet-action.mjs +820 -0
  23. package/package.json +152 -0
  24. package/src/actions/failure-codes.ts +79 -0
  25. package/src/actions/index.ts +1 -0
  26. package/src/analytics/birdeye/actions/wallet-search-address.ts +9 -0
  27. package/src/analytics/birdeye/birdeye-task.ts +175 -0
  28. package/src/analytics/birdeye/birdeye.ts +813 -0
  29. package/src/analytics/birdeye/constants.ts +74 -0
  30. package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +18 -0
  31. package/src/analytics/birdeye/providers/market.ts +227 -0
  32. package/src/analytics/birdeye/providers/portfolio-factory.test.ts +138 -0
  33. package/src/analytics/birdeye/providers/portfolio-factory.ts +252 -0
  34. package/src/analytics/birdeye/providers/trending.ts +365 -0
  35. package/src/analytics/birdeye/providers/wallet.ts +14 -0
  36. package/src/analytics/birdeye/search-category.test.ts +207 -0
  37. package/src/analytics/birdeye/search-category.ts +506 -0
  38. package/src/analytics/birdeye/service.ts +992 -0
  39. package/src/analytics/birdeye/tasks/birdeye.ts +232 -0
  40. package/src/analytics/birdeye/types/api/common.ts +305 -0
  41. package/src/analytics/birdeye/types/api/defi.ts +220 -0
  42. package/src/analytics/birdeye/types/api/pair.ts +200 -0
  43. package/src/analytics/birdeye/types/api/search.ts +86 -0
  44. package/src/analytics/birdeye/types/api/token.ts +635 -0
  45. package/src/analytics/birdeye/types/api/trader.ts +76 -0
  46. package/src/analytics/birdeye/types/api/wallet.ts +181 -0
  47. package/src/analytics/birdeye/types/shared.ts +106 -0
  48. package/src/analytics/birdeye/utils.ts +700 -0
  49. package/src/analytics/dexscreener/errors.ts +28 -0
  50. package/src/analytics/dexscreener/index.ts +3 -0
  51. package/src/analytics/dexscreener/search-category.test.ts +49 -0
  52. package/src/analytics/dexscreener/search-category.ts +42 -0
  53. package/src/analytics/dexscreener/service.ts +595 -0
  54. package/src/analytics/dexscreener/types.ts +128 -0
  55. package/src/analytics/lpinfo/index.d.ts +7 -0
  56. package/src/analytics/lpinfo/index.ts +52 -0
  57. package/src/analytics/lpinfo/kamino/README.md +102 -0
  58. package/src/analytics/lpinfo/kamino/index.ts +24 -0
  59. package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +422 -0
  60. package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +365 -0
  61. package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +496 -0
  62. package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +1123 -0
  63. package/src/analytics/lpinfo/kamino/services/kaminoService.ts +758 -0
  64. package/src/analytics/lpinfo/steer/README.md +169 -0
  65. package/src/analytics/lpinfo/steer/index.ts +23 -0
  66. package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +544 -0
  67. package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +1690 -0
  68. package/src/analytics/lpinfo/steer/steer-display-types.ts +99 -0
  69. package/src/analytics/news/index.ts +52 -0
  70. package/src/analytics/news/interfaces/types.ts +222 -0
  71. package/src/analytics/news/providers/defiNewsProvider.ts +734 -0
  72. package/src/analytics/news/services/newsDataService.ts +332 -0
  73. package/src/analytics/news/utils/formatters.ts +151 -0
  74. package/src/analytics/token-info/action.ts +240 -0
  75. package/src/analytics/token-info/index.ts +3 -0
  76. package/src/analytics/token-info/params.ts +215 -0
  77. package/src/analytics/token-info/providers.ts +681 -0
  78. package/src/analytics/token-info/service.ts +168 -0
  79. package/src/analytics/token-info/types.ts +74 -0
  80. package/src/audit/audit-log.ts +45 -0
  81. package/src/browser-shim/build-shim.ts +123 -0
  82. package/src/browser-shim/index.ts +5 -0
  83. package/src/browser-shim/shim.template.js +563 -0
  84. package/src/chains/evm/.github/workflows/npm-deploy.yml +112 -0
  85. package/src/chains/evm/LICENSE +21 -0
  86. package/src/chains/evm/README.md +106 -0
  87. package/src/chains/evm/actions/helpers.ts +147 -0
  88. package/src/chains/evm/actions/swap.ts +839 -0
  89. package/src/chains/evm/actions/transfer.ts +254 -0
  90. package/src/chains/evm/biome.json +61 -0
  91. package/src/chains/evm/bridge-router.ts +660 -0
  92. package/src/chains/evm/build.ts +89 -0
  93. package/src/chains/evm/chain-handler.ts +416 -0
  94. package/src/chains/evm/constants.ts +23 -0
  95. package/src/chains/evm/contracts/artifacts/OZGovernor.json +1707 -0
  96. package/src/chains/evm/contracts/artifacts/TimelockController.json +1007 -0
  97. package/src/chains/evm/contracts/artifacts/VoteToken.json +895 -0
  98. package/src/chains/evm/dex/aerodrome/index.ts +34 -0
  99. package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +558 -0
  100. package/src/chains/evm/dex/aerodrome/types.ts +318 -0
  101. package/src/chains/evm/dex/pancakeswp/index.ts +35 -0
  102. package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +743 -0
  103. package/src/chains/evm/dex/pancakeswp/types.ts +65 -0
  104. package/src/chains/evm/dex/uniswap/index.ts +35 -0
  105. package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +759 -0
  106. package/src/chains/evm/dex/uniswap/types.ts +390 -0
  107. package/src/chains/evm/generated/specs/spec-helpers.ts +73 -0
  108. package/src/chains/evm/generated/specs/specs.ts +151 -0
  109. package/src/chains/evm/gov-router.ts +250 -0
  110. package/src/chains/evm/index.browser.ts +16 -0
  111. package/src/chains/evm/index.ts +31 -0
  112. package/src/chains/evm/prompts.ts +193 -0
  113. package/src/chains/evm/providers/get-balance.ts +123 -0
  114. package/src/chains/evm/providers/wallet.ts +715 -0
  115. package/src/chains/evm/routes/sign.ts +333 -0
  116. package/src/chains/evm/rpc-providers.ts +410 -0
  117. package/src/chains/evm/service.ts +140 -0
  118. package/src/chains/evm/templates/index.ts +10 -0
  119. package/src/chains/evm/types/index.ts +432 -0
  120. package/src/chains/evm/vitest.config.ts +18 -0
  121. package/src/chains/registry.ts +668 -0
  122. package/src/chains/solana/README.md +367 -0
  123. package/src/chains/wallet-action.ts +533 -0
  124. package/src/chains/wallet-router.test.ts +296 -0
  125. package/src/contracts.ts +65 -0
  126. package/src/core-augmentation.ts +10 -0
  127. package/src/index.ts +71 -0
  128. package/src/lib/server-wallet-trade.ts +192 -0
  129. package/src/lib/wallet-export-guard.ts +330 -0
  130. package/src/lp/actions/liquidity.ts +827 -0
  131. package/src/lp/e2e/real-token-tests.ts +428 -0
  132. package/src/lp/e2e/scenarios.ts +470 -0
  133. package/src/lp/e2e/test-utils.ts +145 -0
  134. package/src/lp/lp-manager-entry.ts +303 -0
  135. package/src/lp/services/ConcentratedLiquidityService.ts +120 -0
  136. package/src/lp/services/DexInteractionService.ts +226 -0
  137. package/src/lp/services/LpManagementService.test.ts +148 -0
  138. package/src/lp/services/LpManagementService.ts +632 -0
  139. package/src/lp/services/UserLpProfileService.ts +163 -0
  140. package/src/lp/services/VaultService.ts +153 -0
  141. package/src/lp/services/YieldOptimizationService.ts +344 -0
  142. package/src/lp/services/__tests__/MockLpService.ts +146 -0
  143. package/src/lp/tasks/LpAutoRebalanceTask.ts +117 -0
  144. package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +370 -0
  145. package/src/lp/types.ts +582 -0
  146. package/src/lp/utils/solanaClient.ts +143 -0
  147. package/src/plugin.ts +125 -0
  148. package/src/policy/policy.ts +19 -0
  149. package/src/providers/canonical-provider.ts +27 -0
  150. package/src/providers/unified-wallet-provider.ts +79 -0
  151. package/src/register-routes.ts +11 -0
  152. package/src/routes/plugin.ts +47 -0
  153. package/src/routes/wallet-market-overview-route.ts +869 -0
  154. package/src/sdk/abi.ts +258 -0
  155. package/src/sdk/bridge/abis.ts +126 -0
  156. package/src/sdk/bridge/client.ts +518 -0
  157. package/src/sdk/bridge/index.ts +56 -0
  158. package/src/sdk/bridge/solana.ts +604 -0
  159. package/src/sdk/bridge/types.ts +202 -0
  160. package/src/sdk/convenience.ts +347 -0
  161. package/src/sdk/escrow/MutualStakeEscrow.ts +480 -0
  162. package/src/sdk/escrow/types.ts +64 -0
  163. package/src/sdk/escrow/verifiers.ts +73 -0
  164. package/src/sdk/identity/erc8004.ts +692 -0
  165. package/src/sdk/identity/reputation.ts +449 -0
  166. package/src/sdk/identity/uaid.ts +497 -0
  167. package/src/sdk/identity/validation.ts +372 -0
  168. package/src/sdk/index.ts +763 -0
  169. package/src/sdk/policy/SpendingPolicy.ts +260 -0
  170. package/src/sdk/policy/UptoBillingPolicy.ts +320 -0
  171. package/src/sdk/router/PaymentRouter.ts +215 -0
  172. package/src/sdk/router/index.ts +8 -0
  173. package/src/sdk/swap/SwapModule.ts +310 -0
  174. package/src/sdk/swap/abi.ts +117 -0
  175. package/src/sdk/swap/index.ts +34 -0
  176. package/src/sdk/swap/types.ts +135 -0
  177. package/src/sdk/tokens/decimals.ts +140 -0
  178. package/src/sdk/tokens/registry.ts +911 -0
  179. package/src/sdk/tokens/solana.ts +419 -0
  180. package/src/sdk/tokens/transfers.ts +327 -0
  181. package/src/sdk/types.ts +158 -0
  182. package/src/sdk/wallet-core.ts +115 -0
  183. package/src/sdk/x402/budget.ts +168 -0
  184. package/src/sdk/x402/chains/abstract/index.ts +280 -0
  185. package/src/sdk/x402/client.ts +320 -0
  186. package/src/sdk/x402/index.ts +46 -0
  187. package/src/sdk/x402/middleware.ts +92 -0
  188. package/src/sdk/x402/multi-asset.ts +144 -0
  189. package/src/sdk/x402/types.ts +156 -0
  190. package/src/services/wallet-backend-service.ts +328 -0
  191. package/src/types/wallet-router.ts +227 -0
  192. package/src/utils/intent-trajectory.ts +106 -0
  193. package/src/wallet/backend.ts +62 -0
  194. package/src/wallet/errors.ts +49 -0
  195. package/src/wallet/index.ts +27 -0
  196. package/src/wallet/local-eoa-backend.ts +201 -0
  197. package/src/wallet/pending.ts +60 -0
  198. package/src/wallet/select-backend.ts +47 -0
  199. package/src/wallet/steward-backend.ts +161 -0
  200. package/src/wallet-action.ts +1 -0
@@ -0,0 +1,813 @@
1
+ // @ts-nocheck — legacy code from absorbed plugins (lp-manager, lpinfo, dexscreener, defi-news, birdeye); strict types pending cleanup
2
+ import { elizaLogger } from "@elizaos/core";
3
+ import {
4
+ API_BASE_URL,
5
+ BIRDEYE_ENDPOINTS,
6
+ DEFAULT_MAX_RETRIES,
7
+ RETRY_DELAY_MS,
8
+ } from "./constants";
9
+ import type { BirdeyeApiParams, BirdeyeApiResponse } from "./types/api/common";
10
+ import type {
11
+ BaseQuoteParams,
12
+ BaseQuoteResponse,
13
+ DefiHistoryPriceParams,
14
+ DefiHistoryPriceResponse,
15
+ DefiMultiPriceParams,
16
+ DefiMultiPriceParamsPOST,
17
+ DefiMultiPriceResponse,
18
+ DefiNetworksResponse,
19
+ DefiPriceParams,
20
+ DefiPriceResponse,
21
+ DefiTradesTokenParams,
22
+ DefiTradesTokenResponse,
23
+ HistoricalPriceUnixParams,
24
+ HistoricalPriceUnixResponse,
25
+ MultiPriceVolumeParams,
26
+ MultiPriceVolumeResponse,
27
+ OHLCVParams,
28
+ OHLCVResponse,
29
+ PriceVolumeParams,
30
+ PriceVolumeResponse,
31
+ } from "./types/api/defi";
32
+ import type {
33
+ OHLCVPairParams,
34
+ OHLCVPairResponse,
35
+ PairOverviewMultiParams,
36
+ PairOverviewMultiResponse,
37
+ PairOverviewSingleParams,
38
+ PairOverviewSingleResponse,
39
+ } from "./types/api/pair";
40
+ import type {
41
+ TokenMarketSearchParams,
42
+ TokenMarketSearchResponse,
43
+ } from "./types/api/search";
44
+ import type {
45
+ AllMarketsParams,
46
+ AllMarketsResponse,
47
+ MintBurnParams,
48
+ MintBurnResponse,
49
+ NewListingParams,
50
+ NewListingResponse,
51
+ TokenCreationInfoParams,
52
+ TokenCreationInfoResponse,
53
+ TokenHoldersParams,
54
+ TokenHoldersResponse,
55
+ TokenListParams,
56
+ TokenListResponse,
57
+ TokenListV2Response,
58
+ TokenMarketDataParams,
59
+ TokenMarketDataResponse,
60
+ TokenMetadataMultiParams,
61
+ TokenMetadataMultiResponse,
62
+ TokenMetadataSingleParams,
63
+ TokenMetadataSingleResponse,
64
+ TokenOverviewParams,
65
+ TokenOverviewResponse,
66
+ TokenSecurityParams,
67
+ TokenSecurityResponse,
68
+ TokenTradeDataMultiParams,
69
+ TokenTradeDataMultiResponse,
70
+ TokenTradeDataSingleParams,
71
+ TokenTradeDataSingleResponse,
72
+ TokenTrendingParams,
73
+ TokenTrendingResponse,
74
+ TopTradersParams,
75
+ TopTradersResponse,
76
+ } from "./types/api/token";
77
+ import type {
78
+ GainersLosersParams,
79
+ GainersLosersResponse,
80
+ TraderTransactionsSeekParams,
81
+ TraderTransactionsSeekResponse,
82
+ } from "./types/api/trader";
83
+ import type {
84
+ WalletPortfolioParams,
85
+ WalletPortfolioResponse,
86
+ WalletSimulationParams,
87
+ WalletSimulationResponse,
88
+ WalletTokenBalanceParams,
89
+ WalletTokenBalanceResponse,
90
+ WalletTransactionHistoryParams,
91
+ WalletTransactionHistoryResponse,
92
+ } from "./types/api/wallet";
93
+ import { convertToStringParams, waitFor } from "./utils";
94
+
95
+ type FetchParams<T> = T & {
96
+ headers?: Record<string, string>;
97
+ };
98
+
99
+ // emulate settings from 0.x
100
+ const settings = process.env;
101
+
102
+ /*
103
+ class BaseCachedProvider {
104
+ private cache: NodeCache;
105
+
106
+ constructor(
107
+ private cacheManager: ICacheManager,
108
+ private cacheKey,
109
+ ttl?: number
110
+ ) {
111
+ this.runtime = runtime
112
+ this.cache = new NodeCache({ stdTTL: ttl || 300 });
113
+ }
114
+
115
+ private readFsCache<T>(key: string): Promise<T | null> {
116
+ return this.cacheManager.get<T>(path.join(this.cacheKey, key));
117
+ }
118
+
119
+ private writeFsCache<T>(key: string, data: T): Promise<void> {
120
+ return this.cacheManager.set(path.join(this.cacheKey, key), data, {
121
+ expires: Date.now() + 5 * 60 * 1000,
122
+ });
123
+ }
124
+
125
+ public async readFromCache<T>(key: string): Promise<T | null> {
126
+ // get memory cache first
127
+ const val = this.cache.get<T>(key);
128
+ if (val) {
129
+ return val;
130
+ }
131
+
132
+ const fsVal = await this.readFsCache<T>(key);
133
+ if (fsVal) {
134
+ // set to memory cache
135
+ this.cache.set(key, fsVal);
136
+ }
137
+
138
+ return fsVal;
139
+ }
140
+
141
+ public async writeToCache<T>(key: string, val: T): Promise<void> {
142
+ // Set in-memory cache
143
+ this.cache.set(key, val);
144
+
145
+ // Write to file-based cache
146
+ await this.writeFsCache(key, val);
147
+ }
148
+ }
149
+ */
150
+
151
+ // Custom error class for HTTP errors to distinguish from network errors
152
+ class HttpError extends Error {
153
+ constructor(
154
+ public status: number,
155
+ message: string,
156
+ ) {
157
+ super(message);
158
+ this.name = "HttpError";
159
+ }
160
+ }
161
+
162
+ // extends BaseCachedProvider
163
+ // really more like a service
164
+ export class BirdeyeProvider {
165
+ private runtime: unknown;
166
+ private maxRetries: number;
167
+
168
+ constructor(
169
+ runtime,
170
+ //cacheManager: ICacheManager,
171
+ _symbolMap?: Record<string, string>,
172
+ maxRetries?: number,
173
+ ) {
174
+ // super(cacheManager, "birdeye/data")
175
+ this.runtime = runtime;
176
+ this.maxRetries = maxRetries || DEFAULT_MAX_RETRIES;
177
+ }
178
+
179
+ /*
180
+ * COMMON FETCH FUNCTIONS
181
+ */
182
+ private async fetchWithRetry<T extends BirdeyeApiResponse>(
183
+ url: string,
184
+ options: RequestInit = {},
185
+ ): Promise<T> {
186
+ let attempts = 0;
187
+
188
+ // allow the user to override the chain
189
+ const chain =
190
+ options.headers?.["x-chain"] || settings.BIRDEYE_CHAIN || "solana";
191
+
192
+ while (attempts < this.maxRetries) {
193
+ attempts++;
194
+ try {
195
+ const resp = await fetch(url, {
196
+ ...options,
197
+ headers: {
198
+ Accept: "application/json",
199
+ "Content-Type": "application/json",
200
+ "x-chain": chain,
201
+ "X-API-KEY": settings.BIRDEYE_API_KEY || "",
202
+ ...options.headers,
203
+ },
204
+ });
205
+
206
+ if (!resp.ok) {
207
+ const errorText = await resp.text();
208
+ const error = new HttpError(
209
+ resp.status,
210
+ `HTTP error! status: ${resp.status}, message: ${errorText}`,
211
+ );
212
+
213
+ // Only retry on transient errors
214
+ const isRetryable =
215
+ resp.status >= 500 || // 5xx server errors
216
+ resp.status === 429 || // Rate limit
217
+ resp.status === 408 || // Request timeout
218
+ resp.status === 503; // Service unavailable
219
+
220
+ if (!isRetryable || attempts === this.maxRetries) {
221
+ throw error;
222
+ }
223
+
224
+ // Wait before retry for transient errors
225
+ await waitFor(RETRY_DELAY_MS);
226
+ continue;
227
+ }
228
+
229
+ const rawData = await resp.json();
230
+ // If the response already has data and success fields, return it
231
+ if (rawData.data !== undefined && rawData.success !== undefined) {
232
+ return rawData as T;
233
+ }
234
+ // Otherwise wrap the response in the expected format
235
+ return {
236
+ data: rawData,
237
+ success: true,
238
+ } as T;
239
+ } catch (error) {
240
+ // Check if this is an HTTP error (already handled status code logic above)
241
+ if (error instanceof HttpError) {
242
+ // HTTP errors are only retried if isRetryable was true (handled above)
243
+ // If we're here, it means it wasn't retryable, so throw
244
+ throw error;
245
+ }
246
+
247
+ // Network errors (fetch failures before getting a response) are retryable
248
+ // This includes: connection failures, DNS errors, timeouts, etc.
249
+ if (attempts === this.maxRetries) {
250
+ // Out of retry attempts
251
+ throw error;
252
+ }
253
+
254
+ // Retry network errors
255
+ await waitFor(RETRY_DELAY_MS);
256
+ }
257
+ }
258
+ // Fallback in case loop completes without returning (shouldn't happen)
259
+ throw new Error(`Failed to fetch after ${this.maxRetries} attempts`);
260
+ }
261
+
262
+ private async fetchWithCacheAndRetry<T extends BirdeyeApiResponse>({
263
+ url,
264
+ params,
265
+ headers,
266
+ method = "GET",
267
+ }: {
268
+ url: string;
269
+ params?: BirdeyeApiParams;
270
+ headers?: Record<string, string>;
271
+ method?: "GET" | "POST";
272
+ }): Promise<T> {
273
+ const stringParams = params ? convertToStringParams(params) : {};
274
+ const fullUrl = `${API_BASE_URL}${url}`;
275
+ const cacheKey =
276
+ method === "GET"
277
+ ? `${url}?${new URLSearchParams(stringParams)}`
278
+ : `${url}:${JSON.stringify(params)}`;
279
+
280
+ // Check cache first
281
+ const cachedVal = await this.runtime.getCache(cacheKey);
282
+ if (cachedVal) return cachedVal as T;
283
+
284
+ const urlWithParams =
285
+ method === "GET" && params
286
+ ? `${fullUrl}?${new URLSearchParams(stringParams)}`
287
+ : fullUrl;
288
+
289
+ elizaLogger.info(`Birdeye fetch: ${urlWithParams}`);
290
+
291
+ const data = await this.fetchWithRetry<T>(urlWithParams, {
292
+ method,
293
+ headers,
294
+ ...(method === "POST" && params && { body: JSON.stringify(params) }),
295
+ });
296
+
297
+ await this.runtime.setCache(cacheKey, data);
298
+ return data as T;
299
+ }
300
+
301
+ /*
302
+ * DEFI FETCH FUNCTIONS
303
+ */
304
+
305
+ // Get a list of all supported networks.
306
+ public async fetchDefiSupportedNetworks() {
307
+ return this.fetchWithCacheAndRetry<DefiNetworksResponse>({
308
+ url: BIRDEYE_ENDPOINTS.defi.networks,
309
+ });
310
+ }
311
+
312
+ // Get price update of a token.
313
+ public async fetchDefiPrice(
314
+ params: DefiPriceParams,
315
+ options: { headers?: Record<string, string> } = {},
316
+ ) {
317
+ return this.fetchWithCacheAndRetry<DefiPriceResponse>({
318
+ url: BIRDEYE_ENDPOINTS.defi.price,
319
+ params,
320
+ headers: options.headers,
321
+ });
322
+ }
323
+
324
+ // Get price updates of multiple tokens in a single API call. Maximum 100 tokens
325
+ public async fetchDefiPriceMultiple(
326
+ params: DefiMultiPriceParams,
327
+ options: { headers?: Record<string, string> } = {},
328
+ ) {
329
+ return this.fetchWithCacheAndRetry<DefiMultiPriceResponse>({
330
+ url: BIRDEYE_ENDPOINTS.defi.price_multi,
331
+ params,
332
+ headers: options.headers,
333
+ });
334
+ }
335
+
336
+ // Get price updates of multiple tokens in a single API call. Maximum 100 tokens
337
+ public async fetchDefiPriceMultiple_POST(
338
+ params: DefiMultiPriceParamsPOST,
339
+ options: { headers?: Record<string, string> } = {},
340
+ ) {
341
+ return this.fetchWithCacheAndRetry<DefiMultiPriceResponse>({
342
+ url: BIRDEYE_ENDPOINTS.defi.price_multi_POST,
343
+ params,
344
+ headers: options.headers,
345
+ method: "POST",
346
+ });
347
+ }
348
+
349
+ // Get historical price line chart of a token.
350
+ public async fetchDefiPriceHistorical(
351
+ params: DefiHistoryPriceParams,
352
+ options: { headers?: Record<string, string> } = {},
353
+ ) {
354
+ return this.fetchWithCacheAndRetry<DefiHistoryPriceResponse>({
355
+ url: BIRDEYE_ENDPOINTS.defi.history_price,
356
+ params,
357
+ headers: options.headers,
358
+ });
359
+ }
360
+
361
+ // Get historical price by unix timestamp
362
+ public async fetchDefiPriceHistoricalByUnixTime(
363
+ params: HistoricalPriceUnixParams,
364
+ options: { headers?: Record<string, string> } = {},
365
+ ) {
366
+ return this.fetchWithCacheAndRetry<HistoricalPriceUnixResponse>({
367
+ url: BIRDEYE_ENDPOINTS.defi.historical_price_unix,
368
+ params,
369
+ headers: options.headers,
370
+ });
371
+ }
372
+
373
+ // Get list of trades of a certain token.
374
+ public async fetchDefiTradesToken(
375
+ params: DefiTradesTokenParams,
376
+ options: { headers?: Record<string, string> } = {},
377
+ ) {
378
+ return this.fetchWithCacheAndRetry<DefiTradesTokenResponse>({
379
+ url: BIRDEYE_ENDPOINTS.defi.trades_token,
380
+ params,
381
+ headers: options.headers,
382
+ });
383
+ }
384
+
385
+ // Get list of trades of a certain pair or market.
386
+ public async fetchDefiTradesPair(
387
+ params: DefiTradesTokenParams,
388
+ options: { headers?: Record<string, string> } = {},
389
+ ) {
390
+ return this.fetchWithCacheAndRetry<DefiTradesTokenResponse>({
391
+ url: BIRDEYE_ENDPOINTS.defi.trades_token,
392
+ params,
393
+ headers: options.headers,
394
+ });
395
+ }
396
+
397
+ // Get list of trades of a token with time bound option.
398
+ public async fetchDefiTradesTokenSeekByTime(
399
+ params: DefiTradesTokenParams,
400
+ options: { headers?: Record<string, string> } = {},
401
+ ) {
402
+ return this.fetchWithCacheAndRetry<DefiTradesTokenResponse>({
403
+ url: BIRDEYE_ENDPOINTS.defi.trades_token_seek,
404
+ params,
405
+ headers: options.headers,
406
+ });
407
+ }
408
+
409
+ // Get list of trades of a certain pair or market with time bound option.
410
+ public async fetchDefiTradesPairSeekByTime(
411
+ params: DefiTradesTokenParams,
412
+ options: { headers?: Record<string, string> } = {},
413
+ ) {
414
+ return this.fetchWithCacheAndRetry<DefiTradesTokenResponse>({
415
+ url: BIRDEYE_ENDPOINTS.defi.trades_pair_seek,
416
+ params,
417
+ headers: options.headers,
418
+ });
419
+ }
420
+
421
+ // Get OHLCV price of a token.
422
+ public async fetchDefiOHLCV(
423
+ params: OHLCVParams,
424
+ options: { headers?: Record<string, string> } = {},
425
+ ) {
426
+ return this.fetchWithCacheAndRetry<OHLCVResponse>({
427
+ url: BIRDEYE_ENDPOINTS.defi.ohlcv,
428
+ params,
429
+ headers: options.headers,
430
+ });
431
+ }
432
+
433
+ // Get OHLCV price of a pair.
434
+ public async fetchDefiOHLCVPair(
435
+ params: OHLCVPairParams,
436
+ options: { headers?: Record<string, string> } = {},
437
+ ) {
438
+ return this.fetchWithCacheAndRetry<OHLCVPairResponse>({
439
+ url: BIRDEYE_ENDPOINTS.defi.ohlcv_pair,
440
+ params,
441
+ headers: options.headers,
442
+ });
443
+ }
444
+
445
+ // Get OHLCV price of a base-quote pair.
446
+ public async fetchDefiOHLCVBaseQuote(
447
+ params: BaseQuoteParams,
448
+ options: { headers?: Record<string, string> } = {},
449
+ ) {
450
+ return this.fetchWithCacheAndRetry<BaseQuoteResponse>({
451
+ url: BIRDEYE_ENDPOINTS.defi.ohlcv_base_quote,
452
+ params,
453
+ headers: options.headers,
454
+ });
455
+ }
456
+
457
+ // Get price and volume of a token.
458
+ public async fetchDefiPriceVolume(
459
+ params: PriceVolumeParams,
460
+ options: { headers?: Record<string, string> } = {},
461
+ ) {
462
+ return this.fetchWithCacheAndRetry<PriceVolumeResponse>({
463
+ url: BIRDEYE_ENDPOINTS.defi.price_volume,
464
+ params,
465
+ headers: options.headers,
466
+ });
467
+ }
468
+
469
+ // Get price and volume updates of maximum 50 tokens
470
+ public async fetchDefiPriceVolumeMulti_POST(
471
+ params: MultiPriceVolumeParams,
472
+ options: { headers?: Record<string, string> } = {},
473
+ ) {
474
+ return this.fetchWithCacheAndRetry<MultiPriceVolumeResponse>({
475
+ url: BIRDEYE_ENDPOINTS.defi.price_volume_multi_POST,
476
+ params,
477
+ headers: options.headers,
478
+ method: "POST",
479
+ });
480
+ }
481
+
482
+ /*
483
+ * TOKEN FETCH FUNCTIONS
484
+ */
485
+
486
+ // Get token list of any supported chains.
487
+ public async fetchTokenList(
488
+ params: TokenListParams,
489
+ options: { headers?: Record<string, string> } = {},
490
+ ) {
491
+ return this.fetchWithCacheAndRetry<TokenListResponse>({
492
+ url: BIRDEYE_ENDPOINTS.token.list_all,
493
+ params,
494
+ headers: options.headers,
495
+ });
496
+ }
497
+
498
+ // Get token security of any supported chains.
499
+ public async fetchTokenSecurityByAddress(
500
+ params: TokenSecurityParams,
501
+ options: { headers?: Record<string, string> } = {},
502
+ ) {
503
+ return this.fetchWithCacheAndRetry<TokenSecurityResponse>({
504
+ url: BIRDEYE_ENDPOINTS.token.security,
505
+ params,
506
+ headers: options.headers,
507
+ });
508
+ }
509
+
510
+ // Get overview of a token.
511
+ public async fetchTokenOverview(
512
+ params: TokenOverviewParams,
513
+ options: { headers?: Record<string, string> } = {},
514
+ ) {
515
+ return this.fetchWithCacheAndRetry<TokenOverviewResponse>({
516
+ url: BIRDEYE_ENDPOINTS.token.overview,
517
+ params,
518
+ headers: options.headers,
519
+ });
520
+ }
521
+
522
+ // Get creation info of token
523
+ public async fetchTokenCreationInfo(
524
+ params: TokenCreationInfoParams,
525
+ options: { headers?: Record<string, string> } = {},
526
+ ) {
527
+ return this.fetchWithCacheAndRetry<TokenCreationInfoResponse>({
528
+ url: BIRDEYE_ENDPOINTS.token.creation_info,
529
+ params,
530
+ headers: options.headers,
531
+ });
532
+ }
533
+
534
+ // Retrieve a dynamic and up-to-date list of trending tokens based on specified sorting criteria.
535
+ public async fetchTokenTrending(
536
+ params?: TokenTrendingParams,
537
+ options: { headers?: Record<string, string> } = {},
538
+ ) {
539
+ return this.fetchWithCacheAndRetry<TokenTrendingResponse>({
540
+ url: BIRDEYE_ENDPOINTS.token.trending,
541
+ params,
542
+ headers: options.headers,
543
+ });
544
+ }
545
+
546
+ // This endpoint facilitates the retrieval of a list of tokens on a specified blockchain network. This upgraded version is exclusive to business and enterprise packages. By simply including the header for the requested blockchain without any query parameters, business and enterprise users can get the full list of tokens on the specified blockchain in the URL returned in the response. This removes the need for the limit response of the previous version and reduces the workload of making multiple calls.
547
+ public async fetchTokenListV2_POST(
548
+ params: FetchParams<Record<string, never>>,
549
+ ) {
550
+ return this.fetchWithCacheAndRetry<TokenListV2Response>({
551
+ url: BIRDEYE_ENDPOINTS.token.list_all_v2_POST,
552
+ params,
553
+ headers: params.headers,
554
+ method: "POST",
555
+ });
556
+ }
557
+
558
+ // Get newly listed tokens of any supported chains.
559
+ public async fetchTokenNewListing(
560
+ params?: NewListingParams,
561
+ options: { headers?: Record<string, string> } = {},
562
+ ) {
563
+ return this.fetchWithCacheAndRetry<NewListingResponse>({
564
+ url: BIRDEYE_ENDPOINTS.token.new_listing,
565
+ params,
566
+ headers: options?.headers,
567
+ });
568
+ }
569
+
570
+ // Get top traders of given token.
571
+ public async fetchTokenTopTraders(
572
+ params: TopTradersParams,
573
+ options: { headers?: Record<string, string> } = {},
574
+ ) {
575
+ return this.fetchWithCacheAndRetry<TopTradersResponse>({
576
+ url: BIRDEYE_ENDPOINTS.token.top_traders,
577
+ params,
578
+ headers: options.headers,
579
+ });
580
+ }
581
+
582
+ // The API provides detailed information about the markets for a specific cryptocurrency token on a specified blockchain. Users can retrieve data for one or multiple markets related to a single token. This endpoint requires the specification of a token address and the blockchain to filter results. Additionally, it supports optional query parameters such as offset, limit, and required sorting by liquidity or sort type (ascending or descending) to refine the output.
583
+ public async fetchTokenAllMarketsList(
584
+ params: AllMarketsParams,
585
+ options: { headers?: Record<string, string> } = {},
586
+ ) {
587
+ return this.fetchWithCacheAndRetry<AllMarketsResponse>({
588
+ url: BIRDEYE_ENDPOINTS.token.all_markets,
589
+ params,
590
+ headers: options.headers,
591
+ });
592
+ }
593
+
594
+ // Get metadata of single token
595
+ public async fetchTokenMetadataSingle(
596
+ params: TokenMetadataSingleParams,
597
+ options: { headers?: Record<string, string> } = {},
598
+ ) {
599
+ return this.fetchWithCacheAndRetry<TokenMetadataSingleResponse>({
600
+ url: BIRDEYE_ENDPOINTS.token.metadata_single,
601
+ params,
602
+ headers: options.headers,
603
+ });
604
+ }
605
+
606
+ // Get metadata of multiple tokens
607
+ public async fetchTokenMetadataMulti(
608
+ params: TokenMetadataMultiParams,
609
+ options: { headers?: Record<string, string> } = {},
610
+ ) {
611
+ return this.fetchWithCacheAndRetry<TokenMetadataMultiResponse>({
612
+ url: BIRDEYE_ENDPOINTS.token.metadata_multi,
613
+ params,
614
+ headers: options.headers,
615
+ });
616
+ }
617
+
618
+ // Get market data of single token
619
+ public async fetchTokenMarketData(
620
+ params: TokenMarketDataParams,
621
+ options: { headers?: Record<string, string> } = {},
622
+ ) {
623
+ return this.fetchWithCacheAndRetry<TokenMarketDataResponse>({
624
+ url: BIRDEYE_ENDPOINTS.token.market_data,
625
+ params,
626
+ headers: options.headers,
627
+ });
628
+ }
629
+
630
+ // Get trade data of single token
631
+ public async fetchTokenTradeDataSingle(
632
+ params: TokenTradeDataSingleParams,
633
+ options: { headers?: Record<string, string> } = {},
634
+ ) {
635
+ return this.fetchWithCacheAndRetry<TokenTradeDataSingleResponse>({
636
+ url: BIRDEYE_ENDPOINTS.token.trade_data_single,
637
+ params,
638
+ headers: options.headers,
639
+ });
640
+ }
641
+
642
+ // Get trade data of multiple tokens
643
+ public async fetchTokenTradeDataMultiple(
644
+ params: TokenTradeDataMultiParams,
645
+ options: { headers?: Record<string, string> } = {},
646
+ ) {
647
+ return this.fetchWithCacheAndRetry<TokenTradeDataMultiResponse>({
648
+ url: BIRDEYE_ENDPOINTS.token.trade_data_multi,
649
+ params,
650
+ headers: options.headers,
651
+ });
652
+ }
653
+
654
+ // Get top holder list of the given token
655
+ public async fetchTokenHolders(
656
+ params: TokenHoldersParams,
657
+ options: { headers?: Record<string, string> } = {},
658
+ ) {
659
+ return this.fetchWithCacheAndRetry<TokenHoldersResponse>({
660
+ url: BIRDEYE_ENDPOINTS.token.holders,
661
+ params,
662
+ headers: options.headers,
663
+ });
664
+ }
665
+
666
+ // Get mint/burn transaction list of the given token. Only support solana currently
667
+ public async fetchTokenMintBurn(
668
+ params: MintBurnParams,
669
+ options: { headers?: Record<string, string> } = {},
670
+ ) {
671
+ return this.fetchWithCacheAndRetry<MintBurnResponse>({
672
+ url: BIRDEYE_ENDPOINTS.token.mint_burn,
673
+ params,
674
+ headers: options.headers,
675
+ });
676
+ }
677
+
678
+ /*
679
+ * WALLET FETCH FUNCTIONS
680
+ */
681
+ public async fetchWalletSupportedNetworks(
682
+ options: { headers?: Record<string, string> } = {},
683
+ ) {
684
+ return this.fetchWithCacheAndRetry<DefiNetworksResponse>({
685
+ url: BIRDEYE_ENDPOINTS.defi.networks,
686
+ headers: options.headers,
687
+ });
688
+ }
689
+
690
+ public async fetchWalletPortfolio(
691
+ params: WalletPortfolioParams,
692
+ options: { headers?: Record<string, string> } = {},
693
+ ) {
694
+ return this.fetchWithCacheAndRetry<WalletPortfolioResponse>({
695
+ url: BIRDEYE_ENDPOINTS.wallet.portfolio,
696
+ params,
697
+ headers: options.headers,
698
+ });
699
+ }
700
+
701
+ public async fetchWalletTokenBalance(
702
+ params: WalletTokenBalanceParams,
703
+ options: { headers?: Record<string, string> } = {},
704
+ ) {
705
+ return this.fetchWithCacheAndRetry<WalletTokenBalanceResponse>({
706
+ url: BIRDEYE_ENDPOINTS.wallet.token_balance,
707
+ params,
708
+ headers: options.headers,
709
+ });
710
+ }
711
+
712
+ public async fetchWalletTransactionHistory(
713
+ params: WalletTransactionHistoryParams,
714
+ options: { headers?: Record<string, string> } = {},
715
+ ) {
716
+ return this.fetchWithCacheAndRetry<WalletTransactionHistoryResponse>({
717
+ url: BIRDEYE_ENDPOINTS.wallet.transaction_history,
718
+ params,
719
+ headers: options.headers,
720
+ });
721
+ }
722
+
723
+ public async fetchWalletTransactionSimulate_POST(
724
+ params: WalletSimulationParams,
725
+ options: { headers?: Record<string, string> } = {},
726
+ ) {
727
+ return this.fetchWithCacheAndRetry<WalletSimulationResponse>({
728
+ url: BIRDEYE_ENDPOINTS.wallet.transaction_simulation_POST,
729
+ params,
730
+ headers: options.headers,
731
+ method: "POST",
732
+ });
733
+ }
734
+
735
+ /*
736
+ * TRADER FETCH FUNCTIONS
737
+ */
738
+
739
+ // The API provides detailed information top gainers/losers
740
+ public async fetchTraderGainersLosers(
741
+ params: GainersLosersParams,
742
+ options: { headers?: Record<string, string> } = {},
743
+ ) {
744
+ return this.fetchWithCacheAndRetry<GainersLosersResponse>({
745
+ url: BIRDEYE_ENDPOINTS.trader.gainers_losers,
746
+ params,
747
+ headers: options.headers,
748
+ });
749
+ }
750
+
751
+ // Get list of trades of a trader with time bound option.
752
+ public async fetchTraderTransactionsSeek(
753
+ params: TraderTransactionsSeekParams,
754
+ options: { headers?: Record<string, string> } = {},
755
+ ) {
756
+ return this.fetchWithCacheAndRetry<TraderTransactionsSeekResponse>({
757
+ url: BIRDEYE_ENDPOINTS.trader.trades_seek,
758
+ params,
759
+ headers: options.headers,
760
+ });
761
+ }
762
+
763
+ /*
764
+ * PAIR FETCH FUNCTIONS
765
+ */
766
+ public async fetchPairOverviewSingle(
767
+ params: PairOverviewSingleParams,
768
+ options: { headers?: Record<string, string> } = {},
769
+ ) {
770
+ return this.fetchWithCacheAndRetry<PairOverviewSingleResponse>({
771
+ url: BIRDEYE_ENDPOINTS.pair.overview_single,
772
+ params,
773
+ headers: options.headers,
774
+ });
775
+ }
776
+
777
+ // Get overview of multiple pairs
778
+ public async fetchMultiPairOverview(
779
+ params: PairOverviewMultiParams,
780
+ options: { headers?: Record<string, string> } = {},
781
+ ) {
782
+ return this.fetchWithCacheAndRetry<PairOverviewMultiResponse>({
783
+ url: BIRDEYE_ENDPOINTS.pair.overview_multi,
784
+ params,
785
+ headers: options.headers,
786
+ });
787
+ }
788
+
789
+ public async fetchPairOverviewMultiple(
790
+ params: PairOverviewMultiParams,
791
+ options: { headers?: Record<string, string> } = {},
792
+ ) {
793
+ return this.fetchWithCacheAndRetry<PairOverviewMultiResponse>({
794
+ url: BIRDEYE_ENDPOINTS.pair.overview_multi,
795
+ params,
796
+ headers: options.headers,
797
+ });
798
+ }
799
+
800
+ /*
801
+ * SEARCH FETCH FUNCTIONS
802
+ */
803
+ public async fetchSearchTokenMarketData(
804
+ params: TokenMarketSearchParams,
805
+ options: { headers?: Record<string, string> } = {},
806
+ ) {
807
+ return this.fetchWithCacheAndRetry<TokenMarketSearchResponse>({
808
+ url: BIRDEYE_ENDPOINTS.search.token_market,
809
+ params,
810
+ headers: options.headers,
811
+ });
812
+ }
813
+ }