DEV Community

Cover image for Mastering Sui DeepBook: A Hands-On DeFi DEX Series (2)
Rajesh Royal
Rajesh Royal

Posted on

Mastering Sui DeepBook: A Hands-On DeFi DEX Series (2)

Welcome back to the Mastering Sui DeepBook series!

In Part 1, we introduced the core concepts of the Sui blockchain, the Move programming language, and the DeepBook protocol. We outlined what we're going to build: a fully functional Decentralised Exchange (DEX) leveraging DeepBook's central limit order book (CLOB) architecture.

In this second instalment, we will roll up our sleeves and get our hands dirty. We'll set up our development environment, install the necessary tools, and bootstrap the project boilerplate. By the end of this tutorial, you'll have a working local environment ready for smart contract development.

Environment Setup

In this section, we will install the necessary tools and dependencies to begin working with Sui DeepBook.

Bootstrapping the Boilerplate

Firstly, let's set up the boilerplate for our Sui DeepBook contract. This boilerplate provides a starting point for your smart contract development.

  1. Open your terminal.

  2. Clone the boilerplate repository using the following command. We use the template branch which contains the starter code:

   git clone -b template https://github.com/Rajesh-Royal/SUI-Deepbookv3-Dex
Enter fullscreen mode Exit fullscreen mode
  1. Change into the boilerplate directory:
   cd SUI-Deepbookv3-Dex
Enter fullscreen mode Exit fullscreen mode

Now we have the boilerplate set up, let's explore installing the necessary tools and dependencies.

Installing Sui and Dev Tools

The first step is to install Sui, Move, and the necessary dev tools. Follow the instructions below based on your operating system.

Installing on Codespaces (Ubuntu/Debian)

If you are using GitHub Codespaces or a Linux environment, follow these steps.

  1. Install Required Dependencies Run the following commands to install the required dependencies.
   sudo apt update
   sudo apt install curl git-all cmake gcc libssl-dev pkg-config libclang-dev libpq-dev build-essential -y
Enter fullscreen mode Exit fullscreen mode
  1. Install Rust and Cargo Run the following command to install Rust and Cargo.
   curl https://sh.rustup.rs -sSf | sh
Enter fullscreen mode Exit fullscreen mode

Type 1 and press Enter when prompted. After installation, configure your shell:

   source "$HOME/.cargo/env"
Enter fullscreen mode Exit fullscreen mode
  1. Install Sui Binaries You can install Sui directly using Cargo (this may take a while):
   cargo install --locked --git https://github.com/MystenLabs/sui.git --branch devnet sui
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

   sui --version
Enter fullscreen mode Exit fullscreen mode

Installing on MacOS

  1. Install Homebrew (if not already installed)
   /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode
  1. Install Sui
   brew install sui
Enter fullscreen mode Exit fullscreen mode
  1. Verify Installation
   sui --version
Enter fullscreen mode Exit fullscreen mode

Understanding the Boilerplate Code

Now that we've set up the boilerplate, let's explore the structure of the provided code, understand the purpose of each file, and prepare the main.move file for our Sui DeepBook contract.

Boilerplate Code Structure

You should see the following code structure in your contract directory:

SUI-Deepbookv3-Dex
├── contract
│   ├── sources
│   │   ├── main-test.move
│   │   ├── main.move
│   │   ├── wbtc.move
│   ├── Move.toml
│   ├── contract-publish.sh
│   ├── README.md
└── package.json
Enter fullscreen mode Exit fullscreen mode

Let's explore the purpose of each file inside the contract folder:

  • sources/main-test.move: An empty file for potential unit tests related to the main contract.
  • sources/main.move: The main file where our Sui DeepBook contract will be implemented. This file is currently empty but will be populated in the next section.
  • sources/wbtc.move: The wbtc.move file contains a basic implementation of a wrapped Bitcoin (WBTC) module. It showcases the structure of a token on the Sui blockchain, including initialization, minting, and burning functions.
  • Move.toml: This file defines the package information for our smart contract. It specifies dependencies on the Sui and DeepBook frameworks, which provide essential functionalities for blockchain development. Additionally, it assigns an address to our smart contract on the blockchain.
  • contract-publish.sh: This script automates the build and publishing process of the smart contract. It extracts necessary information from the build output and sets environment variables for subsequent use.

Top comments (0)