Learn to construct Sui Programmable Transaction Blocks (PTBs) for DeepBook Predict — create managers, deposit DUSDC, build RangeKeys, and mint binary positions in atomic operations.
Before trading, every user needs a PredictManager — a shared object that stores your DUSDC balance and tracks position quantities. You create one by calling registry::create_and_share_manager with the Registry object ID. This is a one-time operation per wallet.
After creating a manager, you deposit DUSDC into it. The deposit transaction uses splitCoins to extract an exact amount from your coin, then calls predict_manager::deposit with the DUSDC type argument.
A PredictManager is designed to be long-lived. You create it once and reuse it across all trading sessions. Understanding its lifecycle helps you build efficient dApps.
Every position is identified by a RangeKey — a combination of oracle, expiry, and strike bounds. For binary UP/DOWN positions, you use sentinel values to encode the direction. The RangeKey is constructed on-chain via range_key::new.
The predict::mint function takes six arguments and one type parameter. It mints new binary position units into your manager, debiting the cost from your deposited DUSDC balance.
Here is the full function that combines RangeKey creation and mint into a single Programmable Transaction Block. Both operations execute atomically — if either fails, the entire transaction reverts.
The real power of Sui PTBs is composability. You can merge multiple DUSDC coin objects, split an exact deposit amount, deposit into your manager, build a RangeKey, and mint a position — all in one atomic transaction.
Handling coin objects correctly is one of the most important patterns in Sui development. PTBs give you powerful primitives for managing coins within a single atomic operation.
After an oracle settles, winning positions can be redeemed for 1 DUSDC each. The redeem transaction follows the same pattern as mint. For settled oracles, anyone can trigger redemption using redeem_permissionless.