Examples#
These examples use the canonical generated v1 surface. They are intentionally small: account validation and wallet signing remain visible application steps.
Read and validate a market#
// docs-check: semantic
import type { Address } from '@solana/addresses';
import {
decodeMarketAccount,
decodeDeepOrderbookAccount,
deriveMarketPda,
deriveOrderbookPda,
} from '@seesaw/core';
export async function readMarket(
feedId: Uint8Array,
durationSeconds: bigint,
marketId: bigint,
creator: Address,
fetchFinalizedBytes: (address: Address) => Promise<Uint8Array>
) {
const [market] = await deriveMarketPda(feedId, durationSeconds, marketId, creator);
const [orderbook] = await deriveOrderbookPda(market);
const marketAccount = decodeMarketAccount(await fetchFinalizedBytes(market));
const bookAccount = decodeDeepOrderbookAccount(await fetchFinalizedBytes(orderbook));
return { market, orderbook, marketAccount, bookAccount };
}
Supply a finalized-bytes fetch adapter that validates account existence and
owner. Derivation needs the feed, duration, epoch and creator; each PDA helper
returns a promise of [address, bump]. Check decoded market state and timing
before trading; there is no string status: 'open' field.
Place an order#
// docs-check: semantic
import {
buildPlaceOrderIx,
buildCancelOrderIx,
buildRedeemIx,
OrderSide,
OrderType,
type PlaceOrderAccounts,
} from '@seesaw/core';
export function buildBuyYes(accounts: PlaceOrderAccounts, protocolTreasuryIndex: number) {
return buildPlaceOrderIx(
{
side: OrderSide.BuyYes,
priceBps: 5100,
quantity: 1_000_000n,
orderType: OrderType.Limit,
protocolTreasuryIndex,
},
accounts
);
}
// Cancel and redeem also take separate params and accounts arguments.
export const buildCancel = (
params: Parameters<typeof buildCancelOrderIx>[0],
accounts: Parameters<typeof buildCancelOrderIx>[1]
) => buildCancelOrderIx(params, accounts);
export const buildRedemption = (
params: Parameters<typeof buildRedeemIx>[0],
accounts: Parameters<typeof buildRedeemIx>[1]
) => buildRedeemIx(params, accounts);
Provide verified PlaceOrderAccounts, including the config-approved treasury
recipient and matching index. The builders accept separate params and accounts;
they do not sign or submit. See Building transactions.
Reclaim external market#
@seesaw/reclaim parses and inspects genuine Reclaim proof JSON. It does not
create a Seesaw proof wire or derive a Seesaw claim identifier: those removed
helpers were incompatible with both Reclaim proofs and the on-chain resolver.
Only submit a proof after its governed provider template and attestor policy
have been validated by the resolver service.
Cross-language vectors#
Rust and Python examples are maintained beside their SDK tests and consume the
same files under packages/test-vectors. Run the vector suite before copying
an example into production code.