@sudobility/heavymath_indexer_client 0.0.3
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/LICENSE.md +80 -0
- package/README.md +380 -0
- package/dist/business/index.d.ts +2 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/index.js +2 -0
- package/dist/business/index.js.map +1 -0
- package/dist/business/indexer-service.d.ts +40 -0
- package/dist/business/indexer-service.d.ts.map +1 -0
- package/dist/business/indexer-service.js +201 -0
- package/dist/business/indexer-service.js.map +1 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useDealers.d.ts +16 -0
- package/dist/hooks/useDealers.d.ts.map +1 -0
- package/dist/hooks/useDealers.js +113 -0
- package/dist/hooks/useDealers.js.map +1 -0
- package/dist/hooks/useFavorites.d.ts +31 -0
- package/dist/hooks/useFavorites.d.ts.map +1 -0
- package/dist/hooks/useFavorites.js +140 -0
- package/dist/hooks/useFavorites.js.map +1 -0
- package/dist/hooks/useMarkets.d.ts +16 -0
- package/dist/hooks/useMarkets.d.ts.map +1 -0
- package/dist/hooks/useMarkets.js +73 -0
- package/dist/hooks/useMarkets.js.map +1 -0
- package/dist/hooks/useOracle.d.ts +9 -0
- package/dist/hooks/useOracle.d.ts.map +1 -0
- package/dist/hooks/useOracle.js +45 -0
- package/dist/hooks/useOracle.js.map +1 -0
- package/dist/hooks/usePredictions.d.ts +15 -0
- package/dist/hooks/usePredictions.d.ts.map +1 -0
- package/dist/hooks/usePredictions.js +58 -0
- package/dist/hooks/usePredictions.js.map +1 -0
- package/dist/hooks/useSSE.d.ts +29 -0
- package/dist/hooks/useSSE.d.ts.map +1 -0
- package/dist/hooks/useSSE.js +217 -0
- package/dist/hooks/useSSE.js.map +1 -0
- package/dist/hooks/useStats.d.ts +6 -0
- package/dist/hooks/useStats.d.ts.map +1 -0
- package/dist/hooks/useStats.js +24 -0
- package/dist/hooks/useStats.js.map +1 -0
- package/dist/hooks/useWithdrawals.d.ts +8 -0
- package/dist/hooks/useWithdrawals.d.ts.map +1 -0
- package/dist/hooks/useWithdrawals.js +35 -0
- package/dist/hooks/useWithdrawals.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/network/IndexerClient.d.ts +26 -0
- package/dist/network/IndexerClient.d.ts.map +1 -0
- package/dist/network/IndexerClient.js +215 -0
- package/dist/network/IndexerClient.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +2 -0
- package/dist/network/index.js.map +1 -0
- package/dist/stores/favorites-store.d.ts +35 -0
- package/dist/stores/favorites-store.d.ts.map +1 -0
- package/dist/stores/favorites-store.js +165 -0
- package/dist/stores/favorites-store.js.map +1 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +2 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/types.d.ts +118 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +77 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of
|
|
4
|
+
MariaDB Corporation Ab.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Sudobility Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: HeavyMath. The Licensed Work is (C) 2025 Sudobility Inc.
|
|
13
|
+
|
|
14
|
+
Additional Use Grant: None
|
|
15
|
+
|
|
16
|
+
Change Date: 2029-11-13
|
|
17
|
+
|
|
18
|
+
Change License: GNU General Public License v3.0 or later
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
Terms
|
|
23
|
+
|
|
24
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production
|
|
25
|
+
use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
|
26
|
+
|
|
27
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific
|
|
28
|
+
version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the
|
|
29
|
+
terms of the Change License, and the rights granted in the paragraph above terminate.
|
|
30
|
+
|
|
31
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License,
|
|
32
|
+
you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must
|
|
33
|
+
refrain from using the Licensed Work.
|
|
34
|
+
|
|
35
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this
|
|
36
|
+
License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each
|
|
37
|
+
version of the Licensed Work released by Licensor.
|
|
38
|
+
|
|
39
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the
|
|
40
|
+
Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply
|
|
41
|
+
to your use of that work.
|
|
42
|
+
|
|
43
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License
|
|
44
|
+
for the current and all other versions of the Licensed Work.
|
|
45
|
+
|
|
46
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may
|
|
47
|
+
use a trademark or logo of Licensor as expressly required by this License).
|
|
48
|
+
|
|
49
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS
|
|
50
|
+
ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
51
|
+
FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
|
52
|
+
|
|
53
|
+
MariaDB hereby grants you permission to use this License's text to license your works, and to refer to it using the
|
|
54
|
+
trademark "Business Source License", as long as you comply with the Covenants of Licensor below.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
Covenants of Licensor
|
|
59
|
+
|
|
60
|
+
In consideration of the right to use this License's text and the "Business Source License" name and trademark, Licensor
|
|
61
|
+
covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
|
62
|
+
|
|
63
|
+
1. To specify as the Change License the GPL Version 3.0 or any later version, or a license that is compatible with GPL
|
|
64
|
+
Version 3.0 or a later version, where "compatible" means that software provided under the Change License can be
|
|
65
|
+
included in a program with software provided under GPL Version 3.0 or a later version. Licensor may specify
|
|
66
|
+
additional Change Licenses without limitation.
|
|
67
|
+
|
|
68
|
+
2. To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the
|
|
69
|
+
right granted in this License, as the Additional Use Grant; or (b) insert the text "None".
|
|
70
|
+
|
|
71
|
+
3. To specify a Change Date.
|
|
72
|
+
|
|
73
|
+
4. Not to modify this License in any other way.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
Notice
|
|
78
|
+
|
|
79
|
+
The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work
|
|
80
|
+
will eventually be made available under an Open Source License, as stated in this License.
|
package/README.md
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
# @heavymath/indexer_client
|
|
2
|
+
|
|
3
|
+
TypeScript client library for the Heavymath Prediction Market Indexer API. Provides React hooks, business services, and low-level API clients for querying prediction market data.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Full API Coverage** - All REST endpoints supported
|
|
8
|
+
- **React Hooks** - Built-in hooks using @tanstack/react-query
|
|
9
|
+
- **Business Services** - High-level services with caching
|
|
10
|
+
- **Network Layer** - Low-level API client for custom integrations
|
|
11
|
+
- **TypeScript First** - Full type definitions included
|
|
12
|
+
- **React Native Compatible** - Works in React Native environments
|
|
13
|
+
- **Dependency Injection** - Uses NetworkClient from @sudobility/di
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @heavymath/indexer_client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Peer Dependencies
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react @tanstack/react-query @sudobility/types @sudobility/heavymath_types @sudobility/di
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### 1. Setup React Query Provider
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
33
|
+
|
|
34
|
+
const queryClient = new QueryClient();
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
return (
|
|
38
|
+
<QueryClientProvider client={queryClient}>
|
|
39
|
+
<YourApp />
|
|
40
|
+
</QueryClientProvider>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Create IndexerClient with NetworkClient
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { useMemo } from 'react';
|
|
49
|
+
import { useNetworkService } from '@sudobility/di'; // Or your DI container
|
|
50
|
+
import { IndexerClient } from '@heavymath/indexer_client';
|
|
51
|
+
|
|
52
|
+
// Create a hook to provide IndexerClient
|
|
53
|
+
function useIndexerClient() {
|
|
54
|
+
const networkClient = useNetworkService();
|
|
55
|
+
return useMemo(
|
|
56
|
+
() => new IndexerClient('http://localhost:42069', networkClient),
|
|
57
|
+
[networkClient]
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3. Use Hooks in Your Components
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { useActiveMarkets, useUserPredictions } from '@heavymath/indexer_client';
|
|
66
|
+
|
|
67
|
+
function BettorDashboard({ wallet }: { wallet: string }) {
|
|
68
|
+
const client = useIndexerClient();
|
|
69
|
+
|
|
70
|
+
const { data: markets, isLoading: marketsLoading } = useActiveMarkets(client, 20);
|
|
71
|
+
const { data: myBets, isLoading: betsLoading } = useUserPredictions(client, wallet);
|
|
72
|
+
|
|
73
|
+
if (marketsLoading || betsLoading) return <div>Loading...</div>;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<h2>Active Markets</h2>
|
|
78
|
+
{markets?.data?.map(market => (
|
|
79
|
+
<MarketCard key={market.id} market={market} />
|
|
80
|
+
))}
|
|
81
|
+
|
|
82
|
+
<h2>My Bets</h2>
|
|
83
|
+
{myBets?.data?.map(bet => (
|
|
84
|
+
<BetCard key={bet.id} bet={bet} />
|
|
85
|
+
))}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Architecture
|
|
92
|
+
|
|
93
|
+
The library is organized into three layers:
|
|
94
|
+
|
|
95
|
+
### 1. Network Layer
|
|
96
|
+
|
|
97
|
+
Low-level API client that accepts a `NetworkClient` instance.
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import type { NetworkClient } from '@sudobility/types';
|
|
101
|
+
import { IndexerClient } from '@heavymath/indexer_client';
|
|
102
|
+
|
|
103
|
+
// Get NetworkClient from your DI container
|
|
104
|
+
const networkClient: NetworkClient = getNetworkService();
|
|
105
|
+
|
|
106
|
+
const client = new IndexerClient('http://localhost:42069', networkClient);
|
|
107
|
+
|
|
108
|
+
// Direct API calls
|
|
109
|
+
const markets = await client.getMarkets({ status: 'Active', limit: 10 });
|
|
110
|
+
const market = await client.getMarket('1-market-123');
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2. Business Layer
|
|
114
|
+
|
|
115
|
+
High-level services with caching and business logic.
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
import type { NetworkClient } from '@sudobility/types';
|
|
119
|
+
import { IndexerService } from '@heavymath/indexer_client';
|
|
120
|
+
|
|
121
|
+
const networkClient: NetworkClient = getNetworkService();
|
|
122
|
+
|
|
123
|
+
const service = new IndexerService({
|
|
124
|
+
indexerUrl: 'http://localhost:42069',
|
|
125
|
+
networkClient,
|
|
126
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes (optional)
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Business methods with caching
|
|
130
|
+
const activeMarkets = await service.getActiveMarkets(20);
|
|
131
|
+
const userPredictions = await service.getUserPredictions('0x123...');
|
|
132
|
+
const dealerDashboard = await service.getDealerDashboard('0x123...');
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 3. Hooks Layer
|
|
136
|
+
|
|
137
|
+
React hooks using @tanstack/react-query for data fetching.
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { useActiveMarkets, useUserPredictions, useDealerDashboard } from '@heavymath/indexer_client';
|
|
141
|
+
|
|
142
|
+
// All hooks take IndexerClient as first parameter
|
|
143
|
+
const { data, isLoading, error, refetch } = useActiveMarkets(client, 20);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Common Use Cases
|
|
147
|
+
|
|
148
|
+
### Dealer Dashboard
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { useDealerDashboard, useIsDealer } from '@heavymath/indexer_client';
|
|
152
|
+
|
|
153
|
+
function DealerDashboard({ wallet }: { wallet: string }) {
|
|
154
|
+
const client = useIndexerClient();
|
|
155
|
+
|
|
156
|
+
const { data: isDealer, isLoading: checkingDealer } = useIsDealer(client, wallet);
|
|
157
|
+
const { nfts, markets, isLoading } = useDealerDashboard(client, wallet);
|
|
158
|
+
|
|
159
|
+
if (checkingDealer) return <div>Checking dealer status...</div>;
|
|
160
|
+
if (!isDealer) return <div>You are not a dealer</div>;
|
|
161
|
+
if (isLoading) return <div>Loading dashboard...</div>;
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<div>
|
|
165
|
+
<h2>My Dealer NFTs</h2>
|
|
166
|
+
{nfts.data?.map(nft => (
|
|
167
|
+
<div key={nft.id}>Token #{nft.tokenId}</div>
|
|
168
|
+
))}
|
|
169
|
+
|
|
170
|
+
<h2>My Markets</h2>
|
|
171
|
+
{markets.data?.map(market => (
|
|
172
|
+
<MarketCard key={market.id} market={market} />
|
|
173
|
+
))}
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Market Details Page
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { useMarketDetails } from '@heavymath/indexer_client';
|
|
183
|
+
|
|
184
|
+
function MarketPage({ marketId }: { marketId: string }) {
|
|
185
|
+
const client = useIndexerClient();
|
|
186
|
+
|
|
187
|
+
const { market, predictions, history, isLoading, isError } = useMarketDetails(client, marketId);
|
|
188
|
+
|
|
189
|
+
if (isLoading) return <div>Loading...</div>;
|
|
190
|
+
if (isError) return <div>Error loading market</div>;
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div>
|
|
194
|
+
<h1>{market.data?.data?.title}</h1>
|
|
195
|
+
<p>{market.data?.data?.description}</p>
|
|
196
|
+
<p>Status: {market.data?.data?.status}</p>
|
|
197
|
+
|
|
198
|
+
<h2>Predictions ({predictions.data?.data?.length || 0})</h2>
|
|
199
|
+
{predictions.data?.data?.map(pred => (
|
|
200
|
+
<div key={pred.id}>
|
|
201
|
+
{pred.userAddress}: {pred.percentage}%
|
|
202
|
+
</div>
|
|
203
|
+
))}
|
|
204
|
+
|
|
205
|
+
<h2>State History</h2>
|
|
206
|
+
{history.data?.data?.map(state => (
|
|
207
|
+
<div key={state.id}>
|
|
208
|
+
{state.fromState} → {state.toState}
|
|
209
|
+
</div>
|
|
210
|
+
))}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Wallet Favorites
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import { useFavorites } from '@heavymath/indexer_client';
|
|
220
|
+
|
|
221
|
+
function FavoritesPage({ wallet }: { wallet: string }) {
|
|
222
|
+
const client = useIndexerClient();
|
|
223
|
+
|
|
224
|
+
const { favorites, isLoading, addFavorite, removeFavorite, refresh } = useFavorites(
|
|
225
|
+
client,
|
|
226
|
+
wallet
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const handleAddFavorite = async () => {
|
|
230
|
+
await addFavorite.mutateAsync({
|
|
231
|
+
category: 'sports',
|
|
232
|
+
subcategory: 'soccer',
|
|
233
|
+
type: 'team',
|
|
234
|
+
id: 'team-123',
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const handleRemoveFavorite = async (id: number) => {
|
|
239
|
+
await removeFavorite.mutateAsync(id);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (isLoading) return <div>Loading...</div>;
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<div>
|
|
246
|
+
<h2>My Favorites</h2>
|
|
247
|
+
{favorites.map(fav => (
|
|
248
|
+
<div key={fav.id}>
|
|
249
|
+
{fav.category}/{fav.subcategory}: {fav.itemId}
|
|
250
|
+
<button onClick={() => handleRemoveFavorite(fav.id)}>Remove</button>
|
|
251
|
+
</div>
|
|
252
|
+
))}
|
|
253
|
+
<button onClick={handleAddFavorite}>Add Favorite</button>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Available Hooks
|
|
260
|
+
|
|
261
|
+
### Market Hooks
|
|
262
|
+
- `useMarkets(client, filters?)` - Get all markets with filtering
|
|
263
|
+
- `useActiveMarkets(client, limit?)` - Get active markets only
|
|
264
|
+
- `useMarket(client, marketId)` - Get specific market
|
|
265
|
+
- `useMarketPredictions(client, marketId)` - Get market's predictions
|
|
266
|
+
- `useMarketHistory(client, marketId)` - Get market's state history
|
|
267
|
+
- `useMarketDetails(client, marketId)` - Get complete market details
|
|
268
|
+
|
|
269
|
+
### Prediction Hooks
|
|
270
|
+
- `usePredictions(client, filters?)` - Get predictions with filtering
|
|
271
|
+
- `useUserPredictions(client, wallet, filters?)` - Get user's predictions
|
|
272
|
+
- `useActiveBets(client, wallet)` - Get user's active bets
|
|
273
|
+
- `usePastBets(client, wallet)` - Get user's claimed bets
|
|
274
|
+
- `usePrediction(client, predictionId)` - Get specific prediction
|
|
275
|
+
- `useUserBettingHistory(client, wallet)` - Get complete betting history
|
|
276
|
+
|
|
277
|
+
### Dealer Hooks
|
|
278
|
+
- `useDealers(client, filters?)` - Get dealer NFTs with filtering
|
|
279
|
+
- `useIsDealer(client, wallet)` - Check if wallet is a dealer
|
|
280
|
+
- `useDealerNFTs(client, wallet)` - Get wallet's dealer NFTs
|
|
281
|
+
- `useDealer(client, dealerId)` - Get specific dealer NFT
|
|
282
|
+
- `useDealerPermissions(client, dealerId)` - Get dealer's permissions
|
|
283
|
+
- `useDealerMarkets(client, dealerId)` - Get dealer's markets
|
|
284
|
+
- `useDealerDashboard(client, wallet)` - Get complete dealer dashboard
|
|
285
|
+
|
|
286
|
+
### Withdrawal Hooks
|
|
287
|
+
- `useWithdrawals(client, filters?)` - Get withdrawals with filtering
|
|
288
|
+
- `useDealerWithdrawals(client, dealer)` - Get dealer's withdrawals
|
|
289
|
+
- `useSystemWithdrawals(client)` - Get system withdrawals
|
|
290
|
+
- `useMarketWithdrawals(client, marketId)` - Get market's withdrawals
|
|
291
|
+
|
|
292
|
+
### Oracle Hooks
|
|
293
|
+
- `useOracleRequests(client, filters?)` - Get oracle requests with filtering
|
|
294
|
+
- `useOracleRequest(client, requestId)` - Get specific oracle request
|
|
295
|
+
- `useMarketOracle(client, marketId)` - Get market's oracle request
|
|
296
|
+
- `useTimedOutOracleRequests(client)` - Get timed out requests
|
|
297
|
+
- `usePendingOracleRequests(client)` - Get pending requests
|
|
298
|
+
|
|
299
|
+
### Favorites Hooks
|
|
300
|
+
- `useFavorites(client, wallet, filters?)` - Get favorites with add/remove/refresh
|
|
301
|
+
- `useCategoryFavorites(client, wallet, category)` - Get favorites by category
|
|
302
|
+
- `useIsFavorite(client, wallet, item)` - Check if item is favorited with toggle
|
|
303
|
+
|
|
304
|
+
### Stats Hooks
|
|
305
|
+
- `useMarketStats(client)` - Get market statistics
|
|
306
|
+
- `useHealth(client)` - Get indexer health status
|
|
307
|
+
|
|
308
|
+
## API Endpoints
|
|
309
|
+
|
|
310
|
+
The client supports all REST endpoints:
|
|
311
|
+
|
|
312
|
+
- **Markets**: `/api/markets`, `/api/markets/:id`, `/api/markets/:id/predictions`, `/api/markets/:id/history`
|
|
313
|
+
- **Predictions**: `/api/predictions`, `/api/predictions/:id`
|
|
314
|
+
- **Dealers**: `/api/dealers`, `/api/dealers/:id`, `/api/dealers/:id/permissions`, `/api/dealers/:id/markets`
|
|
315
|
+
- **Withdrawals**: `/api/withdrawals`
|
|
316
|
+
- **Oracle**: `/api/oracle/requests`, `/api/oracle/requests/:id`
|
|
317
|
+
- **Favorites**: `/api/wallet/:address/favorites` (GET, POST, DELETE)
|
|
318
|
+
- **Analytics**: `/api/stats/markets`, `/api/health`
|
|
319
|
+
|
|
320
|
+
## TypeScript Support
|
|
321
|
+
|
|
322
|
+
Full TypeScript definitions included:
|
|
323
|
+
|
|
324
|
+
```tsx
|
|
325
|
+
import type {
|
|
326
|
+
// Core types (from @sudobility/heavymath_types)
|
|
327
|
+
MarketData,
|
|
328
|
+
PredictionData,
|
|
329
|
+
DealerNftData,
|
|
330
|
+
DealerPermissionData,
|
|
331
|
+
MarketStateHistoryData,
|
|
332
|
+
FeeWithdrawalData,
|
|
333
|
+
OracleRequestData,
|
|
334
|
+
WalletFavoriteData,
|
|
335
|
+
CreateFavoriteRequest,
|
|
336
|
+
// Enums
|
|
337
|
+
MarketStatus,
|
|
338
|
+
ClaimType,
|
|
339
|
+
WithdrawalType,
|
|
340
|
+
// Response wrappers (from @sudobility/types)
|
|
341
|
+
ApiResponse,
|
|
342
|
+
PaginatedResponse,
|
|
343
|
+
NetworkClient,
|
|
344
|
+
// Filter types
|
|
345
|
+
MarketFilters,
|
|
346
|
+
PredictionFilters,
|
|
347
|
+
DealerFilters,
|
|
348
|
+
WithdrawalFilters,
|
|
349
|
+
OracleFilters,
|
|
350
|
+
WalletFavoritesFilters,
|
|
351
|
+
} from '@heavymath/indexer_client';
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Development
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
# Install dependencies
|
|
358
|
+
npm install
|
|
359
|
+
|
|
360
|
+
# Build
|
|
361
|
+
npm run build
|
|
362
|
+
|
|
363
|
+
# Type check
|
|
364
|
+
npm run typecheck
|
|
365
|
+
|
|
366
|
+
# Lint
|
|
367
|
+
npm run lint
|
|
368
|
+
|
|
369
|
+
# Format
|
|
370
|
+
npm run format
|
|
371
|
+
|
|
372
|
+
# Run all checks
|
|
373
|
+
npm run check-all
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## License
|
|
377
|
+
|
|
378
|
+
BUSL 1.1 - Business Use Source License
|
|
379
|
+
|
|
380
|
+
Copyright (c) 2025 Sudobility Inc.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/business/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { NetworkClient } from '@sudobility/types';
|
|
2
|
+
import { IndexerClient } from '../network/IndexerClient';
|
|
3
|
+
import type { Market, Prediction, DealerNFT, PaginatedResponse, ApiResponse, PredictionFilters, StateHistory, MarketStats } from '../types';
|
|
4
|
+
export interface IndexerServiceConfig {
|
|
5
|
+
indexerUrl: string;
|
|
6
|
+
networkClient: NetworkClient;
|
|
7
|
+
cacheTTL?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class IndexerService {
|
|
10
|
+
private static instance;
|
|
11
|
+
private indexerClient;
|
|
12
|
+
private cache;
|
|
13
|
+
private readonly CACHE_TTL;
|
|
14
|
+
constructor(config: IndexerServiceConfig);
|
|
15
|
+
static getInstance(config: IndexerServiceConfig): IndexerService;
|
|
16
|
+
private getCacheKey;
|
|
17
|
+
private getCache;
|
|
18
|
+
private setCache;
|
|
19
|
+
getActiveMarkets(limit?: number): Promise<PaginatedResponse<Market>>;
|
|
20
|
+
getUserPredictions(walletAddress: string, filters?: Omit<PredictionFilters, 'user'>): Promise<PaginatedResponse<Prediction>>;
|
|
21
|
+
getDealerNFTs(walletAddress: string): Promise<DealerNFT[]>;
|
|
22
|
+
getDealerDashboard(walletAddress: string): Promise<{
|
|
23
|
+
nfts: DealerNFT[];
|
|
24
|
+
markets: Market[];
|
|
25
|
+
}>;
|
|
26
|
+
getMarketDetails(marketId: string): Promise<{
|
|
27
|
+
market: Market;
|
|
28
|
+
predictions: Prediction[];
|
|
29
|
+
history: StateHistory[];
|
|
30
|
+
}>;
|
|
31
|
+
getUserBettingHistory(walletAddress: string): Promise<{
|
|
32
|
+
active: Prediction[];
|
|
33
|
+
claimed: Prediction[];
|
|
34
|
+
}>;
|
|
35
|
+
getMarketFromPrediction(predictionId: string): Promise<Market | null>;
|
|
36
|
+
getMarketStats(): Promise<ApiResponse<MarketStats>>;
|
|
37
|
+
clearCache(): void;
|
|
38
|
+
getClient(): IndexerClient;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=indexer-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer-service.d.ts","sourceRoot":"","sources":["../../src/business/indexer-service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACZ,MAAM,UAAU,CAAC;AAKlB,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,KAAK,CAAyD;IACtE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAMvB,MAAM,EAAE,oBAAoB;WAW1B,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc;IAWvE,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,QAAQ;IAeH,gBAAgB,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAyBxE,kBAAkB,CAC7B,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAwB5B,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAwB1D,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;QAC9D,IAAI,EAAE,SAAS,EAAE,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IAoCW,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QACvD,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,UAAU,EAAE,CAAC;QAC1B,OAAO,EAAE,YAAY,EAAE,CAAC;KACzB,CAAC;IAuCW,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;QACjE,MAAM,EAAE,UAAU,EAAE,CAAC;QACrB,OAAO,EAAE,UAAU,EAAE,CAAC;KACvB,CAAC;IAqCW,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAmBrE,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAmBzD,UAAU,IAAI,IAAI;IAOlB,SAAS,IAAI,aAAa;CAGlC"}
|