Skip to content
Permalink
Browse files

Update singleton deployment script (#191)

* Update singleton deployment script

* Reduce deploy gas limit

* Add singleton deployment documentation
  • Loading branch information...
nventuro authored and shahafn committed Aug 1, 2019
1 parent 934f86a commit c696b0be0afb5e39fd2ec3fffc9638cecda21dcd
Showing with 45 additions and 14 deletions.
  1. +22 −10 scripts/singleton/compute.sh
  2. +19 −0 scripts/singleton/deploy.js
  3. +4 −4 scripts/singleton/get-deploy-data.js
@@ -1,25 +1,37 @@
#! /bin/bash

# Computes all artifacts and values required to deploy a RelayHub at the same address on all Ethereum networks (mainnet,
# testnets, local blockchains, etc.).
# Any changes to the source files, including comments and whitespace, will result in a new deployment addresss, so this
# script should only be run once a version has been frozen.

# To learn more about this deployment method, check out how the ERC1820 registry is deployed (https://eips.ethereum.org/EIPS/eip-1820#deployment-method)
# and this blogpost by Nick Johnson (https://medium.com/@weka/how-to-send-ether-to-11-440-people-187e332566b7).

# Artifacts will be stored in a 'singleton' directory:
# - the flattened source file (used to e.g. verify the bytecode on Etherscan)
# - binaries and ABI files
# - a deploy.json file, including the resulting singleton address, the deployment transaction, and the address that
# needs to be funded for the deployment
# These files should be committed to the repository.

# See scripts/singleton/deploy.js for sample code to run a deployment using these files.

# Exit script as soon as a command fails.
set -o errexit

solidity_version="0.5.8"
if solc --version | grep -q "$solidity_version" ; then
echo "Will compile using solc v$solidity_version"
else
echo "solc version v$solidity_version is required"
exit 1
fi

output_dir="singleton"

echo "Storing artifacts in directory '$output_dir'"
echo "Will store artifacts in directory '$output_dir'"

rm -rf "$output_dir" # Delete possible remains from previous run
mkdir -p "$output_dir"

echo "Flattening source files into a single file"
npx truffle-flattener contracts/RelayHub.sol > $output_dir/RelayHub.flattened.sol

solc --optimize --optimize-runs 200 --metadata-literal --combined-json abi,bin,metadata "$output_dir/RelayHub.flattened.sol" > "$output_dir/RelayHub.flattened.json"
echo "Compiling with solcjs version $(npx solcjs --version)"
npx solcjs --optimize --optimize-runs 200 --abi --bin --output-dir $output_dir "$output_dir/RelayHub.flattened.sol"

node scripts/singleton/get-deploy-data.js > "$output_dir/deploy.json"
echo "Stored deployment data in $output_dir/deploy.json"
@@ -0,0 +1,19 @@
const deployData = require('../../singleton/deploy.json');
const { BN, toWei } = require('web3-utils');

// Deploys a RelayHub instance, reading required data from singleton/deploy.json, the output of scripts/singleton/compute.sh
// Call this file with truffle exec on the target network.
async function deploy() {
const funder = (await web3.eth.getAccounts())[0];
await web3.eth.sendTransaction({ from: funder, to: deployData.deployer, value: new BN(toWei('0.42', 'ether')) });

await web3.eth.sendSignedTransaction(deployData.contract.deployTx);
console.log(`Deployed at ${deployData.contract.address}`);
}

// truffle exec passes a callback to be called once execution is finalized
module.exports = async function(callback) {
await deploy(callback);

callback();
}
@@ -4,20 +4,20 @@ const { join } = require('path')
const ethTx = require('ethereumjs-tx');
const ethUtils = require('ethereumjs-util');

const fs = require('fs');

function toHexString(buffer) {
return '0x' + buffer.toString('hex')
}

const bin = require(`../../singleton/RelayHub.flattened.json`)
.contracts['singleton/RelayHub.flattened.sol:RelayHub']
.bin;
const bin = fs.readFileSync('singleton/singleton_RelayHub_flattened_sol_RelayHub.bin', 'ascii');

const tx = new ethTx({
nonce: 0,
data: '0x' + bin,
value: 0,
gasPrice: 100000000000, /// 100 gigawei
gasLimit: 8000000,
gasLimit: 4200000,
v: 27,
r: '0x1613161316131613161316131613161316131613161316131613161316131613',
s: '0x1613161316131613161316131613161316131613161316131613161316131613'

0 comments on commit c696b0b

Please sign in to comment.
You can’t perform that action at this time.