@provable-games/ekubo-sdk 0.1.0 → 0.1.9

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 CHANGED
@@ -79,6 +79,191 @@ const { allCalls } = generateSwapCalls({
79
79
  });
80
80
  ```
81
81
 
82
+ ## React Hooks
83
+
84
+ The SDK provides React hooks for easy integration with React applications.
85
+
86
+ ```bash
87
+ npm install ekubo-sdk react
88
+ ```
89
+
90
+ ### EkuboProvider
91
+
92
+ Wrap your app with `EkuboProvider` to share a single client instance:
93
+
94
+ ```tsx
95
+ import { EkuboProvider } from '@provable-games/ekubo-sdk/react';
96
+
97
+ function App() {
98
+ return (
99
+ <EkuboProvider config={{ chain: 'mainnet' }}>
100
+ <YourApp />
101
+ </EkuboProvider>
102
+ );
103
+ }
104
+ ```
105
+
106
+ ### useEkuboSwap
107
+
108
+ Fetch swap quotes with automatic polling:
109
+
110
+ ```tsx
111
+ import { useEkuboSwap } from '@provable-games/ekubo-sdk/react';
112
+
113
+ function SwapForm() {
114
+ const { state, generateCalls, refetch } = useEkuboSwap({
115
+ sellToken: 'ETH',
116
+ buyToken: 'USDC',
117
+ amount: 1000000000000000000n, // 1 ETH
118
+ pollingInterval: 5000, // Poll every 5 seconds
119
+ });
120
+
121
+ if (state.loading) return <div>Loading quote...</div>;
122
+ if (state.error) return <div>Error: {state.error.message}</div>;
123
+ if (state.insufficientLiquidity) return <div>Insufficient liquidity</div>;
124
+
125
+ const handleSwap = () => {
126
+ const calls = generateCalls(5n); // 5% slippage
127
+ if (calls) {
128
+ // Execute calls with your wallet
129
+ }
130
+ };
131
+
132
+ return (
133
+ <div>
134
+ <p>You will receive: {state.quote?.total}</p>
135
+ <p>Price impact: {state.priceImpact}%</p>
136
+ <button onClick={handleSwap}>Swap</button>
137
+ </div>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### useEkuboPrices
143
+
144
+ Fetch USD prices for multiple tokens:
145
+
146
+ ```tsx
147
+ import { useEkuboPrices } from '@provable-games/ekubo-sdk/react';
148
+
149
+ const ETH_ADDRESS = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7';
150
+ const STRK_ADDRESS = '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d';
151
+
152
+ function TokenPrices() {
153
+ const { prices, isLoading, getPrice, isTokenAvailable } = useEkuboPrices({
154
+ tokens: [ETH_ADDRESS, STRK_ADDRESS],
155
+ });
156
+
157
+ if (isLoading) return <div>Loading prices...</div>;
158
+
159
+ return (
160
+ <div>
161
+ <p>ETH: ${isTokenAvailable(ETH_ADDRESS) ? getPrice(ETH_ADDRESS)?.toFixed(2) : 'N/A'}</p>
162
+ <p>STRK: ${isTokenAvailable(STRK_ADDRESS) ? getPrice(STRK_ADDRESS)?.toFixed(2) : 'N/A'}</p>
163
+ </div>
164
+ );
165
+ }
166
+ ```
167
+
168
+ ### useEkuboTokens
169
+
170
+ Fetch the list of available tokens:
171
+
172
+ ```tsx
173
+ import { useEkuboTokens } from '@provable-games/ekubo-sdk/react';
174
+
175
+ function TokenList() {
176
+ const { tokens, isLoading, getTokenBySymbol } = useEkuboTokens();
177
+
178
+ if (isLoading) return <div>Loading tokens...</div>;
179
+
180
+ const eth = getTokenBySymbol('ETH');
181
+
182
+ return (
183
+ <ul>
184
+ {tokens.map(token => (
185
+ <li key={token.address}>{token.symbol}: {token.name}</li>
186
+ ))}
187
+ </ul>
188
+ );
189
+ }
190
+ ```
191
+
192
+ ### useEkuboStats
193
+
194
+ Fetch protocol statistics:
195
+
196
+ ```tsx
197
+ import { useEkuboStats } from '@provable-games/ekubo-sdk/react';
198
+
199
+ function ProtocolStats() {
200
+ const { tvl, volume, topPairs, isLoading } = useEkuboStats();
201
+
202
+ if (isLoading) return <div>Loading stats...</div>;
203
+
204
+ return (
205
+ <div>
206
+ {tvl && <p>TVL: ${tvl.total.toLocaleString()}</p>}
207
+ {volume && <p>24h Volume: ${volume.total.toLocaleString()}</p>}
208
+ <h3>Top Pairs</h3>
209
+ <ul>
210
+ {topPairs.slice(0, 5).map((pair, i) => (
211
+ <li key={i}>{pair.token0Symbol}/{pair.token1Symbol}</li>
212
+ ))}
213
+ </ul>
214
+ </div>
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### useEkuboPriceHistory
220
+
221
+ Fetch historical price data:
222
+
223
+ ```tsx
224
+ import { useEkuboPriceHistory } from '@provable-games/ekubo-sdk/react';
225
+
226
+ function PriceChart() {
227
+ const { data, isLoading } = useEkuboPriceHistory({
228
+ token: 'ETH',
229
+ quoteToken: 'USDC',
230
+ interval: 3600, // 1 hour intervals
231
+ });
232
+
233
+ if (isLoading) return <div>Loading price history...</div>;
234
+
235
+ return (
236
+ <div>
237
+ {data.map((point) => (
238
+ <div key={point.timestamp}>
239
+ {new Date(point.timestamp * 1000).toLocaleDateString()}: ${point.price}
240
+ </div>
241
+ ))}
242
+ </div>
243
+ );
244
+ }
245
+ ```
246
+
247
+ ### Using Hooks Without Provider
248
+
249
+ Hooks work without `EkuboProvider` by creating a singleton client:
250
+
251
+ ```tsx
252
+ import { useEkuboSwap } from '@provable-games/ekubo-sdk/react';
253
+
254
+ function SwapForm() {
255
+ // Works without EkuboProvider - uses default mainnet config
256
+ const { state } = useEkuboSwap({
257
+ sellToken: 'ETH',
258
+ buyToken: 'USDC',
259
+ amount: 1000000000000000000n,
260
+ config: { chain: 'mainnet' }, // Optional: customize the singleton
261
+ });
262
+
263
+ // ...
264
+ }
265
+ ```
266
+
82
267
  ## Quote Polling
83
268
 
84
269
  For real-time quote updates:
@@ -308,6 +493,20 @@ try {
308
493
  | `prepareSwapCalls(params)` | Generate calls with approval |
309
494
  | `resolveToken(identifier, registry?)` | Resolve token identifier |
310
495
 
496
+ ### React Hooks
497
+
498
+ Import from `@provable-games/ekubo-sdk/react`:
499
+
500
+ | Hook | Description |
501
+ |------|-------------|
502
+ | `EkuboProvider` | Context provider for sharing client |
503
+ | `useEkuboClient()` | Access the client from context |
504
+ | `useEkuboSwap(props)` | Swap quotes with polling |
505
+ | `useEkuboPrices(props)` | USD prices for multiple tokens |
506
+ | `useEkuboTokens(props)` | Fetch available tokens |
507
+ | `useEkuboStats(props)` | Protocol TVL, volume, top pairs |
508
+ | `useEkuboPriceHistory(props)` | Historical price data |
509
+
311
510
  ## Chain IDs
312
511
 
313
512
  ```typescript