Set up the Sui dev environment

Start by defining the working state you want from Building Sui DeFi Primitives. Confirm your local environment has the Sui CLI installed, a funded wallet with Testnet SUI, and access to the Sui Full Node RPC endpoint before you begin coding. Most failed setup attempts come from skipping one boring prerequisite and then trying to diagnose three problems at once.

Keep the setup small for the first pass. Verify the Sui CLI version matches your network requirements, ensure your wallet is connected to the Testnet cluster, and confirm you have sufficient SUI for gas fees. A clean baseline gives you something to return to if a later step breaks.

The simplest way to use this section is to keep the setup small, verify each change, and record the stable configuration before adding optional accessories.

Design assets with Move object semantics

Building Sui DeFi Primitives works best as a clear sequence: define the constraint, compare the realistic options, test the tradeoff, and choose the path with the fewest hidden costs. That order keeps the advice usable instead of decorative.

After each step, pause long enough to check whether the recommendation still fits the reader's actual situation. If it depends on perfect timing, unusual access, or a best-case budget, include a simpler fallback.

The simplest way to use this section is to write down the real constraint first, compare each option against it, and choose the path that still works outside ideal conditions.

Implement parallel transaction logic

Programmable Transaction Blocks (PTBs) are the engine behind Sui’s high-throughput DeFi operations. Unlike standard transactions that execute sequentially, PTBs allow you to bundle multiple operations into a single atomic unit. This structure lets the Sui MoveVM execute independent object accesses in parallel, significantly reducing latency and maximizing capital efficiency for complex protocols.

To build a PTB that leverages parallel execution, follow this sequence.

Sui DeFi primitives
1
Define independent object accesses

Identify all objects (tokens, accounts, or liquidity pools) your transaction will touch. For parallel execution to work, these accesses must be independent. If two operations read or write to the same object, the MoveVM will serialize them, negating the speed benefit. Group operations by object ID to ensure the engine can schedule them concurrently.

to Building Scalable DeFi Primitives on Sui
2
Construct the PTB builder instance

Initialize a ProgrammableTransactionBuilder in your Move code or client SDK. This builder acts as the container for your parallel logic. Instead of sending individual transactions, you will chain operations here. The builder validates that all object dependencies are declared before execution, ensuring the network can plan the parallel schedule.

3
Chain parallel operations

Add operations to the builder using methods like transfer_objects or move_call. Because the objects are independent, the MoveVM’s scheduler will dispatch these operations to different cores simultaneously. This is where the throughput advantage becomes visible, especially for DeFi actions like swapping assets across multiple pools or providing liquidity in batches.

4
Finalize with an output object

Every PTB must produce at least one output object. This could be a modified token balance, a new position in a liquidity pool, or a receipt for a trade. The finalization step signals the end of the block. If any operation fails, the entire PTB reverts, ensuring atomicity across all parallel actions.

By structuring your logic around independent object access, you allow the Sui network to process your DeFi operations at scale. This approach is fundamental for building high-frequency trading bots, automated market makers, and complex yield aggregators that require low-latency execution.

Connect your DeFi primitive to DeepBook

Building a custom automated market maker (AMM) requires significant engineering effort to manage liquidity pools and ensure capital efficiency. Instead of starting from scratch, you can integrate your Sui DeFi primitives with DeepBook’s shared liquidity infrastructure. This approach gives your application access to deep spot and margin pools immediately, allowing users to execute trades with minimal slippage without you managing the underlying order book.

Set up the DeepBook SDK

Initialize the DeepBook client using the Sui JSON-RPC provider. This client acts as the bridge between your smart contract logic and DeepBook’s on-chain data structures. Ensure you are using the latest SDK version compatible with the current Sui network to avoid compatibility issues with the latest Move package updates.

Define liquidity pools

Configure your application to interact with specific DeepBook pools. You can choose between spot pools for standard token swaps or margin pools if your primitive requires leverage. Selecting the right pool ensures that your users have access to the necessary liquidity depth for their intended trades. DeepBook’s architecture allows multiple applications to share these same pools, increasing capital efficiency across the ecosystem.

Execute trades through shared liquidity

Route your trade requests through the DeepBook SDK. The client will automatically find the best prices across the shared liquidity pools, aggregating orders from various sources. This process handles the complex logic of price discovery and order matching, letting your primitive focus on the user experience and specific financial logic.

Sui DeFi primitives

Compare development approaches

Choosing between building a custom AMM and integrating with DeepBook involves trade-offs in development time, liquidity depth, and maintenance overhead. The table below outlines the key differences to help you decide the best path for your project.

FeatureCustom AMMDeepBook Integration
Development TimeHigh (weeks to months)Low (days to weeks)
Liquidity DepthStarts at zeroShared from day one
Capital EfficiencyRequires concentrated liquidityBuilt-in aggregation
MaintenanceHigh (pool management)Low (SDK updates)
ComplexityHigh (order book logic)Medium (SDK integration)

Deploy and verify on Testnet

Deploying Sui DeFi primitives to the Testnet turns local code into a live, testable contract. This stage confirms that your Move package publishes correctly and that object states behave as expected under network conditions. Follow these steps to publish your package and verify the resulting object.

Sui DeFi primitives
1
Connect to the Sui Testnet

Open your terminal and set your SUI environment to the Testnet cluster. Ensure your wallet has sufficient SUI tokens to cover gas fees for the deployment transaction. Use the sui client command to check your active address and balance before proceeding.

Sui DeFi primitives
2
Publish the Move package

Run sui client publish --gas-budget 100000000 in your project root. This command compiles your Move sources and publishes the package to the Testnet. The terminal will return a transaction digest and the new Package ID. Save this ID; it is the unique identifier for your DeFi primitive.

Sui DeFi primitives
3
Verify object states and dependencies

Use sui client object <OBJECT_ID> to inspect the newly created objects. Confirm that the Move structure fields match your code definition. Check that any shared objects or treasury caps are correctly initialized and accessible to the intended addresses.

Sui DeFi primitives
4
Test interaction with the primitive

Execute a simple transaction that calls one of your published entry functions. Verify that the state changes persist and that no runtime errors occur. This final check ensures your DeFi primitive is ready for integration testing or mainnet deployment.

Common sui defi development: what to check next

Developers building on Sui frequently encounter specific constraints around object ownership and parallel execution. These questions address the core mechanics that differentiate Sui from other L1s.

Understanding these mechanics prevents common pitfalls. The parallel execution model is powerful but requires careful state management to avoid conflicts. Object ownership is strict; once an object is moved, it cannot be accessed by the previous owner unless explicitly transferred back.