Skip to content

SNAKexchange - General Information

Welcome to the official documentation for SNAKexchange, a decentralized exchange (DEX) built on the Xian Network. This document provides a high-level overview of the protocol, its core concepts, and its architecture.

What is SNAKexchange?

SNAKexchange is a permissionless, decentralized protocol for automated token exchange on the Xian Network. It is a direct rewrite and adaptation of the highly successful Uniswap V2 protocol, bringing its robust and battle-tested automated market maker (AMM) design to the Xian ecosystem.

The primary goal of SNAKexchange is to enable a decentralized, censorship-resistant, and secure environment where users can swap Xian-based tokens without relying on traditional intermediaries like centralized exchanges.

Core Concepts

SNAKexchange is built upon the core principles of an Automated Market Maker (AMM).

Liquidity Pools

Instead of traditional order books, SNAKexchange uses liquidity pools. These are smart contracts that hold reserves of two different tokens. Users, called Liquidity Providers, can deposit an equal value of each of the two tokens into a pool. In return, they receive Liquidity Pool (LP) tokens, which represent their proportional share of that pool's total assets.

Constant Product Formula

The price of assets in a liquidity pool is determined by a mathematical formula called the constant product formula:

x * y = k

Where:

  • x is the amount of token A in the pool.

  • y is the amount of token B in the pool.

  • k is the "constant product" of the pool.

When a user wants to swap one token for another, they add one token to the pool and remove the other. To keep k constant, the balances of the tokens adjust, which results in a new price. The larger a trade is relative to the size of the pool, the more it will shift the price (this is known as "slippage").

Trading Fees

Every trade on SNAKexchange incurs a 0.3% fee. This fee is distributed as follows:

  • 0.25% is added back into the liquidity pool. This serves as a reward for liquidity providers, who can claim their portion of the fees when they withdraw their liquidity.

  • 0.05% is allocated as a protocol fee. This fee can be turned on or off by the protocol owner and is sent to a designated feeTo address. This mechanism provides a way to fund ongoing development and maintenance of the protocol.

Contract Architecture

The SNAKexchange protocol is primarily composed of two smart contracts:

  1. con_pairs (The Factory & Pair Contract) This is the core contract of the protocol. It functions as both a "factory" for creating new token pair exchange contracts and as the contract that holds the logic for all created pairs. It is responsible for managing liquidity, minting and burning LP tokens, and executing the core swap logic. All token reserves are held within this contract.

  2. con_dex_v2 (The Router Contract) This contract serves as the primary entry point for users interacting with SNAKexchange. It provides a more user-friendly and safer interface for adding/removing liquidity and swapping tokens. Users should almost always interact with the Router contract rather than directly with the pair contracts.

Important Technical Constraints

MAXIMUM_BALANCE

The Xian Contracting language has a limit of 1e29 on the decimal data type. To prevent any potential overflow errors during mathematical operations (especially the multiplication in the constant product formula), the protocol enforces a MAXIMUM_BALANCE of 1e14 for any single token reserve within a pair. If a transaction would cause a pair's balance of either token to exceed this limit, the transaction will be reverted. This is a crucial safety mechanism to ensure the financial stability and integrity of the protocol.