A low-cost orderbook-based decentralized exchange for Ethereum
- Low-cost: only takes 1 transaction (excluding token approvals)
- Orderbook-based: users offer different prices to buy and sell at
- Decentralized: no trust is needed in anyone
- Exchange: users can trade between different cryptocurrencies
- For Ethereum: any EVM-compatible blockchain is capable of running prooftrade
Feature | prooftrade | UniswapV3 | UniswapV2 |
---|---|---|---|
Freely Licensed | Yes | No | Yes |
Zero slippage | Yes | No | No |
Zero LP fees | Almost (only needs approval once) | No | No |
Allows limit orders | Yes | Yes | No |
Gas needed per trade | 137,203 | 129,830 | 105,657 |
- Smart Contracts
- Solidity v0.6.12 - smart contracts written in Solidity
- Hardhat - for tests and deployment
- Web Interface - a frontend for using the contracts
- Next.js - web framework
- MUI - styles and components
- use-ethers-modal - an ethers.js provider (made by me)
- The main contract for a single trading pair is at
contracts/OrderFiller.sol
.
- Person A has 3000 USDC, and Person B has 1 WETH.
- Outside of the blockchain, they agree to trade 3000 USDC for 1WETH.
- Person A signs a message authorizing person B to make that specific trade (this is done off-chain).
- Person A sends their signature to Person B (this is also done off-chain).
- Person B uses that signature to execute the trade on-chain.
- The
OrderFiller
contract verifies that signature during Person B's Transaction. - The trade is completed.
In this example, USDC would be considered token0 and WETH would be token1. This is because the terminology will make more sense because WETH is thought of in terms of USDC.
- "Buying" is trading USDC for WETH.
- "Selling" is trading WETH for USDC.
Here, Person B would execute the sell
function, since they are trading their token1 for token0.
- Run
npm run test
ornpx hardhat test
to run tests. - The
OrderFiller
contract can be deployed as a standalone contract for a given pair of tokens. (Disclaimer: this project is still in development, has some trade-offs to consider (see below), and has not received any audits)
- A liquidity provider can prevent a trade with them from occurring by transfering their tokens to a different account
- I'm unsure if I want this to be possible
- It is good for the liquidity provider because they can cancel their order if they don't like it anymore
- It is bad because they can spoof orders and waste people's time an gas