@provable-games/budokan-sdk 0.1.20 → 0.1.22

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.
@@ -1,5 +1,5 @@
1
1
  import { RpcProvider } from 'starknet';
2
- import { EntryFee, EntryRequirement, QualificationProof } from '@provable-games/metagame-sdk';
2
+ import { EntryFee, EntryRequirement } from '@provable-games/metagame-sdk';
3
3
 
4
4
  type DataSource = "api" | "rpc";
5
5
  interface BudokanClientConfig {
@@ -111,9 +111,20 @@ interface TournamentListParams {
111
111
  whitelistedExtensions?: string[];
112
112
  includePrizeSummary?: "summary" | boolean;
113
113
  }
114
+ /**
115
+ * Discriminator for `QualificationEntry.qualificationKind`. Picks one of
116
+ * the two terminal variants of the on-chain `QualificationProof` enum
117
+ * (NFT, Extension). `nftTokenId` is populated only for `nft`;
118
+ * `extensionConfig` only for `extension`.
119
+ */
120
+ type QualificationKind = "nft" | "extension";
114
121
  interface QualificationEntry {
115
122
  tournamentId: string;
116
- qualificationProof: QualificationProof | null;
123
+ qualificationKind: QualificationKind;
124
+ /** Populated when `qualificationKind === "nft"`. u256 token id, decimal string. */
125
+ nftTokenId: string | null;
126
+ /** Populated when `qualificationKind === "extension"`. List of felt252 hex strings. */
127
+ extensionConfig: string[] | null;
117
128
  entryCount: number;
118
129
  }
119
130
 
@@ -141,23 +152,6 @@ interface Registration {
141
152
  isBanned: boolean;
142
153
  }
143
154
 
144
- type RewardType = {
145
- Prize: {
146
- tokenAddress: string;
147
- tokenType: string;
148
- };
149
- } | {
150
- EntryFee: EntryFeeRewardType;
151
- };
152
- type EntryFeeRewardType = {
153
- Position: number;
154
- } | {
155
- TournamentCreator: Record<string, never>;
156
- } | {
157
- GameCreator: Record<string, never>;
158
- } | {
159
- Refund: string;
160
- };
161
155
  interface Prize {
162
156
  prizeId: string;
163
157
  tournamentId: string;
@@ -174,9 +168,25 @@ interface Prize {
174
168
  distributionCount: number | null;
175
169
  sponsorAddress: string;
176
170
  }
171
+ /**
172
+ * Discriminator for `RewardClaim.claimKind`. Picks one of the six terminal
173
+ * variants of the on-chain `RewardType` enum (Prize::Single, Prize::Distributed,
174
+ * EntryFee::Position / TournamentCreator / GameCreator / Refund). The
175
+ * variant-specific fields below are populated only for the kinds that carry
176
+ * them; the two pure-marker creator kinds leave all four nullable fields null.
177
+ */
178
+ type RewardClaimKind = "prize_single" | "prize_distributed" | "entry_fee_position" | "entry_fee_tournament_creator" | "entry_fee_game_creator" | "entry_fee_refund";
177
179
  interface RewardClaim {
178
180
  tournamentId: string;
179
- rewardType: RewardType;
181
+ claimKind: RewardClaimKind;
182
+ /** Populated for `prize_single` and `prize_distributed`. Stringified u64. */
183
+ prizeId: string | null;
184
+ /** Populated for `prize_distributed`. */
185
+ payoutIndex: number | null;
186
+ /** Populated for `entry_fee_position`. */
187
+ position: number | null;
188
+ /** Populated for `entry_fee_refund`. felt252 hex string of the game token. */
189
+ refundTokenId: string | null;
180
190
  claimed: boolean;
181
191
  }
182
192
  interface PrizeAggregation {
@@ -191,23 +201,6 @@ interface RewardClaimSummary {
191
201
  totalUnclaimed: number;
192
202
  }
193
203
 
194
- interface ActivityEvent {
195
- id: string;
196
- eventType: string;
197
- tournamentId: string | null;
198
- playerAddress: string | null;
199
- data: Record<string, unknown>;
200
- blockNumber: string;
201
- txHash: string;
202
- eventIndex: number;
203
- }
204
- interface ActivityParams {
205
- eventType?: string;
206
- tournamentId?: string;
207
- playerAddress?: string;
208
- limit?: number;
209
- offset?: number;
210
- }
211
204
  interface PlatformStats {
212
205
  totalTournaments: number;
213
206
  totalPrizes: number;
@@ -451,11 +444,6 @@ declare class BudokanClient {
451
444
  * API-only -- no RPC fallback available.
452
445
  */
453
446
  getTournamentPrizeAggregation(tournamentId: string): Promise<PrizeAggregation[]>;
454
- /**
455
- * Fetch activity events with optional filtering.
456
- * API-only — no RPC fallback available.
457
- */
458
- getActivity(params?: ActivityParams): Promise<PaginatedResult<ActivityEvent>>;
459
447
  /**
460
448
  * Fetch platform-wide activity stats.
461
449
  * API-only — no RPC fallback available.
@@ -494,4 +482,4 @@ declare class BudokanClient {
494
482
  */
495
483
  declare function createBudokanClient(config: BudokanClientConfig): BudokanClient;
496
484
 
497
- export { type ActivityParams as A, BudokanClient as B, type ConnectionMode as C, type DataSource as D, type GameConfig as G, type LeaderboardConfig as L, type PrizeAggregation as P, type QualificationEntry as Q, type Registration as R, type Schedule as S, type Tournament as T, type WSSubscribeOptions as W, type Prize as a, type PaginatedResult as b, type RewardClaim as c, type RewardClaimSummary as d, type TournamentListParams as e, type PlatformStats as f, type ActivityEvent as g, type PrizeStats as h, type WSEventHandler as i, type BudokanClientConfig as j, ConnectionStatus as k, type ConnectionStatusState as l, type LeaderboardEntry as m, type Phase as n, type WSChannel as o, type WSEventMessage as p, type WSMessage as q, type WSSubscribeMessage as r, type WSUnsubscribeMessage as s, createBudokanClient as t };
485
+ export { BudokanClient as B, type ConnectionMode as C, type DataSource as D, type GameConfig as G, type LeaderboardConfig as L, type PrizeAggregation as P, type QualificationEntry as Q, type Registration as R, type Schedule as S, type Tournament as T, type WSSubscribeOptions as W, type Prize as a, type PaginatedResult as b, type RewardClaim as c, type RewardClaimSummary as d, type TournamentListParams as e, type PlatformStats as f, type PrizeStats as g, type WSEventHandler as h, type BudokanClientConfig as i, ConnectionStatus as j, type ConnectionStatusState as k, type LeaderboardEntry as l, type Phase as m, type WSChannel as n, type WSEventMessage as o, type WSMessage as p, type WSSubscribeMessage as q, type WSUnsubscribeMessage as r, createBudokanClient as s };
@@ -1,5 +1,5 @@
1
1
  import { RpcProvider } from 'starknet';
2
- import { EntryFee, EntryRequirement, QualificationProof } from '@provable-games/metagame-sdk';
2
+ import { EntryFee, EntryRequirement } from '@provable-games/metagame-sdk';
3
3
 
4
4
  type DataSource = "api" | "rpc";
5
5
  interface BudokanClientConfig {
@@ -111,9 +111,20 @@ interface TournamentListParams {
111
111
  whitelistedExtensions?: string[];
112
112
  includePrizeSummary?: "summary" | boolean;
113
113
  }
114
+ /**
115
+ * Discriminator for `QualificationEntry.qualificationKind`. Picks one of
116
+ * the two terminal variants of the on-chain `QualificationProof` enum
117
+ * (NFT, Extension). `nftTokenId` is populated only for `nft`;
118
+ * `extensionConfig` only for `extension`.
119
+ */
120
+ type QualificationKind = "nft" | "extension";
114
121
  interface QualificationEntry {
115
122
  tournamentId: string;
116
- qualificationProof: QualificationProof | null;
123
+ qualificationKind: QualificationKind;
124
+ /** Populated when `qualificationKind === "nft"`. u256 token id, decimal string. */
125
+ nftTokenId: string | null;
126
+ /** Populated when `qualificationKind === "extension"`. List of felt252 hex strings. */
127
+ extensionConfig: string[] | null;
117
128
  entryCount: number;
118
129
  }
119
130
 
@@ -141,23 +152,6 @@ interface Registration {
141
152
  isBanned: boolean;
142
153
  }
143
154
 
144
- type RewardType = {
145
- Prize: {
146
- tokenAddress: string;
147
- tokenType: string;
148
- };
149
- } | {
150
- EntryFee: EntryFeeRewardType;
151
- };
152
- type EntryFeeRewardType = {
153
- Position: number;
154
- } | {
155
- TournamentCreator: Record<string, never>;
156
- } | {
157
- GameCreator: Record<string, never>;
158
- } | {
159
- Refund: string;
160
- };
161
155
  interface Prize {
162
156
  prizeId: string;
163
157
  tournamentId: string;
@@ -174,9 +168,25 @@ interface Prize {
174
168
  distributionCount: number | null;
175
169
  sponsorAddress: string;
176
170
  }
171
+ /**
172
+ * Discriminator for `RewardClaim.claimKind`. Picks one of the six terminal
173
+ * variants of the on-chain `RewardType` enum (Prize::Single, Prize::Distributed,
174
+ * EntryFee::Position / TournamentCreator / GameCreator / Refund). The
175
+ * variant-specific fields below are populated only for the kinds that carry
176
+ * them; the two pure-marker creator kinds leave all four nullable fields null.
177
+ */
178
+ type RewardClaimKind = "prize_single" | "prize_distributed" | "entry_fee_position" | "entry_fee_tournament_creator" | "entry_fee_game_creator" | "entry_fee_refund";
177
179
  interface RewardClaim {
178
180
  tournamentId: string;
179
- rewardType: RewardType;
181
+ claimKind: RewardClaimKind;
182
+ /** Populated for `prize_single` and `prize_distributed`. Stringified u64. */
183
+ prizeId: string | null;
184
+ /** Populated for `prize_distributed`. */
185
+ payoutIndex: number | null;
186
+ /** Populated for `entry_fee_position`. */
187
+ position: number | null;
188
+ /** Populated for `entry_fee_refund`. felt252 hex string of the game token. */
189
+ refundTokenId: string | null;
180
190
  claimed: boolean;
181
191
  }
182
192
  interface PrizeAggregation {
@@ -191,23 +201,6 @@ interface RewardClaimSummary {
191
201
  totalUnclaimed: number;
192
202
  }
193
203
 
194
- interface ActivityEvent {
195
- id: string;
196
- eventType: string;
197
- tournamentId: string | null;
198
- playerAddress: string | null;
199
- data: Record<string, unknown>;
200
- blockNumber: string;
201
- txHash: string;
202
- eventIndex: number;
203
- }
204
- interface ActivityParams {
205
- eventType?: string;
206
- tournamentId?: string;
207
- playerAddress?: string;
208
- limit?: number;
209
- offset?: number;
210
- }
211
204
  interface PlatformStats {
212
205
  totalTournaments: number;
213
206
  totalPrizes: number;
@@ -451,11 +444,6 @@ declare class BudokanClient {
451
444
  * API-only -- no RPC fallback available.
452
445
  */
453
446
  getTournamentPrizeAggregation(tournamentId: string): Promise<PrizeAggregation[]>;
454
- /**
455
- * Fetch activity events with optional filtering.
456
- * API-only — no RPC fallback available.
457
- */
458
- getActivity(params?: ActivityParams): Promise<PaginatedResult<ActivityEvent>>;
459
447
  /**
460
448
  * Fetch platform-wide activity stats.
461
449
  * API-only — no RPC fallback available.
@@ -494,4 +482,4 @@ declare class BudokanClient {
494
482
  */
495
483
  declare function createBudokanClient(config: BudokanClientConfig): BudokanClient;
496
484
 
497
- export { type ActivityParams as A, BudokanClient as B, type ConnectionMode as C, type DataSource as D, type GameConfig as G, type LeaderboardConfig as L, type PrizeAggregation as P, type QualificationEntry as Q, type Registration as R, type Schedule as S, type Tournament as T, type WSSubscribeOptions as W, type Prize as a, type PaginatedResult as b, type RewardClaim as c, type RewardClaimSummary as d, type TournamentListParams as e, type PlatformStats as f, type ActivityEvent as g, type PrizeStats as h, type WSEventHandler as i, type BudokanClientConfig as j, ConnectionStatus as k, type ConnectionStatusState as l, type LeaderboardEntry as m, type Phase as n, type WSChannel as o, type WSEventMessage as p, type WSMessage as q, type WSSubscribeMessage as r, type WSUnsubscribeMessage as s, createBudokanClient as t };
485
+ export { BudokanClient as B, type ConnectionMode as C, type DataSource as D, type GameConfig as G, type LeaderboardConfig as L, type PrizeAggregation as P, type QualificationEntry as Q, type Registration as R, type Schedule as S, type Tournament as T, type WSSubscribeOptions as W, type Prize as a, type PaginatedResult as b, type RewardClaim as c, type RewardClaimSummary as d, type TournamentListParams as e, type PlatformStats as f, type PrizeStats as g, type WSEventHandler as h, type BudokanClientConfig as i, ConnectionStatus as j, type ConnectionStatusState as k, type LeaderboardEntry as l, type Phase as m, type WSChannel as n, type WSEventMessage as o, type WSMessage as p, type WSSubscribeMessage as q, type WSUnsubscribeMessage as r, createBudokanClient as s };
package/dist/index.cjs CHANGED
@@ -369,23 +369,6 @@ function fetchOpts3(ctx) {
369
369
  timeout: ctx?.timeout
370
370
  };
371
371
  }
372
- async function getActivity(baseUrl, params, ctx) {
373
- const qs = buildQueryString({
374
- event_type: params?.eventType,
375
- tournament_id: params?.tournamentId,
376
- player_address: params?.playerAddress,
377
- limit: params?.limit,
378
- offset: params?.offset
379
- });
380
- const result = await apiFetch(`${baseUrl}/activity${qs}`, fetchOpts3(ctx));
381
- const { total, limit: resLimit, offset: resOffset } = extractPagination(result, { limit: params?.limit, offset: params?.offset });
382
- return {
383
- data: result.data.map((item) => snakeToCamel(item)),
384
- total,
385
- limit: resLimit,
386
- offset: resOffset
387
- };
388
- }
389
372
  async function getActivityStats(baseUrl, ctx) {
390
373
  const result = await apiFetch(
391
374
  `${baseUrl}/activity/stats`,
@@ -1142,6 +1125,84 @@ async function viewerPrizes(contract, tournamentId) {
1142
1125
  return result.map(parsePrize);
1143
1126
  }, contract.address);
1144
1127
  }
1128
+ function translateCairoRewardType(rewardType) {
1129
+ if (!rewardType || typeof rewardType !== "object") {
1130
+ throw new Error(`Unexpected RewardType payload: ${JSON.stringify(rewardType)}`);
1131
+ }
1132
+ const rt = rewardType;
1133
+ const outer = typeof rt.activeVariant === "function" ? rt.activeVariant() : null;
1134
+ const innerBag = typeof rt.activeVariant === "function" ? rt.variant : rt;
1135
+ if (outer === "Prize" || innerBag.Prize !== void 0) {
1136
+ const prize = innerBag.Prize;
1137
+ const subVariant = typeof prize?.activeVariant === "function" ? prize.activeVariant() : null;
1138
+ const subBag = typeof prize?.activeVariant === "function" ? prize.variant : prize;
1139
+ if (subVariant === "Single" || subBag?.Single !== void 0) {
1140
+ return {
1141
+ claimKind: "prize_single",
1142
+ prizeId: BigInt(subBag.Single).toString(),
1143
+ payoutIndex: null,
1144
+ position: null,
1145
+ refundTokenId: null
1146
+ };
1147
+ }
1148
+ if (subVariant === "Distributed" || subBag?.Distributed !== void 0) {
1149
+ const distributed = subBag.Distributed;
1150
+ const prizeId = distributed?.["0"] ?? distributed?.[0];
1151
+ const payoutIndex = distributed?.["1"] ?? distributed?.[1];
1152
+ return {
1153
+ claimKind: "prize_distributed",
1154
+ prizeId: BigInt(prizeId).toString(),
1155
+ payoutIndex: Number(payoutIndex),
1156
+ position: null,
1157
+ refundTokenId: null
1158
+ };
1159
+ }
1160
+ }
1161
+ if (outer === "EntryFee" || innerBag.EntryFee !== void 0) {
1162
+ const entryFee = innerBag.EntryFee;
1163
+ const subVariant = typeof entryFee?.activeVariant === "function" ? entryFee.activeVariant() : null;
1164
+ const subBag = typeof entryFee?.activeVariant === "function" ? entryFee.variant : entryFee;
1165
+ if (subVariant === "Position" || subBag?.Position !== void 0) {
1166
+ return {
1167
+ claimKind: "entry_fee_position",
1168
+ prizeId: null,
1169
+ payoutIndex: null,
1170
+ position: Number(subBag.Position),
1171
+ refundTokenId: null
1172
+ };
1173
+ }
1174
+ if (subVariant === "TournamentCreator" || subBag?.TournamentCreator !== void 0) {
1175
+ return {
1176
+ claimKind: "entry_fee_tournament_creator",
1177
+ prizeId: null,
1178
+ payoutIndex: null,
1179
+ position: null,
1180
+ refundTokenId: null
1181
+ };
1182
+ }
1183
+ if (subVariant === "GameCreator" || subBag?.GameCreator !== void 0) {
1184
+ return {
1185
+ claimKind: "entry_fee_game_creator",
1186
+ prizeId: null,
1187
+ payoutIndex: null,
1188
+ position: null,
1189
+ refundTokenId: null
1190
+ };
1191
+ }
1192
+ if (subVariant === "Refund" || subBag?.Refund !== void 0) {
1193
+ return {
1194
+ claimKind: "entry_fee_refund",
1195
+ prizeId: null,
1196
+ payoutIndex: null,
1197
+ position: null,
1198
+ refundTokenId: `0x${BigInt(subBag.Refund).toString(16)}`
1199
+ };
1200
+ }
1201
+ }
1202
+ throw new Error(
1203
+ `Unrecognised on-chain RewardType variant: ${JSON.stringify(rewardType)}`
1204
+ );
1205
+ }
1145
1206
  async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1146
1207
  return wrapRpcCall(async () => {
1147
1208
  const result = await contract.call("tournament_reward_claims", [tournamentId, offset, limit]);
@@ -1149,7 +1210,7 @@ async function viewerRewardClaims(contract, tournamentId, offset, limit) {
1149
1210
  const claims = obj.claims?.map((raw) => {
1150
1211
  const claim = raw;
1151
1212
  return {
1152
- rewardType: claim.reward_type,
1213
+ ...translateCairoRewardType(claim.reward_type),
1153
1214
  claimed: Boolean(claim.claimed)
1154
1215
  };
1155
1216
  }) ?? [];
@@ -4546,8 +4607,7 @@ var BudokanClient = class {
4546
4607
  const result = await viewerRewardClaims(contract, tournamentId, offset, limit);
4547
4608
  const data = result.claims.map((c) => ({
4548
4609
  tournamentId,
4549
- rewardType: c.rewardType,
4550
- claimed: c.claimed
4610
+ ...c
4551
4611
  }));
4552
4612
  return { data, total: result.total, limit, offset };
4553
4613
  };
@@ -4598,13 +4658,6 @@ var BudokanClient = class {
4598
4658
  return getTournamentPrizeAggregation(this.resolvedConfig.apiBaseUrl, tournamentId, this.apiCtx);
4599
4659
  }
4600
4660
  // ---- Activity Queries (API-only, activity is indexed) ----
4601
- /**
4602
- * Fetch activity events with optional filtering.
4603
- * API-only — no RPC fallback available.
4604
- */
4605
- async getActivity(params) {
4606
- return getActivity(this.resolvedConfig.apiBaseUrl, params, this.apiCtx);
4607
- }
4608
4661
  /**
4609
4662
  * Fetch platform-wide activity stats.
4610
4663
  * API-only — no RPC fallback available.
@@ -4671,7 +4724,6 @@ exports.TournamentNotFoundError = TournamentNotFoundError;
4671
4724
  exports.WSManager = WSManager;
4672
4725
  exports.camelToSnake = camelToSnake;
4673
4726
  exports.createBudokanClient = createBudokanClient;
4674
- exports.getActivity = getActivity;
4675
4727
  exports.getActivityStats = getActivityStats;
4676
4728
  exports.getChainConfig = getChainConfig;
4677
4729
  exports.getGameStats = getGameStats;