Last active
September 17, 2018 10:26
-
-
Save seanwbren/ea37508f5b17054db4ef9b43c850750f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
## This script is invoked like | |
## | |
## $ with-deployed-system node index.js | |
## | |
## which will run Node in the environment of a running Geth testnet | |
## with the Sai system deployed. | |
## | |
## The environment has ETH_RPC_URL set along with the contract addresses. | |
## | |
## When the script exits, the Geth testnet is stopped and deleted. | |
# set -ex | |
START_TIME=`date +%s` | |
function sed_inplace { | |
# sed's -i argument behaves differently on macOS, hence this hack | |
sed -i.bak "$1" $2 && rm $2.bak | |
} | |
# Check if a testnet is already running on port 2000. | |
if ! nc -z 127.0.0.1 2000; then | |
# Fix Sai deploy script | |
sed_inplace '13s/DSToken.*/WETH9)/' ./lib/sai/bin/deploy | |
# Speed up ethers.js polling | |
sed_inplace 's/var pollingInterval = [0-9]*/var pollingInterval = 50/' ./node_modules/ethers/providers/provider.js | |
# Start a local testnet on port 2000; set to stop on exit. | |
./node_modules/.bin/ganache-cli -i 999 -p 2000 -a 1000 -m "hill law jazz limb penalty escape public dish stand bracket blue jar" >./ganache.out 2>&1 & netpid=$! | |
trap "kill $netpid" EXIT | |
# Wait until it's up, then use it for the deployment. | |
echo "Waiting for ganache-cli to start up..." | |
export ETH_RPC_URL=http://127.1:2000 | |
until curl -s -o/dev/null "$ETH_RPC_URL"; do sleep 2; done | |
# Use the Sai system's deploy scripts to start it. | |
cd lib/sai | |
# Configure seth | |
export ETH_GAS=${ETH_GAS:-"4000000"} | |
export ETH_FROM=$(seth rpc eth_coinbase) | |
export SETH_STATUS=yes | |
export ETH_RPC_ACCOUNTS=yes # Don't use ethsign | |
# Build & deploy the SAI contracts | |
echo "Building and deploying contracts..." | |
bin/deploy-fab 2> /dev/null && . load-fab-unknown | |
bin/deploy 2> /dev/null && . load-env-unknown | |
# Set the ETH price feed to 400 USD | |
seth send $SAI_PIP "poke(bytes32)" 0x000000000000000000000000000000000000000000000015af1d78b58c400000 | |
# Setting pep won't work until we can fund test accounts with MKR: | |
# seth send $SAI_PEP "poke(bytes32)" 0x00000000000000000000000000000000000000000000003867bb3260a7cf7200 | |
seth send $SAI_MOM "setCap(uint256)" $(seth --to-uint256 $(seth --to-wei 1000 eth)) | |
# Save the contract addresses to a JSON file | |
cat > ./out/addresses.json <<- EOM | |
{ | |
"GEM": "$SAI_GEM", | |
"GOV": "$SAI_GOV", | |
"PIP": "$SAI_PIP", | |
"PEP": "$SAI_PEP", | |
"PIT": "$SAI_PIT", | |
"ADM": "$SAI_ADM", | |
"SAI": "$SAI_SAI", | |
"SIN": "$SAI_SIN", | |
"SKR": "$SAI_SKR", | |
"DAD": "$SAI_DAD", | |
"MOM": "$SAI_MOM", | |
"VOX": "$SAI_VOX", | |
"TUB": "$SAI_TUB", | |
"TAP": "$SAI_TAP", | |
"TOP": "$SAI_TOP" | |
} | |
EOM | |
cd ../.. | |
./update-abis | |
cd lib/maker-otc | |
export SOLC_FLAGS=${SOLC_FLAGS:-"--optimize"} | |
export ETH_GAS=${ETH_GAS:-"4000000"} | |
export ETH_FROM=$(seth rpc eth_coinbase) | |
export SETH_STATUS=yes | |
export ETH_RPC_ACCOUNTS=yes # Don't use ethsign | |
dapp build 2> /dev/null | |
OTC=$(dapp create MatchingMarket 1577836800) ##this is some random date in 2020 | |
addr1="0xc226f3cd13d508bc319f4f4290172748199d6612" | |
addr2="0x7ba25f791fa76c3ef40ac98ed42634a8bc24c238" | |
seth send $OTC "addTokenPairWhitelist(address, address)" $addr1 $addr2 | |
##seth send $addr2 "deposit()" --value $(seth --to-wei 1 eth) ##wrap some eth to weth | |
##make sure I have WETH | |
##seth send $addr2 "approve(address, uint256)" $OTC ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ##approve weth to oasis | |
##seth send $OTC "offer(uint256, address, uint256, address, uint256, bool)" $(seth --to-uint256 $(seth --to-wei 0.5 eth)) $addr2 $(seth --to-uint256 $(seth --to-wei 1 eth)) $addr1 0 1 ## create an offer to buy Dai for Weth <- this isn't working | |
export OTC=$OTC | |
cd ../.. | |
END_TIME=`date +%s` | |
ELAPSED=`echo $END_TIME - $START_TIME | bc` | |
echo "Created testnet in" $ELAPSED "seconds." | |
else | |
echo "You already have a test network running on port 2000." | |
fi | |
if [[ "$1" != '--ci' ]]; then | |
# We now have SAI_GEM, SAI_SAI, SAI_SKR, etc in the environment. | |
# See the list at the bottom of the in the deploy script. | |
# Proceed to the command given as arguments (but first strip --ci as first param). | |
"$@" | |
# The testnet will continue to run with its deployed contracts | |
# until the user confirms it should shut down. | |
bash ./confirm-kill-testnet | |
else | |
# We now have SAI_GEM, SAI_SAI, SAI_SKR, etc in the environment. | |
# See the list at the bottom of the in the deploy script. | |
# Proceed to the command given as arguments (but first strip --ci as first param). | |
$(echo "$@" | sed 's/^\-\-ci //') | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment