Python SDK#
The seesaw-sdk Python package provides a full client SDK for interacting with the Seesaw binary prediction market protocol on Solana.
Installation#
bash
pip install seesaw-sdk
Or install from source:
bash
cd packages/sdk-python
pip install -e ".[dev]"
Requirements: Python 3.10+, solders (installed automatically).
Quick Start#
python
from seesaw.constants import PROGRAM_ID
from seesaw.pda import derive_market_pda, derive_config_pda
from seesaw.instructions import (
PlaceOrderAccounts, place_order,
)
from seesaw.types import OrderSide, OrderType
from seesaw.codecs import decode_market
from solders.pubkey import Pubkey
# 1. Derive a market PDA
feed_id = bytes([0xAB] * 32)
market_pda, bump = derive_market_pda(feed_id, 900, 1, creator_pubkey)
# 2. Decode a market account from raw bytes
market = decode_market(account_data)
print(f"Market state: {market.state}, outcome: {market.outcome}")
# 3. Build a PlaceOrder instruction
accounts = PlaceOrderAccounts(
market=market_pda,
orderbook=orderbook_pda,
user_position=position_pda,
user_token_account=user_ata,
user_yes_ata=yes_ata,
user_no_ata=no_ata,
vault=vault_pda,
yes_escrow=yes_escrow_pda,
no_escrow=no_escrow_pda,
user=wallet.pubkey(),
config=config_pda,
treasury_token_account=treasury_ata,
creator_token_account=creator_ata,
token_program=TOKEN_PROGRAM_ID,
system_program=SYSTEM_PROGRAM_ID,
)
ix = place_order(
side=OrderSide.BuyYes,
price_bps=5000, # 50%
quantity=100_000_000, # 100 USDC (6 decimals)
order_type=OrderType.Limit,
accounts=accounts,
)
# Add ix to a transaction and send
API Reference#
PDA Derivation (seesaw.pda)#
| Function | Seeds | Returns |
|---|---|---|
derive_config_pda() | ["seesaw", "config"] | (Pubkey, int) |
derive_market_pda() | ["seesaw", "market", feed_id, duration, market_id, creator] | (Pubkey, int) |
derive_orderbook_pda() | ["seesaw", "orderbook", market] | (Pubkey, int) |
derive_vault_pda() | ["seesaw", "vault", market] | (Pubkey, int) |
derive_position_pda() | ["seesaw", "position", market, user] | (Pubkey, int) |
derive_asset_pda() | ["seesaw", "asset", feed_id] | (Pubkey, int) |
derive_yes_mint_pda() | ["seesaw", "yes_mint", market] | (Pubkey, int) |
derive_no_mint_pda() | ["seesaw", "no_mint", market] | (Pubkey, int) |
derive_yes_escrow_pda() | ["seesaw", "escrow_yes", market] | (Pubkey, int) |
derive_no_escrow_pda() | ["seesaw", "escrow_no", market] | (Pubkey, int) |
Instruction Builders (seesaw.instructions)#
All 16 on-chain instructions are supported. Each function returns a solders.instruction.Instruction:
| Function | Discriminator | Data Size |
|---|---|---|
initialize_config() | 0x00 | 7 bytes |
create_market() | 0x01 | 11 bytes |
snapshot_end() | 0x02 | 1 byte |
resolve_market() | 0x03 | 1 byte |
expire_market() | 0x04 | 1 byte |
place_order() | 0x05 | 13 bytes |
cancel_order() | 0x06 | 9 bytes |
mint_shares() | 0x07 | 9 bytes |
redeem() | 0x08 | 10 bytes |
withdraw_shares() | 0x09 | 10 bytes |
pause() | 0x0A | 1 byte |
unpause() | 0x0B | 1 byte |
update_fees() | 0x0C | 7 bytes |
update_tick_size() | 0x0D | 3 bytes |
force_close() | 0x0E | 1 byte |
close_market() | 0x0F | 1 byte |
Account Decoders (seesaw.codecs)#
| Function | Account Size | Returns |
|---|---|---|
decode_config() | 256 bytes | ConfigAccount |
decode_market() | 512 bytes | MarketAccount |
decode_orderbook() | 10,240 bytes | OrderbookAccount |
decode_position() | 256 bytes | UserPositionAccount |
decode_asset_state() | 128 bytes | AssetState |
Types (seesaw.types)#
Enums (all IntEnum): MarketState, Outcome, OrderSide, OrderType, TokenType
Account dataclasses: ConfigAccount, MarketAccount, OrderbookAccount, Order, UserPositionAccount, AssetState
Error Codes (seesaw.errors)#
All 50+ on-chain error codes are available via SeesawError(IntEnum). Use get_error_description(code) for human-readable messages.
Cross-Language Validation#
The Python SDK validates against the same golden test vectors used by the TypeScript and Rust SDKs. Run:
bash
cd packages/sdk-python
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest -v