This article is a development report of a Dex223 decentralized exchange.
We’re building an exchange to speed up adoption of the ERC-223 token standard. ERC-223 was created to solve a security problem in the older ERC-20 standard. Security issue of ERC-20 caused $200M losses on Ethereum in 2023.
Take a look at other Dex223 development reports.
This month we've received the necessary legal data (privacy policies for our web services, protocol terms of use etc.) and established a Dex223 DAO LLC which would help us to apply for exchange listings in the future.
We have already agreed on a listing with BitMart as soon as the ICO round will be finished. It would be a huge step for the ecosystem if ERC-223 versions of existing ERC-20 tokens would be available for trading on some centralized exchanges and this was part of a deal with BitMart. Therefore we will soon see ERC-223 USDT tradeable on CEX.
Core smart-contracts of Dex223 were finalized. You can find them here:
Basic level of the ERC-223 support in Uniswap is already implemented. One remaining major improvement which is still pending is the implementation of the "merged liquidity" i.e. a feature that would allow two different versions of one token (ERC-20 one and ERC-223 one) created via Token Converter to be merged in one liquidity pool. This is a cumbersome task so it is likely that it will be completed after the basic margin trading implementation.
As it can be seen in our previous report we were mostly finalizing the conceptions during February. During March we started the development and finished the basic implementation of the exchange prototype already.
There are Dex223 test contracts on Sepolia testnet:
- Dex223 Factory 0x41368e68e2eb0a74cba9d4f6b418b487b7df5e58 (source code)
- ERC-223 compatible NonfungiblePositionManager 0xc70b2f2db899b8d0e73ee53dbc4b40a12d0e2be5 (source code)
- ERC-223 compatible SwapRouter 0xd71B50caF51f39657BA358759c54777FA44357Fb (source code)
- Test token (ERC-20) 0x723fe0a6415a25ec74cf0c4cf33f600f001d1aec
- Test token (ERC-223) 0x1d796072232c797cd07892fffab79170af07e5d7
- Dex223 pool for the test tokens 0x383Abb4CE818b9AB021cb296dCB52328fa602946 (source code)
We are starting the implementation of the basic margin trading and we expect to have a fully functional prototype of the exchange at the end of April. Also, the UI should allow for test trading in the coming weeks.
- (done) Updating libraries
- (done) Finalizing ERC-223 workflow concepts
- (done) Basic support of ERC-223 in Router and NonfungiblePositionManager: swaps and adding liquidity with ERC-223 tokens without approval() transaction
- (done) Routerless single swap implementation in a Pool contract
- (in progress) Auto-listing contracts
- (in progress) Lending & Margin trading implementation
- Merged ERC-20 & ERC-223 liquidity
Initially we were stating that ERC-223 support will allow us to reduce the gas costs of swaps by approximately 15%. Well, the testing results demonstrated that in some specific cases we can reduce the swap costs by up to 40% which is huge!
There is a fundamental difference between how to deposit ERC-20 and ERC-223 tokens to a smart-contract. In case of ERC-20 a user needs to "authorize" the contract to pull the tokens from the users's address first, then the user must tell the contract "hey, take my tokens and do something". These are two different transactions for ERC-20.
In case of ERC-223 the user can simply send the tokens to the destination smart-contract and tell it "do something" in the same transaction.
Also, Uniswap V3 implements a special contract called "Router" that processes the swaps. On the other hand, when you make a swap, you ultimately need to reach the smart-contract that stores the assets you want to receive - and this is a Pool smart-contract i.e. if you want to swap TokenA for TokenB then the A-B-Pool is the place where both tokens A and B are held. In case of Uniswap V3 a user can't directly contact the Pool and tell it to swap one token for another due to security reasons related to ERC-20 workflows. In case of Dex223 it is safe to swap tokens directly via the Pool which allows us to eliminate an intermediary from the process and therefore reduce the gas costs.
Routing. So what is the purpose of this "Router" contract? Well, it allows a user to swap tokens via multiple trading pairs. Imagine that you want to sell 10000 BTC on the market. It would impact the price severely if you will just dump these in one trading pair and you will end up selling at a much lower price than you could. It would be a good idea to find pairs with the best liquidity and sell your BTC to this pairs. This is exactly what the Router does.
It is important to note that the advantages of ERC-223 apply to certain specific cases. The most benefit is achieved for the first-time swap of a token without routing!
You can find a few transaction examples below.
- Approve (46K gas) https://sepolia.etherscan.io/tx/0x0734a0dd4f20597378ce717847cc7571657477b041b21416280190ceb1a4dbbd
- Swap function call (104K gas) https://sepolia.etherscan.io/tx/0xc20d94095877773909cb9ba67f79b6c3509afdba6014c5aca30b25d49451202b
A user needs to wait for the "approve" transaction to complete first. It is not possible to perform any further actions before this transaction completes.
- Transfer & swap (115K gas) https://sepolia.etherscan.io/tx/0xfdeb2e5db18f17644e29e7ccde7ad5928558761b06562ce6fa6710cf12d14620
A single transaction, no waiting delays.
- Deposit the first token to the NonfungiblePositionManager contract (65K gas) https://sepolia.etherscan.io/tx/0x1a8231c68bc88d9a317d04b25aa5a07087445d56ca9e4e2795700ebf238810d2
- Deposit the second token to the NonfungiblePositionManager contract (65K gas) https://sepolia.etherscan.io/tx/0xa185fd6e8b913f09711e89d870c2862b1836fd03120f292ecb3f6763f995365e
- Call Mint() function (335K gas) https://sepolia.etherscan.io/tx/0x0d83830f8703cbf21ce191e37859d69865d3c531ebf031e0bf70b51ecb289606
- Approve the first token (46K gas) https://sepolia.etherscan.io/tx/0x643b7107fd4204c99f0775c4670aa5dff8213599c82f143c25ff494795fa48c4
- Approve the second token (46K gas) https://sepolia.etherscan.io/tx/0x09019d1ce6d92317466ec12048c71c028536ea671cf37f73352e15a0dacc0872
- Call Mint() function (474K gas) https://sepolia.etherscan.io/tx/0xc48c0a5a7e77ec24bafcabaee080c603227e12b5d8bf10f018e17ea7687f270b
You can browse the state of the UI templates here: https://www.figma.com/file/euVeT6nAhnD55JUktI1WGr/%F0%9F%94%84-DEX223-Exchange-%F0%9F%94%84-(Copy)?type=design&node-id=2460%3A62488&mode=design&t=mwquP6ESFxyCvrku-1
We've made significant progress on finalizing the UI templates and currently the "Liquidity adding" and "Swap" pages are finished. We have brought the pages to a general style and are now polishing the details. "Margin trading" page is not yet ready but it will requite us to finalize the smart-contracts first (which is currently in progress). Auto-listing is partially completed.
Another major change that we did in the UI is the support of the "double standard" tokens. We are now planning to integrate the tokens created via the Token Converter natively in order to establish a new paradigm "Now every token is available in two versions on Ethereum mainnet: ERC-20 and ERC-223". Here are few example of the rework:
If you have any wishes or feature requests feel free to submit them in the comments to thig github gist or via our telegram channel.
We implemented a new trust score systems that will automatically calculate the value for every token displayable in the user's interface. This system is purely UI-based and it's just comparing the token lists. The main purpose of this system is to protect user from an obvious scam. For example if the user is going to swap some token USDT for a token called "USDC" but there is another token called USDC with a different contract address and the other USDC is listed in more token lists and (most importantly) it is listed in the default token list while the one the user is going to trade is not. This raises a big red flag indicating that the pseudo-USDC can be a scam token and we need to highlight it.
There was a small but important update to the Token Converter which is basically related to the live ERC-223 implementation. There was a lot of debates on whether the native currency can be transferred with the token in one transaction or not. As of now - we decided to focus on the implementation that allows the native currency (ETH on Ethereum) to be paid alongside token.
This will allow us to make it possible to deposit liquidity of ERC-223 token and native currency in one transaction potentially lowering the gas costs.
https://github.com/Dexaran/TokenStandardConverter/commit/082ee1f06c8dbb5ae996d02019a765bb488a88d1
Looks good! Keep up the good work!