@provable-games/metagame-sdk 0.1.2 → 0.1.4
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/abis.cjs +2794 -0
- package/dist/abis.cjs.map +1 -0
- package/dist/abis.d.cts +2012 -0
- package/dist/abis.d.ts +2012 -0
- package/dist/abis.js +2786 -0
- package/dist/abis.js.map +1 -0
- package/dist/{prizeAggregation-CHwIJzXr.d.cts → client-CD-q6Alx.d.ts} +36 -2
- package/dist/{prizeAggregation-CHwIJzXr.d.ts → client-CcoKJS8i.d.cts} +36 -2
- package/dist/index.cjs +309 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -3
- package/dist/index.d.ts +123 -3
- package/dist/index.js +302 -7
- package/dist/index.js.map +1 -1
- package/dist/merkle.cjs +209 -0
- package/dist/merkle.cjs.map +1 -0
- package/dist/merkle.d.cts +151 -0
- package/dist/merkle.d.ts +151 -0
- package/dist/merkle.js +200 -0
- package/dist/merkle.js.map +1 -0
- package/dist/react.cjs +243 -22
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +53 -18
- package/dist/react.d.ts +53 -18
- package/dist/react.js +242 -25
- package/dist/react.js.map +1 -1
- package/dist/rpc.cjs.map +1 -1
- package/dist/rpc.js.map +1 -1
- package/package.json +31 -11
package/dist/react.d.cts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { m as MetagameClientConfig, l as MetagameClient, u as Token, S as StatusTimestamps, a as StatusResult, n as Participant, P as Prize, o 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 './client-CcoKJS8i.cjs';
|
|
4
|
+
import { MerkleTree, MerkleProofResponse } from './merkle.cjs';
|
|
2
5
|
import { S as StarknetCallProvider } from './extensions-BskkhEHk.cjs';
|
|
3
6
|
import 'starknet';
|
|
4
7
|
|
|
8
|
+
interface MetagameProviderProps extends MetagameClientConfig {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare function MetagameProvider({ children, ...config }: MetagameProviderProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare function useMetagameClient(): MetagameClient;
|
|
13
|
+
|
|
14
|
+
interface UseMerkleTreesOptions {
|
|
15
|
+
page?: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
interface UseMerkleTreesReturn {
|
|
19
|
+
trees: MerkleTree[];
|
|
20
|
+
total: number;
|
|
21
|
+
totalPages: number;
|
|
22
|
+
page: number;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function useMerkleTrees(options?: UseMerkleTreesOptions): UseMerkleTreesReturn;
|
|
26
|
+
|
|
27
|
+
interface UseMerkleProofReturn {
|
|
28
|
+
proof: MerkleProofResponse | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch a merkle proof for a player address.
|
|
33
|
+
* Returns null when treeId or playerAddress is falsy (skips the fetch).
|
|
34
|
+
*/
|
|
35
|
+
declare function useMerkleProof(treeId: string | number | undefined, playerAddress: string | undefined): UseMerkleProofReturn;
|
|
36
|
+
|
|
5
37
|
declare function useDebounce<T>(value: T, delay: number): T;
|
|
6
38
|
|
|
7
39
|
interface UsePaginationOptions {
|
|
@@ -224,7 +256,9 @@ declare function useEntryQualification(options: UseEntryQualificationOptions): U
|
|
|
224
256
|
/**
|
|
225
257
|
* Hook to check extension qualification and entries left for multiple proofs.
|
|
226
258
|
*
|
|
227
|
-
*
|
|
259
|
+
* Generic across all extension types — each extension provides its own proof
|
|
260
|
+
* format. The hook simply passes the proof to `entries_left` on the contract
|
|
261
|
+
* and reports results.
|
|
228
262
|
*/
|
|
229
263
|
|
|
230
264
|
/** A single qualification method for an extension */
|
|
@@ -233,13 +267,7 @@ interface ExtensionQualification {
|
|
|
233
267
|
proof: string[];
|
|
234
268
|
entriesLeft: number;
|
|
235
269
|
label?: string;
|
|
236
|
-
metadata?:
|
|
237
|
-
tournamentId?: string;
|
|
238
|
-
tournamentName?: string;
|
|
239
|
-
tokenId?: string;
|
|
240
|
-
position?: number;
|
|
241
|
-
[key: string]: unknown;
|
|
242
|
-
};
|
|
270
|
+
metadata?: Record<string, unknown>;
|
|
243
271
|
}
|
|
244
272
|
/** Result from extension qualification check */
|
|
245
273
|
interface ExtensionQualificationResult {
|
|
@@ -249,24 +277,31 @@ interface ExtensionQualificationResult {
|
|
|
249
277
|
loading: boolean;
|
|
250
278
|
error: Error | null;
|
|
251
279
|
}
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
280
|
+
/**
|
|
281
|
+
* A potential qualification to check against the extension contract.
|
|
282
|
+
* The proof format is extension-specific — the SDK doesn't interpret it.
|
|
283
|
+
*/
|
|
284
|
+
interface QualificationInput {
|
|
285
|
+
/** Unique ID for this qualification method */
|
|
286
|
+
id: string;
|
|
287
|
+
/** Raw proof data (felt252 array) to pass to entries_left */
|
|
288
|
+
proof: string[];
|
|
289
|
+
/** Human-readable label for display */
|
|
290
|
+
label?: string;
|
|
291
|
+
/** Additional metadata for display */
|
|
292
|
+
metadata?: Record<string, unknown>;
|
|
258
293
|
}
|
|
259
294
|
/**
|
|
260
295
|
* Check extension qualification and entries left for multiple proofs.
|
|
261
296
|
*
|
|
262
297
|
* @param provider - Starknet RPC provider (or null to disable)
|
|
263
298
|
* @param extensionAddress - The extension contract address
|
|
264
|
-
* @param contextId - The metagame
|
|
299
|
+
* @param contextId - The metagame context ID
|
|
265
300
|
* @param playerAddress - The player's address
|
|
266
301
|
* @param qualificationInputs - Potential qualifications to check
|
|
267
302
|
* @param enabled - Whether to run the check (default: true)
|
|
268
303
|
*/
|
|
269
|
-
declare const useExtensionQualification: (provider: StarknetCallProvider | null, extensionAddress: string | undefined, contextId: string | undefined, playerAddress: string | undefined, qualificationInputs:
|
|
304
|
+
declare const useExtensionQualification: (provider: StarknetCallProvider | null, extensionAddress: string | undefined, contextId: string | undefined, playerAddress: string | undefined, qualificationInputs: QualificationInput[], enabled?: boolean) => ExtensionQualificationResult;
|
|
270
305
|
|
|
271
306
|
/**
|
|
272
307
|
* Hook to calculate bannable entries for Opus Troves extension.
|
|
@@ -297,4 +332,4 @@ declare const useOpusTrovesBannableEntries: (provider: StarknetCallProvider | nu
|
|
|
297
332
|
owner?: string;
|
|
298
333
|
}>, config: OpusTrovesValidatorConfig | undefined, enabled: boolean) => UseOpusTrovesBannableEntriesResult;
|
|
299
334
|
|
|
300
|
-
export { type CheckedExtensionQualification, type ExtensionQualification, type ExtensionQualificationResult, type
|
|
335
|
+
export { type CheckedExtensionQualification, type ExtensionQualification, type ExtensionQualificationResult, MetagameProvider, type MetagameProviderProps, type QualificationInput, type QualificationMethod, type UseEntryFeePreviewOptions, type UseEntryFeePreviewReturn, type UseEntryQualificationOptions, type UseEntryQualificationReturn, type UseMerkleProofReturn, type UseMerkleTreesOptions, type UseMerkleTreesReturn, 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, useMerkleProof, useMerkleTrees, useMetagameClient, useOpusTrovesBannableEntries, usePagination, usePrizeTable, useScoreTable, useSearchFilter, useStatusIndicator, useTokenSelector };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { m as MetagameClientConfig, l as MetagameClient, u as Token, S as StatusTimestamps, a as StatusResult, n as Participant, P as Prize, o 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 './client-CD-q6Alx.js';
|
|
4
|
+
import { MerkleTree, MerkleProofResponse } from './merkle.js';
|
|
2
5
|
import { S as StarknetCallProvider } from './extensions-BskkhEHk.js';
|
|
3
6
|
import 'starknet';
|
|
4
7
|
|
|
8
|
+
interface MetagameProviderProps extends MetagameClientConfig {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare function MetagameProvider({ children, ...config }: MetagameProviderProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare function useMetagameClient(): MetagameClient;
|
|
13
|
+
|
|
14
|
+
interface UseMerkleTreesOptions {
|
|
15
|
+
page?: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
interface UseMerkleTreesReturn {
|
|
19
|
+
trees: MerkleTree[];
|
|
20
|
+
total: number;
|
|
21
|
+
totalPages: number;
|
|
22
|
+
page: number;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function useMerkleTrees(options?: UseMerkleTreesOptions): UseMerkleTreesReturn;
|
|
26
|
+
|
|
27
|
+
interface UseMerkleProofReturn {
|
|
28
|
+
proof: MerkleProofResponse | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fetch a merkle proof for a player address.
|
|
33
|
+
* Returns null when treeId or playerAddress is falsy (skips the fetch).
|
|
34
|
+
*/
|
|
35
|
+
declare function useMerkleProof(treeId: string | number | undefined, playerAddress: string | undefined): UseMerkleProofReturn;
|
|
36
|
+
|
|
5
37
|
declare function useDebounce<T>(value: T, delay: number): T;
|
|
6
38
|
|
|
7
39
|
interface UsePaginationOptions {
|
|
@@ -224,7 +256,9 @@ declare function useEntryQualification(options: UseEntryQualificationOptions): U
|
|
|
224
256
|
/**
|
|
225
257
|
* Hook to check extension qualification and entries left for multiple proofs.
|
|
226
258
|
*
|
|
227
|
-
*
|
|
259
|
+
* Generic across all extension types — each extension provides its own proof
|
|
260
|
+
* format. The hook simply passes the proof to `entries_left` on the contract
|
|
261
|
+
* and reports results.
|
|
228
262
|
*/
|
|
229
263
|
|
|
230
264
|
/** A single qualification method for an extension */
|
|
@@ -233,13 +267,7 @@ interface ExtensionQualification {
|
|
|
233
267
|
proof: string[];
|
|
234
268
|
entriesLeft: number;
|
|
235
269
|
label?: string;
|
|
236
|
-
metadata?:
|
|
237
|
-
tournamentId?: string;
|
|
238
|
-
tournamentName?: string;
|
|
239
|
-
tokenId?: string;
|
|
240
|
-
position?: number;
|
|
241
|
-
[key: string]: unknown;
|
|
242
|
-
};
|
|
270
|
+
metadata?: Record<string, unknown>;
|
|
243
271
|
}
|
|
244
272
|
/** Result from extension qualification check */
|
|
245
273
|
interface ExtensionQualificationResult {
|
|
@@ -249,24 +277,31 @@ interface ExtensionQualificationResult {
|
|
|
249
277
|
loading: boolean;
|
|
250
278
|
error: Error | null;
|
|
251
279
|
}
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
280
|
+
/**
|
|
281
|
+
* A potential qualification to check against the extension contract.
|
|
282
|
+
* The proof format is extension-specific — the SDK doesn't interpret it.
|
|
283
|
+
*/
|
|
284
|
+
interface QualificationInput {
|
|
285
|
+
/** Unique ID for this qualification method */
|
|
286
|
+
id: string;
|
|
287
|
+
/** Raw proof data (felt252 array) to pass to entries_left */
|
|
288
|
+
proof: string[];
|
|
289
|
+
/** Human-readable label for display */
|
|
290
|
+
label?: string;
|
|
291
|
+
/** Additional metadata for display */
|
|
292
|
+
metadata?: Record<string, unknown>;
|
|
258
293
|
}
|
|
259
294
|
/**
|
|
260
295
|
* Check extension qualification and entries left for multiple proofs.
|
|
261
296
|
*
|
|
262
297
|
* @param provider - Starknet RPC provider (or null to disable)
|
|
263
298
|
* @param extensionAddress - The extension contract address
|
|
264
|
-
* @param contextId - The metagame
|
|
299
|
+
* @param contextId - The metagame context ID
|
|
265
300
|
* @param playerAddress - The player's address
|
|
266
301
|
* @param qualificationInputs - Potential qualifications to check
|
|
267
302
|
* @param enabled - Whether to run the check (default: true)
|
|
268
303
|
*/
|
|
269
|
-
declare const useExtensionQualification: (provider: StarknetCallProvider | null, extensionAddress: string | undefined, contextId: string | undefined, playerAddress: string | undefined, qualificationInputs:
|
|
304
|
+
declare const useExtensionQualification: (provider: StarknetCallProvider | null, extensionAddress: string | undefined, contextId: string | undefined, playerAddress: string | undefined, qualificationInputs: QualificationInput[], enabled?: boolean) => ExtensionQualificationResult;
|
|
270
305
|
|
|
271
306
|
/**
|
|
272
307
|
* Hook to calculate bannable entries for Opus Troves extension.
|
|
@@ -297,4 +332,4 @@ declare const useOpusTrovesBannableEntries: (provider: StarknetCallProvider | nu
|
|
|
297
332
|
owner?: string;
|
|
298
333
|
}>, config: OpusTrovesValidatorConfig | undefined, enabled: boolean) => UseOpusTrovesBannableEntriesResult;
|
|
299
334
|
|
|
300
|
-
export { type CheckedExtensionQualification, type ExtensionQualification, type ExtensionQualificationResult, type
|
|
335
|
+
export { type CheckedExtensionQualification, type ExtensionQualification, type ExtensionQualificationResult, MetagameProvider, type MetagameProviderProps, type QualificationInput, type QualificationMethod, type UseEntryFeePreviewOptions, type UseEntryFeePreviewReturn, type UseEntryQualificationOptions, type UseEntryQualificationReturn, type UseMerkleProofReturn, type UseMerkleTreesOptions, type UseMerkleTreesReturn, 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, useMerkleProof, useMerkleTrees, useMetagameClient, useOpusTrovesBannableEntries, usePagination, usePrizeTable, useScoreTable, useSearchFilter, useStatusIndicator, useTokenSelector };
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,238 @@
|
|
|
1
|
-
import { useState, useEffect,
|
|
2
|
-
import {
|
|
1
|
+
import { createContext, useMemo, useContext, useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import { StandardMerkleTree } from '@ericnordelo/strk-merkle-tree';
|
|
3
|
+
import { CallData, hash } from 'starknet';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
5
|
|
|
4
|
-
// src/react/
|
|
6
|
+
// src/react/MetagameProvider.tsx
|
|
7
|
+
function computeLeafValue(address, count) {
|
|
8
|
+
const intermediate = hash.computePedersenHash("0x0", address);
|
|
9
|
+
return hash.computePedersenHash(intermediate, "0x" + count.toString(16));
|
|
10
|
+
}
|
|
11
|
+
function buildMerkleTree(entries) {
|
|
12
|
+
if (entries.length === 0) {
|
|
13
|
+
throw new Error("Cannot build merkle tree with no entries");
|
|
14
|
+
}
|
|
15
|
+
const leaves = entries.map((e) => [computeLeafValue(e.address, e.count)]);
|
|
16
|
+
const tree = StandardMerkleTree.of(leaves, ["felt252"], {
|
|
17
|
+
sortLeaves: true
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
version: 2,
|
|
21
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22
|
+
entries,
|
|
23
|
+
root: tree.root,
|
|
24
|
+
tree: tree.dump()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/merkle/client.ts
|
|
29
|
+
var DEFAULT_MERKLE_API_URLS = {
|
|
30
|
+
SN_SEPOLIA: "https://merkle-api-sepolia.up.railway.app",
|
|
31
|
+
SN_MAIN: "https://merkle-api.up.railway.app"
|
|
32
|
+
};
|
|
33
|
+
var MerkleClient = class {
|
|
34
|
+
apiUrl;
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.apiUrl = config.apiUrl ?? DEFAULT_MERKLE_API_URLS[config.chainId] ?? DEFAULT_MERKLE_API_URLS.SN_MAIN;
|
|
37
|
+
}
|
|
38
|
+
/** Fetch paginated list of merkle trees. */
|
|
39
|
+
async getTrees(options) {
|
|
40
|
+
const empty2 = {
|
|
41
|
+
data: [],
|
|
42
|
+
total: 0,
|
|
43
|
+
page: 1,
|
|
44
|
+
limit: 20,
|
|
45
|
+
totalPages: 0
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const params = new URLSearchParams();
|
|
49
|
+
if (options?.page) params.set("page", String(options.page));
|
|
50
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
51
|
+
const qs = params.toString();
|
|
52
|
+
const res = await fetch(`${this.apiUrl}/trees${qs ? `?${qs}` : ""}`);
|
|
53
|
+
if (!res.ok) return empty2;
|
|
54
|
+
const json = await res.json();
|
|
55
|
+
return {
|
|
56
|
+
data: json.data ?? [],
|
|
57
|
+
total: json.total ?? 0,
|
|
58
|
+
page: json.page ?? 1,
|
|
59
|
+
limit: json.limit ?? 20,
|
|
60
|
+
totalPages: json.totalPages ?? 0
|
|
61
|
+
};
|
|
62
|
+
} catch {
|
|
63
|
+
return empty2;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Fetch entries for a specific merkle tree. */
|
|
67
|
+
async getTreeEntries(treeId, options) {
|
|
68
|
+
const empty2 = {
|
|
69
|
+
data: [],
|
|
70
|
+
total: 0,
|
|
71
|
+
page: 1,
|
|
72
|
+
limit: 50,
|
|
73
|
+
totalPages: 0
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const params = new URLSearchParams();
|
|
77
|
+
if (options?.page) params.set("page", String(options.page));
|
|
78
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
79
|
+
const qs = params.toString();
|
|
80
|
+
const res = await fetch(
|
|
81
|
+
`${this.apiUrl}/trees/${treeId}/entries${qs ? `?${qs}` : ""}`
|
|
82
|
+
);
|
|
83
|
+
if (!res.ok) return empty2;
|
|
84
|
+
const json = await res.json();
|
|
85
|
+
return {
|
|
86
|
+
data: json.data ?? [],
|
|
87
|
+
total: json.total ?? 0,
|
|
88
|
+
page: json.page ?? 1,
|
|
89
|
+
limit: json.limit ?? 50,
|
|
90
|
+
totalPages: json.totalPages ?? 0
|
|
91
|
+
};
|
|
92
|
+
} catch {
|
|
93
|
+
return empty2;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Fetch a merkle proof for a player address. */
|
|
97
|
+
async getProof(treeId, playerAddress) {
|
|
98
|
+
try {
|
|
99
|
+
const res = await fetch(
|
|
100
|
+
`${this.apiUrl}/trees/${treeId}/proof/${playerAddress.toLowerCase()}`
|
|
101
|
+
);
|
|
102
|
+
if (!res.ok) return null;
|
|
103
|
+
return await res.json();
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Store a merkle tree in the API (after on-chain registration). */
|
|
109
|
+
async storeTree(request) {
|
|
110
|
+
const res = await fetch(`${this.apiUrl}/trees`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { "Content-Type": "application/json" },
|
|
113
|
+
body: JSON.stringify(request)
|
|
114
|
+
});
|
|
115
|
+
if (!res.ok) {
|
|
116
|
+
const text = await res.text();
|
|
117
|
+
throw new Error(`Failed to create merkle tree: ${text}`);
|
|
118
|
+
}
|
|
119
|
+
return await res.json();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Build a merkle tree locally and return the calldata needed
|
|
123
|
+
* to register it on-chain via the validator contract.
|
|
124
|
+
*
|
|
125
|
+
* The consumer is responsible for executing the call with their
|
|
126
|
+
* own account/signer.
|
|
127
|
+
*/
|
|
128
|
+
buildTreeCalldata(entries, validatorAddress) {
|
|
129
|
+
const tree = buildMerkleTree(entries);
|
|
130
|
+
return {
|
|
131
|
+
tree,
|
|
132
|
+
call: {
|
|
133
|
+
contractAddress: validatorAddress,
|
|
134
|
+
entrypoint: "create_tree",
|
|
135
|
+
calldata: [tree.root]
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Parse the tree ID from transaction receipt events.
|
|
141
|
+
* Returns null if the event cannot be found.
|
|
142
|
+
*/
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
144
|
+
parseTreeIdFromEvents(events, validatorAddress) {
|
|
145
|
+
const validatorBigInt = BigInt(validatorAddress);
|
|
146
|
+
const treeEvent = events.find((e) => {
|
|
147
|
+
try {
|
|
148
|
+
return BigInt(e.from_address) === validatorBigInt;
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (!treeEvent?.keys?.[1]) return null;
|
|
154
|
+
return Number(BigInt(treeEvent.keys[1]));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Store the tree in the API after on-chain registration.
|
|
158
|
+
* Pass the tree ID from the on-chain event along with the original entries.
|
|
159
|
+
*/
|
|
160
|
+
async createTree(params) {
|
|
161
|
+
return this.storeTree({
|
|
162
|
+
id: params.treeId,
|
|
163
|
+
name: params.name,
|
|
164
|
+
description: params.description,
|
|
165
|
+
entries: params.entries
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/client.ts
|
|
171
|
+
var MetagameClient = class {
|
|
172
|
+
chainId;
|
|
173
|
+
merkle;
|
|
174
|
+
constructor(config) {
|
|
175
|
+
this.chainId = config.chainId;
|
|
176
|
+
const merkleConfig = {
|
|
177
|
+
chainId: config.chainId,
|
|
178
|
+
apiUrl: config.merkleApiUrl
|
|
179
|
+
};
|
|
180
|
+
this.merkle = new MerkleClient(merkleConfig);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
function createMetagameClient(config) {
|
|
184
|
+
return new MetagameClient(config);
|
|
185
|
+
}
|
|
186
|
+
var MetagameContext = createContext(null);
|
|
187
|
+
function MetagameProvider({
|
|
188
|
+
children,
|
|
189
|
+
...config
|
|
190
|
+
}) {
|
|
191
|
+
const client = useMemo(
|
|
192
|
+
() => createMetagameClient(config),
|
|
193
|
+
[config.chainId, config.merkleApiUrl]
|
|
194
|
+
);
|
|
195
|
+
return /* @__PURE__ */ jsx(MetagameContext.Provider, { value: client, children });
|
|
196
|
+
}
|
|
197
|
+
function useMetagameClient() {
|
|
198
|
+
const client = useContext(MetagameContext);
|
|
199
|
+
if (!client) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
"useMetagameClient must be used within a MetagameProvider"
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return client;
|
|
205
|
+
}
|
|
206
|
+
function useMerkleTrees(options) {
|
|
207
|
+
const client = useMetagameClient();
|
|
208
|
+
const [data, setData] = useState(null);
|
|
209
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
setIsLoading(true);
|
|
212
|
+
client.merkle.getTrees({ page: options?.page, limit: options?.limit }).then(setData).finally(() => setIsLoading(false));
|
|
213
|
+
}, [client, options?.page, options?.limit]);
|
|
214
|
+
return {
|
|
215
|
+
trees: data?.data ?? [],
|
|
216
|
+
total: data?.total ?? 0,
|
|
217
|
+
totalPages: data?.totalPages ?? 0,
|
|
218
|
+
page: data?.page ?? 1,
|
|
219
|
+
isLoading
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function useMerkleProof(treeId, playerAddress) {
|
|
223
|
+
const client = useMetagameClient();
|
|
224
|
+
const [proof, setProof] = useState(null);
|
|
225
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (!treeId || !playerAddress) {
|
|
228
|
+
setProof(null);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setIsLoading(true);
|
|
232
|
+
client.merkle.getProof(treeId, playerAddress).then(setProof).finally(() => setIsLoading(false));
|
|
233
|
+
}, [client, treeId, playerAddress]);
|
|
234
|
+
return { proof, isLoading };
|
|
235
|
+
}
|
|
5
236
|
function useDebounce(value, delay) {
|
|
6
237
|
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
7
238
|
useEffect(() => {
|
|
@@ -700,11 +931,7 @@ var useExtensionQualification = (provider, extensionAddress, contextId, playerAd
|
|
|
700
931
|
extensionAddress,
|
|
701
932
|
contextId,
|
|
702
933
|
playerAddress,
|
|
703
|
-
inputs: qualificationInputs.map((i) => ({
|
|
704
|
-
tid: i.tournamentId,
|
|
705
|
-
token: i.tokenId,
|
|
706
|
-
pos: i.position
|
|
707
|
-
}))
|
|
934
|
+
inputs: qualificationInputs.map((i) => ({ id: i.id, proof: i.proof }))
|
|
708
935
|
});
|
|
709
936
|
}, [enabled, provider, extensionAddress, contextId, playerAddress, qualificationInputs]);
|
|
710
937
|
const lastFetchedKey = useRef("");
|
|
@@ -727,36 +954,26 @@ var useExtensionQualification = (provider, extensionAddress, contextId, playerAd
|
|
|
727
954
|
const results = await Promise.all(
|
|
728
955
|
qualificationInputs.map(async (input) => {
|
|
729
956
|
try {
|
|
730
|
-
const proof = [
|
|
731
|
-
input.tournamentId,
|
|
732
|
-
input.tokenId,
|
|
733
|
-
input.position.toString()
|
|
734
|
-
];
|
|
735
957
|
const entriesLeft = await getExtensionEntriesLeft(
|
|
736
958
|
provider,
|
|
737
959
|
extensionAddress,
|
|
738
960
|
contextId,
|
|
739
961
|
playerAddress,
|
|
740
|
-
proof
|
|
962
|
+
input.proof
|
|
741
963
|
);
|
|
742
964
|
if (entriesLeft !== null && entriesLeft > 0) {
|
|
743
965
|
return {
|
|
744
|
-
id:
|
|
745
|
-
proof,
|
|
966
|
+
id: input.id,
|
|
967
|
+
proof: input.proof,
|
|
746
968
|
entriesLeft,
|
|
747
|
-
label: input.
|
|
748
|
-
metadata:
|
|
749
|
-
tournamentId: input.tournamentId,
|
|
750
|
-
tournamentName: input.tournamentName,
|
|
751
|
-
tokenId: input.tokenId,
|
|
752
|
-
position: input.position
|
|
753
|
-
}
|
|
969
|
+
label: input.label,
|
|
970
|
+
metadata: input.metadata
|
|
754
971
|
};
|
|
755
972
|
}
|
|
756
973
|
return null;
|
|
757
974
|
} catch (err) {
|
|
758
975
|
console.error(
|
|
759
|
-
`Error checking qualification
|
|
976
|
+
`Error checking qualification ${input.id}:`,
|
|
760
977
|
err
|
|
761
978
|
);
|
|
762
979
|
return null;
|
|
@@ -901,6 +1118,6 @@ var useOpusTrovesBannableEntries = (provider, games, config, enabled) => {
|
|
|
901
1118
|
};
|
|
902
1119
|
};
|
|
903
1120
|
|
|
904
|
-
export { useDebounce, useEntryFeePreview, useEntryQualification, useExtensionQualification, useOpusTrovesBannableEntries, usePagination, usePrizeTable, useScoreTable, useSearchFilter, useStatusIndicator, useTokenSelector };
|
|
1121
|
+
export { MetagameProvider, useDebounce, useEntryFeePreview, useEntryQualification, useExtensionQualification, useMerkleProof, useMerkleTrees, useMetagameClient, useOpusTrovesBannableEntries, usePagination, usePrizeTable, useScoreTable, useSearchFilter, useStatusIndicator, useTokenSelector };
|
|
905
1122
|
//# sourceMappingURL=react.js.map
|
|
906
1123
|
//# sourceMappingURL=react.js.map
|