A Closer Look at Concordex’s Smart Contracts

Concordex Labs
5 min readAug 17, 2023

--

One of the main advantages of DEX over centralized exchanges is its open code. Every user can access a smart contract at any time, check it, and make sure it is competent. This may sound complicated now, so let’s use an example!

Imagine coming to your favorite coffee shop and wanting to know what a delicious chocolate cake is made of. The barista not only tells you the ingredients but even knows the name of the cow that gave the milk for the cake. Moreover, he shows you a video of the whole process from cooking to display. So, in our case, the cake is Concordex’s smart contract, and the barista is the guide you’re reading right now.

Fasten your virtual seatbelts, and let’s take a tour of the main functions Concordex’s smart contract performs and how they’re implemented in code lines! 🤔

1. Initializing the Contract

Initialization is the process of setting up the contract with basic parameters.

  • Owner ID: Identifies the account with administrative control over the DEX.
  • Protocol Fee Fraction: Sets the portion of fees going to the DEX. Calculated as a fraction of FEE_DIVISOR. For example, 1300 out of 10000 represents a 13% fee.
  • Fee Rates: Specific fee rates for different levels, specified as units of 1.0001^fee_rate — 1.

2. Managing Deposits and Withdrawals

Users interact with their funds through deposit and withdrawal functions.

  • Get_Deposits: Retrieves balances outside any pools.
  • Get_Deposit: Retrieves the balance for a specific user and token.
  • Withdraw: Allows a user to withdraw a given token, with options for callbacks and unregistering the token.

3. Handling Tokens and Pools

The contract allows interaction with specific tokens and liquidity pools.

  • Get_Verified_Tokens: Retrieves a list of allowed tokens.
  • Get_User_Tokens: Retrieves a specific user’s tokens.
  • Get Pool Info: Gives detailed information about a particular pool, including reserves, spot prices, and liquidities (a group of tokens locked in a smart contract and used for trading).

4. Trading and Swapping Tokens

Users can engage in various trading and swapping activities.

  • Swap_Exact_In: Exchanges a specific amount of one token for another, with a minimum output amount.
  • Swap_Exact_Out: Exchanges tokens to receive a specific output amount, setting the maximum amount of token that can be spent
  • Swap_To_Price: Performs a swap to achieve a specific price in the pool.

5. Special Permissions and Controls

This section encompasses methods that allow the owner to manage tokens and guard accounts, control API calls, and adjust protocol fees.

Owner and Guard Control

  • Get_Owner: Retrieves the owner’s address.
  • Extend/Remove_Verified_Tokens: Adds or removes verified tokens. Only callable by the owner.
  • Extend_Guard_Accounts: Adds guard accounts. Only callable by the owner.
  • Remove_Guard_Accounts: Removes guard accounts. Only callable by the owner.

API Suspension and Resumption

  • Suspend_Payable_API: Halts payable API calls, which can be done by the owner or guards.
  • Resume_Payable_API: Resumes payable API calls, also accessible to the owner or guards.

Protocol Fee Adjustment

  • Set_Protocol_Fee_Fraction: Modifies the portion of the fee going to the DEX. Only changeable by the owner.

6. Position Management

Managing positions, including opening, closing, and retrieving information about a position.

  • Open_Position: Deposits tokens in the pool as a liquidity provider.
  • Close_Position: Closes an existing position.
  • Get_Position_Info: Retrieves detailed information about a specific position.
  • Withdraw_Fee: Withdraws fees accumulated on the specified liquidity position. It can only be called by the position’s owner.

7. Miscellaneous Functions

Other essential methods for interacting with the contract.

  • Get_Version: Retrieves the contract’s version.
  • Execute_Actions: Executes a series of actions such as swaps, deposits, or position management.

Conclusion

The Concordex Smart Contract is an intricate and robust piece of software, defining the rules and functions for managing the decentralized exchange (DEX). Through a diverse set of functions, it accommodates typical user interactions such as deposits, withdrawals, and swaps, and provides advanced control features for owners and administrators.

Understanding this contract will offer you a deeper insight into the working mechanics of modern decentralized exchanges and the innovative technology behind them. And to get even more details, we recommend reading some docs from the official website of Concordex!

--

--

Concordex Labs

Institutional-Grade Decentralized Exchange on the Concordium Blockchain