intermediate
+300 XP

Building Trading Transactions

Learn to construct Sui Programmable Transaction Blocks (PTBs) for DeepBook Predict — create managers, deposit DUSDC, build RangeKeys, and mint binary positions in atomic operations.

Lesson Syllabus

PredictManager Setup
🏗️

Creating a PredictManager

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.

💰

Depositing DUSDC

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.

♻️

Manager Lifecycle

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.

Minting Binary Positions
🔑

Building the RangeKey

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 Mint Transaction

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.

📦

Complete mintPositionTx Function

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.

Atomic Operations
🔗

Deposit + Mint in One PTB

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.

🪙

Coin Management Patterns

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.

💸

Redeeming Positions

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.