@provable-games/ekubo-sdk 0.1.0 → 0.1.8
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.
- package/README.md +199 -0
- package/dist/client-DPSUVYSv.d.cts +659 -0
- package/dist/client-DPSUVYSv.d.ts +659 -0
- package/dist/index.d.cts +3 -658
- package/dist/index.d.ts +3 -658
- package/dist/react.cjs +1999 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +332 -0
- package/dist/react.d.ts +332 -0
- package/dist/react.js +1990 -0
- package/dist/react.js.map +1 -0
- package/package.json +18 -1
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { b as EkuboClientConfig, E as EkuboClient, S as SwapQuote, s as SwapCallsResult, A as ApiTokenInfo, O as OverviewStats, P as PairStats, l as PriceDataPoint } from './client-DPSUVYSv.cjs';
|
|
4
|
+
|
|
5
|
+
interface EkuboProviderProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Client configuration */
|
|
8
|
+
config?: EkuboClientConfig;
|
|
9
|
+
/** Pre-created client instance (alternative to config) */
|
|
10
|
+
client?: EkuboClient;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provider component for EkuboClient
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { EkuboProvider } from '@provable-games/ekubo-sdk/react';
|
|
18
|
+
*
|
|
19
|
+
* function App() {
|
|
20
|
+
* return (
|
|
21
|
+
* <EkuboProvider config={{ chain: 'mainnet' }}>
|
|
22
|
+
* <YourApp />
|
|
23
|
+
* </EkuboProvider>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function EkuboProvider({ children, config, client: providedClient, }: EkuboProviderProps): react_jsx_runtime.JSX.Element;
|
|
29
|
+
/**
|
|
30
|
+
* Hook to access the EkuboClient from context
|
|
31
|
+
*
|
|
32
|
+
* @throws Error if used outside of EkuboProvider
|
|
33
|
+
*/
|
|
34
|
+
declare function useEkuboClient(): EkuboClient;
|
|
35
|
+
/**
|
|
36
|
+
* Hook to optionally access the EkuboClient from context
|
|
37
|
+
* Returns null if used outside of EkuboProvider
|
|
38
|
+
*/
|
|
39
|
+
declare function useOptionalEkuboClient(): EkuboClient | null;
|
|
40
|
+
|
|
41
|
+
interface UseEkuboSwapState {
|
|
42
|
+
/** Current swap quote */
|
|
43
|
+
quote: SwapQuote | null;
|
|
44
|
+
/** Whether a quote is being fetched */
|
|
45
|
+
loading: boolean;
|
|
46
|
+
/** Error from the last quote fetch */
|
|
47
|
+
error: Error | null;
|
|
48
|
+
/** Price impact percentage */
|
|
49
|
+
priceImpact: number | null;
|
|
50
|
+
/** Whether there's insufficient liquidity for this swap */
|
|
51
|
+
insufficientLiquidity: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface UseEkuboSwapResult {
|
|
54
|
+
/** Current state */
|
|
55
|
+
state: UseEkuboSwapState;
|
|
56
|
+
/** Generate swap calls from the current quote */
|
|
57
|
+
generateCalls: (slippagePercent?: bigint, minimumReceived?: bigint) => SwapCallsResult | null;
|
|
58
|
+
/** Manually trigger a quote refetch */
|
|
59
|
+
refetch: () => void;
|
|
60
|
+
}
|
|
61
|
+
interface UseEkuboSwapProps {
|
|
62
|
+
/** Token being sold (address or symbol) */
|
|
63
|
+
sellToken: string | null;
|
|
64
|
+
/** Token being bought (address or symbol) */
|
|
65
|
+
buyToken: string | null;
|
|
66
|
+
/** Amount to swap (positive for exact input, negative for exact output) */
|
|
67
|
+
amount: bigint;
|
|
68
|
+
/** Whether to enable quote polling (default: true when tokens are valid) */
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
/** Polling interval in ms (default: 5000) */
|
|
71
|
+
pollingInterval?: number;
|
|
72
|
+
/** Default slippage percent (default: 5n = 5%) */
|
|
73
|
+
defaultSlippagePercent?: bigint;
|
|
74
|
+
/** Client config (optional if using EkuboProvider) */
|
|
75
|
+
config?: EkuboClientConfig;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook for fetching swap quotes with automatic polling
|
|
79
|
+
*
|
|
80
|
+
* Uses EkuboProvider client if available, otherwise creates a singleton client.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { useEkuboSwap } from '@provable-games/ekubo-sdk/react';
|
|
85
|
+
*
|
|
86
|
+
* function SwapForm() {
|
|
87
|
+
* const { state, generateCalls, refetch } = useEkuboSwap({
|
|
88
|
+
* sellToken: 'ETH',
|
|
89
|
+
* buyToken: 'USDC',
|
|
90
|
+
* amount: 1000000000000000000n, // 1 ETH
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* if (state.loading) return <div>Loading quote...</div>;
|
|
94
|
+
* if (state.error) return <div>Error: {state.error.message}</div>;
|
|
95
|
+
* if (state.insufficientLiquidity) return <div>Insufficient liquidity</div>;
|
|
96
|
+
*
|
|
97
|
+
* const handleSwap = () => {
|
|
98
|
+
* const calls = generateCalls(5n); // 5% slippage
|
|
99
|
+
* if (calls) {
|
|
100
|
+
* // Execute calls with your wallet
|
|
101
|
+
* }
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* return (
|
|
105
|
+
* <div>
|
|
106
|
+
* <p>You will receive: {state.quote?.total}</p>
|
|
107
|
+
* <button onClick={handleSwap}>Swap</button>
|
|
108
|
+
* </div>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function useEkuboSwap({ sellToken, buyToken, amount, enabled, pollingInterval, defaultSlippagePercent, config, }: UseEkuboSwapProps): UseEkuboSwapResult;
|
|
114
|
+
|
|
115
|
+
interface TokenPrices {
|
|
116
|
+
[address: string]: number | undefined;
|
|
117
|
+
}
|
|
118
|
+
interface UseEkuboPricesResult {
|
|
119
|
+
/** Map of token addresses to USD prices */
|
|
120
|
+
prices: TokenPrices;
|
|
121
|
+
/** Whether any prices are still loading */
|
|
122
|
+
isLoading: boolean;
|
|
123
|
+
/** Check if a specific token is still loading */
|
|
124
|
+
isTokenLoading: (tokenAddress: string) => boolean;
|
|
125
|
+
/** Check if a specific token had an error */
|
|
126
|
+
hasTokenError: (tokenAddress: string) => boolean;
|
|
127
|
+
/** Check if a token has a valid price (loaded, no error) */
|
|
128
|
+
isTokenAvailable: (tokenAddress: string) => boolean;
|
|
129
|
+
/** Get a token's price (returns undefined if not available) */
|
|
130
|
+
getPrice: (tokenAddress: string) => number | undefined;
|
|
131
|
+
/** Manually refetch all prices */
|
|
132
|
+
refetch: () => void;
|
|
133
|
+
}
|
|
134
|
+
interface UseEkuboPricesProps {
|
|
135
|
+
/** Array of token addresses to fetch prices for */
|
|
136
|
+
tokens: string[];
|
|
137
|
+
/** Timeout for each price fetch in ms (default: 10000) */
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
/** Client config (optional if using EkuboProvider) */
|
|
140
|
+
config?: EkuboClientConfig;
|
|
141
|
+
/** Whether to enable price fetching (default: true) */
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
/** Standard amount for price calculation (default: 1e18 - 1 token with 18 decimals) */
|
|
144
|
+
standardAmount?: bigint;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Hook for fetching USD prices for multiple tokens
|
|
148
|
+
*
|
|
149
|
+
* Uses EkuboProvider client if available, otherwise creates a singleton client.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```tsx
|
|
153
|
+
* import { useEkuboPrices } from '@provable-games/ekubo-sdk/react';
|
|
154
|
+
*
|
|
155
|
+
* function TokenPrices() {
|
|
156
|
+
* const {
|
|
157
|
+
* prices,
|
|
158
|
+
* isLoading,
|
|
159
|
+
* getPrice,
|
|
160
|
+
* isTokenAvailable
|
|
161
|
+
* } = useEkuboPrices({
|
|
162
|
+
* tokens: [ETH_ADDRESS, STRK_ADDRESS]
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* if (isLoading) return <div>Loading prices...</div>;
|
|
166
|
+
*
|
|
167
|
+
* return (
|
|
168
|
+
* <div>
|
|
169
|
+
* <p>ETH: ${isTokenAvailable(ETH_ADDRESS) ? getPrice(ETH_ADDRESS) : 'N/A'}</p>
|
|
170
|
+
* <p>STRK: ${isTokenAvailable(STRK_ADDRESS) ? getPrice(STRK_ADDRESS) : 'N/A'}</p>
|
|
171
|
+
* </div>
|
|
172
|
+
* );
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function useEkuboPrices({ tokens, timeoutMs, config, enabled, standardAmount, }: UseEkuboPricesProps): UseEkuboPricesResult;
|
|
177
|
+
|
|
178
|
+
interface UseEkuboTokensResult {
|
|
179
|
+
/** Array of tokens from the API */
|
|
180
|
+
tokens: ApiTokenInfo[];
|
|
181
|
+
/** Whether tokens are loading */
|
|
182
|
+
isLoading: boolean;
|
|
183
|
+
/** Error from fetching tokens */
|
|
184
|
+
error: Error | null;
|
|
185
|
+
/** Manually refetch tokens */
|
|
186
|
+
refetch: () => void;
|
|
187
|
+
/** Get a token by address */
|
|
188
|
+
getToken: (address: string) => ApiTokenInfo | undefined;
|
|
189
|
+
/** Get a token by symbol */
|
|
190
|
+
getTokenBySymbol: (symbol: string) => ApiTokenInfo | undefined;
|
|
191
|
+
}
|
|
192
|
+
interface UseEkuboTokensProps {
|
|
193
|
+
/** Client config (optional if using EkuboProvider) */
|
|
194
|
+
config?: EkuboClientConfig;
|
|
195
|
+
/** Whether to enable token fetching (default: true) */
|
|
196
|
+
enabled?: boolean;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Hook for fetching the list of available tokens from Ekubo API
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* import { useEkuboTokens } from '@provable-games/ekubo-sdk/react';
|
|
204
|
+
*
|
|
205
|
+
* function TokenList() {
|
|
206
|
+
* const { tokens, isLoading, getTokenBySymbol } = useEkuboTokens();
|
|
207
|
+
*
|
|
208
|
+
* if (isLoading) return <div>Loading tokens...</div>;
|
|
209
|
+
*
|
|
210
|
+
* const eth = getTokenBySymbol('ETH');
|
|
211
|
+
*
|
|
212
|
+
* return (
|
|
213
|
+
* <ul>
|
|
214
|
+
* {tokens.map(token => (
|
|
215
|
+
* <li key={token.address}>{token.symbol}: {token.name}</li>
|
|
216
|
+
* ))}
|
|
217
|
+
* </ul>
|
|
218
|
+
* );
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function useEkuboTokens({ config, enabled, }?: UseEkuboTokensProps): UseEkuboTokensResult;
|
|
223
|
+
|
|
224
|
+
interface UseEkuboStatsResult {
|
|
225
|
+
/** Protocol TVL statistics */
|
|
226
|
+
tvl: OverviewStats | null;
|
|
227
|
+
/** Protocol volume statistics */
|
|
228
|
+
volume: OverviewStats | null;
|
|
229
|
+
/** Top trading pairs */
|
|
230
|
+
topPairs: PairStats[];
|
|
231
|
+
/** Whether stats are loading */
|
|
232
|
+
isLoading: boolean;
|
|
233
|
+
/** Error from fetching stats */
|
|
234
|
+
error: Error | null;
|
|
235
|
+
/** Manually refetch stats */
|
|
236
|
+
refetch: () => void;
|
|
237
|
+
}
|
|
238
|
+
interface UseEkuboStatsProps {
|
|
239
|
+
/** Client config (optional if using EkuboProvider) */
|
|
240
|
+
config?: EkuboClientConfig;
|
|
241
|
+
/** Whether to enable stats fetching (default: true) */
|
|
242
|
+
enabled?: boolean;
|
|
243
|
+
/** Whether to fetch TVL (default: true) */
|
|
244
|
+
fetchTvl?: boolean;
|
|
245
|
+
/** Whether to fetch volume (default: true) */
|
|
246
|
+
fetchVolume?: boolean;
|
|
247
|
+
/** Whether to fetch top pairs (default: true) */
|
|
248
|
+
fetchTopPairs?: boolean;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Hook for fetching Ekubo protocol statistics (TVL, volume, top pairs)
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```tsx
|
|
255
|
+
* import { useEkuboStats } from '@provable-games/ekubo-sdk/react';
|
|
256
|
+
*
|
|
257
|
+
* function ProtocolStats() {
|
|
258
|
+
* const { tvl, volume, topPairs, isLoading } = useEkuboStats();
|
|
259
|
+
*
|
|
260
|
+
* if (isLoading) return <div>Loading stats...</div>;
|
|
261
|
+
*
|
|
262
|
+
* return (
|
|
263
|
+
* <div>
|
|
264
|
+
* <h2>Protocol Statistics</h2>
|
|
265
|
+
* {tvl && <p>TVL: ${tvl.total.toLocaleString()}</p>}
|
|
266
|
+
* {volume && <p>24h Volume: ${volume.total.toLocaleString()}</p>}
|
|
267
|
+
* <h3>Top Pairs</h3>
|
|
268
|
+
* <ul>
|
|
269
|
+
* {topPairs.slice(0, 5).map((pair, i) => (
|
|
270
|
+
* <li key={i}>{pair.token0Symbol}/{pair.token1Symbol}</li>
|
|
271
|
+
* ))}
|
|
272
|
+
* </ul>
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function useEkuboStats({ config, enabled, fetchTvl, fetchVolume, fetchTopPairs, }?: UseEkuboStatsProps): UseEkuboStatsResult;
|
|
279
|
+
|
|
280
|
+
interface UseEkuboPriceHistoryResult {
|
|
281
|
+
/** Array of price data points */
|
|
282
|
+
data: PriceDataPoint[];
|
|
283
|
+
/** Whether price history is loading */
|
|
284
|
+
isLoading: boolean;
|
|
285
|
+
/** Error from fetching price history */
|
|
286
|
+
error: Error | null;
|
|
287
|
+
/** Manually refetch price history */
|
|
288
|
+
refetch: () => void;
|
|
289
|
+
}
|
|
290
|
+
interface UseEkuboPriceHistoryProps {
|
|
291
|
+
/** Token to get price for (address or symbol) */
|
|
292
|
+
token: string;
|
|
293
|
+
/** Quote token (address or symbol, e.g., 'USDC') */
|
|
294
|
+
quoteToken: string;
|
|
295
|
+
/** Time interval in seconds (default: 7000) */
|
|
296
|
+
interval?: number;
|
|
297
|
+
/** Client config (optional if using EkuboProvider) */
|
|
298
|
+
config?: EkuboClientConfig;
|
|
299
|
+
/** Whether to enable price history fetching (default: true) */
|
|
300
|
+
enabled?: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Hook for fetching historical price data for a token pair
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```tsx
|
|
307
|
+
* import { useEkuboPriceHistory } from '@provable-games/ekubo-sdk/react';
|
|
308
|
+
*
|
|
309
|
+
* function PriceChart() {
|
|
310
|
+
* const { data, isLoading } = useEkuboPriceHistory({
|
|
311
|
+
* token: 'ETH',
|
|
312
|
+
* quoteToken: 'USDC',
|
|
313
|
+
* interval: 3600, // 1 hour intervals
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* if (isLoading) return <div>Loading price history...</div>;
|
|
317
|
+
*
|
|
318
|
+
* return (
|
|
319
|
+
* <div>
|
|
320
|
+
* {data.map((point) => (
|
|
321
|
+
* <div key={point.timestamp}>
|
|
322
|
+
* {new Date(point.timestamp * 1000).toLocaleDateString()}: ${point.price}
|
|
323
|
+
* </div>
|
|
324
|
+
* ))}
|
|
325
|
+
* </div>
|
|
326
|
+
* );
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
declare function useEkuboPriceHistory({ token, quoteToken, interval, config, enabled, }: UseEkuboPriceHistoryProps): UseEkuboPriceHistoryResult;
|
|
331
|
+
|
|
332
|
+
export { EkuboProvider, type EkuboProviderProps, type TokenPrices, type UseEkuboPriceHistoryProps, type UseEkuboPriceHistoryResult, type UseEkuboPricesProps, type UseEkuboPricesResult, type UseEkuboStatsProps, type UseEkuboStatsResult, type UseEkuboSwapProps, type UseEkuboSwapResult, type UseEkuboSwapState, type UseEkuboTokensProps, type UseEkuboTokensResult, useEkuboClient, useEkuboPriceHistory, useEkuboPrices, useEkuboStats, useEkuboSwap, useEkuboTokens, useOptionalEkuboClient };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { b as EkuboClientConfig, E as EkuboClient, S as SwapQuote, s as SwapCallsResult, A as ApiTokenInfo, O as OverviewStats, P as PairStats, l as PriceDataPoint } from './client-DPSUVYSv.js';
|
|
4
|
+
|
|
5
|
+
interface EkuboProviderProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Client configuration */
|
|
8
|
+
config?: EkuboClientConfig;
|
|
9
|
+
/** Pre-created client instance (alternative to config) */
|
|
10
|
+
client?: EkuboClient;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Provider component for EkuboClient
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { EkuboProvider } from '@provable-games/ekubo-sdk/react';
|
|
18
|
+
*
|
|
19
|
+
* function App() {
|
|
20
|
+
* return (
|
|
21
|
+
* <EkuboProvider config={{ chain: 'mainnet' }}>
|
|
22
|
+
* <YourApp />
|
|
23
|
+
* </EkuboProvider>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function EkuboProvider({ children, config, client: providedClient, }: EkuboProviderProps): react_jsx_runtime.JSX.Element;
|
|
29
|
+
/**
|
|
30
|
+
* Hook to access the EkuboClient from context
|
|
31
|
+
*
|
|
32
|
+
* @throws Error if used outside of EkuboProvider
|
|
33
|
+
*/
|
|
34
|
+
declare function useEkuboClient(): EkuboClient;
|
|
35
|
+
/**
|
|
36
|
+
* Hook to optionally access the EkuboClient from context
|
|
37
|
+
* Returns null if used outside of EkuboProvider
|
|
38
|
+
*/
|
|
39
|
+
declare function useOptionalEkuboClient(): EkuboClient | null;
|
|
40
|
+
|
|
41
|
+
interface UseEkuboSwapState {
|
|
42
|
+
/** Current swap quote */
|
|
43
|
+
quote: SwapQuote | null;
|
|
44
|
+
/** Whether a quote is being fetched */
|
|
45
|
+
loading: boolean;
|
|
46
|
+
/** Error from the last quote fetch */
|
|
47
|
+
error: Error | null;
|
|
48
|
+
/** Price impact percentage */
|
|
49
|
+
priceImpact: number | null;
|
|
50
|
+
/** Whether there's insufficient liquidity for this swap */
|
|
51
|
+
insufficientLiquidity: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface UseEkuboSwapResult {
|
|
54
|
+
/** Current state */
|
|
55
|
+
state: UseEkuboSwapState;
|
|
56
|
+
/** Generate swap calls from the current quote */
|
|
57
|
+
generateCalls: (slippagePercent?: bigint, minimumReceived?: bigint) => SwapCallsResult | null;
|
|
58
|
+
/** Manually trigger a quote refetch */
|
|
59
|
+
refetch: () => void;
|
|
60
|
+
}
|
|
61
|
+
interface UseEkuboSwapProps {
|
|
62
|
+
/** Token being sold (address or symbol) */
|
|
63
|
+
sellToken: string | null;
|
|
64
|
+
/** Token being bought (address or symbol) */
|
|
65
|
+
buyToken: string | null;
|
|
66
|
+
/** Amount to swap (positive for exact input, negative for exact output) */
|
|
67
|
+
amount: bigint;
|
|
68
|
+
/** Whether to enable quote polling (default: true when tokens are valid) */
|
|
69
|
+
enabled?: boolean;
|
|
70
|
+
/** Polling interval in ms (default: 5000) */
|
|
71
|
+
pollingInterval?: number;
|
|
72
|
+
/** Default slippage percent (default: 5n = 5%) */
|
|
73
|
+
defaultSlippagePercent?: bigint;
|
|
74
|
+
/** Client config (optional if using EkuboProvider) */
|
|
75
|
+
config?: EkuboClientConfig;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook for fetching swap quotes with automatic polling
|
|
79
|
+
*
|
|
80
|
+
* Uses EkuboProvider client if available, otherwise creates a singleton client.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { useEkuboSwap } from '@provable-games/ekubo-sdk/react';
|
|
85
|
+
*
|
|
86
|
+
* function SwapForm() {
|
|
87
|
+
* const { state, generateCalls, refetch } = useEkuboSwap({
|
|
88
|
+
* sellToken: 'ETH',
|
|
89
|
+
* buyToken: 'USDC',
|
|
90
|
+
* amount: 1000000000000000000n, // 1 ETH
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* if (state.loading) return <div>Loading quote...</div>;
|
|
94
|
+
* if (state.error) return <div>Error: {state.error.message}</div>;
|
|
95
|
+
* if (state.insufficientLiquidity) return <div>Insufficient liquidity</div>;
|
|
96
|
+
*
|
|
97
|
+
* const handleSwap = () => {
|
|
98
|
+
* const calls = generateCalls(5n); // 5% slippage
|
|
99
|
+
* if (calls) {
|
|
100
|
+
* // Execute calls with your wallet
|
|
101
|
+
* }
|
|
102
|
+
* };
|
|
103
|
+
*
|
|
104
|
+
* return (
|
|
105
|
+
* <div>
|
|
106
|
+
* <p>You will receive: {state.quote?.total}</p>
|
|
107
|
+
* <button onClick={handleSwap}>Swap</button>
|
|
108
|
+
* </div>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
declare function useEkuboSwap({ sellToken, buyToken, amount, enabled, pollingInterval, defaultSlippagePercent, config, }: UseEkuboSwapProps): UseEkuboSwapResult;
|
|
114
|
+
|
|
115
|
+
interface TokenPrices {
|
|
116
|
+
[address: string]: number | undefined;
|
|
117
|
+
}
|
|
118
|
+
interface UseEkuboPricesResult {
|
|
119
|
+
/** Map of token addresses to USD prices */
|
|
120
|
+
prices: TokenPrices;
|
|
121
|
+
/** Whether any prices are still loading */
|
|
122
|
+
isLoading: boolean;
|
|
123
|
+
/** Check if a specific token is still loading */
|
|
124
|
+
isTokenLoading: (tokenAddress: string) => boolean;
|
|
125
|
+
/** Check if a specific token had an error */
|
|
126
|
+
hasTokenError: (tokenAddress: string) => boolean;
|
|
127
|
+
/** Check if a token has a valid price (loaded, no error) */
|
|
128
|
+
isTokenAvailable: (tokenAddress: string) => boolean;
|
|
129
|
+
/** Get a token's price (returns undefined if not available) */
|
|
130
|
+
getPrice: (tokenAddress: string) => number | undefined;
|
|
131
|
+
/** Manually refetch all prices */
|
|
132
|
+
refetch: () => void;
|
|
133
|
+
}
|
|
134
|
+
interface UseEkuboPricesProps {
|
|
135
|
+
/** Array of token addresses to fetch prices for */
|
|
136
|
+
tokens: string[];
|
|
137
|
+
/** Timeout for each price fetch in ms (default: 10000) */
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
/** Client config (optional if using EkuboProvider) */
|
|
140
|
+
config?: EkuboClientConfig;
|
|
141
|
+
/** Whether to enable price fetching (default: true) */
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
/** Standard amount for price calculation (default: 1e18 - 1 token with 18 decimals) */
|
|
144
|
+
standardAmount?: bigint;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Hook for fetching USD prices for multiple tokens
|
|
148
|
+
*
|
|
149
|
+
* Uses EkuboProvider client if available, otherwise creates a singleton client.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```tsx
|
|
153
|
+
* import { useEkuboPrices } from '@provable-games/ekubo-sdk/react';
|
|
154
|
+
*
|
|
155
|
+
* function TokenPrices() {
|
|
156
|
+
* const {
|
|
157
|
+
* prices,
|
|
158
|
+
* isLoading,
|
|
159
|
+
* getPrice,
|
|
160
|
+
* isTokenAvailable
|
|
161
|
+
* } = useEkuboPrices({
|
|
162
|
+
* tokens: [ETH_ADDRESS, STRK_ADDRESS]
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* if (isLoading) return <div>Loading prices...</div>;
|
|
166
|
+
*
|
|
167
|
+
* return (
|
|
168
|
+
* <div>
|
|
169
|
+
* <p>ETH: ${isTokenAvailable(ETH_ADDRESS) ? getPrice(ETH_ADDRESS) : 'N/A'}</p>
|
|
170
|
+
* <p>STRK: ${isTokenAvailable(STRK_ADDRESS) ? getPrice(STRK_ADDRESS) : 'N/A'}</p>
|
|
171
|
+
* </div>
|
|
172
|
+
* );
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function useEkuboPrices({ tokens, timeoutMs, config, enabled, standardAmount, }: UseEkuboPricesProps): UseEkuboPricesResult;
|
|
177
|
+
|
|
178
|
+
interface UseEkuboTokensResult {
|
|
179
|
+
/** Array of tokens from the API */
|
|
180
|
+
tokens: ApiTokenInfo[];
|
|
181
|
+
/** Whether tokens are loading */
|
|
182
|
+
isLoading: boolean;
|
|
183
|
+
/** Error from fetching tokens */
|
|
184
|
+
error: Error | null;
|
|
185
|
+
/** Manually refetch tokens */
|
|
186
|
+
refetch: () => void;
|
|
187
|
+
/** Get a token by address */
|
|
188
|
+
getToken: (address: string) => ApiTokenInfo | undefined;
|
|
189
|
+
/** Get a token by symbol */
|
|
190
|
+
getTokenBySymbol: (symbol: string) => ApiTokenInfo | undefined;
|
|
191
|
+
}
|
|
192
|
+
interface UseEkuboTokensProps {
|
|
193
|
+
/** Client config (optional if using EkuboProvider) */
|
|
194
|
+
config?: EkuboClientConfig;
|
|
195
|
+
/** Whether to enable token fetching (default: true) */
|
|
196
|
+
enabled?: boolean;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Hook for fetching the list of available tokens from Ekubo API
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* import { useEkuboTokens } from '@provable-games/ekubo-sdk/react';
|
|
204
|
+
*
|
|
205
|
+
* function TokenList() {
|
|
206
|
+
* const { tokens, isLoading, getTokenBySymbol } = useEkuboTokens();
|
|
207
|
+
*
|
|
208
|
+
* if (isLoading) return <div>Loading tokens...</div>;
|
|
209
|
+
*
|
|
210
|
+
* const eth = getTokenBySymbol('ETH');
|
|
211
|
+
*
|
|
212
|
+
* return (
|
|
213
|
+
* <ul>
|
|
214
|
+
* {tokens.map(token => (
|
|
215
|
+
* <li key={token.address}>{token.symbol}: {token.name}</li>
|
|
216
|
+
* ))}
|
|
217
|
+
* </ul>
|
|
218
|
+
* );
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function useEkuboTokens({ config, enabled, }?: UseEkuboTokensProps): UseEkuboTokensResult;
|
|
223
|
+
|
|
224
|
+
interface UseEkuboStatsResult {
|
|
225
|
+
/** Protocol TVL statistics */
|
|
226
|
+
tvl: OverviewStats | null;
|
|
227
|
+
/** Protocol volume statistics */
|
|
228
|
+
volume: OverviewStats | null;
|
|
229
|
+
/** Top trading pairs */
|
|
230
|
+
topPairs: PairStats[];
|
|
231
|
+
/** Whether stats are loading */
|
|
232
|
+
isLoading: boolean;
|
|
233
|
+
/** Error from fetching stats */
|
|
234
|
+
error: Error | null;
|
|
235
|
+
/** Manually refetch stats */
|
|
236
|
+
refetch: () => void;
|
|
237
|
+
}
|
|
238
|
+
interface UseEkuboStatsProps {
|
|
239
|
+
/** Client config (optional if using EkuboProvider) */
|
|
240
|
+
config?: EkuboClientConfig;
|
|
241
|
+
/** Whether to enable stats fetching (default: true) */
|
|
242
|
+
enabled?: boolean;
|
|
243
|
+
/** Whether to fetch TVL (default: true) */
|
|
244
|
+
fetchTvl?: boolean;
|
|
245
|
+
/** Whether to fetch volume (default: true) */
|
|
246
|
+
fetchVolume?: boolean;
|
|
247
|
+
/** Whether to fetch top pairs (default: true) */
|
|
248
|
+
fetchTopPairs?: boolean;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Hook for fetching Ekubo protocol statistics (TVL, volume, top pairs)
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```tsx
|
|
255
|
+
* import { useEkuboStats } from '@provable-games/ekubo-sdk/react';
|
|
256
|
+
*
|
|
257
|
+
* function ProtocolStats() {
|
|
258
|
+
* const { tvl, volume, topPairs, isLoading } = useEkuboStats();
|
|
259
|
+
*
|
|
260
|
+
* if (isLoading) return <div>Loading stats...</div>;
|
|
261
|
+
*
|
|
262
|
+
* return (
|
|
263
|
+
* <div>
|
|
264
|
+
* <h2>Protocol Statistics</h2>
|
|
265
|
+
* {tvl && <p>TVL: ${tvl.total.toLocaleString()}</p>}
|
|
266
|
+
* {volume && <p>24h Volume: ${volume.total.toLocaleString()}</p>}
|
|
267
|
+
* <h3>Top Pairs</h3>
|
|
268
|
+
* <ul>
|
|
269
|
+
* {topPairs.slice(0, 5).map((pair, i) => (
|
|
270
|
+
* <li key={i}>{pair.token0Symbol}/{pair.token1Symbol}</li>
|
|
271
|
+
* ))}
|
|
272
|
+
* </ul>
|
|
273
|
+
* </div>
|
|
274
|
+
* );
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function useEkuboStats({ config, enabled, fetchTvl, fetchVolume, fetchTopPairs, }?: UseEkuboStatsProps): UseEkuboStatsResult;
|
|
279
|
+
|
|
280
|
+
interface UseEkuboPriceHistoryResult {
|
|
281
|
+
/** Array of price data points */
|
|
282
|
+
data: PriceDataPoint[];
|
|
283
|
+
/** Whether price history is loading */
|
|
284
|
+
isLoading: boolean;
|
|
285
|
+
/** Error from fetching price history */
|
|
286
|
+
error: Error | null;
|
|
287
|
+
/** Manually refetch price history */
|
|
288
|
+
refetch: () => void;
|
|
289
|
+
}
|
|
290
|
+
interface UseEkuboPriceHistoryProps {
|
|
291
|
+
/** Token to get price for (address or symbol) */
|
|
292
|
+
token: string;
|
|
293
|
+
/** Quote token (address or symbol, e.g., 'USDC') */
|
|
294
|
+
quoteToken: string;
|
|
295
|
+
/** Time interval in seconds (default: 7000) */
|
|
296
|
+
interval?: number;
|
|
297
|
+
/** Client config (optional if using EkuboProvider) */
|
|
298
|
+
config?: EkuboClientConfig;
|
|
299
|
+
/** Whether to enable price history fetching (default: true) */
|
|
300
|
+
enabled?: boolean;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Hook for fetching historical price data for a token pair
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```tsx
|
|
307
|
+
* import { useEkuboPriceHistory } from '@provable-games/ekubo-sdk/react';
|
|
308
|
+
*
|
|
309
|
+
* function PriceChart() {
|
|
310
|
+
* const { data, isLoading } = useEkuboPriceHistory({
|
|
311
|
+
* token: 'ETH',
|
|
312
|
+
* quoteToken: 'USDC',
|
|
313
|
+
* interval: 3600, // 1 hour intervals
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* if (isLoading) return <div>Loading price history...</div>;
|
|
317
|
+
*
|
|
318
|
+
* return (
|
|
319
|
+
* <div>
|
|
320
|
+
* {data.map((point) => (
|
|
321
|
+
* <div key={point.timestamp}>
|
|
322
|
+
* {new Date(point.timestamp * 1000).toLocaleDateString()}: ${point.price}
|
|
323
|
+
* </div>
|
|
324
|
+
* ))}
|
|
325
|
+
* </div>
|
|
326
|
+
* );
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
declare function useEkuboPriceHistory({ token, quoteToken, interval, config, enabled, }: UseEkuboPriceHistoryProps): UseEkuboPriceHistoryResult;
|
|
331
|
+
|
|
332
|
+
export { EkuboProvider, type EkuboProviderProps, type TokenPrices, type UseEkuboPriceHistoryProps, type UseEkuboPriceHistoryResult, type UseEkuboPricesProps, type UseEkuboPricesResult, type UseEkuboStatsProps, type UseEkuboStatsResult, type UseEkuboSwapProps, type UseEkuboSwapResult, type UseEkuboSwapState, type UseEkuboTokensProps, type UseEkuboTokensResult, useEkuboClient, useEkuboPriceHistory, useEkuboPrices, useEkuboStats, useEkuboSwap, useEkuboTokens, useOptionalEkuboClient };
|