From f499172946b8c8e6aa81e8cc831563c37e1da85e Mon Sep 17 00:00:00 2001 From: Michael Yeates Date: Wed, 3 Oct 2018 16:06:58 +0100 Subject: [PATCH] Initial commit of eosdac-testnet scripts --- eosdac-testnet/README.md | 25 ++++ eosdac-testnet/boot.sh | 90 ++++++++++++ eosdac-testnet/build.sh | 35 +++++ eosdac-testnet/conf.example.sh | 4 + eosdac-testnet/conf_dac.example.sh | 12 ++ eosdac-testnet/conf_private.example.sh | 5 + eosdac-testnet/dac_config.json | 1 + eosdac-testnet/permissions.sh | 54 +++++++ .../perms/daccustodian_transfer.json | 8 ++ .../perms/daccustodian_updateauth.json | 8 ++ eosdac-testnet/perms/resign.json | 6 + eosdac-testnet/populate.sh | 133 ++++++++++++++++++ eosdac-testnet/terms.json | 1 + 13 files changed, 382 insertions(+) create mode 100644 eosdac-testnet/README.md create mode 100755 eosdac-testnet/boot.sh create mode 100755 eosdac-testnet/build.sh create mode 100644 eosdac-testnet/conf.example.sh create mode 100644 eosdac-testnet/conf_dac.example.sh create mode 100644 eosdac-testnet/conf_private.example.sh create mode 100644 eosdac-testnet/dac_config.json create mode 100755 eosdac-testnet/permissions.sh create mode 100644 eosdac-testnet/perms/daccustodian_transfer.json create mode 100644 eosdac-testnet/perms/daccustodian_updateauth.json create mode 100644 eosdac-testnet/perms/resign.json create mode 100755 eosdac-testnet/populate.sh create mode 100644 eosdac-testnet/terms.json diff --git a/eosdac-testnet/README.md b/eosdac-testnet/README.md new file mode 100644 index 0000000..9989ffc --- /dev/null +++ b/eosdac-testnet/README.md @@ -0,0 +1,25 @@ +# eosDAC testnet + +These scripts will install and configure eosDAC contracts on a freshly started chain. + +## Configuration + +Copy the configuration files conf.example.sh, conf_private.example.sh and conf_dac.example.sh to conf.sh, conf_private.sh and conf_dac.sh + +You will need to modify all of the files to your needs, make sure that the public key in conf_private.sh matches your genesis.json file + +## boot.sh + +This script will boot the base eosio chain and install the system contracts. + +## populate.sh + +This will populate all of the eosDAC contracts as well as developer, test custodian and test voter accounts. + +## build.sh + +Will compile and install the eosDAC contrats, run this if you modify the contracts after booting for the first time. + +## permissions.sh + +All the DAC accounts will be resigned and permissions set up to allow the dac to operate. diff --git a/eosdac-testnet/boot.sh b/eosdac-testnet/boot.sh new file mode 100755 index 0000000..31e7351 --- /dev/null +++ b/eosdac-testnet/boot.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +green=`tput setaf 2` +reset=`tput sgr0` + +source ./conf_private.sh +source ./conf.sh + + + +echo -e "\n\n----------------- BOOT SEQUENCE -------------------\n\n"; + +run_cmd() { + cmd="$1"; + echo -e "\n\n >> ${green} Next command: $1 \n\n ${reset}"; + #wait; + #read -p "Press enter to continue ${reset}"; + eval "cleos -u $API_URL $1"; +} + +create_act() { + act="$1" + key="$2" + eval "cleos -u $API_URL system newaccount --stake-cpu \"10.0000 EOS\" --stake-net \"10.0000 EOS\" --transfer --buy-ram-kbytes 1024 eosio $act $key" +} + + +run_cmd "set contract eosio "$CONTRACTS/eosio.bios" -p eosio"; + +run_cmd "create account eosio eosio.msig $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.msig; + +run_cmd "create account eosio eosio.token $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.token; + +run_cmd "create account eosio eosio.ram $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.ram; + +run_cmd "create account eosio eosio.ramfee $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.ramfee; + +run_cmd "create account eosio eosio.names $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.names; + +run_cmd "create account eosio eosio.stake $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.stake; + +run_cmd "create account eosio eosio.saving $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.saving; + +run_cmd "create account eosio eosio.bpay $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.bpay; + +run_cmd "create account eosio eosio.vpay $EOSIO_PUB" +sleep 1; +cleos -u $API_URL get account eosio.vpay; + +run_cmd "push action eosio setpriv "'["eosio.msig",1]'" -p eosio" +sleep 1; +cleos -u $API_URL get account -j eosio.msig | jq + +run_cmd "set contract eosio.msig "$CONTRACTS/eosio.msig" -p eosio.msig" +run_cmd "get code eosio.msig" + +run_cmd "set contract eosio.token "$CONTRACTS/eosio.token" -p eosio.token" +run_cmd "get code eosio.token" + +cleos -u $API_URL push action eosio.token create '["eosio","10000000000.0000 EOS"]' -p eosio.token + +cleos -u $API_URL get currency stats eosio.token EOS + +cleos -u $API_URL push action eosio.token issue '["eosio", "1000000000.0000 EOS", "initial issuance"]' -p eosio + +cleos -u $API_URL get currency stats eosio.token EOS + + + + +# Install system contract +run_cmd "set contract eosio "$CONTRACTS/eosio.system" -p eosio" + +run_cmd "get code eosio" diff --git a/eosdac-testnet/build.sh b/eosdac-testnet/build.sh new file mode 100755 index 0000000..ea098fc --- /dev/null +++ b/eosdac-testnet/build.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +green=`tput setaf 2` +reset=`tput sgr0` + +source ./conf_private.sh +source ./conf_dac.sh +source ./conf.sh + +run_cmd() { + cmd="$1"; + echo -e "\n\n >> ${green} Next command: $1 \n\n ${reset}"; + #wait; + #read -p "Press enter to continue ${reset}"; + eval "cleos -u $API_URL $1"; +} + +echo -e "\n\n----------------- BUILDING CONTRACTS -------------------\n\n"; + +PWD=`pwd` + +cd $DACCONTRACTS/daccustodian/ +git pull +$EOSIOCPP -o daccustodian.wast daccustodian.cpp + +cd $DACCONTRACTS/eosdactoken/ +git pull +cd eosdactoken/ +$EOSIOCPP -o eosdactoken.wast eosdactoken.cpp + +cd $PWD + +run_cmd "set contract "$dactokens" "$DACCONTRACTS/eosdactoken/eosdactoken" -p eosdactokens" + +run_cmd "set contract "$daccustodian" "$DACCONTRACTS/daccustodian" -p daccustodian" diff --git a/eosdac-testnet/conf.example.sh b/eosdac-testnet/conf.example.sh new file mode 100644 index 0000000..a44f5d6 --- /dev/null +++ b/eosdac-testnet/conf.example.sh @@ -0,0 +1,4 @@ +API_URL="http://127.0.0.1:8888" +CONTRACTS="/path/to/eos/build/contracts" +DACCONTRACTS="/path/to/eosdac/contracts" +EOSIOCPP="eosio-cpp" diff --git a/eosdac-testnet/conf_dac.example.sh b/eosdac-testnet/conf_dac.example.sh new file mode 100644 index 0000000..42c3a01 --- /dev/null +++ b/eosdac-testnet/conf_dac.example.sh @@ -0,0 +1,12 @@ +# eosDAC specific accounts and contracts +# The account holding the custodian (voting) contract +daccustodian="daccustodian" +# An empty account used to represent various permission levels +# All other DAC accounts will eventually point back to this +dacauthority="dacauthority" +# The token contract account +dactokens="eosdactokens" +# The money owning account. It is assumed that all tokens owned will be kept here +dacowner="eosdacthedac" +# An extra account used by eosDAC +dacextra="eosdacserver" diff --git a/eosdac-testnet/conf_private.example.sh b/eosdac-testnet/conf_private.example.sh new file mode 100644 index 0000000..13b6a22 --- /dev/null +++ b/eosdac-testnet/conf_private.example.sh @@ -0,0 +1,5 @@ +# Enter public and private key for eosio, this should match the public key in +# the genesis.json file. This key will also be used to create all system and +# DAC accounts +EOSIO_PUB="EOS..."; +EOSIO_PVT="5..."; diff --git a/eosdac-testnet/dac_config.json b/eosdac-testnet/dac_config.json new file mode 100644 index 0000000..95252c2 --- /dev/null +++ b/eosdac-testnet/dac_config.json @@ -0,0 +1 @@ +["10.0000 EOSDAC", 5, 12, 600, "dacauthority", "eosdacthedac", 15, 3, 11, 9, 7, 360, "50.0000 EOS"] diff --git a/eosdac-testnet/permissions.sh b/eosdac-testnet/permissions.sh new file mode 100755 index 0000000..4385d41 --- /dev/null +++ b/eosdac-testnet/permissions.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +green=`tput setaf 2` +reset=`tput sgr0` + +source ./conf_private.sh +source ./conf_dac.sh +source ./conf.sh + + + +echo -e "\n\n----------------- PERMISSIONS -------------------\n\n"; + +run_cmd() { + cmd="$1"; + echo -e "\n\n >> ${green} Next command: $1 \n\n ${reset}"; + #wait; + #read -p "Press enter to continue ${reset}"; + eval "cleos -u $API_URL $1"; +} + + + + +dacaccounts="$dacextra $dacowner $dactokens $dacauthority $daccustodian" + +# resign extra account to dacauthority@active +run_cmd "set account permission $dacextra active ./perms/resign.json owner -p $dacextra@owner" +run_cmd "set account permission $dacextra owner ./perms/resign.json '' -p $dacextra@owner" +# resign dactokens account to dacauthority@active +run_cmd "set account permission $dactokens active ./perms/resign.json owner -p $dactokens@owner" +run_cmd "set account permission $dactokens owner ./perms/resign.json '' -p $dactokens@owner" +# resign daccustodian account to dacauthority@active +run_cmd "set account permission $daccustodian active ./perms/resign.json owner -p $daccustodian@owner" +run_cmd "set account permission $daccustodian owner ./perms/resign.json '' -p $daccustodian@owner" +# resign dacowner account to dacauthority@active, must allow timelocked transfers from daccustodian@eosio.code +run_cmd "set account permission $dacowner xfer ./perms/daccustodian_transfer.json active -p $dacowner@owner" +run_cmd "set action permission $dacowner eosio.token transfer xfer -p $dacowner@owner" +run_cmd "set account permission $dacowner active ./perms/resign.json owner -p $dacowner@owner" +run_cmd "set account permission $dacowner owner ./perms/resign.json '' -p $dacowner@owner" +# daccustodian@eosio.code has to be able to updateauth on dacauthority +run_cmd "set account permission $dacauthority owner ./perms/daccustodian_updateauth.json '' -p $dacauthority@owner" +run_cmd "set action permission $dacauthority eosio updateauth owner -p $dacauthority@owner" + + +dacaccounts="$dacextra $dacowner $dactokens $dacauthority $daccustodian" + +for act in $dacaccounts +do + echo "------------- $act ---------------" + cleos -u $API_URL get account -j $act | jq '.permissions' +done + +#run_cmd "set account permission $dacauthority owner ./dac_auth_perms.json '' -p dacauthority@owner" diff --git a/eosdac-testnet/perms/daccustodian_transfer.json b/eosdac-testnet/perms/daccustodian_transfer.json new file mode 100644 index 0000000..c896149 --- /dev/null +++ b/eosdac-testnet/perms/daccustodian_transfer.json @@ -0,0 +1,8 @@ +{ + "threshold": 2, + "keys": [], + "accounts": [ + {"permission":{"actor":"daccustodian", "permission":"eosio.code"}, "weight":1} + ], + "waits": [{"wait_sec":30, "weight":1}] +} diff --git a/eosdac-testnet/perms/daccustodian_updateauth.json b/eosdac-testnet/perms/daccustodian_updateauth.json new file mode 100644 index 0000000..d0b7718 --- /dev/null +++ b/eosdac-testnet/perms/daccustodian_updateauth.json @@ -0,0 +1,8 @@ +{ + "threshold": 1, + "keys": [], + "accounts": [ + {"permission":{"actor":"daccustodian", "permission":"eosio.code"}, "weight":1} + ], + "waits": [] +} diff --git a/eosdac-testnet/perms/resign.json b/eosdac-testnet/perms/resign.json new file mode 100644 index 0000000..6e054e2 --- /dev/null +++ b/eosdac-testnet/perms/resign.json @@ -0,0 +1,6 @@ +{ + "threshold" : 1, + "keys" : [], + "accounts": [{"permission":{"actor":"dacauthority", "permission":"active"}, "weight":1}], + "waits": [] +} diff --git a/eosdac-testnet/populate.sh b/eosdac-testnet/populate.sh new file mode 100755 index 0000000..b468948 --- /dev/null +++ b/eosdac-testnet/populate.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +green=`tput setaf 2` +reset=`tput sgr0` + +source ./conf_private.sh +source ./conf_dac.sh +source ./conf.sh + + + +echo -e "\n\n----------------- POPULATE SEQUENCE -------------------\n\n"; + +run_cmd() { + cmd="$1"; + echo -e "\n\n >> ${green} Next command: $1 \n\n ${reset}"; + #wait; + #read -p "Press enter to continue ${reset}"; + eval "cleos -u $API_URL $1"; +} + +create_act() { + act="$1" + key="$2" + eval "cleos -u $API_URL system newaccount --stake-cpu \"10.0000 EOS\" --stake-net \"10.0000 EOS\" --transfer --buy-ram-kbytes 1024 eosio $act $key" +} + + +dacaccounts="$dacextra $dacowner $dactokens $dacauthority $daccustodian" + +for act in $dacaccounts +do + create_act $act $EOSIO_PUB + #run_cmd "system newaccount --stake-cpu \"10.0000 EOS\" --stake-net \"10.0000 EOS\" --transfer --buy-ram-kbytes 1024 eosio $act $EOSIO_PUB" + #sleep 1; + #cleos -u $API_URL get account $act; +done + +run_cmd "transfer eosio $dacowner \"100000.0000 EOS\"" + +run_cmd "set contract "$dactokens" "$DACCONTRACTS/eosdactoken/eosdactoken" -p eosdactokens" +run_cmd "get code $dactokens" + +cleos -u $API_URL push action $dactokens create '["eosdactokens", "10000000000.0000 EOSDAC", 0]' -p $dactokens +cleos -u $API_URL push action $dactokens issue '["eosdactokens", "1000000000.0000 EOSDAC", "Issue"]' -p $dactokens + +run_cmd "set contract daccustodian "$DACCONTRACTS/daccustodian" -p daccustodian" +run_cmd "get code daccustodian" + + +run_cmd "push action daccustodian updateconfig dac_config.json -p daccustodian" +sleep 1; +run_cmd "get table daccustodian daccustodian config" + +run_cmd "push action eosdactokens newmemterms terms.json -p eosdactokens" + + +# Developer accounts +create_devs() { + create_act evilmikehere EOS54NkNpEt9aotyBvEZVfj54NuFAebaDLnyg2GtJ6pyvBoxxg9Aw + run_cmd "transfer eosio evilmikehere \"10000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens evilmikehere \"100000000.0000 EOSDAC\"" + + create_act kasperkasper EOS5JLKQDsJwqh6vVTbqVnHsHDk6He1Xo6nsQSy3536B1gx3FGzZJ + run_cmd "transfer eosio kasperkasper \"10000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens kasperkasper \"10000000.0000 EOSDAC\"" + + create_act dallasdallas EOS5kt3N8qEwwRYYvWWZaJvsoz9iuVurLRhw36vckmSesHdm8A9su + run_cmd "transfer eosio dallasdallas \"10000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens dallasdallas \"10000000.0000 EOSDAC\"" + + create_act lukedactest1 EOS8YE3xbMVSiDxrJCK3qRsxT8e7ThfvpxdmwaXgeMAn5VYJxE26G + run_cmd "transfer eosio lukedactest1 \"5000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens lukedactest1 \"5000000.0000 EOSDAC\"" + + create_act lukedactest2 EOS5qhoS2McrhC6mkW2gN4eDPZZJhf3EQEvUf1gZoRxJTJXoNrFVk + run_cmd "transfer eosio lukedactest2 \"5000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens lukedactest2 \"5000000.0000 EOSDAC\"" + + create_act tiktiktiktik EOS5yMoSRtLecubsQmTVSmdurCAnh6etwRsVDNoXx697Jr193GRKp + run_cmd "transfer eosio tiktiktiktik \"10000000.0000 EOS\"" + run_cmd "transfer -c eosdactokens eosdactokens tiktiktiktik \"10000000.0000 EOSDAC\"" +} +create_devs + + +# Get the terms to hash it for registration +CONSTITUTION=$(cleos -u $API_URL get table eosdactokens eosdactokens memberterms | jq '.rows[0].terms' | tr -d '"') +wget -O constitution.md $CONSTITUTION +CON_MD5=$(md5sum constitution.md | cut -d' ' -f1) +rm -f constitution.md + + +# Build this array for random voting later +CUST_ACCTS=() + + +# Custodian accounts +for x in {a..z} +do + CUST="eosdaccusta$x" + CUST_ACTS+=($CUST) + create_act $CUST $EOSIO_PUB + run_cmd "transfer -c eosdactokens eosdactokens $CUST \"100000.0000 EOSDAC\"" + run_cmd "push action eosdactokens memberreg '[\"$CUST\", \"$CON_MD5\"]' -p $CUST" + run_cmd "transfer -c eosdactokens $CUST daccustodian \"10.0000 EOSDAC\" \"daccustodian\"" + run_cmd "push action daccustodian nominatecand '[\"$CUST\", \"10.0000 EOS\"]' -p $CUST" +done + +# Voter accounts +for x in {a..z} +do + for y in {a..z} + do + VOT="eosdacvote$x$y" + create_act $VOT $EOSIO_PUB + run_cmd "transfer -c eosdactokens eosdactokens $VOT \"100000.0000 EOSDAC\"" + run_cmd "push action eosdactokens memberreg '[\"$VOT\", \"$CON_MD5\"]' -p $VOT" + # random votes + numbers=$(jot -r 5 0 26) + votes=() + while read -r number; do + vote=${CUST_ACTS[$number]} + echo $vote + votes+=($vote) + done <<< "$numbers" + + votes_arr=($(tr ' ' '\n' <<< "${votes[@]}" | sort -u | tr '\n' ' ')) + json=$(jq -n --arg va "${votes_arr}" --arg v "${VOT}" '[$v, ($va | split(" ")) ]') + echo $json > vote_data.json + run_cmd "push action daccustodian votecust ./vote_data.json -p $VOT" + done +done diff --git a/eosdac-testnet/terms.json b/eosdac-testnet/terms.json new file mode 100644 index 0000000..a457865 --- /dev/null +++ b/eosdac-testnet/terms.json @@ -0,0 +1 @@ +["https://raw.githubusercontent.com/eosdac/constitution/14d8d6d0262707f7c72183cff505d19e321f1cb3/constitution.md", "6d2cc6201302b3f485e2a939881ae451"]