Developers
How settlement works
How a Game program settles a Pot through tesoro_core.
A Match is settled by the Game program, not by a Studio server. The Game keeps its state in a rollup, works out the result itself, and then calls tesoro_core, signing as the authority registered for that Game. tesoro_core moves the Gemas.
- Playertesoro_coreopen_match / join_matchEntries are drawn from each Player's basket by the program. Fee basis points, the Game's listing and its deploy slot are snapshotted.
- Game operatorSolanaassign_matchNames an idle table (delegated once to the approved TEE validator and reused). Players and asset come from the Match itself.
- PlayersRollupcheck in, playHidden state sits in private seats. The program enforces the rules and its own clock.
- RollupSolanacommit_tableThe outcome is written into the table's result ring and the table is committed to the base layer. The table stays delegated.
- AnyoneGamefinalizeReads only the committed table's result ring: the Game never trusts a caller for the winner.
- Gametesoro_coresettle_match(result) by CPISigned by the Game's authority PDA with invoke_signed.
- tesoro_corePlayerscredit payout lines, take FeesLeaderboard Fee goes to the Pool. A MatchWon event is emitted.
Match lifecycle in tesoro_core
| Instruction | Who | Effect |
|---|---|---|
open_match(match_id, game, entry) | A Player | Creates the Match, draws the opener's entry from their basket by the program's Entry draw (or consumes an Entry Ticket), and snapshots the Platform and Studio Fee basis points, the Game's listing state and its deploy slot. Entries are 100, 500 or 1,000 by default; the admin can set others. |
join_match | A Player | Draws the joiner's entry, sets status Active, sets the refund deadline to one hour later. |
open_match_backed, join_match_backed | A backed Player | The same, funded by an accepted Offer's reserved Gemas. The Player's own Gemas are never touched. |
extend_match_deadline(new_deadline) | Game authority | Pushes an Active, unexpired Match's refund deadline later, never earlier and never past 7 days after the Match opened, so a slow Game cannot be refunded out from under itself and no Game can hold a Match forever. |
settle_match(result) | Game authority only | Starts settling once, from Open or Active, only before 7 days after open and only if the Game's deploy slot still matches (same build); later chunks, which anyone can continue, cut the fees and credit the payouts. Result is Opener, Joiner or Draw. |
refund_match | Game authority any time; the opener of an unjoined Match; anyone after the deadline | Starts refunding: every entry goes back to its funder as the exact lines, in chunks anyone can continue. Liveness fallback, and the only way out after the 7-day limit or a Game upgrade. |
What a Game must provide
- A program id and an authority: a PDA of the Game program is the norm (seeds
["authority"]), signing byinvoke_signed. A server key also works but is the weaker trust boundary. - Registration by whoever controls the Game program:
register_game(settle_authority, studio_bps), signed by the program's upgrade authority (or, for a program that can no longer be upgraded, by the program itself through its["tesoro-register"]address). Each Game has its own record. The Studio Fee is at most 1,000 bps (10%) and Platform plus Studio Fee together are capped at 5,000 bps. The Studio recipient cannot be the Pool, the Treasury or the Platform recipient. A change waits 7 days. - A way to compute the winner from state the Game controls. Block Burst replays moves against the Seed; Hold'em plays out the chips; Trading Duel scores both Books' picks against the recorded price line, closed by a pinned final price; Vanguard applies each move to the Battle and ends it on a captured Supply Truck, or on the surviving ranks at the limit.
- Liveness: timeouts and forfeits enforced by the program, with
extend_match_deadlinewhere the Game's own clock exceeds the one-hour default.
// Inside a Game program (block_puzzle's finalize, abridged): settle by CPI into tesoro_core.
// game_authority is the Game program's own ["authority"] PDA, so it signs with invoke_signed.
let signer = &[&[AUTHORITY_SEED, &[session.authority_bump]][..]];
tesoro_core::cpi::settle_match(
CpiContext::new_with_signer(
tesoro_core_program,
tesoro_core::cpi::accounts::SettleMatch { game_authority, config, game_record, match_state },
signer,
)
.with_remaining_accounts(payout_accounts), // per payout: the recipient's basket and spill
result, // MatchResult::Opener | Joiner | Draw
)?;No change to tesoro_core was needed to support PDA authorities: settle_match only requires that the signer equals the registered authority.
The Pot is a list of lines
A Pot is a list of (source, amount) lines per side. The winner receives the loser's actual lines, each keeping its Source, plus their own entry back. The recipient's basket line of each Source is credited; it is on the own side only if they own that Source's Lock. A credit that does not fit the basket goes to the recipient's spill, which is created with the Account, so a recipient cannot block a settlement. Each line keeps its class and tranche, and carries its repaid part and its staking-token shares with it.
Fees
- Fees are
platform_bps(on Config, 200) plus the Game'sstudio_bps(300 for every Game), both snapshotted when the Match opens, plus the Leaderboard Feeleaderboard_bps(on Config, 100), read from Config when the Match settles. Together they are capped at 5,000 bps of the Pot. - They are taken in Gemas from the loser's lines, from as few lines as possible, largest first: Platform Fee first, then Studio Fee, then Leaderboard Fee, then (for a backed win) the Player's share of what remains. Each cut first syncs its Source, and the cut Gemas land in the fee counters of the Source (or in an outside studio's basket). The Payout order then repays them first.
- The Leaderboard Fee is paid to the Leaderboard Pool, a Tesoro Account owned by the address
["leaderboard"], as a fee-class line. Each decisive settlement also emitsMatchWon(Player, loser, entry, points, season) as an event of the core program; the Season ranking reads only those. Points are 0 for a Match of an unlisted Game. - Fees are floored, so the winner gets the dust. A Draw or abandonment takes none; a no-show takes the Platform Fee from each side.
- Match Fees are separate from Tesoro's other two revenues, which never touch a Pot: the Yield Fee (20% of the value of Gemas cashed out, split in half with the Leaderboard Pool) and the Instant Redeem Fee (25% of what a Redeem would pay, on Gemas sold early). The Yield Fee is taken at cash-out, not when yield accrues; Match Fee Gemas and prize Gemas pay none. The Treasury keeps both.
Entry draw and bounds
- The program draws the lines of an entry: own Gemas first, then won Gemas by earliest planned repayment date. The client cannot choose or skip lines. An entry that needs more lines than one transaction fits is staged in an Entry Ticket (no cap on lines); a Player whose free Gemas cover an entry can always enter.
- Settlement and refund run in idempotent chunks with a cursor, started once and continued by anyone, so the number of lines a Pot holds no longer bounds a transaction. Per-transaction line caps and compute numbers come from ticket 09's measurements; see
docs/tesoro-core.md.
Backing in the ledger
create_request, create_offer (on one Request), accept_offer, cancel_offer, expire_offer. Every Offer answers one Request; there are no public Offers. Offers reserve an amount of the Backer's Gemas; the lines are drawn when the backed Match opens, and only a Listed Game can be Backed. Requests and Offers live 24 hours; an accepted Offer has 24 hours to be used and is consumed when the backed Match opens or is joined. Win: the Backer's entry first, then the Player's share of the surplus after Fees, the rest to the Backer. Loss: the Backer loses the entry, nothing more.
Errors
Ledger errors surface as custom program error 6100 + CoreError::code(). Program errors start at 6000 (Unauthorized = 6000, GameNotRegistered = 6001, InvalidAccount = 6003).