@provable-games/budokan-sdk 0.1.25 → 0.1.26
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.cjs +286 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +230 -3
- package/dist/index.d.ts +230 -3
- package/dist/index.js +278 -3
- package/dist/index.js.map +1 -1
- package/dist/{player-P6Dd1lNb.d.cts → player-CbAYHoW8.d.cts} +10 -2
- package/dist/{player-P6Dd1lNb.d.ts → player-CbAYHoW8.d.ts} +10 -2
- package/dist/react.cjs +35 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +35 -2
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
-
export { B as BudokanClient,
|
|
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, j as PlayerPlacement, k as Phase } from './player-CbAYHoW8.cjs';
|
|
2
|
+
export { B as BudokanClient, l as BudokanClientConfig, C as ConnectionMode, m as ConnectionStatus, n as ConnectionStatusState, D as DataSource, o as Erc20Prize, p as Erc721Prize, G as GameConfig, L as LeaderboardConfig, q as LeaderboardEntry, 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-CbAYHoW8.cjs';
|
|
3
3
|
import { ExtensionPrize, PrizeLike, Prize as Prize$1 } from '@provable-games/metagame-sdk';
|
|
4
4
|
export { EntryFee } from '@provable-games/metagame-sdk';
|
|
5
5
|
import 'starknet';
|
|
@@ -696,6 +696,233 @@ interface ReceiptWithEvents {
|
|
|
696
696
|
*/
|
|
697
697
|
declare function parseTournamentIdFromReceipt(receipt: ReceiptWithEvents, budokanAddress: string): bigint | undefined;
|
|
698
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Pure distribution + entry-fee math for Budokan.
|
|
701
|
+
*
|
|
702
|
+
* This module is the single source of truth for "how much does position N
|
|
703
|
+
* get?" — the same arithmetic the budokan client used to duplicate in
|
|
704
|
+
* `computeEntryFeeAmount` / `computePrizePercentages` / `processEntryFeePrizes`.
|
|
705
|
+
*
|
|
706
|
+
* All functions are pure: no I/O, no contract calls, no `Date.now()`. Token
|
|
707
|
+
* amounts are `bigint` in smallest token units; basis-point shares are plain
|
|
708
|
+
* numbers (0–10000). USD conversion, decimals, and formatting stay in the
|
|
709
|
+
* consumer.
|
|
710
|
+
*
|
|
711
|
+
* Distribution percentages are computed with the shared `calculateDistribution`
|
|
712
|
+
* from `@provable-games/metagame-sdk` — the *exact* function the budokan client
|
|
713
|
+
* renders payouts with — so amounts match between the SDK, budokan.gg, and any
|
|
714
|
+
* third-party integration. (The final on-chain claim amount is computed by the
|
|
715
|
+
* contract's fixed-point math; these values are the canonical client-side
|
|
716
|
+
* estimate, suitable for display and for filtering unclaimable zero slices.)
|
|
717
|
+
*
|
|
718
|
+
* Entry-fee split semantics follow the contract
|
|
719
|
+
* (`packages/rewards/src/budokan_rewards.cairo::_claim_entry_fee_position`):
|
|
720
|
+
* the position pool is the entry-fee pool **minus** the tournament-creator,
|
|
721
|
+
* game-creator, refund, *and protocol-fee* shares. The client historically
|
|
722
|
+
* omitted the protocol fee here and over-counted the position pool — this
|
|
723
|
+
* module fixes that by taking `protocolFeeShare` as an explicit input.
|
|
724
|
+
*/
|
|
725
|
+
|
|
726
|
+
type DistributionKind = "linear" | "exponential" | "uniform" | "custom" | "unknown";
|
|
727
|
+
interface ParsedDistribution {
|
|
728
|
+
type: DistributionKind;
|
|
729
|
+
/**
|
|
730
|
+
* Raw weight as stored on-chain (scaled ×10 — e.g. `10` = 1.0). `0` for
|
|
731
|
+
* Uniform/Custom. `distributionPercentages` divides by 10 internally.
|
|
732
|
+
*/
|
|
733
|
+
weight: number;
|
|
734
|
+
/** For Custom distributions, the raw u16 basis-point shares (one per paid position). */
|
|
735
|
+
customWeights?: number[];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Normalize the many wire shapes of the Cairo `Distribution` enum into a flat
|
|
739
|
+
* `{ type, weight, customWeights }`. Handles:
|
|
740
|
+
* - starknet.js v9 CairoCustomEnum: `{ variant: { Exponential: 100 } }`
|
|
741
|
+
* - SDK / PascalCase: `{ Exponential: 100 }`
|
|
742
|
+
* - lower-cased JSON (indexer/API): `{ exponential: 100 }`
|
|
743
|
+
* - explicit `{ type, weight }`
|
|
744
|
+
* - `Option`-wrapped weights (`{ Some: n }`)
|
|
745
|
+
*
|
|
746
|
+
* Unknown / missing input → `{ type: "unknown", weight: 0 }`, which
|
|
747
|
+
* `distributionPercentages` treats as Uniform.
|
|
748
|
+
*/
|
|
749
|
+
declare function parseDistribution(dist: unknown): ParsedDistribution;
|
|
750
|
+
/**
|
|
751
|
+
* Build a `ParsedDistribution` from the flat fields the SDK carries on a
|
|
752
|
+
* sponsored `Prize` (`distributionType` / `distributionWeight` /
|
|
753
|
+
* `distributionShares`).
|
|
754
|
+
*/
|
|
755
|
+
declare function prizeDistribution(prize: Pick<Prize, "distributionType" | "distributionWeight" | "distributionShares">): ParsedDistribution;
|
|
756
|
+
/**
|
|
757
|
+
* Per-position percentages (each 0–100, summing to ~100) for a distribution
|
|
758
|
+
* across `count` paid positions. Generalizes the client's
|
|
759
|
+
* `computeEntryFeePercentages` / `computePrizePercentages`.
|
|
760
|
+
*
|
|
761
|
+
* - linear/exponential: delegates to metagame-sdk's `calculateDistribution`
|
|
762
|
+
* (weight is divided by 10 to undo the on-chain ×10 scaling).
|
|
763
|
+
* - uniform / unknown: equal split.
|
|
764
|
+
* - custom: raw basis-point shares ÷ 100; falls back to uniform when the
|
|
765
|
+
* shares array length doesn't match `count`.
|
|
766
|
+
*/
|
|
767
|
+
declare function distributionPercentages(dist: ParsedDistribution, count: number): number[];
|
|
768
|
+
/** Input shape for entry-fee split math. Mirrors the on-chain built-in `EntryFee`
|
|
769
|
+
* plus the per-tournament protocol-fee snapshot (carried on `Tournament`). */
|
|
770
|
+
interface EntryFeeSplitInput {
|
|
771
|
+
/** Per-entry fee in smallest token units (decimal string or bigint). */
|
|
772
|
+
amount: string | bigint;
|
|
773
|
+
/** Number of paid entries collected. */
|
|
774
|
+
entryCount: number;
|
|
775
|
+
/** Basis-point shares (0–10000). Omitted / null → 0. */
|
|
776
|
+
tournamentCreatorShare?: number | null;
|
|
777
|
+
gameCreatorShare?: number | null;
|
|
778
|
+
refundShare?: number | null;
|
|
779
|
+
/** Protocol-fee bps snapshotted for the tournament (`Tournament.protocolFeeShare`). */
|
|
780
|
+
protocolFeeShare?: number | null;
|
|
781
|
+
}
|
|
782
|
+
interface EntryFeeSplit {
|
|
783
|
+
/** Total fee pool = amount × entryCount. */
|
|
784
|
+
total: bigint;
|
|
785
|
+
/** Pool shared across leaderboard positions = floor(availableShare × total / 10000). */
|
|
786
|
+
positionPool: bigint;
|
|
787
|
+
tournamentCreator: bigint;
|
|
788
|
+
gameCreator: bigint;
|
|
789
|
+
refund: bigint;
|
|
790
|
+
protocolFee: bigint;
|
|
791
|
+
/** Basis points left for positions after fixed shares (clamped ≥ 0). */
|
|
792
|
+
availableShareBps: number;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Split a built-in entry-fee pool into its on-chain components. The position
|
|
796
|
+
* pool reserves the tournament-creator, game-creator, refund, *and* protocol
|
|
797
|
+
* fee — matching `_claim_entry_fee_position`'s `available_share`.
|
|
798
|
+
*
|
|
799
|
+
* Note: each component is floored independently (sub-wei dust may not sum to
|
|
800
|
+
* `total`, exactly as on-chain).
|
|
801
|
+
*/
|
|
802
|
+
declare function entryFeeSplit(input: EntryFeeSplitInput): EntryFeeSplit;
|
|
803
|
+
/** The on-chain `EntryFee` distribution shape this module needs to size a
|
|
804
|
+
* position payout. A superset of `EntryFeeSplitInput`. */
|
|
805
|
+
interface EntryFeePositionInput extends EntryFeeSplitInput {
|
|
806
|
+
/** Raw on-chain `Distribution` (any wire shape — parsed internally). */
|
|
807
|
+
distribution: unknown;
|
|
808
|
+
/** Number of paid positions (`distribution_count`). */
|
|
809
|
+
distributionCount: number;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Amount a single leaderboard `position` (1-indexed) claims from the entry-fee
|
|
813
|
+
* pool. Generalizes the client's `computeEntryFeeAmount` — and fixes its
|
|
814
|
+
* protocol-fee over-count by reserving `protocolFeeShare`.
|
|
815
|
+
*
|
|
816
|
+
* Returns `0n` when the position is outside the paid range, the pool is empty,
|
|
817
|
+
* or the share rounds to zero (the contract makes such positions unclaimable).
|
|
818
|
+
*/
|
|
819
|
+
declare function entryFeePositionPayout(input: EntryFeePositionInput, position: number): bigint;
|
|
820
|
+
/**
|
|
821
|
+
* Amount a single `position` (1-indexed) claims from a distributed sponsored
|
|
822
|
+
* ERC20 prize. Generalizes the client's per-position `computePrizePercentages`
|
|
823
|
+
* + amount slicing. Returns `0n` for non-distributed / non-ERC20 prizes, a
|
|
824
|
+
* position outside the paid range, or a zero slice.
|
|
825
|
+
*/
|
|
826
|
+
declare function sponsorPrizePayout(prize: Prize, position: number): bigint;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Player reward resolution — "which rewards can this player still claim, and
|
|
830
|
+
* what `claim_reward` calls assemble them?"
|
|
831
|
+
*
|
|
832
|
+
* Generalizes the budokan client's `buildPlayerClaimCalls` + `computeEarnings`
|
|
833
|
+
* + `getClaimablePrizes`. Pure: walks placements + prize/entry-fee data +
|
|
834
|
+
* existing claims and returns not-yet-claimed, non-zero rewards plus the
|
|
835
|
+
* `Call`s to claim them (via the tested `buildClaimRewardCall` encoder — so
|
|
836
|
+
* the claim-encoding bug class the SDK was created to kill can't recur).
|
|
837
|
+
*
|
|
838
|
+
* Scope (matches the client): the connected player's own placements only —
|
|
839
|
+
* entry-fee position prizes + sponsored prizes. Creator shares, protocol fee,
|
|
840
|
+
* and per-token refunds are pool/owner concerns, not placement-derived, and
|
|
841
|
+
* are intentionally excluded.
|
|
842
|
+
*/
|
|
843
|
+
|
|
844
|
+
type ClaimableRewardSource = "entry_fee_position" | "sponsor_single" | "sponsor_distributed";
|
|
845
|
+
interface ClaimableReward {
|
|
846
|
+
tournamentId: string;
|
|
847
|
+
/** Human label for UI/telemetry (`tournament.name` or `#id`). */
|
|
848
|
+
tournamentName: string;
|
|
849
|
+
/** Reward descriptor — feed straight to `buildClaimRewardCall` / `buildClaimCalls`. */
|
|
850
|
+
reward: RewardType;
|
|
851
|
+
/** Where the reward comes from (UI grouping / telemetry). */
|
|
852
|
+
source: ClaimableRewardSource;
|
|
853
|
+
/** 1-indexed leaderboard position the reward is for. */
|
|
854
|
+
position: number;
|
|
855
|
+
/** Token contract (ERC20/ERC721). */
|
|
856
|
+
tokenAddress: string | null;
|
|
857
|
+
tokenType: "erc20" | "erc721";
|
|
858
|
+
/** ERC20 amount in smallest units; `undefined` for ERC721 (one NFT). */
|
|
859
|
+
amount?: bigint;
|
|
860
|
+
/** ERC721 token id, when applicable. */
|
|
861
|
+
tokenId?: string | null;
|
|
862
|
+
}
|
|
863
|
+
interface GetClaimableRewardsInput {
|
|
864
|
+
placements: PlayerPlacement[];
|
|
865
|
+
tournaments: Tournament[];
|
|
866
|
+
prizes: Prize[];
|
|
867
|
+
/** Existing reward-claim records. Only those with `claimed === true` filter rewards out. */
|
|
868
|
+
existingClaims: RewardClaim[];
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* The not-yet-claimed, non-zero rewards across the player's placements.
|
|
872
|
+
*
|
|
873
|
+
* Skips:
|
|
874
|
+
* - already-claimed rewards (would revert),
|
|
875
|
+
* - 0-amount ERC20 slices (contract truncation makes them unclaimable),
|
|
876
|
+
* - creator/protocol/refund shares (not placement-derived).
|
|
877
|
+
*/
|
|
878
|
+
declare function getClaimableRewards(input: GetClaimableRewardsInput): ClaimableReward[];
|
|
879
|
+
/**
|
|
880
|
+
* Turn resolved {@link ClaimableReward}s into `claim_reward` `Call`s for
|
|
881
|
+
* `account.execute([...])`. Order is preserved.
|
|
882
|
+
*/
|
|
883
|
+
declare function buildClaimCalls(rewards: ClaimableReward[], budokanAddress: string): Call[];
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Tournament phase derivation — the single source of truth for "what phase is
|
|
887
|
+
* this tournament in right now?", mirroring the contract exactly
|
|
888
|
+
* (`packages/budokan/src/libs/schedule.cairo::current_phase`).
|
|
889
|
+
*
|
|
890
|
+
* The client used to recompute this inline (`isStarted/isEnded/isSubmitted`);
|
|
891
|
+
* this generalizes it so the client, bot, and any integration agree with the
|
|
892
|
+
* chain on phase boundaries (all comparisons are strict `<`, so a boundary
|
|
893
|
+
* second belongs to the *later* phase, matching the Cairo `if` ladder).
|
|
894
|
+
*/
|
|
895
|
+
|
|
896
|
+
/** Minimal schedule + creation-time shape needed to derive a phase. Matches
|
|
897
|
+
* the relevant subset of `Tournament` (top-level delay fields + on-chain
|
|
898
|
+
* created-at), so a full `Tournament` satisfies it directly. */
|
|
899
|
+
interface PhaseInput {
|
|
900
|
+
/** Unix seconds (string or number) the tournament was created on-chain. */
|
|
901
|
+
createdAtOnchain?: string | number | null;
|
|
902
|
+
registrationStartDelay?: number | null;
|
|
903
|
+
registrationEndDelay?: number | null;
|
|
904
|
+
gameStartDelay?: number | null;
|
|
905
|
+
gameEndDelay?: number | null;
|
|
906
|
+
submissionDuration?: number | null;
|
|
907
|
+
/** Fallback structured schedule (used when top-level delays are absent). */
|
|
908
|
+
schedule?: {
|
|
909
|
+
registrationStartDelay: number;
|
|
910
|
+
registrationEndDelay: number;
|
|
911
|
+
gameStartDelay: number;
|
|
912
|
+
gameEndDelay: number;
|
|
913
|
+
submissionDuration: number;
|
|
914
|
+
} | null;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Derive the current {@link Phase}. Returns `null` when the on-chain
|
|
918
|
+
* creation time is unknown (can't anchor the schedule).
|
|
919
|
+
*
|
|
920
|
+
* @param t - tournament schedule + `createdAtOnchain`
|
|
921
|
+
* @param nowSeconds - Unix seconds to evaluate at (defaults to wall-clock now).
|
|
922
|
+
* Pass an explicit value for deterministic/testable derivation.
|
|
923
|
+
*/
|
|
924
|
+
declare function tournamentPhase(t: PhaseInput, nowSeconds?: number): Phase | null;
|
|
925
|
+
|
|
699
926
|
/**
|
|
700
927
|
* Entry-requirement validator extensions.
|
|
701
928
|
*
|
|
@@ -802,4 +1029,4 @@ interface TournamentValidatorConfig {
|
|
|
802
1029
|
*/
|
|
803
1030
|
declare function buildTournamentValidatorConfig(cfg: TournamentValidatorConfig): string[];
|
|
804
1031
|
|
|
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 };
|
|
1032
|
+
export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type ClaimableReward, type ClaimableRewardSource, type CreateTournamentArgs, DataSourceError, type DistributionKind, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryFeePositionInput, type EntryFeeSplit, type EntryFeeSplitInput, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, ExtensionPrize$1 as ExtensionPrize, type GameDefaults, type GetClaimableRewardsInput, type MerkleConfig, type MetagameExtensionPrize, type MetagamePrizeLike, type MetagameTokenPrize, type OpusTrovesConfig, PaginatedResult, type ParsedDistribution, Phase, type PhaseInput, PlatformStats, PlayerPlacement, 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, buildClaimCalls, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, distributionPercentages, entryFeePositionPayout, entryFeeSplit, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getClaimableRewards, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getRawTokenPrizes, getTokenPrizes, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isExtensionPrize, isGameWhitelisted, isMetagameAdaptablePrize, isRawExtensionPrize, isRawTokenPrize, isTokenPrize, normalizeAddress, parseDistribution, parseTournamentIdFromReceipt, prizeDistribution, snakeToCamel, sponsorPrizePayout, toMetagameExtensionPrize, toMetagamePrize, toMetagamePrizes, toMetagameTokenPrize, toMetagameTokenPrizes, tournamentPageUrl, tournamentPhase, tryToMetagamePrize, tryToMetagamePrizes, u256ToLowHigh, withRetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
-
export { B as BudokanClient,
|
|
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, j as PlayerPlacement, k as Phase } from './player-CbAYHoW8.js';
|
|
2
|
+
export { B as BudokanClient, l as BudokanClientConfig, C as ConnectionMode, m as ConnectionStatus, n as ConnectionStatusState, D as DataSource, o as Erc20Prize, p as Erc721Prize, G as GameConfig, L as LeaderboardConfig, q as LeaderboardEntry, 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-CbAYHoW8.js';
|
|
3
3
|
import { ExtensionPrize, PrizeLike, Prize as Prize$1 } from '@provable-games/metagame-sdk';
|
|
4
4
|
export { EntryFee } from '@provable-games/metagame-sdk';
|
|
5
5
|
import 'starknet';
|
|
@@ -696,6 +696,233 @@ interface ReceiptWithEvents {
|
|
|
696
696
|
*/
|
|
697
697
|
declare function parseTournamentIdFromReceipt(receipt: ReceiptWithEvents, budokanAddress: string): bigint | undefined;
|
|
698
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Pure distribution + entry-fee math for Budokan.
|
|
701
|
+
*
|
|
702
|
+
* This module is the single source of truth for "how much does position N
|
|
703
|
+
* get?" — the same arithmetic the budokan client used to duplicate in
|
|
704
|
+
* `computeEntryFeeAmount` / `computePrizePercentages` / `processEntryFeePrizes`.
|
|
705
|
+
*
|
|
706
|
+
* All functions are pure: no I/O, no contract calls, no `Date.now()`. Token
|
|
707
|
+
* amounts are `bigint` in smallest token units; basis-point shares are plain
|
|
708
|
+
* numbers (0–10000). USD conversion, decimals, and formatting stay in the
|
|
709
|
+
* consumer.
|
|
710
|
+
*
|
|
711
|
+
* Distribution percentages are computed with the shared `calculateDistribution`
|
|
712
|
+
* from `@provable-games/metagame-sdk` — the *exact* function the budokan client
|
|
713
|
+
* renders payouts with — so amounts match between the SDK, budokan.gg, and any
|
|
714
|
+
* third-party integration. (The final on-chain claim amount is computed by the
|
|
715
|
+
* contract's fixed-point math; these values are the canonical client-side
|
|
716
|
+
* estimate, suitable for display and for filtering unclaimable zero slices.)
|
|
717
|
+
*
|
|
718
|
+
* Entry-fee split semantics follow the contract
|
|
719
|
+
* (`packages/rewards/src/budokan_rewards.cairo::_claim_entry_fee_position`):
|
|
720
|
+
* the position pool is the entry-fee pool **minus** the tournament-creator,
|
|
721
|
+
* game-creator, refund, *and protocol-fee* shares. The client historically
|
|
722
|
+
* omitted the protocol fee here and over-counted the position pool — this
|
|
723
|
+
* module fixes that by taking `protocolFeeShare` as an explicit input.
|
|
724
|
+
*/
|
|
725
|
+
|
|
726
|
+
type DistributionKind = "linear" | "exponential" | "uniform" | "custom" | "unknown";
|
|
727
|
+
interface ParsedDistribution {
|
|
728
|
+
type: DistributionKind;
|
|
729
|
+
/**
|
|
730
|
+
* Raw weight as stored on-chain (scaled ×10 — e.g. `10` = 1.0). `0` for
|
|
731
|
+
* Uniform/Custom. `distributionPercentages` divides by 10 internally.
|
|
732
|
+
*/
|
|
733
|
+
weight: number;
|
|
734
|
+
/** For Custom distributions, the raw u16 basis-point shares (one per paid position). */
|
|
735
|
+
customWeights?: number[];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Normalize the many wire shapes of the Cairo `Distribution` enum into a flat
|
|
739
|
+
* `{ type, weight, customWeights }`. Handles:
|
|
740
|
+
* - starknet.js v9 CairoCustomEnum: `{ variant: { Exponential: 100 } }`
|
|
741
|
+
* - SDK / PascalCase: `{ Exponential: 100 }`
|
|
742
|
+
* - lower-cased JSON (indexer/API): `{ exponential: 100 }`
|
|
743
|
+
* - explicit `{ type, weight }`
|
|
744
|
+
* - `Option`-wrapped weights (`{ Some: n }`)
|
|
745
|
+
*
|
|
746
|
+
* Unknown / missing input → `{ type: "unknown", weight: 0 }`, which
|
|
747
|
+
* `distributionPercentages` treats as Uniform.
|
|
748
|
+
*/
|
|
749
|
+
declare function parseDistribution(dist: unknown): ParsedDistribution;
|
|
750
|
+
/**
|
|
751
|
+
* Build a `ParsedDistribution` from the flat fields the SDK carries on a
|
|
752
|
+
* sponsored `Prize` (`distributionType` / `distributionWeight` /
|
|
753
|
+
* `distributionShares`).
|
|
754
|
+
*/
|
|
755
|
+
declare function prizeDistribution(prize: Pick<Prize, "distributionType" | "distributionWeight" | "distributionShares">): ParsedDistribution;
|
|
756
|
+
/**
|
|
757
|
+
* Per-position percentages (each 0–100, summing to ~100) for a distribution
|
|
758
|
+
* across `count` paid positions. Generalizes the client's
|
|
759
|
+
* `computeEntryFeePercentages` / `computePrizePercentages`.
|
|
760
|
+
*
|
|
761
|
+
* - linear/exponential: delegates to metagame-sdk's `calculateDistribution`
|
|
762
|
+
* (weight is divided by 10 to undo the on-chain ×10 scaling).
|
|
763
|
+
* - uniform / unknown: equal split.
|
|
764
|
+
* - custom: raw basis-point shares ÷ 100; falls back to uniform when the
|
|
765
|
+
* shares array length doesn't match `count`.
|
|
766
|
+
*/
|
|
767
|
+
declare function distributionPercentages(dist: ParsedDistribution, count: number): number[];
|
|
768
|
+
/** Input shape for entry-fee split math. Mirrors the on-chain built-in `EntryFee`
|
|
769
|
+
* plus the per-tournament protocol-fee snapshot (carried on `Tournament`). */
|
|
770
|
+
interface EntryFeeSplitInput {
|
|
771
|
+
/** Per-entry fee in smallest token units (decimal string or bigint). */
|
|
772
|
+
amount: string | bigint;
|
|
773
|
+
/** Number of paid entries collected. */
|
|
774
|
+
entryCount: number;
|
|
775
|
+
/** Basis-point shares (0–10000). Omitted / null → 0. */
|
|
776
|
+
tournamentCreatorShare?: number | null;
|
|
777
|
+
gameCreatorShare?: number | null;
|
|
778
|
+
refundShare?: number | null;
|
|
779
|
+
/** Protocol-fee bps snapshotted for the tournament (`Tournament.protocolFeeShare`). */
|
|
780
|
+
protocolFeeShare?: number | null;
|
|
781
|
+
}
|
|
782
|
+
interface EntryFeeSplit {
|
|
783
|
+
/** Total fee pool = amount × entryCount. */
|
|
784
|
+
total: bigint;
|
|
785
|
+
/** Pool shared across leaderboard positions = floor(availableShare × total / 10000). */
|
|
786
|
+
positionPool: bigint;
|
|
787
|
+
tournamentCreator: bigint;
|
|
788
|
+
gameCreator: bigint;
|
|
789
|
+
refund: bigint;
|
|
790
|
+
protocolFee: bigint;
|
|
791
|
+
/** Basis points left for positions after fixed shares (clamped ≥ 0). */
|
|
792
|
+
availableShareBps: number;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Split a built-in entry-fee pool into its on-chain components. The position
|
|
796
|
+
* pool reserves the tournament-creator, game-creator, refund, *and* protocol
|
|
797
|
+
* fee — matching `_claim_entry_fee_position`'s `available_share`.
|
|
798
|
+
*
|
|
799
|
+
* Note: each component is floored independently (sub-wei dust may not sum to
|
|
800
|
+
* `total`, exactly as on-chain).
|
|
801
|
+
*/
|
|
802
|
+
declare function entryFeeSplit(input: EntryFeeSplitInput): EntryFeeSplit;
|
|
803
|
+
/** The on-chain `EntryFee` distribution shape this module needs to size a
|
|
804
|
+
* position payout. A superset of `EntryFeeSplitInput`. */
|
|
805
|
+
interface EntryFeePositionInput extends EntryFeeSplitInput {
|
|
806
|
+
/** Raw on-chain `Distribution` (any wire shape — parsed internally). */
|
|
807
|
+
distribution: unknown;
|
|
808
|
+
/** Number of paid positions (`distribution_count`). */
|
|
809
|
+
distributionCount: number;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Amount a single leaderboard `position` (1-indexed) claims from the entry-fee
|
|
813
|
+
* pool. Generalizes the client's `computeEntryFeeAmount` — and fixes its
|
|
814
|
+
* protocol-fee over-count by reserving `protocolFeeShare`.
|
|
815
|
+
*
|
|
816
|
+
* Returns `0n` when the position is outside the paid range, the pool is empty,
|
|
817
|
+
* or the share rounds to zero (the contract makes such positions unclaimable).
|
|
818
|
+
*/
|
|
819
|
+
declare function entryFeePositionPayout(input: EntryFeePositionInput, position: number): bigint;
|
|
820
|
+
/**
|
|
821
|
+
* Amount a single `position` (1-indexed) claims from a distributed sponsored
|
|
822
|
+
* ERC20 prize. Generalizes the client's per-position `computePrizePercentages`
|
|
823
|
+
* + amount slicing. Returns `0n` for non-distributed / non-ERC20 prizes, a
|
|
824
|
+
* position outside the paid range, or a zero slice.
|
|
825
|
+
*/
|
|
826
|
+
declare function sponsorPrizePayout(prize: Prize, position: number): bigint;
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Player reward resolution — "which rewards can this player still claim, and
|
|
830
|
+
* what `claim_reward` calls assemble them?"
|
|
831
|
+
*
|
|
832
|
+
* Generalizes the budokan client's `buildPlayerClaimCalls` + `computeEarnings`
|
|
833
|
+
* + `getClaimablePrizes`. Pure: walks placements + prize/entry-fee data +
|
|
834
|
+
* existing claims and returns not-yet-claimed, non-zero rewards plus the
|
|
835
|
+
* `Call`s to claim them (via the tested `buildClaimRewardCall` encoder — so
|
|
836
|
+
* the claim-encoding bug class the SDK was created to kill can't recur).
|
|
837
|
+
*
|
|
838
|
+
* Scope (matches the client): the connected player's own placements only —
|
|
839
|
+
* entry-fee position prizes + sponsored prizes. Creator shares, protocol fee,
|
|
840
|
+
* and per-token refunds are pool/owner concerns, not placement-derived, and
|
|
841
|
+
* are intentionally excluded.
|
|
842
|
+
*/
|
|
843
|
+
|
|
844
|
+
type ClaimableRewardSource = "entry_fee_position" | "sponsor_single" | "sponsor_distributed";
|
|
845
|
+
interface ClaimableReward {
|
|
846
|
+
tournamentId: string;
|
|
847
|
+
/** Human label for UI/telemetry (`tournament.name` or `#id`). */
|
|
848
|
+
tournamentName: string;
|
|
849
|
+
/** Reward descriptor — feed straight to `buildClaimRewardCall` / `buildClaimCalls`. */
|
|
850
|
+
reward: RewardType;
|
|
851
|
+
/** Where the reward comes from (UI grouping / telemetry). */
|
|
852
|
+
source: ClaimableRewardSource;
|
|
853
|
+
/** 1-indexed leaderboard position the reward is for. */
|
|
854
|
+
position: number;
|
|
855
|
+
/** Token contract (ERC20/ERC721). */
|
|
856
|
+
tokenAddress: string | null;
|
|
857
|
+
tokenType: "erc20" | "erc721";
|
|
858
|
+
/** ERC20 amount in smallest units; `undefined` for ERC721 (one NFT). */
|
|
859
|
+
amount?: bigint;
|
|
860
|
+
/** ERC721 token id, when applicable. */
|
|
861
|
+
tokenId?: string | null;
|
|
862
|
+
}
|
|
863
|
+
interface GetClaimableRewardsInput {
|
|
864
|
+
placements: PlayerPlacement[];
|
|
865
|
+
tournaments: Tournament[];
|
|
866
|
+
prizes: Prize[];
|
|
867
|
+
/** Existing reward-claim records. Only those with `claimed === true` filter rewards out. */
|
|
868
|
+
existingClaims: RewardClaim[];
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* The not-yet-claimed, non-zero rewards across the player's placements.
|
|
872
|
+
*
|
|
873
|
+
* Skips:
|
|
874
|
+
* - already-claimed rewards (would revert),
|
|
875
|
+
* - 0-amount ERC20 slices (contract truncation makes them unclaimable),
|
|
876
|
+
* - creator/protocol/refund shares (not placement-derived).
|
|
877
|
+
*/
|
|
878
|
+
declare function getClaimableRewards(input: GetClaimableRewardsInput): ClaimableReward[];
|
|
879
|
+
/**
|
|
880
|
+
* Turn resolved {@link ClaimableReward}s into `claim_reward` `Call`s for
|
|
881
|
+
* `account.execute([...])`. Order is preserved.
|
|
882
|
+
*/
|
|
883
|
+
declare function buildClaimCalls(rewards: ClaimableReward[], budokanAddress: string): Call[];
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Tournament phase derivation — the single source of truth for "what phase is
|
|
887
|
+
* this tournament in right now?", mirroring the contract exactly
|
|
888
|
+
* (`packages/budokan/src/libs/schedule.cairo::current_phase`).
|
|
889
|
+
*
|
|
890
|
+
* The client used to recompute this inline (`isStarted/isEnded/isSubmitted`);
|
|
891
|
+
* this generalizes it so the client, bot, and any integration agree with the
|
|
892
|
+
* chain on phase boundaries (all comparisons are strict `<`, so a boundary
|
|
893
|
+
* second belongs to the *later* phase, matching the Cairo `if` ladder).
|
|
894
|
+
*/
|
|
895
|
+
|
|
896
|
+
/** Minimal schedule + creation-time shape needed to derive a phase. Matches
|
|
897
|
+
* the relevant subset of `Tournament` (top-level delay fields + on-chain
|
|
898
|
+
* created-at), so a full `Tournament` satisfies it directly. */
|
|
899
|
+
interface PhaseInput {
|
|
900
|
+
/** Unix seconds (string or number) the tournament was created on-chain. */
|
|
901
|
+
createdAtOnchain?: string | number | null;
|
|
902
|
+
registrationStartDelay?: number | null;
|
|
903
|
+
registrationEndDelay?: number | null;
|
|
904
|
+
gameStartDelay?: number | null;
|
|
905
|
+
gameEndDelay?: number | null;
|
|
906
|
+
submissionDuration?: number | null;
|
|
907
|
+
/** Fallback structured schedule (used when top-level delays are absent). */
|
|
908
|
+
schedule?: {
|
|
909
|
+
registrationStartDelay: number;
|
|
910
|
+
registrationEndDelay: number;
|
|
911
|
+
gameStartDelay: number;
|
|
912
|
+
gameEndDelay: number;
|
|
913
|
+
submissionDuration: number;
|
|
914
|
+
} | null;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Derive the current {@link Phase}. Returns `null` when the on-chain
|
|
918
|
+
* creation time is unknown (can't anchor the schedule).
|
|
919
|
+
*
|
|
920
|
+
* @param t - tournament schedule + `createdAtOnchain`
|
|
921
|
+
* @param nowSeconds - Unix seconds to evaluate at (defaults to wall-clock now).
|
|
922
|
+
* Pass an explicit value for deterministic/testable derivation.
|
|
923
|
+
*/
|
|
924
|
+
declare function tournamentPhase(t: PhaseInput, nowSeconds?: number): Phase | null;
|
|
925
|
+
|
|
699
926
|
/**
|
|
700
927
|
* Entry-requirement validator extensions.
|
|
701
928
|
*
|
|
@@ -802,4 +1029,4 @@ interface TournamentValidatorConfig {
|
|
|
802
1029
|
*/
|
|
803
1030
|
declare function buildTournamentValidatorConfig(cfg: TournamentValidatorConfig): string[];
|
|
804
1031
|
|
|
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 };
|
|
1032
|
+
export { type AddPrizeArgs, BudokanApiError, BudokanConnectionError, BudokanError, BudokanTimeoutError, CHAINS, type Call, type ChainConfig, type ClaimableReward, type ClaimableRewardSource, type CreateTournamentArgs, DataSourceError, type DistributionKind, type DistributionSpec, type EnterTournamentArgs, type EntryFeeArgs, type EntryFeePositionInput, type EntryFeeSplit, type EntryFeeSplitInput, type EntryRequirementArgs, type EntryRequirementSpec, type Erc20BalanceConfig, type ExtensionPresetKind, ExtensionPrize$1 as ExtensionPrize, type GameDefaults, type GetClaimableRewardsInput, type MerkleConfig, type MetagameExtensionPrize, type MetagamePrizeLike, type MetagameTokenPrize, type OpusTrovesConfig, PaginatedResult, type ParsedDistribution, Phase, type PhaseInput, PlatformStats, PlayerPlacement, 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, buildClaimCalls, buildClaimRewardCall, buildCreateTournamentCall, buildEnterTournamentCall, buildErc20ApproveCall, buildErc20BalanceConfig, buildMerkleConfig, buildOpusTrovesConfig, buildSubmitScoreCall, buildTournamentValidatorConfig, camelToSnake, distributionPercentages, entryFeePositionPayout, entryFeeSplit, explorerAddressUrl, explorerBaseUrl, explorerTxUrl, extensionAddressFor, findWhitelistedGame, getActivityStats, getChainConfig, getClaimableRewards, getGameDefaults, getGameStats, getGameTournaments, getPrizeStats, getRawTokenPrizes, getTokenPrizes, getTournament, getTournamentPrizeAggregation, getTournamentPrizes, getTournamentQualifications, getTournamentRegistrations, getTournamentRewardClaims, getTournamentRewardClaimsSummary, getTournaments, getWhitelistedGames, isExtensionPrize, isGameWhitelisted, isMetagameAdaptablePrize, isRawExtensionPrize, isRawTokenPrize, isTokenPrize, normalizeAddress, parseDistribution, parseTournamentIdFromReceipt, prizeDistribution, snakeToCamel, sponsorPrizePayout, toMetagameExtensionPrize, toMetagamePrize, toMetagamePrizes, toMetagameTokenPrize, toMetagameTokenPrizes, tournamentPageUrl, tournamentPhase, tryToMetagamePrize, tryToMetagamePrizes, u256ToLowHigh, withRetry };
|