This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from keep-network/uniswap-deployment
This issue breaks away work from #160 into something more deliverable: - introduces a script to deploy external systems, based on discussions in #270. Uniswap is deployed from a newly-created package at https://github.com/keep-network/uniswap - updates README with respect to this - includes Uniswap Solidity interfaces - separates unit and integration testing into two suites, new circleci flows for this - includes an E2E test with our TBTCToken of a Uniswap trade
- Loading branch information
Showing
19 changed files
with
367 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ jobs: | |
set -ex | ||
npm install | ||
npm run sol:lint | ||
test_solidity: | ||
unit_test_contracts: | ||
executor: docker-node | ||
steps: | ||
- checkout | ||
|
@@ -49,6 +49,23 @@ jobs: | |
name: Run NPM tests | ||
working_directory: ~/project/implementation/contracts | ||
command: npm install && npm run test | ||
integration_test_contracts: | ||
executor: docker-node | ||
steps: | ||
- checkout | ||
- run: sudo npm install -g [email protected] | ||
- run: | ||
name: Running testrpc | ||
command: ganache-cli | ||
background: true | ||
- run: | ||
name: Deploy Uniswap | ||
working_directory: ~/project/implementation/scripts | ||
command: ./deploy_uniswap.sh | ||
- run: | ||
name: Run NPM tests | ||
working_directory: ~/project/implementation/contracts | ||
command: npm install && npm run integration-test | ||
generate_pngs: | ||
docker: | ||
- image: keepnetwork/texlive:15 | ||
|
@@ -213,9 +230,10 @@ workflows: | |
jobs: | ||
- lint_js | ||
- lint_solidity | ||
solidity: | ||
test: | ||
jobs: | ||
- test_solidity | ||
- unit_test_contracts | ||
- integration_test_contracts | ||
docs: | ||
jobs: | ||
- generate_pngs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ sudo cp docs/latex/tikz-uml.sty /usr/local/texlive/texmf-local/ | |
# Update TeX package tree | ||
sudo texhash | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "stage-2", "stage-3"] | ||
"presets": ["es2015", "stage-2", "stage-3"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pragma solidity 0.5.10; | ||
|
||
interface IUniswapExchange { | ||
// Provide Liquidity | ||
function addLiquidity(uint256 min_liquidity, uint256 max_tokens, uint256 deadline) external payable returns (uint256); | ||
|
||
// Get Prices | ||
function getEthToTokenOutputPrice(uint256 tokens_bought) external view returns (uint256 eth_sold); | ||
|
||
// Trade ETH to ERC20 | ||
function ethToTokenSwapOutput(uint256 tokens_bought, uint256 deadline) external payable returns (uint256 eth_sold); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pragma solidity 0.5.10; | ||
|
||
interface IUniswapFactory { | ||
// Create Exchange | ||
function createExchange(address token) external returns (address exchange); | ||
|
||
// Get Exchange and Token Info | ||
function getExchange(address token) external view returns (address exchange); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const TBTCToken = artifacts.require('TBTCToken') | ||
const IUniswapFactory = artifacts.require('IUniswapFactory') | ||
const KeepBridge = artifacts.require('KeepBridge') | ||
const TBTCSystem = artifacts.require('TBTCSystem') | ||
|
||
const { | ||
KeepRegistryAddress, | ||
UniswapFactoryAddress, | ||
} = require('./externals') | ||
|
||
module.exports = async function(deployer) { | ||
// Don't enact this setup during unit testing. | ||
if (process.env.NODE_ENV == 'test' && !process.env.INTEGRATION_TEST) return | ||
|
||
// Keep | ||
const keepBridge = await KeepBridge.deployed() | ||
await keepBridge.initialize(KeepRegistryAddress) | ||
|
||
// Uniswap | ||
const tbtcToken = await TBTCToken.deployed() | ||
const uniswapFactory = await IUniswapFactory.at(UniswapFactoryAddress) | ||
|
||
let tbtcExchangeAddress = await uniswapFactory.getExchange(tbtcToken.address) | ||
if (tbtcExchangeAddress == '0x0000000000000000000000000000000000000000') { | ||
await uniswapFactory.createExchange(tbtcToken.address) | ||
tbtcExchangeAddress = await uniswapFactory.getExchange(tbtcToken.address) | ||
} | ||
|
||
const tbtcSystem = await TBTCSystem.deployed() | ||
await tbtcSystem.initialize(tbtcExchangeAddress) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Configuration for addresses of externally deployed smart contracts | ||
const KeepRegistryAddress = '0x622B525445aD939f1b0fF1193E57DC0ED75dAb6e' | ||
const UniswapFactoryAddress = '0x1304C8c4233E7b68Cb51b0DDEE33Da9A6dbD0A4A' | ||
|
||
module.exports = { | ||
KeepRegistryAddress, | ||
UniswapFactoryAddress, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
SED="sed" | ||
|
||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
if ! [ -x "$(command -v gsed)" ]; then | ||
# See also: https://unix.stackexchange.com/questions/13711/differences-between-sed-on-mac-osx-and-other-standard-sed | ||
echo 'Error: gsed is not installed.' >&2 | ||
echo 'GNU sed is required due to difference in functionality from OSX/FreeBSD sed.' | ||
echo 'Install with: brew install gnu-sed' | ||
exit 1 | ||
fi | ||
SED="gsed" | ||
fi | ||
|
||
|
||
# Clone Uniswap for deployment | ||
if [ ! -d uniswap ]; then | ||
git clone https://github.com/keep-network/uniswap | ||
fi | ||
|
||
# Setup repo | ||
cd uniswap | ||
git checkout v0.1.0 | ||
npm i | ||
export ETH_RPC_URL="http://localhost:8545" | ||
|
||
# Run migration | ||
UNISWAP_DEPLOYMENT=$(npm run migrate) | ||
|
||
# Get address of UniswapFactory | ||
FACTORY=$(echo "$UNISWAP_DEPLOYMENT" | sed -n /Factory/p | cut -d' ' -f2) | ||
|
||
# Update UniswapFactoryAddress in migration | ||
$SED -i -e "/UniswapFactoryAddress/s/0x[a-fA-F0-9]\{0,40\}/$FACTORY/" ../../migrations/externals.js | ||
|
||
# Clean up | ||
cd .. | ||
rm -rf uniswap/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.