@hexcrypto/exchange-wrappers v0.6.0
Uniswap Exchange Wrapper
Exchange wrapper for connecting hYhX contracts to Uniswap Exchange on-chain.
Testing
Tests fork mainnet contracts for use locally. This makes testing already deployed contracts and infrastructure against new contracts locally incredibly easy.
Setup for this is done in the test/helpers/setup.ts file.
Tests use jest and ethers
along with the local blockchain setup in the setup.ts file. Typescript preprocessing
for tests is done using ts-jest.
To run tests simply run yarn test
For development, yarn test:watch will watch contract and tests for changes and
rerun the tests.
Test configuration files can be found at:
jest.config.js(basic configuration for jest and typescript)jest.setup.js(adds a longer timeout to tests)
Linting
Relevant linting files can be found at the following locations:
.eslintrs.js.pretierrc.jstsconfig.json
Smart Contracts
Linting is done using ethlint.
Run yarn lint:sol to lint the contracts.
Typescript
Linting is performed through eslint along with
prettier. Typescript is linted though plugins for eslint.
See package.json for more info on plugins.
Building the Contracts
Contract compilation is done using waffle. Waffle is not used for tests.
To compile, simply run yarn compile:sol.
For a nice development flow, yarn compile:sol:watch can be used for automatic recompiling.
Deploying Contracts
Ensure that the correct .env variables are set before deploying. See .env.example for details.
Deployed contracts are saved to deployments.json at the root of the repo. This is committed to source.
The GAS_PRICE_GWEI .env variable is optional. If it is not supplied, an estimate will be fetched from
the network. This is NOT recommended when deploying to mainnet.
For a list of already deployed contracts, see deployments.json at the root of the repo.
Private Network (dev AKA ganache)
For testing migrations locally, a local blockchain forked off of mainnet can be used:
yarn start:devchainDeployment can then be run using:
yarn deploy:contractsPublic Networks (mainnet, kovan, etc.)
Simply run:
yarn deploy:contractsEverything should work fine as long as .env vars were set correctly.
Contract Layout
Contract directory is as follows:
contracts
├── exchange-wrappers
│ ├── TestExchangeWrapper.sol
│ └── UniswapV2ExchangeWrapper.sol
├── external
│ ├── README.md
│ └── uniswap
│ ├── IUniswapV2Factory.sol
│ ├── IUniswapV2Pair.sol
│ ├── IUniswapV2Router01.sol
│ └── UniswapV2Library.sol
├── interfaces
│ ├── ExchangeReader.sol
│ └── ExchangeWrapper.sol
└── lib
├── GeneralERC20.sol
└── TokenInteract.solbase
The main contract is UniswapV2ExchangeWrapper.sol. This is the contract which
acts as the connector between the hYhX contracts and Uniswap. A test exchange wrapper
named TestExchangeWrapper.sol has been included for later testing purposes.
external
This directory contains libraries and interfaces relating to external projects
(namely Uniswap). These are used for interaction with Uniswap from the exchange
wrapper named UniswapV2ExchangeWrapper.sol.
interfaces
These contracts are contracts specifically relating to interfacing with hYhX contracts.
lib
These are miscellaneous libraries which are used by UniswapV2ExchangeWrapper at some
point in its dependency graph.
Javascript package
This is used in order to convert orderData specific to either TestExchangeWrapper or UniswapV2ExchangeWrapper
into bytes which can be used with the smart contract.
It makes creating this bytes orderData a more straightforward ordeal.
Legal
All Rights Reserved