This is the main DEX contract for Switcheo Exchange
- Install Truffle ^5.0.29
- Install Ganache-CLI ^6.5.0
$ npm install ganache-cli@latest -g
- Run Ganache-CLI with:
$ ganache-cli -m "ladder soft balcony kiwi sword shadow volcano reform cricket wall initial normal" -p 7545 -l 8000000
- Install node modules with
npm install
- Install solc v0.5.12:
$ cd /usr/local/lib/node_modules/truffle
$ npm install [email protected]
- Run
truffle migrate
to deploy the contracts to Ganache - Run
truffle test
to run test files truffle test test/TestBrokerV2/trade/*.js
can be used to test files in a folder
.
├── contracts
│ ├── BrokerV2.sol # Main exchange contract
│ ├── Migrations.sol # Truffle's migration contract
│ ├── Utils.sol # Utility library
│ ├── extensions # Contracts to extend BrokerV2 features
│ ├── lib # OpenZeppelin contracts
│ ├── markets # Market contracts for testing
│ └── tokens # Token contracts for testing
├── migrations # Migration files
├── test # Test files
The BrokerV2 contract facilitates trading between users. The trades occur securely by requiring users to sign all actions concerning their funds with their Ethereum private key.
Users can deposit funds, make offers, fill offers, cancel offers, perform atomic swaps and withdraw funds.
In addition to the main features, the BrokerV2 contract allows for extensibility through spender contracts and market DApps.
Spender contracts allow the BrokerV2.owner
to whitelist new Ethereum contracts with new features. After a spender contract is whitelisted, a user can enable the new features by individually approving the spender contract to transfer funds on their behalf.
Market DApps allow offers to be filled by external markets. For example, KyberSwapDapp.sol
allows offers to be filled by the KyberSwap DApp while UniswapDapp.sol
allows offers to be filled by the Uniswap DApp.
The BrokerV2 contract provides escape hatches using the methods announceCancel
, slowCancel
, announceWithdraw
, slowWithdraw
.
These methods ensure that users will always be able to withdraw their funds without having to rely on the owner or admin of the BrokerV2 contract.
The BrokerV2 contract provides adminWithdraw
and adminCancel
methods which do not require user signatures. These methods can be invoked if the BrokerV2.adminState
is Escalated
and the invoker of the method is an admin address.
This is to allow contract admin to transfer entitled balances of users from the contract back to the users, in the case of an emergency or contract upgrade.