Bot Trading Guide
Bot Trading Guide
Buy / Sell / Redeem — programmatic trading on Supra L1. This guide shows how to trade HypeMarket prediction markets programmatically from a bot: read prices and quotes via view functions, and buy / sell / redeem via Move entry-function transactions on the Supra L1.
Operational notes. Bot accounts are ordinary Supra accounts — use a dedicated key with limited funds, never your main wallet. Platform limits (e.g. the 100 SUPRA minimum trade) are listed in Fees and Limits.
1. Setup
Environment
# --- Supra chain ---
SUPRA_RPC_URL=https://rpc-mainnet.supra.com/rpc/v3
BOT_PRIVATE_KEY=0x... # funded Supra account (holds SUPRA for gas + collateral)
# --- HypeMarket packages (mainnet) ---
MARKET_PACKAGE=0xbe08b388cc1a21ba8d8a514c1857369f4908d4b478bb8d66a369bfb9ca5a2da8
MARKET_HELPER_PACKAGE=0x60063863e728b3be5c994c3474e08410cc6e8c1ea9cd4bddc07112bd267d6151
# --- Off-chain discovery API ---
BACKEND_API=https://api.hypemarket.trade/apiDependencies
2. Key concepts (read this first)
Where the logic lives
Entry functions on MARKET_PACKAGE::market, called with market: address as arg 1
Reads
POST {RPC}/view with {function, type_arguments, arguments}
Writes
Move entry-function tx, BCS-encoded args, signed with BOT_PRIVATE_KEY
Share unit
Share units == collateral units. 1 whole share = 10 ** collateralDecimals
SUPRA decimals
8 → 1 SUPRA = 100_000_000 atomic
Collateral standard
SUPRA is a coin (collateralToken == "0xa") → use buy_with_coin. FA collateral (e.g. USDC) → use buy
AMM
LS-LMSR with fixed alpha (500 bps). Marginal prices need not sum to 1
Fee units
basis points; BPS = 10_000
Status enum
The market status is an 8-value enum (index → name):
Buy / sell allowed only when status == 2 (ACTIVE).
Redeem allowed when status == 5 (CLOSED) or 8 (VOIDED_CLOSED).
Always re-check status on-chain right before trading — never cache it. A market can pause or expire between your discovery call and your trade.
3. Contract interface
Write functions (MARKET_PACKAGE::market)
View functions
get_market_data returns a tuple; the fields you care about, in order:
Each Summary (from get_market_user_summary_batch) contains, among others:
Pass the market address itself (or 0x0) as user when you only want market-level fields (winning_outcome, redeemable_amount_per_share, status) and don't care about per-user holdings.
4. Market discovery (REST)
status buckets are lowercase: open | resolved | closed | all (where resolved = RESOLVED|VOIDED, closed = CLOSED|VOIDED_CLOSED).
Useful fields on each item: market (address), title, outcomes ([{id,title}]), outcomeCount, collateralToken ("0xa" == SUPRA), creatorFeeBps, status, expiresAt.
5. Reading state (view calls)
All reads are one HTTP call:
Argument encoding (critical — the endpoint validates against the Move type)
u8 / u16 / u32
integer (a string is rejected)
u64 / u128 / u256
string (a number is rejected, even when small)
bool
boolean
address
"0x…" string
vector<u8>
"0x…" hex string (Move treats vector<u8> as a byte string)
vector<T> (T ≠ u8)
JSON array of encoded T
So outcomes: vector<u8> = [0] → "0x00", and amounts: vector<u64> = [100000000] → ["100000000"].
Verified examples (live mainnet)
6. Fees & slippage
BPS = 10_000. Three fee sources:
creatorFeeBps— per-market (get_market_data[3], or the backendcreatorFeeBps).protocolFeeBps— global (market_config_manager::get_protocol_fee_bps); a market may override it whenoverride_protocol_fee_bpsis true.userFeeBps— global (market_config_manager::get_user_fee_bps); charged on the creator fee.
The contract enforces max_cost (buy) and min_return (sell) on-chain, so a slightly stale quote is safe — the tx reverts rather than filling at a bad price.
7. Building & submitting a transaction
Writes are Move entry-function calls with BCS-encoded arguments. Encoders (from the SDK):
The entry-function payload (module addr, module, fn, type-args, BCS arg array, options):
Submit it with the bot's key via the Supra SDK (headless equivalent of what the dapp does through the StarKey wallet). Gas note: Supra reserves maxGas × gasUnitPrice up front — the sender must hold that much SUPRA even though actual usage is far lower. A single trade clears at maxGas ≈ 30_000; rebalance / create_market need more (scale with outcome count).
8. Buy flow
sharesis atomic: 1 whole share =10 ** collateralDecimals(SUPRA →100_000_000).Use
buy(no type argument) for FA collateral;buy_with_coin<CoinType>for coin collateral (SUPRA).
9. Sell flow
10. Redeem flow
redeem pays winning_outcome_amount × redeemable_amount_per_share / 1e8 in collateral, then burns your winning shares. redeemable_amount_per_share is usually ≥ 1 SUPRA (losing-side collateral flows to winners, minus fees).
11. Decimals cheat-sheet
Share units == collateral units. 1 whole share =
10 ** collateralDecimals.SUPRA = 8 decimals → 1 share =
100_000_000;41635836atomic =0.41635836SUPRA.Every
amounts,max_cost,min_return, price, and quote is atomic. Convert for display only:human = atomic / 10 ** decimals.
12. Status state machine
Trade only in
ACTIVE(2).Redeem only in
CLOSED(5)/VOIDED_CLOSED(8).Re-check on-chain before every trade — do not cache.
13. Reference
Supra RPC (views)
https://rpc-mainnet.supra.com/rpc/v3/view
MARKET_PACKAGE (core: entry fns + market views)
0xbe08b388cc1a21ba8d8a514c1857369f4908d4b478bb8d66a369bfb9ca5a2da8
MARKET_HELPER_PACKAGE (aggregate views)
0x60063863e728b3be5c994c3474e08410cc6e8c1ea9cd4bddc07112bd267d6151
Discovery API
https://api.hypemarket.trade/api
SUPRA collateral marker
collateralToken == "0xa" (8 decimals, coin standard)
BPS
10_000
Function IDs at a glance
Last updated