Skip to content

Commit 61f9bb7

Browse files
authored
Merge pull request #2309 from keep-network/keep-core-on-celo
Keep Random Beacon on Celo - development environment setup scripts
2 parents bceb332 + 03fdc44 commit 61f9bb7

File tree

8 files changed

+1904
-122
lines changed

8 files changed

+1904
-122
lines changed

scripts/install-celo.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
LOG_START='\n\e[1;36m' # new line + bold + color
5+
LOG_END='\n\e[0m' # new line + reset color
6+
7+
KEEP_CORE_PATH=$PWD
8+
KEEP_CORE_SOL_PATH="$KEEP_CORE_PATH/solidity"
9+
10+
# Defaults, can be overwritten by env variables/input parameters
11+
CONFIG_DIR_PATH_DEFAULT="$KEEP_CORE_PATH/configs"
12+
NETWORK_DEFAULT="local"
13+
KEEP_CELO_PASSWORD=${KEEP_CELO_PASSWORD:-"password"}
14+
CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY=${CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY:-""}
15+
16+
help()
17+
{
18+
echo -e "\nUsage: ENV_VAR(S) $0"\
19+
"--config-dir <path>"\
20+
"--network <network>"
21+
echo -e "\nEnvironment variables:\n"
22+
echo -e "\tKEEP_CELO_PASSWORD: The password to unlock local Celo accounts to set up delegations."\
23+
"Required only for 'local' network. Default value is 'password'"
24+
echo -e "\tCONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY: Contracts owner private key on Celo"
25+
echo -e "\nCommand line arguments:\n"
26+
echo -e "\t--config-dir: Path to keep-core client configuration file(s)"
27+
echo -e "\t--network: Celo network for keep-core client."\
28+
"Available networks and settings are specified in the 'truffle-config.js'\n"
29+
exit 1 # Exit script after printing help
30+
}
31+
32+
# Transform long options to short ones
33+
for arg in "$@"; do
34+
shift
35+
case "$arg" in
36+
"--config-dir") set -- "$@" "-c" ;;
37+
"--network") set -- "$@" "-n" ;;
38+
"--help") set -- "$@" "-h" ;;
39+
*) set -- "$@" "$arg"
40+
esac
41+
done
42+
43+
# Parse short options
44+
OPTIND=1
45+
while getopts "c:n:h" opt
46+
do
47+
case "$opt" in
48+
c ) config_dir_path="$OPTARG" ;;
49+
n ) network="$OPTARG" ;;
50+
h ) help ;;
51+
? ) help ;; # Print help in case parameter is non-existent
52+
esac
53+
done
54+
shift $(expr $OPTIND - 1) # remove options from positional parameters
55+
56+
# Overwrite default properties
57+
CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT}
58+
NETWORK=${network:-$NETWORK_DEFAULT}
59+
60+
# Run script
61+
printf "${LOG_START}Starting installation...${LOG_END}"
62+
63+
printf "Config dir path: $CONFIG_DIR_PATH\n"
64+
printf "Network: $NETWORK"
65+
66+
cd $KEEP_CORE_SOL_PATH
67+
68+
printf "${LOG_START}Installing NPM dependencies...${LOG_END}"
69+
npm install
70+
71+
if [ "$NETWORK" == "local" ]; then
72+
printf "${LOG_START}Unlocking celo accounts...${LOG_END}"
73+
KEEP_ETHEREUM_PASSWORD=$KEEP_CELO_PASSWORD \
74+
npx truffle exec scripts/unlock-eth-accounts.js --network $NETWORK
75+
fi
76+
77+
printf "${LOG_START}Migrating contracts...${LOG_END}"
78+
rm -rf build/
79+
80+
CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY \
81+
npx truffle migrate --reset --network $NETWORK
82+
83+
KEEP_CORE_SOL_ARTIFACTS_PATH="$KEEP_CORE_SOL_PATH/build/contracts"
84+
85+
printf "${LOG_START}Initializing contracts...${LOG_END}"
86+
87+
CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY \
88+
npx truffle exec scripts/delegate-tokens.js --network $NETWORK
89+
90+
printf "${LOG_START}Updating keep-core client configs...${LOG_END}"
91+
for CONFIG_FILE in $CONFIG_DIR_PATH/*.toml
92+
do
93+
KEEP_CORE_CONFIG_FILE_PATH=$CONFIG_FILE \
94+
CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_CELO_ACCOUNT_PRIVATE_KEY \
95+
npx truffle exec scripts/lcl-client-config.js --network $NETWORK
96+
done
97+
98+
printf "${LOG_START}Building keep-core client...${LOG_END}"
99+
cd $KEEP_CORE_PATH
100+
go generate ./...
101+
go build -a -o keep-core .

scripts/install.sh

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,98 @@
11
#!/bin/bash
2-
set -e
2+
set -euo pipefail
3+
4+
LOG_START='\n\e[1;36m' # new line + bold + color
5+
LOG_END='\n\e[0m' # new line + reset color
36

4-
# Dafault inputs.
5-
KEEP_ETHEREUM_PASSWORD_DEFAULT="password"
67
KEEP_CORE_PATH=$PWD
8+
KEEP_CORE_SOL_PATH="$KEEP_CORE_PATH/solidity"
9+
10+
# Defaults, can be overwritten by env variables/input parameters
711
CONFIG_DIR_PATH_DEFAULT="$KEEP_CORE_PATH/configs"
12+
NETWORK_DEFAULT="local"
13+
KEEP_ETHEREUM_PASSWORD=${KEEP_ETHEREUM_PASSWORD:-"password"}
14+
CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=${CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY:-""}
815

9-
# Read user inputs.
10-
read -p "Enter ethereum accounts password [$KEEP_ETHEREUM_PASSWORD_DEFAULT]: " ethereum_password
11-
KEEP_ETHEREUM_PASSWORD=${ethereum_password:-$KEEP_ETHEREUM_PASSWORD_DEFAULT}
16+
help()
17+
{
18+
echo -e "\nUsage: ENV_VAR(S) $0"\
19+
"--config-dir <path>"\
20+
"--network <network>"
21+
echo -e "\nEnvironment variables:\n"
22+
echo -e "\tKEEP_ETHEREUM_PASSWORD: The password to unlock local Ethereum accounts to set up delegations."\
23+
"Required only for 'local' network. Default value is 'password'"
24+
echo -e "\tCONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY: Contracts owner private key on Ethereum"
25+
echo -e "\nCommand line arguments:\n"
26+
echo -e "\t--config-dir: Path to keep-core client configuration file(s)"
27+
echo -e "\t--network: Ethereum network for keep-core client."\
28+
"Available networks and settings are specified in the 'truffle-config.js'\n"
29+
exit 1 # Exit script after printing help
30+
}
1231

13-
read -p "Enter dir path to keep-core client configs [$CONFIG_DIR_PATH_DEFAULT]: " config_dir_path
14-
CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT}
32+
# Transform long options to short ones
33+
for arg in "$@"; do
34+
shift
35+
case "$arg" in
36+
"--config-dir") set -- "$@" "-c" ;;
37+
"--network") set -- "$@" "-n" ;;
38+
"--help") set -- "$@" "-h" ;;
39+
*) set -- "$@" "$arg"
40+
esac
41+
done
1542

16-
# Run script.
17-
LOG_START='\n\e[1;36m' # new line + bold + color
18-
LOG_END='\n\e[0m' # new line + reset color
43+
# Parse short options
44+
OPTIND=1
45+
while getopts "c:n:h" opt
46+
do
47+
case "$opt" in
48+
c ) config_dir_path="$OPTARG" ;;
49+
n ) network="$OPTARG" ;;
50+
h ) help ;;
51+
? ) help ;; # Print help in case parameter is non-existent
52+
esac
53+
done
54+
shift $(expr $OPTIND - 1) # remove options from positional parameters
55+
56+
# Overwrite default properties
57+
CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT}
58+
NETWORK=${network:-$NETWORK_DEFAULT}
1959

60+
# Run script
2061
printf "${LOG_START}Starting installation...${LOG_END}"
21-
KEEP_CORE_CONFIG_DIR_PATH=$CONFIG_DIR_PATH
22-
KEEP_CORE_SOL_PATH="$KEEP_CORE_PATH/solidity"
62+
63+
printf "Config dir path: $CONFIG_DIR_PATH\n"
64+
printf "Network: $NETWORK"
2365

2466
cd $KEEP_CORE_SOL_PATH
2567

2668
printf "${LOG_START}Installing NPM dependencies...${LOG_END}"
2769
npm install
2870

29-
printf "${LOG_START}Unlocking ethereum accounts...${LOG_END}"
30-
KEEP_ETHEREUM_PASSWORD=$KEEP_ETHEREUM_PASSWORD \
31-
npx truffle exec scripts/unlock-eth-accounts.js --network local
71+
if [ "$NETWORK" == "local" ]; then
72+
printf "${LOG_START}Unlocking ethereum accounts...${LOG_END}"
73+
KEEP_ETHEREUM_PASSWORD=$KEEP_ETHEREUM_PASSWORD \
74+
npx truffle exec scripts/unlock-eth-accounts.js --network $NETWORK
75+
fi
3276

3377
printf "${LOG_START}Migrating contracts...${LOG_END}"
3478
rm -rf build/
35-
npx truffle migrate --reset --network local
79+
80+
CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \
81+
npx truffle migrate --reset --network $NETWORK
3682

3783
KEEP_CORE_SOL_ARTIFACTS_PATH="$KEEP_CORE_SOL_PATH/build/contracts"
3884

3985
printf "${LOG_START}Initializing contracts...${LOG_END}"
40-
npx truffle exec scripts/delegate-tokens.js --network local
86+
87+
CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \
88+
npx truffle exec scripts/delegate-tokens.js --network $NETWORK
4189

4290
printf "${LOG_START}Updating keep-core client configs...${LOG_END}"
43-
for CONFIG_FILE in $KEEP_CORE_CONFIG_DIR_PATH/*.toml
91+
for CONFIG_FILE in $CONFIG_DIR_PATH/*.toml
4492
do
4593
KEEP_CORE_CONFIG_FILE_PATH=$CONFIG_FILE \
46-
npx truffle exec scripts/lcl-client-config.js --network local
94+
CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY=$CONTRACT_OWNER_ETH_ACCOUNT_PRIVATE_KEY \
95+
npx truffle exec scripts/lcl-client-config.js --network $NETWORK
4796
done
4897

4998
printf "${LOG_START}Building keep-core client...${LOG_END}"

scripts/start.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ LOG_LEVEL_DEFAULT="info"
77
KEEP_CORE_PATH=$PWD
88
CONFIG_DIR_PATH_DEFAULT="$KEEP_CORE_PATH/configs"
99

10+
# FIXME: set this value as env var when calling this script. Approach should
11+
# stay consistent between 'install.sh' & 'start.sh' scripts.
12+
#
1013
# Read user inputs.
1114
read -p "Enter ethereum accounts password [$KEEP_ETHEREUM_PASSWORD_DEFAULT]: " ethereum_password
1215
KEEP_ETHEREUM_PASSWORD=${ethereum_password:-$KEEP_ETHEREUM_PASSWORD_DEFAULT}
1316

14-
read -p "Enter path to keep-core config files directory [$CONFIG_DIR_PATH_DEFAULT]: " config_dir_path
17+
# Transform long options to short ones
18+
for arg in "$@"; do
19+
shift
20+
case "$arg" in
21+
"--config-dir") set -- "$@" "-c" ;;
22+
*) set -- "$@" "$arg"
23+
esac
24+
done
25+
26+
# Parse short options
27+
OPTIND=1
28+
while getopts "c:" opt
29+
do
30+
case "$opt" in
31+
c ) config_dir_path="$OPTARG" ;;
32+
esac
33+
done
34+
shift $(expr $OPTIND - 1) # remove options from positional parameters
35+
1536
CONFIG_DIR_PATH=${config_dir_path:-$CONFIG_DIR_PATH_DEFAULT}
1637

1738
config_files=($CONFIG_DIR_PATH/*.toml)

solidity/migrations/2_deploy_contracts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ const KeepVault = artifacts.require("./geyser/KeepVault.sol")
4949

5050
let initializationPeriod = 43200 // ~12 hours
5151
const dkgContributionMargin = 1 // 1%
52+
const testNetworks = ["local", "ropsten", "keep_dev", "alfajores"]
5253

5354
module.exports = async function (deployer, network) {
5455
// Set the stake initialization period to 1 block for local development and testnet.
55-
if (network === "local" || network === "ropsten" || network === "keep_dev") {
56+
if (testNetworks.includes(network)) {
5657
initializationPeriod = 1
5758
}
5859

@@ -87,7 +88,7 @@ module.exports = async function (deployer, network) {
8788
)
8889

8990
let oldStakingContractAddress
90-
if (network === "local" || network === "ropsten") {
91+
if (testNetworks.includes(network)) {
9192
const OldTokenStaking = artifacts.require("./stubs/OldTokenStaking.sol")
9293
await deployer.link(MinimumStakeSchedule, OldTokenStaking)
9394
await deployer.link(GrantStaking, OldTokenStaking)

0 commit comments

Comments
 (0)