Understand Sui Move object model

Sui replaces the traditional account-based model with an object-centric architecture. In most EVM chains, state is a single blob tied to an address. On Sui, every asset is an independent object with its own unique ID, type, and version number. This shift allows the network to process assets in parallel rather than forcing them through a single sequential chain of events.

This object-centric design is critical for building DeFi primitives. Because objects can be updated or transferred independently, the network can execute transactions concurrently. This means your liquidity pools, lending markets, or DEXs can handle higher throughput without the gas wars or bottlenecks common in account-based systems.

When you start building Sui DeFi primitives, you are no longer managing balances in a shared account state. You are manipulating specific objects. This granularity enables new composability patterns where assets can be locked, transferred, or modified without locking the entire user account.

Sui DeFi primitives

Design the core liquidity primitive

To build a functional Sui DeFi primitive, you must first define the on-chain data structures that hold liquidity. In Move, this means creating a struct that manages two distinct token reserves and enforces strict ownership rules. Unlike Ethereum smart contracts, Move objects are distinct resources that require explicit transfer and destruction logic, preventing common reentrancy and balance errors before they happen.

Sui DeFi primitives
1
Define the pool struct

Start by declaring a LiquidityPool struct. This struct must hold two generic token types (e.g., Coin<T> and Coin<U>) representing the trading pairs. Crucially, you must tag the struct with key and store abilities so it can be stored in the global storage and accessed by other modules. Without these abilities, the pool becomes inaccessible to the rest of your DeFi protocol.

Sui Move
2
Implement minting logic for LP tokens

Once the pool exists, users need a way to prove their share. Create a LPToken resource that represents the user's proportional ownership of the pool. When a user deposits assets, your code should calculate the minted LP token amount based on the current total supply and the user's deposit ratio. This ensures that liquidity providers receive fair, proportional shares of the trading fees generated by the pool.

Sui DeFi primitives
3
Enforce swap and withdrawal rules

The core economic logic lives in the swap function. You must implement a constant product formula or a similar algorithm to determine the output amount based on the input. Ensure that the function checks for zero-division errors and slippage limits before executing the trade. After the swap, update the reserves and emit the appropriate tokens to the trader, maintaining the invariant that the pool remains solvent.

Sui primitives are designed to facilitate efficient liquidity sharing across different protocols. By keeping the pool logic modular, you allow other DeFi applications to interact with your liquidity without needing to rebuild the entire exchange infrastructure. This composability is central to how Sui DeFi flourishes, enabling builders to ship complex trading products with built-in leverage and shared depth from day one.

Integrate DeepBook for shared liquidity

Siloed liquidity fragments depth and increases slippage for end users. DeepBook solves this by providing a shared liquidity layer that your custom primitives can tap into directly. Instead of building isolated order books for every token pair, you route orders through DeepBook’s Spot and Margin pools to aggregate depth across the ecosystem.

Step 1: Connect to the DeepBook SDK

Initialize the DeepBook client using the official Sui TypeScript SDK. This client handles the low-level interactions with the DeepBook Move modules on-chain. Ensure you are using the latest version of the SDK to support the most recent liquidity pool structures.

Step 2: Route Orders Through Spot Pools

For standard token swaps, route your order through DeepBook’s Spot liquidity layer. This layer aggregates limit orders from various providers, offering deeper depth than isolated pools. Your primitive should calculate the optimal path through these shared pools to minimize slippage for the user.

Step 3: Enable Margin Trading

To support leveraged positions, integrate with the Margin liquidity layer. This allows users to borrow assets from the shared pool while trading. By using DeepBook’s margin primitives, you avoid the need to build complex lending logic from scratch, ensuring that leverage is backed by deep, shared liquidity.

Isolated vs. Shared Liquidity

Understanding the difference between isolated pools and DeepBook’s shared model is critical for designing efficient primitives. The table below compares the two approaches.

FeatureIsolated PoolDeepBook Shared
Liquidity DepthFragmented per poolAggregated across ecosystem
SlippageHigher for low volumeLower due to depth
Leverage SupportManual integration requiredBuilt-in margin layer
Builder EffortHigh (custom logic)Low (SDK integration)

By leveraging DeepBook, you ship trading products that offer better prices and deeper liquidity from day one, without the overhead of managing isolated order books. For more details on the primitives, refer to the official Sui Blog.

Secure user interactions with zkLogin

zkLogin bridges the gap between traditional web2 convenience and web3 security. By leveraging OpenID Connect providers like Google, it allows users to authenticate without managing private keys or seed phrases. For DeFi primitives, this reduces onboarding friction significantly while maintaining cryptographic proof of identity.

Sui DeFi primitives
1
Initialize the zkLogin provider

Begin by configuring the Sui wallet adapter to support zkLogin. Import the SuiClient and getFullnodeUrl from the @mysten/sui.js package. Set up the environment variables for your OpenID provider (e.g., Google) and generate the necessary JWT claims. This step ensures your application can recognize and process zkLogin tokens.

Sui Move
2
Handle the authentication flow

Implement the login button that triggers the OpenID Connect flow. When a user clicks "Login with Google," they are redirected to the provider to authenticate. Upon success, the provider returns an ID token. Your application must verify this token using the Sui zkLogin library, which extracts the public key derived from the user’s identity claims.

3
Generate the Sui address

Use the verified ID token to derive the user’s Sui address. The zkLogin protocol maps the OpenID identity to a specific Sui address deterministically. This means the same user will always have the same address across sessions, allowing you to link their DeFi activity to a consistent identity without requiring them to copy-paste wallet addresses.

4
Sign transactions securely

Once authenticated, the user can sign transactions using their zkLogin-derived key. The Sui Wallet Adapter handles the signing process, ensuring that every transaction is cryptographically secure. For DeFi operations like swapping or lending, this process is seamless, as the user never manually handles private keys, reducing the risk of phishing or key loss.

This approach transforms user interaction from a technical hurdle into a standard login experience. By integrating zkLogin, your DeFi primitive becomes accessible to a broader audience while adhering to the security standards required for financial transactions.

Test and Deploy on Sui Mainnet

Before routing real capital to your Sui DeFi primitives, you must validate the entire stack against mainnet conditions. Mainnet introduces real gas costs, actual liquidity constraints, and adversarial actors that testnets cannot replicate. A thorough pre-launch checklist ensures your contract survives these pressures without draining user funds or wasting transaction fees.

1
Simulate mainnet conditions with a testnet fork

Run your integration tests against a fork of the Sui mainnet state. This reveals how your contract interacts with existing on-chain assets, such as SUI or established stablecoins, under current network congestion and gas price fluctuations. Tools like the Sui Move CLI allow you to fork the state and execute transactions as if you were on the live network.

2
Optimize gas consumption and storage deposit

Sui charges gas based on the number of Move operations and storage footprint. Use the Sui Profiler to identify hot paths in your Move code. Refactor functions to minimize object transfers and storage deposits, ensuring your DeFi primitive remains cost-effective for high-frequency trading or frequent interactions.

3
Complete security audits and formal verification

Engage a reputable audit firm specializing in Move and Sui. Require a formal verification report for critical financial logic, such as swap rates or lending collateral factors. Address all high-severity findings before deployment. Do not skip this step; even minor logic errors in DeFi can lead to irreversible exploits.

4
Execute a controlled mainnet deployment

Deploy your contract using the sui client publish command with the --with-all-dependencies flag. Verify the published module ID on the Sui Explorer. Immediately run a small-scale transaction test to confirm the contract is accessible and functional. Monitor the event logs for any unexpected errors or gas anomalies.

Sui DeFi primitives

Your deployment is only as strong as your validation process. By following this sequence, you reduce the risk of mainnet failure and build a foundation for sustainable DeFi growth on Sui.

Common questions about Sui DeFi

Developers often ask how Sui fits into the broader decentralized finance landscape. Understanding the token’s role and the underlying stack structure helps clarify why Sui is positioned for high-performance financial applications.