ClearDEX orderbook

Github repo

⚫Stacks wallet address for payment - SP3GBF53536DAFFD3HJDE3V2CP7XWRF8E68Y069HK

ClearDEX orderbook features

Instructions

⚫Run clarinet check to check smart contracts for error and warnings

⚫Run clarinet console for local Stacks environment where you can call smart contract functions

⚫Run clarinet test to execute tests for the smart contracts

Inspiration

I saw some simple DEX implemented on Stacks but couldn't find any implementation for orderbook-based one.

Using orderbook has many benefits over AMM-based one such as:

⚫Users can take advantage of limit orders

⚫Users benefit of lower slippage and lower trading fees

⚫User can see the specific prices points at which liquidity is most concentrated, which might benefit their trading strategy

Finally I thought creating this project would be fun and challenging way to test my Clarity coding skills and get another piece for my portfolio.

What it does

This DEX orderbook will allow users to place buy and sell orders for various cryptocurrencies in a decentralized manner, without the need for a central authority. Currently for demonstration purposes it's only limited to trades between STX and custom clear token but it could be deployed with other tokens available on the Stacks. It's important to emphasize that it uses orderbook instead of typical AMM to facilitate token swaps.

Features:

⚫adding new buy order

⚫adding new sell order

⚫flat 1% fee on all transactions

⚫filling buy order

⚫filling sell order

⚫getting details for buy/sell orders

⚫canceling buy/sell order(removes liquidity from contract and send STC/custom token back to user)

How we built it

In this project I have create orderbook-based decentralized exchange using Clarity's developer environment on the Stacks. I have started by mapping buy / sell orders and sending tokens from users to the smart contracts. Once that was working I focused on finalizing orders and testing to make sure that there aren't any bugs or vulnerabilities.

Challenges we ran into

I am not as experienced with Clarity as with Solidity for example so lack of familiarity with many features was quite an issue. Luckily after spending some time with documentation I was able to figure most of the things out to end up with functional version of the project.

Accomplishments that we're proud of

I am happy that I was able to finish my MVP within just a few days. Now this Open-Source proof of concept could become backbone of bigger project or could serve as learning material for other Clarity developers.

What we learned

I was able to learn more about calling different smart contracts with Clarity and interacting with sip 010 tokens.

What's next for ClearDEX

In the future I will work on adding more features to make this project more complete. Such as

⚫calculating market price

⚫filling bigger orders at market price

⚫Completing multiple buy / sell orders from different users at the same time in 1 transaction

Built With

Share this project:

Updates