@provable-games/metagame-sdk 0.1.0 → 0.1.2
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/dist/extensions-BskkhEHk.d.cts +101 -0
- package/dist/extensions-BskkhEHk.d.ts +101 -0
- package/dist/index.cjs +1071 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +489 -0
- package/dist/index.d.ts +489 -0
- package/dist/index.js +1015 -0
- package/dist/index.js.map +1 -0
- package/dist/prizeAggregation-CHwIJzXr.d.cts +325 -0
- package/dist/prizeAggregation-CHwIJzXr.d.ts +325 -0
- package/dist/react.cjs +918 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +300 -0
- package/dist/react.d.ts +300 -0
- package/dist/react.js +906 -0
- package/dist/react.js.map +1 -0
- package/dist/rpc.cjs +161 -0
- package/dist/rpc.cjs.map +1 -0
- package/dist/rpc.d.cts +48 -0
- package/dist/rpc.d.ts +48 -0
- package/dist/rpc.js +146 -0
- package/dist/rpc.js.map +1 -0
- package/package.json +10 -10
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { s as Token, S as StatusTimestamps, a as StatusResult, l as Participant, P as Prize, m as PositionPrizeGroup, j as EntryFeeShares, D as DistributionType, h as EntryFeeBreakdown, g as QualificationProof, f as EntryRequirementVariant, T as TournamentValidatorConfig, e as QualificationResult, O as OpusTrovesValidatorConfig } from './prizeAggregation-CHwIJzXr.js';
|
|
2
|
+
import { S as StarknetCallProvider } from './extensions-BskkhEHk.js';
|
|
3
|
+
import 'starknet';
|
|
4
|
+
|
|
5
|
+
declare function useDebounce<T>(value: T, delay: number): T;
|
|
6
|
+
|
|
7
|
+
interface UsePaginationOptions {
|
|
8
|
+
totalItems: number;
|
|
9
|
+
pageSize?: number;
|
|
10
|
+
}
|
|
11
|
+
interface UsePaginationReturn {
|
|
12
|
+
currentPage: number;
|
|
13
|
+
totalPages: number;
|
|
14
|
+
hasNext: boolean;
|
|
15
|
+
hasPrev: boolean;
|
|
16
|
+
next: () => void;
|
|
17
|
+
prev: () => void;
|
|
18
|
+
reset: () => void;
|
|
19
|
+
startIndex: number;
|
|
20
|
+
endIndex: number;
|
|
21
|
+
}
|
|
22
|
+
declare function usePagination({ totalItems, pageSize, }: UsePaginationOptions): UsePaginationReturn;
|
|
23
|
+
|
|
24
|
+
interface UseSearchFilterOptions<T> {
|
|
25
|
+
items: T[];
|
|
26
|
+
searchFields: (keyof T)[];
|
|
27
|
+
debounceMs?: number;
|
|
28
|
+
}
|
|
29
|
+
interface UseSearchFilterReturn<T> {
|
|
30
|
+
search: string;
|
|
31
|
+
setSearch: (q: string) => void;
|
|
32
|
+
filteredItems: T[];
|
|
33
|
+
resultCount: number;
|
|
34
|
+
}
|
|
35
|
+
declare function useSearchFilter<T>({ items, searchFields, debounceMs, }: UseSearchFilterOptions<T>): UseSearchFilterReturn<T>;
|
|
36
|
+
|
|
37
|
+
interface UseTokenSelectorOptions {
|
|
38
|
+
tokens: Token[];
|
|
39
|
+
tokenType?: "erc20" | "erc721";
|
|
40
|
+
pageSize?: number;
|
|
41
|
+
debounceMs?: number;
|
|
42
|
+
}
|
|
43
|
+
interface UseTokenSelectorReturn {
|
|
44
|
+
search: string;
|
|
45
|
+
setSearch: (q: string) => void;
|
|
46
|
+
filteredTokens: Token[];
|
|
47
|
+
selectedToken: Token | null;
|
|
48
|
+
select: (token: Token) => void;
|
|
49
|
+
clear: () => void;
|
|
50
|
+
isSelected: (token: Token) => boolean;
|
|
51
|
+
pagination: UsePaginationReturn;
|
|
52
|
+
getTokenProps: (token: Token) => {
|
|
53
|
+
onClick: () => void;
|
|
54
|
+
"data-selected": boolean;
|
|
55
|
+
role: "option";
|
|
56
|
+
"aria-selected": boolean;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
declare function useTokenSelector({ tokens, tokenType, pageSize, debounceMs, }: UseTokenSelectorOptions): UseTokenSelectorReturn;
|
|
60
|
+
|
|
61
|
+
declare function useStatusIndicator(timestamps: StatusTimestamps, refreshMs?: number): StatusResult;
|
|
62
|
+
|
|
63
|
+
type SortField = "rank" | "score" | "name";
|
|
64
|
+
type SortDirection = "asc" | "desc";
|
|
65
|
+
interface UseScoreTableOptions {
|
|
66
|
+
participants: Participant[];
|
|
67
|
+
pageSize?: number;
|
|
68
|
+
sortField?: SortField;
|
|
69
|
+
sortDirection?: SortDirection;
|
|
70
|
+
}
|
|
71
|
+
interface UseScoreTableReturn {
|
|
72
|
+
rows: Participant[];
|
|
73
|
+
pagination: UsePaginationReturn;
|
|
74
|
+
sort: {
|
|
75
|
+
field: SortField;
|
|
76
|
+
direction: SortDirection;
|
|
77
|
+
};
|
|
78
|
+
setSort: (field: string) => void;
|
|
79
|
+
search: string;
|
|
80
|
+
setSearch: (q: string) => void;
|
|
81
|
+
}
|
|
82
|
+
declare function useScoreTable({ participants, pageSize, sortField, sortDirection, }: UseScoreTableOptions): UseScoreTableReturn;
|
|
83
|
+
|
|
84
|
+
interface UsePrizeTableOptions {
|
|
85
|
+
prizes: Prize[];
|
|
86
|
+
positionsPerPage?: number;
|
|
87
|
+
}
|
|
88
|
+
interface UsePrizeTableReturn {
|
|
89
|
+
/** Prize groups for the current page, sorted by position */
|
|
90
|
+
rows: PositionPrizeGroup[];
|
|
91
|
+
/** Total number of positions across all prizes */
|
|
92
|
+
totalPositions: number;
|
|
93
|
+
/** Pagination state and controls */
|
|
94
|
+
pagination: UsePaginationReturn;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Headless hook for displaying a paginated prize table.
|
|
98
|
+
*
|
|
99
|
+
* Aggregates prizes by position (summing ERC20 amounts, grouping ERC721 IDs),
|
|
100
|
+
* then paginates the position groups. Metagame UIs render each position group
|
|
101
|
+
* however they like — the hook only manages data and pagination state.
|
|
102
|
+
*/
|
|
103
|
+
declare function usePrizeTable({ prizes, positionsPerPage, }: UsePrizeTableOptions): UsePrizeTableReturn;
|
|
104
|
+
|
|
105
|
+
interface UseEntryFeePreviewOptions {
|
|
106
|
+
/** Fee per entry in smallest token units (as bigint) */
|
|
107
|
+
feePerEntry: bigint;
|
|
108
|
+
/** Expected number of entries (for preview) */
|
|
109
|
+
entryCount: number;
|
|
110
|
+
/** Share percentages in basis points */
|
|
111
|
+
shares: EntryFeeShares;
|
|
112
|
+
/** Number of positions to distribute prizes across */
|
|
113
|
+
distributionPositions: number;
|
|
114
|
+
/** Distribution curve type */
|
|
115
|
+
distributionType: DistributionType;
|
|
116
|
+
/** Weight for linear/exponential curves */
|
|
117
|
+
distributionWeight: number;
|
|
118
|
+
}
|
|
119
|
+
interface UseEntryFeePreviewReturn {
|
|
120
|
+
/** Breakdown of total fees into creator/game/refund/pool buckets */
|
|
121
|
+
breakdown: EntryFeeBreakdown;
|
|
122
|
+
/** Per-position prize amounts from the pool */
|
|
123
|
+
positionPrizes: Array<{
|
|
124
|
+
position: number;
|
|
125
|
+
amount: bigint;
|
|
126
|
+
}>;
|
|
127
|
+
/** Distribution percentages per position (0-100 scale) */
|
|
128
|
+
percentages: number[];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Headless hook for live entry fee breakdown preview.
|
|
132
|
+
*
|
|
133
|
+
* As form values change (fee amount, shares, distribution curve),
|
|
134
|
+
* this hook recomputes the full breakdown and per-position prizes.
|
|
135
|
+
* Useful for "create tournament/quest" forms where you want to show
|
|
136
|
+
* the user a live preview of how entry fees will be distributed.
|
|
137
|
+
*/
|
|
138
|
+
declare function useEntryFeePreview({ feePerEntry, entryCount, shares, distributionPositions, distributionType, distributionWeight, }: UseEntryFeePreviewOptions): UseEntryFeePreviewReturn;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A potential qualification the user has — e.g., an owned NFT, a tournament
|
|
142
|
+
* they won.
|
|
143
|
+
*/
|
|
144
|
+
interface QualificationMethod {
|
|
145
|
+
/** Unique ID for deduplication */
|
|
146
|
+
id: string;
|
|
147
|
+
/** The proof to submit if this method is used */
|
|
148
|
+
proof: QualificationProof;
|
|
149
|
+
/** Human-readable label */
|
|
150
|
+
label?: string;
|
|
151
|
+
/** Additional display metadata */
|
|
152
|
+
metadata?: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Pre-checked extension result from calling the extension contract.
|
|
156
|
+
* Each metagame calls `entries_left` on-chain and passes results here.
|
|
157
|
+
*/
|
|
158
|
+
interface CheckedExtensionQualification {
|
|
159
|
+
id: string;
|
|
160
|
+
entriesLeft: number;
|
|
161
|
+
proof: string[];
|
|
162
|
+
label?: string;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
interface UseEntryQualificationOptions {
|
|
166
|
+
/** The type of entry requirement */
|
|
167
|
+
variant: EntryRequirementVariant;
|
|
168
|
+
/** NFT token IDs owned by the player */
|
|
169
|
+
ownedTokenIds?: string[];
|
|
170
|
+
/** How many times each token has been used (tokenId → count) */
|
|
171
|
+
tokenEntryCounts?: Record<string, number>;
|
|
172
|
+
/** The player's address */
|
|
173
|
+
playerAddress?: string;
|
|
174
|
+
/** Pre-checked results from calling extension contract */
|
|
175
|
+
extensionQualifications?: CheckedExtensionQualification[];
|
|
176
|
+
/** For tournament validator: the parsed config */
|
|
177
|
+
tournamentValidatorConfig?: TournamentValidatorConfig | null;
|
|
178
|
+
/** For generic extensions: whether the contract says entry is valid */
|
|
179
|
+
extensionValidEntry?: boolean;
|
|
180
|
+
/** For generic extensions: entries left from contract */
|
|
181
|
+
extensionEntriesLeft?: number | null;
|
|
182
|
+
/** Max entries allowed (0 = unlimited) */
|
|
183
|
+
entryLimit?: number;
|
|
184
|
+
}
|
|
185
|
+
interface UseEntryQualificationReturn {
|
|
186
|
+
/** Whether the user meets the entry requirements */
|
|
187
|
+
meetsRequirements: boolean;
|
|
188
|
+
/** The best proof to use for entering */
|
|
189
|
+
bestProof: QualificationProof | null;
|
|
190
|
+
/** All valid qualification methods */
|
|
191
|
+
qualifications: QualificationResult["qualifications"];
|
|
192
|
+
/** Total entries remaining */
|
|
193
|
+
totalEntriesLeft: number;
|
|
194
|
+
/** Entries remaining grouped by source (tournament ID, token address, etc.) */
|
|
195
|
+
entriesLeftBySource: Array<{
|
|
196
|
+
sourceId?: string;
|
|
197
|
+
sourceType?: string;
|
|
198
|
+
entriesLeft: number;
|
|
199
|
+
}>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Headless hook that evaluates whether a user qualifies to enter a
|
|
203
|
+
* metagame event. Works for all requirement types (token, extension).
|
|
204
|
+
*
|
|
205
|
+
* Each metagame fetches the data through their own SDK (owned NFTs,
|
|
206
|
+
* registrations, extension contract calls), then passes it here.
|
|
207
|
+
* The evaluation logic is the same across all metagames.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```tsx
|
|
211
|
+
* const { meetsRequirements, bestProof, entriesLeftBySource } = useEntryQualification({
|
|
212
|
+
* variant: "token",
|
|
213
|
+
* ownedTokenIds: ["123", "456"],
|
|
214
|
+
* tokenEntryCounts: { "123": 2, "456": 0 },
|
|
215
|
+
* entryLimit: 3,
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* // To enter, serialize the proof:
|
|
219
|
+
* const onChainProof = buildQualificationProof(bestProof);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function useEntryQualification(options: UseEntryQualificationOptions): UseEntryQualificationReturn;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Hook to check extension qualification and entries left for multiple proofs.
|
|
226
|
+
*
|
|
227
|
+
* Ported from budokan — accepts a provider instead of relying on app-specific hooks.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/** A single qualification method for an extension */
|
|
231
|
+
interface ExtensionQualification {
|
|
232
|
+
id: string;
|
|
233
|
+
proof: string[];
|
|
234
|
+
entriesLeft: number;
|
|
235
|
+
label?: string;
|
|
236
|
+
metadata?: {
|
|
237
|
+
tournamentId?: string;
|
|
238
|
+
tournamentName?: string;
|
|
239
|
+
tokenId?: string;
|
|
240
|
+
position?: number;
|
|
241
|
+
[key: string]: unknown;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Result from extension qualification check */
|
|
245
|
+
interface ExtensionQualificationResult {
|
|
246
|
+
qualifications: ExtensionQualification[];
|
|
247
|
+
totalEntriesLeft: number;
|
|
248
|
+
bestQualification: ExtensionQualification | null;
|
|
249
|
+
loading: boolean;
|
|
250
|
+
error: Error | null;
|
|
251
|
+
}
|
|
252
|
+
/** Input for building qualifications — tournament validator specific */
|
|
253
|
+
interface TournamentValidatorInput {
|
|
254
|
+
tournamentId: string;
|
|
255
|
+
tokenId: string;
|
|
256
|
+
position: number;
|
|
257
|
+
tournamentName?: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Check extension qualification and entries left for multiple proofs.
|
|
261
|
+
*
|
|
262
|
+
* @param provider - Starknet RPC provider (or null to disable)
|
|
263
|
+
* @param extensionAddress - The extension contract address
|
|
264
|
+
* @param contextId - The metagame event ID (tournament ID, etc.)
|
|
265
|
+
* @param playerAddress - The player's address
|
|
266
|
+
* @param qualificationInputs - Potential qualifications to check
|
|
267
|
+
* @param enabled - Whether to run the check (default: true)
|
|
268
|
+
*/
|
|
269
|
+
declare const useExtensionQualification: (provider: StarknetCallProvider | null, extensionAddress: string | undefined, contextId: string | undefined, playerAddress: string | undefined, qualificationInputs: TournamentValidatorInput[], enabled?: boolean) => ExtensionQualificationResult;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Hook to calculate bannable entries for Opus Troves extension.
|
|
273
|
+
*
|
|
274
|
+
* Ported from budokan — accepts a provider instead of relying on app-specific hooks.
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
interface Game {
|
|
278
|
+
tokenId: number | bigint;
|
|
279
|
+
owner?: string;
|
|
280
|
+
}
|
|
281
|
+
interface UseOpusTrovesBannableEntriesResult {
|
|
282
|
+
bannableEntries: Set<string>;
|
|
283
|
+
troveDebts: Map<string, bigint>;
|
|
284
|
+
isLoading: boolean;
|
|
285
|
+
playerGroups: Map<string, Game[]>;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Calculate bannable entries for Opus Troves extension.
|
|
289
|
+
*
|
|
290
|
+
* @param provider - Starknet RPC provider (or null to disable)
|
|
291
|
+
* @param games - Array of game entries with tokenId and owner
|
|
292
|
+
* @param config - Opus Troves validator config (or undefined to disable)
|
|
293
|
+
* @param enabled - Whether to run the check
|
|
294
|
+
*/
|
|
295
|
+
declare const useOpusTrovesBannableEntries: (provider: StarknetCallProvider | null, games: Array<{
|
|
296
|
+
tokenId: number | bigint;
|
|
297
|
+
owner?: string;
|
|
298
|
+
}>, config: OpusTrovesValidatorConfig | undefined, enabled: boolean) => UseOpusTrovesBannableEntriesResult;
|
|
299
|
+
|
|
300
|
+
export { type CheckedExtensionQualification, type ExtensionQualification, type ExtensionQualificationResult, type QualificationMethod, type TournamentValidatorInput, type UseEntryFeePreviewOptions, type UseEntryFeePreviewReturn, type UseEntryQualificationOptions, type UseEntryQualificationReturn, type UseOpusTrovesBannableEntriesResult, type UsePaginationOptions, type UsePaginationReturn, type UsePrizeTableOptions, type UsePrizeTableReturn, type UseScoreTableOptions, type UseScoreTableReturn, type UseSearchFilterOptions, type UseSearchFilterReturn, type UseTokenSelectorOptions, type UseTokenSelectorReturn, useDebounce, useEntryFeePreview, useEntryQualification, useExtensionQualification, useOpusTrovesBannableEntries, usePagination, usePrizeTable, useScoreTable, useSearchFilter, useStatusIndicator, useTokenSelector };
|