@provable-games/budokan-sdk 0.1.24 → 0.1.25

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/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { T as Tournament, P as PrizeAggregation, a as Prize, b as PaginatedResult, Q as QualificationEntry, R as Registration, c as RewardClaim, d as RewardClaimSummary, e as TournamentListParams, f as PlatformStats, g as PrizeStats, W as WSSubscribeOptions, h as WSEventHandler } from './player-C2GE9Lop.cjs';
2
- export { B as BudokanClient, i as BudokanClientConfig, C as ConnectionMode, j as ConnectionStatus, k as ConnectionStatusState, D as DataSource, G as GameConfig, L as LeaderboardConfig, l as LeaderboardEntry, m as Phase, n as PlayerPlacement, o as PlayerRewards, S as Schedule, p as WSChannel, q as WSEventMessage, r as WSMessage, s as WSSubscribeMessage, t as WSUnsubscribeMessage, u as createBudokanClient } from './player-C2GE9Lop.cjs';
1
+ import { T as Tournament, P as PrizeAggregation, a as Prize, b as PaginatedResult, Q as QualificationEntry, R as Registration, c as RewardClaim, d as RewardClaimSummary, e as TournamentListParams, f as PlatformStats, g as PrizeStats, W as WSSubscribeOptions, h as WSEventHandler, i as TokenPrize, E as ExtensionPrize$1 } from './player-P6Dd1lNb.cjs';
2
+ export { B as BudokanClient, j as BudokanClientConfig, C as ConnectionMode, k as ConnectionStatus, l as ConnectionStatusState, D as DataSource, m as Erc20Prize, n as Erc721Prize, G as GameConfig, L as LeaderboardConfig, o as LeaderboardEntry, p as Phase, q as PlayerPlacement, r as PlayerRewards, S as Schedule, s as WSChannel, t as WSEventMessage, u as WSMessage, v as WSSubscribeMessage, w as WSUnsubscribeMessage, x as createBudokanClient } from './player-P6Dd1lNb.cjs';
3
+ import { ExtensionPrize, PrizeLike, Prize as Prize$1 } from '@provable-games/metagame-sdk';
3
4
  export { EntryFee } from '@provable-games/metagame-sdk';
4
5
  import 'starknet';
5
6
 
@@ -180,6 +181,80 @@ declare function camelToSnake<T>(obj: unknown): T;
180
181
 
181
182
  declare function withRetry<T>(fn: () => Promise<T>, attempts?: number, delay?: number): Promise<T>;
182
183
 
184
+ type MetagameTokenPrize = Prize$1;
185
+ type MetagameExtensionPrize = ExtensionPrize;
186
+ type MetagamePrizeLike = PrizeLike;
187
+ declare function isRawTokenPrize(prize: Prize): prize is TokenPrize;
188
+ declare function isRawExtensionPrize(prize: Prize): prize is ExtensionPrize$1;
189
+ declare function isTokenPrize(prize: Prize): prize is TokenPrize;
190
+ declare function isExtensionPrize(prize: Prize): prize is ExtensionPrize$1;
191
+ /**
192
+ * Returns true when a prize is a valid Budokan token/extension prize and has a
193
+ * hydrated leaderboard position suitable for the metagame prize shape.
194
+ */
195
+ declare function isMetagameAdaptablePrize(prize: Prize): prize is TokenPrize | ExtensionPrize$1;
196
+ /**
197
+ * Returns validated raw token prizes. Extension records are skipped without
198
+ * validation; malformed `erc20`/`erc721` records throw instead of being
199
+ * silently dropped. RPC records with `payoutPosition === 0` are returned here
200
+ * for raw token-prize visibility.
201
+ */
202
+ declare function getRawTokenPrizes(prizes: readonly Prize[]): TokenPrize[];
203
+ /**
204
+ * Returns validated hydrated token prizes. Extension records are skipped
205
+ * without validation, and valid raw token prizes with `payoutPosition === 0`
206
+ * are skipped; malformed `erc20`/`erc721` records throw instead of being
207
+ * silently dropped.
208
+ */
209
+ declare function getTokenPrizes(prizes: readonly Prize[]): TokenPrize[];
210
+ /**
211
+ * Converts a guard-validated Budokan token prize into the Metagame SDK token
212
+ * prize shape. Metagame token prizes do not carry Budokan distribution fields,
213
+ * so distributed ERC20 prizes are represented by their aggregate `amount` at
214
+ * `payoutPosition`; use the original Budokan `Prize` for payout-split math.
215
+ * For ERC721 prizes, metagame-sdk@0.1.13 uses `amount` to carry the token ID.
216
+ * Throws when `payoutPosition` is zero because the RPC path uses zero for
217
+ * unhydrated token-prize positions and metagame positions are leaderboard slots.
218
+ */
219
+ declare function toMetagameTokenPrize(prize: TokenPrize): MetagameTokenPrize;
220
+ /**
221
+ * Converts a guard-validated Budokan extension prize into the Metagame SDK
222
+ * extension-prize shape. Throws when `payoutPosition` is zero because metagame
223
+ * positions are leaderboard slots and the RPC path uses zero for unhydrated
224
+ * prize positions.
225
+ */
226
+ declare function toMetagameExtensionPrize(prize: ExtensionPrize$1): MetagameExtensionPrize;
227
+ /**
228
+ * Converts supported Budokan prize variants into Metagame SDK prize shapes.
229
+ * Throws when a prize has malformed fields or an unhydrated payout position.
230
+ * Raw-but-valid zero-position prizes throw the unhydrated-position error.
231
+ * See `toMetagameTokenPrize` for token prize distribution behavior.
232
+ */
233
+ declare function toMetagamePrize(prize: Prize): MetagamePrizeLike;
234
+ /**
235
+ * Non-throwing metagame adapter. Returns null for malformed prize records and
236
+ * for valid RPC-sourced prizes whose `payoutPosition` is not hydrated yet.
237
+ */
238
+ declare function tryToMetagamePrize(prize: Prize): MetagamePrizeLike | null;
239
+ /**
240
+ * Converts supported Budokan prize variants into Metagame SDK prize shapes.
241
+ * Throws when any prize has malformed fields or an unhydrated payout position.
242
+ * See `toMetagameTokenPrize` for token prize distribution behavior.
243
+ */
244
+ declare function toMetagamePrizes(prizes: readonly Prize[]): MetagamePrizeLike[];
245
+ /**
246
+ * Non-throwing batch metagame adapter. Skips malformed records and valid
247
+ * RPC-sourced prizes whose `payoutPosition` is not hydrated yet.
248
+ */
249
+ declare function tryToMetagamePrizes(prizes: readonly Prize[]): MetagamePrizeLike[];
250
+ /**
251
+ * Converts Budokan token prizes into Metagame SDK token prize shapes. Extension
252
+ * records are skipped without validation. Throws for malformed token records
253
+ * and unhydrated token positions. See `toMetagameTokenPrize` for distribution
254
+ * behavior.
255
+ */
256
+ declare function toMetagameTokenPrizes(prizes: readonly Prize[]): MetagameTokenPrize[];
257
+
183
258
  interface ChainConfig {
184
259
  rpcUrl: string;
185
260
  apiBaseUrl: string;
@@ -517,6 +592,8 @@ type RewardType = {
517
592
  kind: "entry_fee_tournament_creator";
518
593
  } | {
519
594
  kind: "entry_fee_game_creator";
595
+ } | {
596
+ kind: "entry_fee_protocol_fee";
520
597
  } | {
521
598
  kind: "entry_fee_refund";
522
599
  tokenId: string;
@@ -725,4 +802,4 @@ interface TournamentValidatorConfig {
725
802
  */
726
803
  declare function buildTournamentValidatorConfig(cfg: TournamentValidatorConfig): string[];
727
804
 
728
- export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type CreateTournamentArgs, DataSourceError, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, type GameDefaults, type MerkleConfig, type OpusTrovesConfig, PaginatedResult, PlatformStats, Prize, PrizeAggregation, type PrizeSpec, PrizeStats, QualificationEntry, type ReceiptWithEvents, Registration, RewardClaim, RewardClaimSummary, type RewardType, RpcError, type TokenTypeSpec, Tournament, TournamentListParams, TournamentNotFoundError, type TournamentRequirementType, type TournamentValidatorConfig, WSEventHandler, WSManager, WSSubscribeOptions, type WhitelistChain, type WhitelistedGame, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isGameWhitelisted, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, tournamentPageUrl, u256ToLowHigh, withRetry };
805
+ export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type CreateTournamentArgs, DataSourceError, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, ExtensionPrize$1 as ExtensionPrize, type GameDefaults, type MerkleConfig, type MetagameExtensionPrize, type MetagamePrizeLike, type MetagameTokenPrize, type OpusTrovesConfig, PaginatedResult, PlatformStats, Prize, PrizeAggregation, type PrizeSpec, PrizeStats, QualificationEntry, type ReceiptWithEvents, Registration, RewardClaim, RewardClaimSummary, type RewardType, RpcError, TokenPrize, type TokenTypeSpec, Tournament, TournamentListParams, TournamentNotFoundError, type TournamentRequirementType, type TournamentValidatorConfig, WSEventHandler, WSManager, WSSubscribeOptions, type WhitelistChain, type WhitelistedGame, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getRawTokenPrizes, getTokenPrizes, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isExtensionPrize, isGameWhitelisted, isMetagameAdaptablePrize, isRawExtensionPrize, isRawTokenPrize, isTokenPrize, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, toMetagameExtensionPrize, toMetagamePrize, toMetagamePrizes, toMetagameTokenPrize, toMetagameTokenPrizes, tournamentPageUrl, tryToMetagamePrize, tryToMetagamePrizes, u256ToLowHigh, withRetry };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { T as Tournament, P as PrizeAggregation, a as Prize, b as PaginatedResult, Q as QualificationEntry, R as Registration, c as RewardClaim, d as RewardClaimSummary, e as TournamentListParams, f as PlatformStats, g as PrizeStats, W as WSSubscribeOptions, h as WSEventHandler } from './player-C2GE9Lop.js';
2
- export { B as BudokanClient, i as BudokanClientConfig, C as ConnectionMode, j as ConnectionStatus, k as ConnectionStatusState, D as DataSource, G as GameConfig, L as LeaderboardConfig, l as LeaderboardEntry, m as Phase, n as PlayerPlacement, o as PlayerRewards, S as Schedule, p as WSChannel, q as WSEventMessage, r as WSMessage, s as WSSubscribeMessage, t as WSUnsubscribeMessage, u as createBudokanClient } from './player-C2GE9Lop.js';
1
+ import { T as Tournament, P as PrizeAggregation, a as Prize, b as PaginatedResult, Q as QualificationEntry, R as Registration, c as RewardClaim, d as RewardClaimSummary, e as TournamentListParams, f as PlatformStats, g as PrizeStats, W as WSSubscribeOptions, h as WSEventHandler, i as TokenPrize, E as ExtensionPrize$1 } from './player-P6Dd1lNb.js';
2
+ export { B as BudokanClient, j as BudokanClientConfig, C as ConnectionMode, k as ConnectionStatus, l as ConnectionStatusState, D as DataSource, m as Erc20Prize, n as Erc721Prize, G as GameConfig, L as LeaderboardConfig, o as LeaderboardEntry, p as Phase, q as PlayerPlacement, r as PlayerRewards, S as Schedule, s as WSChannel, t as WSEventMessage, u as WSMessage, v as WSSubscribeMessage, w as WSUnsubscribeMessage, x as createBudokanClient } from './player-P6Dd1lNb.js';
3
+ import { ExtensionPrize, PrizeLike, Prize as Prize$1 } from '@provable-games/metagame-sdk';
3
4
  export { EntryFee } from '@provable-games/metagame-sdk';
4
5
  import 'starknet';
5
6
 
@@ -180,6 +181,80 @@ declare function camelToSnake<T>(obj: unknown): T;
180
181
 
181
182
  declare function withRetry<T>(fn: () => Promise<T>, attempts?: number, delay?: number): Promise<T>;
182
183
 
184
+ type MetagameTokenPrize = Prize$1;
185
+ type MetagameExtensionPrize = ExtensionPrize;
186
+ type MetagamePrizeLike = PrizeLike;
187
+ declare function isRawTokenPrize(prize: Prize): prize is TokenPrize;
188
+ declare function isRawExtensionPrize(prize: Prize): prize is ExtensionPrize$1;
189
+ declare function isTokenPrize(prize: Prize): prize is TokenPrize;
190
+ declare function isExtensionPrize(prize: Prize): prize is ExtensionPrize$1;
191
+ /**
192
+ * Returns true when a prize is a valid Budokan token/extension prize and has a
193
+ * hydrated leaderboard position suitable for the metagame prize shape.
194
+ */
195
+ declare function isMetagameAdaptablePrize(prize: Prize): prize is TokenPrize | ExtensionPrize$1;
196
+ /**
197
+ * Returns validated raw token prizes. Extension records are skipped without
198
+ * validation; malformed `erc20`/`erc721` records throw instead of being
199
+ * silently dropped. RPC records with `payoutPosition === 0` are returned here
200
+ * for raw token-prize visibility.
201
+ */
202
+ declare function getRawTokenPrizes(prizes: readonly Prize[]): TokenPrize[];
203
+ /**
204
+ * Returns validated hydrated token prizes. Extension records are skipped
205
+ * without validation, and valid raw token prizes with `payoutPosition === 0`
206
+ * are skipped; malformed `erc20`/`erc721` records throw instead of being
207
+ * silently dropped.
208
+ */
209
+ declare function getTokenPrizes(prizes: readonly Prize[]): TokenPrize[];
210
+ /**
211
+ * Converts a guard-validated Budokan token prize into the Metagame SDK token
212
+ * prize shape. Metagame token prizes do not carry Budokan distribution fields,
213
+ * so distributed ERC20 prizes are represented by their aggregate `amount` at
214
+ * `payoutPosition`; use the original Budokan `Prize` for payout-split math.
215
+ * For ERC721 prizes, metagame-sdk@0.1.13 uses `amount` to carry the token ID.
216
+ * Throws when `payoutPosition` is zero because the RPC path uses zero for
217
+ * unhydrated token-prize positions and metagame positions are leaderboard slots.
218
+ */
219
+ declare function toMetagameTokenPrize(prize: TokenPrize): MetagameTokenPrize;
220
+ /**
221
+ * Converts a guard-validated Budokan extension prize into the Metagame SDK
222
+ * extension-prize shape. Throws when `payoutPosition` is zero because metagame
223
+ * positions are leaderboard slots and the RPC path uses zero for unhydrated
224
+ * prize positions.
225
+ */
226
+ declare function toMetagameExtensionPrize(prize: ExtensionPrize$1): MetagameExtensionPrize;
227
+ /**
228
+ * Converts supported Budokan prize variants into Metagame SDK prize shapes.
229
+ * Throws when a prize has malformed fields or an unhydrated payout position.
230
+ * Raw-but-valid zero-position prizes throw the unhydrated-position error.
231
+ * See `toMetagameTokenPrize` for token prize distribution behavior.
232
+ */
233
+ declare function toMetagamePrize(prize: Prize): MetagamePrizeLike;
234
+ /**
235
+ * Non-throwing metagame adapter. Returns null for malformed prize records and
236
+ * for valid RPC-sourced prizes whose `payoutPosition` is not hydrated yet.
237
+ */
238
+ declare function tryToMetagamePrize(prize: Prize): MetagamePrizeLike | null;
239
+ /**
240
+ * Converts supported Budokan prize variants into Metagame SDK prize shapes.
241
+ * Throws when any prize has malformed fields or an unhydrated payout position.
242
+ * See `toMetagameTokenPrize` for token prize distribution behavior.
243
+ */
244
+ declare function toMetagamePrizes(prizes: readonly Prize[]): MetagamePrizeLike[];
245
+ /**
246
+ * Non-throwing batch metagame adapter. Skips malformed records and valid
247
+ * RPC-sourced prizes whose `payoutPosition` is not hydrated yet.
248
+ */
249
+ declare function tryToMetagamePrizes(prizes: readonly Prize[]): MetagamePrizeLike[];
250
+ /**
251
+ * Converts Budokan token prizes into Metagame SDK token prize shapes. Extension
252
+ * records are skipped without validation. Throws for malformed token records
253
+ * and unhydrated token positions. See `toMetagameTokenPrize` for distribution
254
+ * behavior.
255
+ */
256
+ declare function toMetagameTokenPrizes(prizes: readonly Prize[]): MetagameTokenPrize[];
257
+
183
258
  interface ChainConfig {
184
259
  rpcUrl: string;
185
260
  apiBaseUrl: string;
@@ -517,6 +592,8 @@ type RewardType = {
517
592
  kind: "entry_fee_tournament_creator";
518
593
  } | {
519
594
  kind: "entry_fee_game_creator";
595
+ } | {
596
+ kind: "entry_fee_protocol_fee";
520
597
  } | {
521
598
  kind: "entry_fee_refund";
522
599
  tokenId: string;
@@ -725,4 +802,4 @@ interface TournamentValidatorConfig {
725
802
  */
726
803
  declare function buildTournamentValidatorConfig(cfg: TournamentValidatorConfig): string[];
727
804
 
728
- export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type CreateTournamentArgs, DataSourceError, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, type GameDefaults, type MerkleConfig, type OpusTrovesConfig, PaginatedResult, PlatformStats, Prize, PrizeAggregation, type PrizeSpec, PrizeStats, QualificationEntry, type ReceiptWithEvents, Registration, RewardClaim, RewardClaimSummary, type RewardType, RpcError, type TokenTypeSpec, Tournament, TournamentListParams, TournamentNotFoundError, type TournamentRequirementType, type TournamentValidatorConfig, WSEventHandler, WSManager, WSSubscribeOptions, type WhitelistChain, type WhitelistedGame, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isGameWhitelisted, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, tournamentPageUrl, u256ToLowHigh, withRetry };
805
+ export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type CreateTournamentArgs, DataSourceError, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, ExtensionPrize$1 as ExtensionPrize, type GameDefaults, type MerkleConfig, type MetagameExtensionPrize, type MetagamePrizeLike, type MetagameTokenPrize, type OpusTrovesConfig, PaginatedResult, PlatformStats, Prize, PrizeAggregation, type PrizeSpec, PrizeStats, QualificationEntry, type ReceiptWithEvents, Registration, RewardClaim, RewardClaimSummary, type RewardType, RpcError, TokenPrize, type TokenTypeSpec, Tournament, TournamentListParams, TournamentNotFoundError, type TournamentRequirementType, type TournamentValidatorConfig, WSEventHandler, WSManager, WSSubscribeOptions, type WhitelistChain, type WhitelistedGame, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getRawTokenPrizes, getTokenPrizes, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isExtensionPrize, isGameWhitelisted, isMetagameAdaptablePrize, isRawExtensionPrize, isRawTokenPrize, isTokenPrize, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, toMetagameExtensionPrize, toMetagamePrize, toMetagamePrizes, toMetagameTokenPrize, toMetagameTokenPrizes, tournamentPageUrl, tryToMetagamePrize, tryToMetagamePrizes, u256ToLowHigh, withRetry };
package/dist/index.js CHANGED
@@ -213,7 +213,8 @@ function camelToSnake(obj) {
213
213
  function normalizeTournament(raw) {
214
214
  const t = snakeToCamel(raw);
215
215
  const id = t.id ?? t.tournamentId;
216
- return { ...t, id, tournamentId: id };
216
+ const protocolFeeShare = t.protocolFeeShare ?? t.entryFee?.protocolFeeShare ?? null;
217
+ return { ...t, id, tournamentId: id, protocolFeeShare };
217
218
  }
218
219
  function fetchOpts(ctx) {
219
220
  return {
@@ -830,7 +831,7 @@ function phaseToRpcArg(phase) {
830
831
  }
831
832
  return new CairoCustomEnum(variants);
832
833
  }
833
- function parseTournament(raw, entryCount) {
834
+ function parseTournament(raw, entryCount, protocolFeeShare = null) {
834
835
  const obj = raw;
835
836
  const id = String(obj.id ?? "0");
836
837
  const createdAt = Number(obj.created_at ?? 0);
@@ -928,6 +929,8 @@ function parseTournament(raw, entryCount) {
928
929
  leaderboardGameMustBeOver: gameMustBeOver,
929
930
  entryFeeToken,
930
931
  entryFeeAmount,
932
+ // Protocol-fee bps snapshot, surfaced by the viewer's TournamentFullState.
933
+ protocolFeeShare,
931
934
  hasEntryRequirement,
932
935
  schedule: {
933
936
  registrationStartDelay,
@@ -1094,7 +1097,8 @@ function parseFilterResult(raw) {
1094
1097
  function parseTournamentFullState(raw) {
1095
1098
  const obj = raw;
1096
1099
  const entryCount = Number(obj.entry_count ?? 0);
1097
- return parseTournament(obj.tournament, entryCount);
1100
+ const protocolFeeShare = obj.protocol_fee_bps != null ? Number(obj.protocol_fee_bps) : null;
1101
+ return parseTournament(obj.tournament, entryCount, protocolFeeShare);
1098
1102
  }
1099
1103
  async function viewerTournaments(contract, offset, limit) {
1100
1104
  return wrapRpcCall(async () => {
@@ -1270,6 +1274,9 @@ function translateCairoRewardType(rewardType) {
1270
1274
  if (subVariant === "GameCreator" || subBag?.GameCreator !== void 0) {
1271
1275
  return rewardClaim({ claimKind: "entry_fee_game_creator" });
1272
1276
  }
1277
+ if (subVariant === "ProtocolFee" || subBag?.ProtocolFee !== void 0) {
1278
+ return rewardClaim({ claimKind: "entry_fee_protocol_fee" });
1279
+ }
1273
1280
  if (subVariant === "Refund" || subBag?.Refund !== void 0) {
1274
1281
  return rewardClaim({
1275
1282
  claimKind: "entry_fee_refund",
@@ -1742,6 +1749,10 @@ var budokanViewer_default = [
1742
1749
  {
1743
1750
  name: "phase",
1744
1751
  type: "budokan_interfaces::budokan::Phase"
1752
+ },
1753
+ {
1754
+ name: "protocol_fee_bps",
1755
+ type: "core::integer::u16"
1745
1756
  }
1746
1757
  ]
1747
1758
  },
@@ -2012,6 +2023,10 @@ var budokanViewer_default = [
2012
2023
  {
2013
2024
  name: "Refund",
2014
2025
  type: "core::felt252"
2026
+ },
2027
+ {
2028
+ name: "ProtocolFee",
2029
+ type: "()"
2015
2030
  }
2016
2031
  ]
2017
2032
  },
@@ -3390,6 +3405,10 @@ var budokan_default = [
3390
3405
  {
3391
3406
  name: "Refund",
3392
3407
  type: "core::felt252"
3408
+ },
3409
+ {
3410
+ name: "ProtocolFee",
3411
+ type: "()"
3393
3412
  }
3394
3413
  ]
3395
3414
  },
@@ -4678,6 +4697,11 @@ var budokan_default = [
4678
4697
  name: "entry_requirement",
4679
4698
  type: "core::option::Option::<game_components_interfaces::entry_requirement::EntryRequirement>",
4680
4699
  kind: "data"
4700
+ },
4701
+ {
4702
+ name: "protocol_fee_bps",
4703
+ type: "core::integer::u16",
4704
+ kind: "data"
4681
4705
  }
4682
4706
  ]
4683
4707
  },
@@ -4900,6 +4924,108 @@ var budokan_default = [
4900
4924
  name: "QualificationEntriesUpdated",
4901
4925
  type: "budokan::events::QualificationEntriesUpdated",
4902
4926
  kind: "nested"
4927
+ },
4928
+ {
4929
+ name: "ProtocolFeeBpsUpdated",
4930
+ type: "budokan::events::ProtocolFeeBpsUpdated",
4931
+ kind: "nested"
4932
+ },
4933
+ {
4934
+ name: "ProtocolFeeRecipientUpdated",
4935
+ type: "budokan::events::ProtocolFeeRecipientUpdated",
4936
+ kind: "nested"
4937
+ }
4938
+ ]
4939
+ },
4940
+ {
4941
+ type: "interface",
4942
+ name: "budokan::budokan::Budokan::IBudokanProtocolFeeAdmin",
4943
+ items: [
4944
+ {
4945
+ type: "function",
4946
+ name: "set_protocol_fee_bps",
4947
+ inputs: [
4948
+ {
4949
+ name: "bps",
4950
+ type: "core::integer::u16"
4951
+ }
4952
+ ],
4953
+ outputs: [],
4954
+ state_mutability: "external"
4955
+ },
4956
+ {
4957
+ type: "function",
4958
+ name: "set_protocol_fee_recipient",
4959
+ inputs: [
4960
+ {
4961
+ name: "recipient",
4962
+ type: "core::starknet::contract_address::ContractAddress"
4963
+ }
4964
+ ],
4965
+ outputs: [],
4966
+ state_mutability: "external"
4967
+ },
4968
+ {
4969
+ type: "function",
4970
+ name: "protocol_fee_bps",
4971
+ inputs: [],
4972
+ outputs: [
4973
+ {
4974
+ type: "core::integer::u16"
4975
+ }
4976
+ ],
4977
+ state_mutability: "view"
4978
+ },
4979
+ {
4980
+ type: "function",
4981
+ name: "protocol_fee_recipient",
4982
+ inputs: [],
4983
+ outputs: [
4984
+ {
4985
+ type: "core::starknet::contract_address::ContractAddress"
4986
+ }
4987
+ ],
4988
+ state_mutability: "view"
4989
+ },
4990
+ {
4991
+ type: "function",
4992
+ name: "tournament_protocol_fee_bps",
4993
+ inputs: [
4994
+ {
4995
+ name: "tournament_id",
4996
+ type: "core::integer::u64"
4997
+ }
4998
+ ],
4999
+ outputs: [
5000
+ {
5001
+ type: "core::integer::u16"
5002
+ }
5003
+ ],
5004
+ state_mutability: "view"
5005
+ }
5006
+ ]
5007
+ },
5008
+ {
5009
+ type: "event",
5010
+ name: "budokan::events::ProtocolFeeBpsUpdated",
5011
+ kind: "struct",
5012
+ members: [
5013
+ {
5014
+ name: "bps",
5015
+ type: "core::integer::u16",
5016
+ kind: "data"
5017
+ }
5018
+ ]
5019
+ },
5020
+ {
5021
+ type: "event",
5022
+ name: "budokan::events::ProtocolFeeRecipientUpdated",
5023
+ kind: "struct",
5024
+ members: [
5025
+ {
5026
+ name: "recipient",
5027
+ type: "core::starknet::contract_address::ContractAddress",
5028
+ kind: "key"
4903
5029
  }
4904
5030
  ]
4905
5031
  }
@@ -5367,6 +5493,185 @@ function createBudokanClient(config) {
5367
5493
  return new BudokanClient(config);
5368
5494
  }
5369
5495
 
5496
+ // src/utils/prizes.ts
5497
+ function isNonEmptyString(value) {
5498
+ return typeof value === "string" && value.length > 0;
5499
+ }
5500
+ function isNonNegativeIntegerString(value) {
5501
+ if (!isNonEmptyString(value) || value.trim() !== value) return false;
5502
+ if (!/^\d+$/.test(value)) return false;
5503
+ try {
5504
+ return BigInt(value) >= 0n;
5505
+ } catch {
5506
+ return false;
5507
+ }
5508
+ }
5509
+ function isNonNegativeIntegerNumber(value) {
5510
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
5511
+ }
5512
+ function isPositiveIntegerNumber(value) {
5513
+ return typeof value === "number" && Number.isInteger(value) && value > 0;
5514
+ }
5515
+ function isDistributionType(value) {
5516
+ return value === "linear" || value === "exponential" || value === "uniform" || value === "custom";
5517
+ }
5518
+ function hasNoDistributionFields(prize) {
5519
+ return prize.distributionType === null && prize.distributionWeight === null && prize.distributionShares === null && prize.distributionCount === null;
5520
+ }
5521
+ function hasValidDistributionFields(prize) {
5522
+ if (prize.distributionType === null) return hasNoDistributionFields(prize);
5523
+ if (!isDistributionType(prize.distributionType)) return false;
5524
+ if (!isPositiveIntegerNumber(prize.distributionCount)) return false;
5525
+ if (prize.distributionType === "custom") {
5526
+ return prize.distributionWeight === null && Array.isArray(prize.distributionShares) && prize.distributionShares.length === prize.distributionCount && prize.distributionShares.every(isNonNegativeIntegerNumber) && prize.distributionShares.reduce((sum, share) => sum + share, 0) === 1e4;
5527
+ }
5528
+ if (prize.distributionType === "uniform") {
5529
+ return prize.distributionWeight === null && prize.distributionShares === null;
5530
+ }
5531
+ return isNonNegativeIntegerNumber(prize.distributionWeight) && prize.distributionShares === null;
5532
+ }
5533
+ function hasBasePrizeFields(prize) {
5534
+ return isNonNegativeIntegerString(prize.prizeId) && isNonNegativeIntegerString(prize.tournamentId) && Number.isInteger(prize.payoutPosition) && prize.payoutPosition >= 0 && isNonEmptyString(prize.sponsorAddress);
5535
+ }
5536
+ function hasExtensionConfig(value) {
5537
+ return value === null || Array.isArray(value) && value.every((entry) => typeof entry === "string");
5538
+ }
5539
+ function describePrize(prize) {
5540
+ const prizeId = isNonEmptyString(prize.prizeId) ? prize.prizeId : "<invalid>";
5541
+ return `prizeId=${prizeId}, tokenType=${prize.tokenType}`;
5542
+ }
5543
+ function malformedTokenPrizeError(action, prize) {
5544
+ return new TypeError(
5545
+ `Cannot ${action} malformed Budokan token prize (${describePrize(prize)})`
5546
+ );
5547
+ }
5548
+ function malformedExtensionPrizeError(action, prize) {
5549
+ return new TypeError(
5550
+ `Cannot ${action} malformed Budokan extension prize (${describePrize(prize)})`
5551
+ );
5552
+ }
5553
+ function assertMetagameTokenPosition(prize) {
5554
+ if (Number.isInteger(prize.payoutPosition) && prize.payoutPosition > 0) {
5555
+ return;
5556
+ }
5557
+ if (prize.payoutPosition !== 0) {
5558
+ throw new TypeError(
5559
+ `Cannot adapt Budokan token prize with invalid payout position (${describePrize(prize)})`
5560
+ );
5561
+ }
5562
+ throw new TypeError(
5563
+ `Cannot adapt Budokan token prize with unhydrated payout position (${describePrize(prize)})`
5564
+ );
5565
+ }
5566
+ function assertMetagameExtensionPosition(prize) {
5567
+ if (Number.isInteger(prize.payoutPosition) && prize.payoutPosition > 0) {
5568
+ return;
5569
+ }
5570
+ if (prize.payoutPosition !== 0) {
5571
+ throw new TypeError(
5572
+ `Cannot adapt Budokan extension prize with invalid payout position (${describePrize(prize)})`
5573
+ );
5574
+ }
5575
+ throw new TypeError(
5576
+ `Cannot adapt Budokan extension prize with unhydrated payout position (${describePrize(prize)})`
5577
+ );
5578
+ }
5579
+ function hasHydratedPayoutPosition(prize) {
5580
+ return prize.payoutPosition > 0;
5581
+ }
5582
+ function isRawTokenPrize(prize) {
5583
+ if (!hasBasePrizeFields(prize) || !isNonEmptyString(prize.tokenAddress)) {
5584
+ return false;
5585
+ }
5586
+ return prize.tokenType === "erc20" ? isNonNegativeIntegerString(prize.amount) && prize.tokenId === null && prize.extensionAddress === null && prize.extensionConfig === null && hasValidDistributionFields(prize) : prize.tokenType === "erc721" && prize.amount === null && isNonNegativeIntegerString(prize.tokenId) && prize.extensionAddress === null && prize.extensionConfig === null && hasNoDistributionFields(prize);
5587
+ }
5588
+ function isRawExtensionPrize(prize) {
5589
+ return hasBasePrizeFields(prize) && prize.tokenType === "extension" && prize.tokenAddress === null && prize.amount === null && prize.tokenId === null && hasNoDistributionFields(prize) && isNonEmptyString(prize.extensionAddress) && hasExtensionConfig(prize.extensionConfig);
5590
+ }
5591
+ function isTokenPrize(prize) {
5592
+ return isRawTokenPrize(prize) && hasHydratedPayoutPosition(prize);
5593
+ }
5594
+ function isExtensionPrize(prize) {
5595
+ return isRawExtensionPrize(prize) && hasHydratedPayoutPosition(prize);
5596
+ }
5597
+ function isMetagameAdaptablePrize(prize) {
5598
+ return isTokenPrize(prize) || isExtensionPrize(prize);
5599
+ }
5600
+ function getRawTokenPrizes(prizes) {
5601
+ return prizes.flatMap((prize) => {
5602
+ if (isRawTokenPrize(prize)) return [prize];
5603
+ if (prize.tokenType === "extension") return [];
5604
+ throw malformedTokenPrizeError("read", prize);
5605
+ });
5606
+ }
5607
+ function getTokenPrizes(prizes) {
5608
+ return prizes.flatMap((prize) => {
5609
+ if (isTokenPrize(prize)) return [prize];
5610
+ if (isRawTokenPrize(prize) || prize.tokenType === "extension") return [];
5611
+ throw malformedTokenPrizeError("read", prize);
5612
+ });
5613
+ }
5614
+ function toMetagameTokenPrize(prize) {
5615
+ assertMetagameTokenPosition(prize);
5616
+ if (!isRawTokenPrize(prize)) {
5617
+ throw malformedTokenPrizeError("adapt", prize);
5618
+ }
5619
+ const adapted = {
5620
+ id: prize.prizeId,
5621
+ position: prize.payoutPosition,
5622
+ tokenAddress: prize.tokenAddress,
5623
+ tokenType: prize.tokenType,
5624
+ // Metagame token prizes use `amount` as the token id for ERC721 entries.
5625
+ amount: prize.tokenType === "erc20" ? prize.amount : prize.tokenId,
5626
+ sponsorAddress: prize.sponsorAddress
5627
+ };
5628
+ return adapted;
5629
+ }
5630
+ function toMetagameExtensionPrize(prize) {
5631
+ assertMetagameExtensionPosition(prize);
5632
+ if (!isRawExtensionPrize(prize)) {
5633
+ throw malformedExtensionPrizeError("adapt", prize);
5634
+ }
5635
+ const adapted = {
5636
+ id: prize.prizeId,
5637
+ position: prize.payoutPosition,
5638
+ tokenAddress: null,
5639
+ tokenType: "extension",
5640
+ amount: null,
5641
+ sponsorAddress: prize.sponsorAddress,
5642
+ extensionAddress: prize.extensionAddress,
5643
+ extensionConfig: prize.extensionConfig
5644
+ };
5645
+ return adapted;
5646
+ }
5647
+ function toMetagamePrize(prize) {
5648
+ if (isRawTokenPrize(prize)) return toMetagameTokenPrize(prize);
5649
+ if (isRawExtensionPrize(prize)) return toMetagameExtensionPrize(prize);
5650
+ throw new TypeError(
5651
+ `Cannot adapt malformed Budokan prize (${describePrize(prize)})`
5652
+ );
5653
+ }
5654
+ function tryToMetagamePrize(prize) {
5655
+ if (!isMetagameAdaptablePrize(prize)) return null;
5656
+ return prize.tokenType === "extension" ? toMetagameExtensionPrize(prize) : toMetagameTokenPrize(prize);
5657
+ }
5658
+ function toMetagamePrizes(prizes) {
5659
+ return prizes.map(toMetagamePrize);
5660
+ }
5661
+ function tryToMetagamePrizes(prizes) {
5662
+ return prizes.flatMap((prize) => {
5663
+ const adapted = tryToMetagamePrize(prize);
5664
+ return adapted ? [adapted] : [];
5665
+ });
5666
+ }
5667
+ function toMetagameTokenPrizes(prizes) {
5668
+ return prizes.flatMap((prize) => {
5669
+ if (isRawTokenPrize(prize)) return [toMetagameTokenPrize(prize)];
5670
+ if (prize.tokenType === "extension") return [];
5671
+ throw malformedTokenPrizeError("adapt", prize);
5672
+ });
5673
+ }
5674
+
5370
5675
  // src/games/whitelist.ts
5371
5676
  var STRK = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
5372
5677
  var MAINNET_GAMES_RAW = [
@@ -5753,6 +6058,9 @@ function pushRewardTypeFelts(out, reward) {
5753
6058
  case "entry_fee_refund":
5754
6059
  out.push("0x1", "0x0", "0x3", num.toHex(reward.tokenId));
5755
6060
  return;
6061
+ case "entry_fee_protocol_fee":
6062
+ out.push("0x1", "0x0", "0x4");
6063
+ return;
5756
6064
  case "entry_fee_extension": {
5757
6065
  out.push("0x1", "0x1");
5758
6066
  if (reward.tokenId !== void 0) {
@@ -5862,6 +6170,6 @@ function buildTournamentValidatorConfig(cfg) {
5862
6170
  return [qualifierType, qualifyingMode, topPositions, ...cfg.tournamentIds];
5863
6171
  }
5864
6172
 
5865
- export { BudokanApiError, BudokanClient, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, ConnectionStatus, DataSourceError, RpcError, TournamentNotFoundError, WSManager, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, createBudokanClient, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isGameWhitelisted, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, tournamentPageUrl, u256ToLowHigh, withRetry };
6173
+ export { BudokanApiError, BudokanClient, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, ConnectionStatus, DataSourceError, RpcError, TournamentNotFoundError, WSManager, buildAddPrizeCall, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, createBudokanClient, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getRawTokenPrizes, getTokenPrizes, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isExtensionPrize, isGameWhitelisted, isMetagameAdaptablePrize, isRawExtensionPrize, isRawTokenPrize, isTokenPrize, normalizeAddress, parseTournamentIdFromReceipt, snakeToCamel, toMetagameExtensionPrize, toMetagamePrize, toMetagamePrizes, toMetagameTokenPrize, toMetagameTokenPrizes, tournamentPageUrl, tryToMetagamePrize, tryToMetagamePrizes, u256ToLowHigh, withRetry };
5866
6174
  //# sourceMappingURL=index.js.map
5867
6175
  //# sourceMappingURL=index.js.map