- Notifications
You must be signed in to change notification settings - Fork7
Fully on-chain orderbook ERC-20/ERC-20 DEX using Red-Black Trees and Queues (WIP)
bokkypoobah/chadex
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
chadex is a non-custodial peer-to-peer ERC-20/ERC-20 decentralised exchange protocol.
- Users permit the chadex smart contract to perform ERC-20 token transfers
- Users express their desire to exchange ERC-20 tokens to other ERC-20 tokens by adding orders to the exchange
- If the prices match between users, the exchange takes place.
Fully on-chain ERC-20/ERC-20 DEX using Red-Black Trees and queues for sorted orderbook executions.
Status: Work in progress
https://bokkypoobah.github.io/chadex/
npm install --save-dev @nomiclabs/hardhat-truffle5 @nomiclabs/hardhat-web3 web3
https://docs.openzeppelin.com/test-helpers/0.5/
npm install --save-dev @openzeppelin/test-helpersnpm install --save-dev solidity-coverage
npm install --save-dev @nomiclabs/hardhat-ethers 'ethers@^5.0.0'
Coverage
Run coverage reports using the command
npx hardhat coverage
Output will be in the generated coverage directory
If you are using yarn, you can run
yarn hardhat coverage
Token incompatibilities -An Incompatibility in Ethereum Smart Contract Threatening dApp Ecosystem
- Token registry includes rating
- 0 scam, 1 suspect, 2 unrated, 3 OK, 5 reputable
- Prevent front running
hash(ccy1/ccy2) => Orderbook
OrderbookRedBlackTree index by pricebuyOrders - Expiring Queue=> Order* OrderType orderType;* address baseToken; // GNT* address quoteToken; // ETH* uint price; // GNT/ETH = 0.00054087 = #quoteToken per unit baseToken* uint expiry;* uint amount; // GNT - baseTokensellOrders
TODO:
- Move past consumed orders, graceful gas limit exit
- Handle canTransferFrom() -ethereum/EIPs#1594`function canTransferFrom(address _from, address _to, uint256 _value, bytes _data) external view returns (bool, byte, bytes32);``
functiontrade(uintorderFlag,addressbaseToken,addressquoteToken,uintprice,uintexpiry,uintbaseTokens,addressuiFeeAccount)publicpayablereturns(uint_baseTokensFilled,uint_quoteTokensFilled,uint_baseTokensOnOrder,bytes32_orderKey);
| Parameters | Notes |
|---|---|
orderFlag | uint256 |
baseToken | address of the baseToken |
quoteToken | address of the quoteToken |
price | uint256 |
expiry | uint256 |
baseTokens | uint256 |
uiFeeAccount | address |
AndorderFlag is constructed using the following bitmasks
// Note that the BUY and SELL flags are used as indicesuintconstantpublicORDERTYPE_BUY=0x00;uintconstantpublicORDERTYPE_SELL=0x01;uintconstantpublicORDERFLAG_BUYSELL_MASK=0x01;// BK Default is to fill as much as possibleuintconstantpublicORDERFLAG_FILL=0x00;uintconstantpublicORDERFLAG_FILLALL_OR_REVERT=0x10;uintconstantpublicORDERFLAG_FILL_AND_ADD_ORDER=0x20;
About
Fully on-chain orderbook ERC-20/ERC-20 DEX using Red-Black Trees and Queues (WIP)
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.