import type { GameModelAPI } from '../domains/gameModel.js'; import type { EngineDetector } from './engine.js'; import type { Scalars, SeedPropertyInput } from '../generated/graphql.js'; import { type KitInvokeResult } from './shared.js'; /** Options for {@link EconomyKit}. Must match the deployed economy blueprint. */ export interface EconomyKitOptions { /** The `typePrefix` the economy blueprint was deployed with. */ typePrefix?: string; /** The `currencies` the blueprint was deployed with. Defaults to `['gold']`. */ currencies?: string[]; /** The order-book market engine module. Defaults to `'market-engine'`. */ marketModuleName?: string; } /** A parsed view of one wallet. */ export interface KitWallet { containerId: string; displayName: string; ownerUserId: string | null; /** Balance per currency property. */ balances: Record; } /** A parsed view of one shop listing. */ export interface KitShopListing { containerId: string; displayName: string; itemId: string; price: number; stock: number; maxStock: number; } /** A parsed view of one escrow trade offer. */ export interface KitTradeOffer { containerId: string; displayName: string; /** The offer creator (server-assigned container owner). */ fromUserId: string | null; toUserId: number; giveStackId: string; receiveStackId: string; giveItemId: string; giveQty: number; wantItemId: string; wantQty: number; status: string; } /** A parsed view of one market listing. */ export interface KitMarketListing { containerId: string; displayName: string; /** The seller (server-assigned container owner). */ sellerUserId: string | null; stackId: string; itemId: string; quantity: number; price: number; active: boolean; } /** * Runtime helpers for the {@link economyBlueprint} conventions: wallets with * per-currency balances, shop purchases, escrow trades, and player market * listings. Every movement of currency or items is a single gated invoke — * balances, stock, item identity, and ownership are all verified * server-side, and a denial resolves with `success: false` (never an * exception). * * `earn` is a trusted grant: with the default blueprint authority * (`'server'`) it succeeds only for app admins — call it from studio/backend * code, or drive grants through automations instead. * * Obtained via `client.kit(appId).economy`. */ export declare class EconomyKit { private readonly appId; private readonly gameModel; private readonly names; private readonly typePrefix; private readonly currencies; constructor(appId: Scalars['BigInt']['input'], gameModel: GameModelAPI, options?: EconomyKitOptions, engines?: EngineDetector); /** * The order-book market (Wave 2 engine): bid/ask methods over the * market-engine's escrowed order books. The model-side listing `market` * on this kit keeps working without it (fixed-price stack listings); * `orderBook` adds real price discovery when the engine is deployed. */ readonly orderBook: MarketKit; private get defaultCurrency(); /** * Find the player's wallet, creating it when absent (member-instantiable; * the server assigns ownership to the caller). Sets the `owner_user_id` * mirror property the blueprint's guards read. * * @param ownerUserId - The calling player's user id (decimal string). */ ensureWallet(ownerUserId: Scalars['BigInt']['input'], options?: { displayName?: string; sessionId?: string; }): Promise<{ __typename?: "GmContainer"; containerId: string; appId: string; sessionId: string | null; typeName: string; displayName: string; description: string | null; ownerUserId: string | null; metadataJson: string; }>; /** Read one currency balance (default: the blueprint's first currency). */ balance(walletId: string, currency?: string): Promise; /** Read a wallet with every configured currency balance parsed. */ wallet(walletId: string): Promise; /** * Mint currency into a wallet — a **trusted** grant (default blueprint * authority: app admins only). Resolves with the new balance. */ earn(walletId: string, amount: number, currency?: string): Promise>; /** * Spend currency from the caller's own wallet. The server refuses to * overdraw. Resolves with the new balance. */ spend(walletId: string, amount: number, currency?: string): Promise>; /** Shop (admin-priced listings; atomic buys). */ readonly shop: { /** * Create a shop listing (admin — the type is admin-instantiable). * `maxStock` feeds the optional restock automation. */ create: (input: { displayName: string; itemId: string; price: number; stock?: number; maxStock?: number; properties?: SeedPropertyInput[]; }) => Promise<{ __typename?: "GmContainer"; containerId: string; appId: string; sessionId: string | null; typeName: string; displayName: string; description: string | null; ownerUserId: string | null; metadataJson: string; }>; /** List shop listings with parsed state. */ list: () => Promise; /** * Buy one unit: wallet debit + stock decrement + item grant into * `toStackId` (a stack of the listed item), all in one transaction. * Resolves with the wallet's remaining balance. */ buy: (input: { listingId: string; walletId: string; toStackId: string; }) => Promise>; }; /** Escrow trades (player↔player item swaps, atomic on accept). */ readonly trades: { /** * Create a trade offer to another player. The stacks named here are the * OFFERER's: `giveStackId` is the escrowed source, `receiveStackId` * receives the wanted items when the trade is accepted. The offer's * container ownership (server-assigned to the caller) is what the accept * guards trust — a forged offer over someone else's stacks can never be * accepted. */ offer: (input: { toUserId: Scalars["BigInt"]["input"]; giveStackId: string; giveItemId: string; giveQty: number; wantItemId: string; wantQty: number; receiveStackId: string; displayName?: string; sessionId?: string; }) => Promise<{ __typename?: "GmContainer"; containerId: string; appId: string; sessionId: string | null; typeName: string; displayName: string; description: string | null; ownerUserId: string | null; metadataJson: string; }>; /** * Accept a trade as the invited player, supplying YOUR two stacks: the * one paying the wanted items and the one receiving the given items. The * offerer's stacks come from the offer record. All four quantity writes * commit atomically or not at all. */ accept: (input: { offerId: string; wantStackId: string; toGiveStackId: string; }) => Promise>; /** Cancel an open trade (either party may). */ cancel: (offerId: string) => Promise>; /** Read one trade offer with parsed state. */ get: (offerId: string) => Promise; /** List trades the user created or was invited to (open ones first). */ listMine: (userId: Scalars["BigInt"]["input"]) => Promise; }; /** Player market (list a stack for currency; atomic purchases). */ readonly market: { /** * List items for sale: names YOUR escrowed source stack and the ask * price. Payment lands straight in your wallet when someone buys. */ list: (input: { stackId: string; itemId: string; quantity: number; price: number; displayName?: string; sessionId?: string; }) => Promise<{ __typename?: "GmContainer"; containerId: string; appId: string; sessionId: string | null; typeName: string; displayName: string; description: string | null; ownerUserId: string | null; metadataJson: string; }>; /** Browse market listings (active ones only by default). */ browse: (options?: { includeInactive?: boolean; }) => Promise; /** * Buy a market listing: pays the seller's wallet and transfers the items * into `toStackId` in one transaction. The seller's wallet and source * stack are resolved from the listing. Resolves with the buyer wallet's * remaining balance. */ buy: (input: { listingId: string; walletId: string; toStackId: string; }) => Promise>; /** Take a listing down (seller only). */ cancel: (listingId: string) => Promise>; }; /** Find an existing wallet container id for a user (no creation). */ private ensureSellerWallet; private toTrade; } /** * Order-book market methods over the market-engine (Wave 2): price-time * priority matching with escrowed settlement. Deposits/withdrawals bridge * to the game's wallets via compute events the game layer consumes. * * Obtained via `client.kit(appId).economy.market`. */ export declare class MarketKit { private readonly engines; private readonly moduleName; constructor(engines: EngineDetector | undefined, moduleName: string); /** Is the market engine deployed + enabled (cached per session)? */ engineAvailable(): Promise; /** Move coins into your market account (escrow source for bids). */ depositCoins(amount: number): Promise>; /** Move items into your market account (escrow source for asks). */ depositItems(item: string, quantity: number): Promise>; /** Place a limit bid: locks coins at your limit; fills at maker price. */ bid(item: string, price: number, quantity: number): Promise>; /** Place a limit ask: locks items until filled or cancelled. */ ask(item: string, price: number, quantity: number): Promise>; /** Cancel a resting order (owner only); escrow refunds instantly. */ cancel(item: string, orderId: number): Promise>; /** Book depth: best bids/asks as [price, quantity] levels. */ book(item: string): Promise>; /** Your market account (settled + locked balances). */ account(): Promise>; /** Withdraw settled balances back to the game layer. */ withdraw(input: { coins?: number; item?: string; quantity?: number; }): Promise>; private invoke; } //# sourceMappingURL=economy.d.ts.map