Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bokkypoobah/chadex
Fully on-chain orderbook ERC-20/ERC-20 DEX using Red-Black Trees and Queues (WIP)
https://github.com/bokkypoobah/chadex
dex erc-20 ethereum on-chain orderbook red-black-tree solidity
Last synced: 3 days ago
JSON representation
Fully on-chain orderbook ERC-20/ERC-20 DEX using Red-Black Trees and Queues (WIP)
- Host: GitHub
- URL: https://github.com/bokkypoobah/chadex
- Owner: bokkypoobah
- Created: 2018-12-25T04:48:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T03:36:04.000Z (about 1 month ago)
- Last Synced: 2024-10-18T15:59:01.875Z (30 days ago)
- Topics: dex, erc-20, ethereum, on-chain, orderbook, red-black-tree, solidity
- Language: Solidity
- Homepage: https://bokkypoobah.github.io/Dexz/
- Size: 6.75 MB
- Stars: 24
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chadex
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/
---
## Notes
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-helpers
npm install --save-dev solidity-coveragenpm 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`
---
## Old Stuff
Token incompatibilities - [An Incompatibility in Ethereum Smart Contract Threatening dApp Ecosystem](https://medium.com/loopring-protocol/an-incompatibility-in-smart-contract-threatening-dapp-ecosystem-72b8ca5db4da)
* Token registry includes rating
* 0 scam, 1 suspect, 2 unrated, 3 OK, 5 reputable
* Prevent front runninghash(ccy1/ccy2) => Orderbook
Orderbook
RedBlackTree index by price
buyOrders - 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 - baseToken
sellOrdersTODO:
* Move past consumed orders, graceful gas limit exit
* Handle canTransferFrom() - https://github.com/ethereum/EIPs/issues/1594
`function canTransferFrom(address _from, address _to, uint256 _value, bytes _data) external view returns (bool, byte, bytes32);``
## Function Calls
### trade
```javascript
function trade(uint orderFlag, address baseToken, address quoteToken, uint price, uint expiry, uint baseTokens, address uiFeeAccount) public payable returns (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`And `orderFlag` is constructed using the following bitmasks
```javascript
// Note that the BUY and SELL flags are used as indices
uint constant public ORDERTYPE_BUY = 0x00;
uint constant public ORDERTYPE_SELL = 0x01;
uint constant public ORDERFLAG_BUYSELL_MASK = 0x01;
// BK Default is to fill as much as possible
uint constant public ORDERFLAG_FILL = 0x00;
uint constant public ORDERFLAG_FILLALL_OR_REVERT = 0x10;
uint constant public ORDERFLAG_FILL_AND_ADD_ORDER = 0x20;
```