Introduction

The purpose of the Acuity DEX is to overcome some of the major issues holding back the blockchain ecosystem.

Debasement

Cryptocurrencies are typically traded on centralized exchanges. This is especially true when trading between chains as non-custodial cross-chain exchanges are less mature than intra-chain or centralized exchanges.

Because centralized exchanges can debase any currency that is trading on their platform, they can collaborate and decide which currencies are going to succeed. They can then use this information to make even more profit.

Loss of funds

It's a common occurrence for cryptocurrency holders to deposit their funds to a centralized exchange and be unable to withdraw them again.

Because Acuity DEX is non-custodial, this is not an issue.

Censorship

Increased regulations are making it harder and harder to use centralized exchanges to trade. Because Acuity DEX is fully autonomous traders can have total confidence that they can participate.

Asset Identification

During the trading process it is essential that traders can identify which assets are being bought and sold. Acuity has a 32 byte asset_id that can identify any asset on any chain.

The first 2 bytes identify the chain. The layout of the remaining bytes depends on the chain.

1 - Substrate
2 - EVM
3 - Cosmos
4 - Bitcoin

Here is the layout for EVM chains:

2 bytes chain type 0x0002 for EVM chain
6 bytes chain_id - see https://chainlist.org/
2 bytes asset_type - 0x0000 for base, 0x0001 for ERC20
2 bytes adapter_id - which atomic swap smart contract to use
20 bytes token address - for ERC20 tokens the address is stored here

For each chain_id / asset_type / adapter_id the DEX software knows the correct smart contract to use

Supported Chains

Initially, Acuity DEX will support Acuity (Substrate) and just about all EVM chains.

Substrate chains need to either install the Acuity Atomic Swap pallet via the governance mechanism, or if they have a smart contracts pallet deployed the DEX contracts can be deployed permissionlessly.

Because all EVM chains are largely compatible, it's simply a matter of deploying the smart contracts.

Trading the base coin and all ERC20s on the following EVM chains will be supported:

Price Calculations

For the exchange to operate correctly it is critical that price calculations on different devices give exactly the same results. To ensure that this is the case all currency prices and values are stored as an arbitrary-precision integer count of the smallest unit. Division is performed using Integer Division.

The price the seller publishes in the order book is the integer number of small units of buy currency to buy one big unit of sell currency. For example if the seller wanted to sell 1 BTC for 18.9 ETH, the price would be stored as 18,900,000,000,000,000,000. The smallest unit of ETH is WEI and 1 ETH = 10^18 WEI.

Of course, prices can be rendered in a much more human-readable format.

The buyer decides how much of the sell order they wish to buy. To determine the cost in small buy units from price in small buy units and the sell quantity in small sell units, the following equation is used:

sell_value - small units of sell asset being bought
sell_price - small units of buy asset to buy one big unit of sell asset
sell_decimals - decimal places between big and small units of sell asset
buy_value - small units of buy asset required to buy sell_value

buy_value = (sell_value * sell_price) \ (10 ^ sell_decimals)

Order Book

There are two participants in a trade on the Acuity DEX - the buyer and the seller. The seller is typically a bot and publishes sell orders via the Acuity DEX blockchain.

The order book will be maintained offchain by an indexer than can be run locally. This ensures transactions fees are as low as possible.

For a given trading pair, the Acuity Bot (written in Rust) first constructs the current state of the order book.

  • It uses the Acuity DEX Indexer to get all active orders.
  • It checks the balance on the sell chain of the sell address of each order. Orders with insufficient balance are marked as such.
  • The orders are ordered by sell price.

The bot then watches for order changes from the Acuity chain and locks on the trading chains to keep the order book up to date.

The bot can be queried at any time to obtain the full order book. It can be subscribed to for updates.

Connected Accounts

In order to trade on the Acuity DEX traders must link their addresses on trading chains with their Acuity address.

The link is 2-way. This proves that the link is correct and enables lookups to occur in both directions.

  • Transactions on the Acuity chain can register the sender's addresses on other chains. This occurs in the order book pallet.
  • Transactions on the EVM trading chains can register the sender's Acuity address in the AcuityAccount smart contract.

When the buyer creates a buy order they need to know the seller's address on the buy chain. They look this up on the Acuity chain.

For the seller to create the sell lock they need to use the buyer's address from the buy lock to look up the buyer's address on the sell chain.

Atomic Swap

Once the buyer has decided to proceed with a trade they can start the process by locking up the funds on the buy chain that they want to use to pay for funds on the sell chain.

Buy Lock

The buyer issues a transaction on the buy chain to create a buy lock. On an EVM chain this is handled by a smart contract. On a Substrate chain it is handled by the Acuity Atomic Swap pallet.

The parameters are as follows:

token - address of the token contract (if ERC20 token)
value - quantity of buy asset to be locked up to buy the sell asset
recipient - the address of the seller on the buy chain
hashed_secret - keccak256(secret)
timeout - how long the lock will last before the buyer can retrieve the value
sell_asset_id - the asset_id of the asset identified on the order book
sell_price - the price of the asset listed on the order book

buy_value must be determined exactly using sell_price as described in the Price Calculations section.

recipient is determined by querying connected accounts on the Acuity chain to get the address of the seller on the buy chain.

The buyer must generate a 32 byte random number and keep it secret until the swap is complete. hashed_secret is calculated by taking the keccak256 hash of the secret.

timeout should be far enough in the future so that half of the time until the timeout expires will be sufficient for the buyer to submit a transaction to unlock the sell lock. If the buy process is being handled manually the timeout will need to be much longer than if it is being handled by a bot. For EVM chains timeout should be specified in seconds, for Substrate chains it should be specified in milliseconds.

Sell Lock

The sell bot will detect that a buy lock has been created with the seller as the recipient. It needs to determine that the buy lock is valid.

First the following values need to be calculated:

  • sell_value
  • sell_timeout
  • buy_asset_id
  • buy_lock_id - keccak256(abi.encode(buyer, seller, hashedSecret, buy_timeout))

The following conditions must be met:

  • sell_asset_id must be in the seller's order book
  • sell_price must be the current price or higher in the seller's order book
  • sell_value must be less than or equal to the value for sale in the order book
  • timeout must be sufficiently far in the future
  • the buyer's address on the buy chain or sell chain must not be in the seller's blacklist

If they are not met, the seller can call the reject_lock() method on the buy chain with the rejection reason?

If the conditions are met the seller should create a lock on the sell chain with the following parameters:

token - address of the token contract (if ERC20 token)
value - quantity of sell asset to be locked up vwwto buy the sell asset
recipient - the address of the buyer on the sell chain
hashed_secret - same as the buy lock
timeout - calculated above
buy_asset_id - calculated above
buy_lock_id - calculated above

Buyer Unlocks Sell Lock

The buyer's software will detect the sell lock event. It needs to ensure that all the event parameters are correct.

The sell lock should be approximately 50% as long as the buy lock.

The buyer publishes a transaction to unlock the sell lock and obtain the funds they are buying. This transaction includes the unhashed secret.

Seller Unlocks Buy Lock

Now that the buyer has revealed the secret the seller now has to unlock the buy lock to retrieve the funds.

Trading Bots

In order for buyers to be able to quickly buy on the DEX, it is vital that sellers are running automated trading bots to provide liquidity.

Acuity trading bots actually have two components:

DEX Bot

Written in Rust.

This program performs trades on the Acuity DEX as instructed by the controller via WebSockets.

It maintains a hot wallet of all the cryptocurrencies that it is trading.

Watches for Acuity atomic swap events on trading chains.

Maintains sell orders on the Acuity chain as instructed by the controller.

Executes sell orders.

Controller Bot

Can be written in any language. Communicates with the automated trader via WS.

Instructs the automated trader what should be in the orderbook.

Acuity DEX Blockchain

The DEX operates via the Acuity DEX chain.

It provides the following functionality:

  • Order publishing
  • Cross-chain account connection
  • Trusted accounts

ACU is the base coin.

This chain was originally launched as an EVM chain on 27th April 2017 called LINK. It was renamed to MIX on 12th October 2017 due to the announcement of Chainlink. On 1st September 2020 MIX migrated to a Substrate chain called ACU.

The ACU chain did not produce any blocks between July 4th 2023 and the hard spoon on 29th January 2024.

Why Substrate?

On 25th July 2016 Acuity Founder Jonathan Brown published the Federated Ethereum Blockchains blog post. It is essentially a wishlist for the perfect blockchain technology. Polkadot satisfies the items on the wishlist almost perfectly. Substrate is the framework Polkadot is built upon.

Repository

Order Book Pallet

Repository

Trusted Accounts Pallet

Repository

DEX Blockchain Indexer

Both the dapp and the trader bot need to be able to query and subscribe to events from the following on the DEX blockchain:

  • Connected Accounts
  • Trusted Accounts
  • Order Book
  • Atomic Swap

This component uses Hybrid Indexer to enable indexing of and subscribing to events on the Acuity blockchain.

Acuity DEX EVM Indexer

This indexer can index the Acuity DEX smart contracts on any EVM chain.

Intra-chain Trading Contracts

While the main purpose of the Acuity DEX is to facilitate cross-chain atomic swap trades, it will also support intra-chain trading. This will be the first component to be deployed and will support any EVM chain.

Intra-chain trading is dominated by constant function market maker exchanges such as Uniswap. These exchanges are unable to determine asset market value in isolation. Rather, they rely on arbitrage with order book exchanges (typically centralized) for the trading price to be correct.

The purpose of Acuity intra-chain trading is to provide an on-chain order book exchange so that asset market value can be determined fully on-chain.

The under-development ERC20/ERC20 contract is here.

Architecture

Sell Orders

Each order is composed of a key and a value. The key is 32 bytes (EVM word size) containing the account that is selling and the price they are selling at.

 32 bytes
╭─────────────────────┬─────────────╮
│ seller address      │ sell price  │
│ 20 bytes            │ 12 bytes    │
╰─────────────────────┴─────────────╯

The meaning of the 96-bit sell price integer is explained in the Price Calculations section.

Each order key is mapped to a 256-bit integer that represents how much of the sell asset is for sale in the order. This mapping is the value in a double mapping of sell token and buy token.

sell_token => (buy_token => (order_key => value))

The order keys are also stored in an ordered linked list for each token pair. Orders are ordered by sell price from lowest to highest.

sell_token => (buy_token => (order_key => next_order_key))

The lowest priced sell order is linked to by an order key of 0.

When sell creates a sell order the token is transferred to the smart contract and the linked list is traversed to find the correct place to insert the order.

When amending an order it is simply a matter of increasing or decreasing the mapped value. If the value is reduced to 0 the order is removed from the linked list completely.

Buying

To buy from an order book, the buyer specifies the sell_token, buy_token and buy_value. The order book for the pair is traversed from the beginning.

For each order:

  • Calculate matched_sell_value - how much of sell_asset the buyer would get if they sold buy_value at the order's sell_price.
  • If the order value is greater than matched_sell_value, a partial buy is performed. The order is reduced by matched_sell_value and buy_value is transferred directly from buyer to seller. total_sell_value is incremented by matched_sell_value. Order traversing stops.
  • Otherwise, a full buy is performed. The order is deleted and the buy value to purchase the whole order is transferred from buyer to seller. total_sell_value is incremented by the value of the order. Now the process continues with the next order.

total_sell_value is transferred from the DEX contract to the buyer.

Atomic Swap Contracts

Most EVM chains can have their base coin and ERC20 tokens traded on Acuity by deploying these contracts.

Repository

Atomic Swap Pallet

Substrate chains without smart contract functionality will need to add this pallet to their runtime via the on-chain governance mechanism before the base coin can be traded on Acuity.

Currently, tokens managed by the Assets Pallet are not supported.

Repository

DEX Bot

Has the keys to the trader's hot wallet.

Automatically issues the transactions necessary to perform an atomic swap as either seller or buyer. It can also be instructed to set and remove sell orders.

Repository

Controller Bot

A controller bot can be written in any language to tell the DEX bot what the sell orders should be.

Desktop App

The Acuity DEX Desktop App is being written in Rust using the iced GUI library. It will be available for macOS, Windows and Linux.

It will enable buyers and sellers to easily trade on the DEX.

repo

Browser App

Acuity DEX user interface built with Rust, Sycamore & Tailwind.

Supports trading on both the intra-chain DEX and the cross-chain atomic swap DEX.

Wallets

Transactions are issued via third-party wallets such as MetaMask (EVM chains) and Polkadot{.js} (Substrate chains such as Acuity DEX).

Status

Status: Needs to be rebuilt from previous app (written in Vue 3 & TypeScript).

Comparisons

BasicSwap

Fairly similar architecture to Acuity DEX.

  • no KYC
  • atomic swap (scriptless chain, OtVES)
  • distributed order book (SMSG)
  • non-custodial
  • particl, bitcoin, litecoin, monero, PIVX, Dash, Firo (scriptless scripts - EVM chains not supported yet)
  • desktop, no web yet

Block DX

Komodo Wallet

ThorDex

Bisq

Haveno

Polkadex

Tokenomics

Before the Regenesis as ACU, MIX was funded by a 2000-day linear vesting smart contract [source] starting on 27th April 2017. The original documentation shows the issuance schedule.

At the 29th January 2024 hardspoon the total issuance of ACU was 85.2m, 4m being held by founder Jonathan Brown from the linear vesting. He will continue to use these funds to promote development and adoption of ACU.

ACU currently follows the DOT inflation model with a maximum annual inflation rate of 10%.

Unlike most other cryptocurrencies, ACU has an anti-debasement strategy. For example, it has been estimated that centralized exchanges had expanded the tradable supply of Bitcoin by 100 million BTC during the last bull run. This has a long term downward pressure on the trading price and is likely one of the major reasons for the crypto bull/bear cycle.

Once the centralized exchanges go bust at the bottom of the market the tradable supply is reduced dramatically, enabling the price to slowly start to increase and the cycle repeats itself.

The Acuity community will use non-violent methods to ensure that ACU is not traded on exchanges that can debase. This is one of the primary reasons why the Acuity DEX is being built.

ACU is used to pay for transactions on the Acuity DEX blockchain. Primarily to publish sell orders (these are extremely cheap), but also for balance transfers, to publish a list of trusted accounts and to participate in governance.

Note that the goal of the Acuity DEX is not to make the value of ACU trade higher. The goal is to provide fully permissionless, non-custodial, autonomous cross-chain trading.

How to buy

In order to hold ACU, you need to create install the Polkadot browser extension and create an account on the Acuity blockchain.

Until the DEX is up and running and has sufficient liquidity ACU can be purchased directly from Acuity founder Jonathan Brown. This helps fund development. Email purchase@acuity.social.