Split contract migration into three separate steps

This commit is contained in:
nolash 2021-10-14 11:33:50 +02:00
parent 6b59c87f68
commit 36e791e08a
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
8 changed files with 342 additions and 38 deletions

View File

@ -0,0 +1,27 @@
#!/bin/bash
. util.sh
set -a
. ${DEV_DATA_DIR}/env_reset
set -e
if [ ! -z $DEV_ETH_GAS_PRICE ]; then
gas_price_arg="--gas-price $DEV_ETH_GAS_PRICE"
fee_price_arg="--fee-price $DEV_ETH_GAS_PRICE"
fi
must_eth_rpc
# Deploy address declarator registry
>&2 echo -e "\033[;96mDeploy address declarator contract\033[;39m"
echo "DEV_ADDRESS_DECLARATOR=eth-address-declarator-deploy -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG $DEV_DECLARATOR_DESCRIPTION"
DEV_ADDRESS_DECLARATOR=`eth-address-declarator-deploy -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG $DEV_DECLARATOR_DESCRIPTION`
echo -e "\033[;96mWriting env_reset file\033[;39m"
confini-dump --schema-dir ./config --prefix export > ${DEV_DATA_DIR}/env_reset
set +a
set +e

View File

@ -0,0 +1,82 @@
#!/bin/bash
. util.sh
set -a
. ${DEV_DATA_DIR}/env_reset
WAIT_FOR_TIMEOUT=${WAIT_FOR_TIMEOUT:-60}
set -e
must_address "$DEV_ADDRESS_DECLARATOR" "address declarator"
must_eth_rpc
if [ ! -z $DEV_ETH_GAS_PRICE ]; then
gas_price_arg="--gas-price $DEV_ETH_GAS_PRICE"
fee_price_arg="--fee-price $DEV_ETH_GAS_PRICE"
fi
# Deploy contract registry contract
>&2 echo -e "\033[;96mDeploy contract registry contract\033[;39m"
CIC_REGISTRY_ADDRESS=`okota-contract-registry-deploy $fee_price_arg -i $CHAIN_SPEC -y $WALLET_KEY_FILE --identifier AccountRegistry --identifier TokenRegistry --identifier AddressDeclarator --identifier Faucet --identifier TransferAuthorization --identifier ContractRegistry --identifier DefaultToken --address-declarator $DEV_ADDRESS_DECLARATOR -p $RPC_PROVIDER $DEV_DEBUG_FLAG -s -u -w`
>&2 echo -e "\033[;96mAdd contract registry record to itself\033[;39m"
eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier ContractRegistry $CIC_REGISTRY_ADDRESS
>&2 echo -e "\033[;96mAdd address declarator record to contract registry\033[;39m"
eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier AddressDeclarator $DEV_ADDRESS_DECLARATOR
# Deploy accounts index contact
#>&2 echo -e "\033[;96mdeploy accounts index contract\033[;39m"
#DEV_ACCOUNT_INDEX_ADDRESS=`okota-accounts-index-deploy $fee_price_arg -i $CHAIN_SPEC -p $RPC_PROVIDER -y $WALLET_KEY_FILE $DEV_DEBUG_FLAG -s -u -w --address-declarator $DEV_ADDRESS_DECLARATOR --token-address $DEV_RESERVE_ADDRESS`
#>&2 echo "add deployer address as account index writer"
#eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier AccountRegistry $DEV_ACCOUNT_INDEX_ADDRESS
# Deploy transfer authorization contact
>&2 echo -e "\033[;96mDeploy transfer authorization contract\033[;39m"
DEV_TRANSFER_AUTHORIZATION_ADDRESS=`erc20-transfer-auth-deploy $gas_price_arg -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG`
>&2 echo -e "\033[;96mAdd transfer authorization record to contract registry\033[;39m"
eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier TransferAuthorization $DEV_TRANSFER_AUTHORIZATION_ADDRESS
# Deploy token index contract
>&2 echo -e "\033[;96mDeploy token symbol index contract\033[;39m"
DEV_TOKEN_INDEX_ADDRESS=`okota-token-index-deploy -s -u $fee_price_arg -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG --address-declarator $DEV_ADDRESS_DECLARATOR`
>&2 echo -e "\033[;96mAdd token symbol index record to contract registry\033[;39m"
eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier TokenRegistry $DEV_TOKEN_INDEX_ADDRESS
#>&2 echo "add reserve token to token index"
#eth-token-index-add $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG -e $DEV_TOKEN_INDEX_ADDRESS $DEV_RESERVE_ADDRESS
## Sarafu faucet contract
#>&2 echo "deploy token faucet contract"
#DEV_FAUCET_ADDRESS=`sarafu-faucet-deploy $fee_price_arg -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG --account-index-address $DEV_ACCOUNT_INDEX_ADDRESS $DEV_RESERVE_ADDRESS -s`
#
#>&2 echo "set token faucet amount"
#sarafu-faucet-set $fee_price_arg -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -e $DEV_FAUCET_ADDRESS $DEV_DEBUG_FLAG -s --fee-limit 100000 $DEV_FAUCET_AMOUNT
#
#>&2 echo "register faucet in registry"
#eth-contract-registry-set -s -u $fee_price_arg -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier Faucet $DEV_FAUCET_ADDRESS
#>&2 echo "set faucet as token minter"
#giftable-token-minter -s -u $fee_price_arg -w -y $WALLET_KEY_FILE -e $DEV_RESERVE_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG $DEV_FAUCET_ADDRESS
echo -e "\033[;96mWriting env_reset file\033[;39m"
confini-dump --schema-dir ./config --prefix export > ${DEV_DATA_DIR}/env_reset
#echo "export CIC_REGISTRY_ADDRESS=$CIC_REGISTRY_ADDRESS
#export CIC_DEFAULT_TOKEN_SYMBOL=$CIC_DEFAULT_TOKEN_SYMBOL
#export TOKEN_NAME=$TOKEN_NAME
#" >> "${DEV_DATA_DIR}"/env_reset
set +a
set +e

View File

@ -0,0 +1,122 @@
#!/bin/bash
. util.sh
set -a
. ${DEV_DATA_DIR}/env_reset
WAIT_FOR_TIMEOUT=${WAIT_FOR_TIMEOUT:-60}
set -e
if [ ! -z $DEV_ETH_GAS_PRICE ]; then
gas_price_arg="--gas-price $DEV_ETH_GAS_PRICE"
fee_price_arg="--fee-price $DEV_ETH_GAS_PRICE"
fi
must_address "$DEV_ADDRESS_DECLARATOR" "address declarator"
must_address "$CIC_REGISTRY_ADDRESS" "registry"
must_eth_rpc
have_default_token=1
token_feedback_display_string='token'
function _deploy_token_defaults {
if [ -z "$TOKEN_SYMBOL" ]; then
>&2 echo -e "\033[;33mtoken symbol not set, setting defaults for type $TOKEN_TYPE\033[;39m"
TOKEN_SYMBOL=$1
TOKEN_NAME=$2
elif [ -z "$TOKEN_NAME" ]; then
>&2 echo -e "\033[;33mtoken name not set, setting same as symbol for type $TOKEN_TYPE\033[;39m"
TOKEN_NAME=$TOKEN_SYMBOL
fi
TOKEN_DECIMALS=${TOKEN_DECIMALS:-6}
default_token_registered=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw DefaultToken`
if [ $default_token_registered == '0000000000000000000000000000000000000000' ]; then
>&2 echo -e "\033[;33mFound no existing default token in token registry"
have_default_token=''
token_feedback_display_string='default token'
fi
>&2 echo -e "\033[;96mdeploying $token_feedback_display_string ..."
>&2 echo -e "Type: $TOKEN_TYPE"
>&2 echo -e "Name: $TOKEN_NAME"
>&2 echo -e "Symbol: $TOKEN_SYMBOL"
>&2 echo -e "Decimals: $TOKEN_DECIMALS\033[;39m"
}
function deploy_token_giftable_erc20_token() {
_deploy_token_defaults "GFT" "Giftable Token"
TOKEN_ADDRESS=`giftable-token-deploy $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC -s -ww --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL --decimals $TOKEN_DECIMALS $DEV_DEBUG_FLAG`
}
function deploy_token_erc20_demurrage_token() {
_deploy_token_defaults "DET" "Demurrage Token"
TOKEN_ADDRESS=`erc20-demurrage-token-deploy $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL $DEV_DEBUG_FLAG -ww -s`
}
function deploy_minter_faucet() {
FAUCET_AMOUNT=${FAUCET_AMOUNT:-0}
# Token faucet contract
>&2 echo -e "\033[;96mDeploy token faucet contract\033[;39m"
accounts_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw AccountRegistry`
faucet_address=`sarafu-faucet-deploy $fee_price_arg -s -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG --account-index-address $accounts_index_address $1`
>&2 echo -e "\033[;96mSet token faucet amount\033[;39m"
r=`sarafu-faucet-set $fee_price_arg -s -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -e $faucet_address $DEV_DEBUG_FLAG -s --fee-limit 100000 $FAUCET_AMOUNT`
add_pending_tx_hash $r
if [ -z $have_default_token ]; then
>&2 echo -e "\033[;96mRegister faucet in registry\033[;39m"
r=`eth-contract-registry-set -s -u $fee_price_arg -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier Faucet $faucet_address`
add_pending_tx_hash $r
fi
>&2 echo -e "\033[;96mSet faucet as token minter\033[;39m"
r=`giftable-token-minter -s -u $fee_price_arg -w -y $WALLET_KEY_FILE -e $TOKEN_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG $faucet_address`
add_pending_tx_hash $r
}
deploy_token_${TOKEN_TYPE}
if [ -z "$have_default_token" ]; then
>&2 echo -e "\033[;96mAdd default token to contract registry\033[;39m"
r=`eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier DefaultToken $TOKEN_ADDRESS`
add_pending_tx_hash $r
fi
>&2 echo -e "\033[;96mAdd token to token index\033[;39m"
token_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw TokenRegistry`
r=`eth-token-index-add $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG -e $token_index_address $TOKEN_ADDRESS`
add_pending_tx_hash $r
>&2 echo -e "\033[;96mMinting $DEV_TOKEN_MINT_AMOUNT tokens\033[;39m"
r=`giftable-token-gift $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC -u $DEV_DEBUG_FLAG -s -w -e $TOKEN_ADDRESS "$DEV_TOKEN_MINT_AMOUNT"`
add_pending_tx_hash $r
# Connect a minter component if defined
TOKEN_MINTER_MODE=${TOKEN_MINTER_MODE:-"faucet"}
if [ -z "$TOKEN_MINTER_MODE" ]; then
>&2 echo -e "\033[;33mNo token minter mode set.\033[;39m"
else
deploy_minter_${TOKEN_MINTER_MODE} $TOKEN_ADDRESS
fi
>&2 echo -e "\033[;96mWriting env_reset file\033[;39m"
confini-dump --schema-dir ./config --prefix export > ${DEV_DATA_DIR}/env_reset
set +e
set +a

View File

@ -8,11 +8,16 @@ else
mkdir -p $DEV_DATA_DIR
fi
# By default configuration values generated from previous runs will be used in subsequent invocations
# Setting the config reset
if [ -z $DEV_CONFIG_RESET ]; then
if [ -f ${DEV_DATA_DIR}/env_reset ]; then
>&2 echo "importing existing configuration values from ${DEV_DATA_DIR}/env_reset"
if [ -f $DEV_DATA_DIR/env_reset ]; then
>&2 echo -e "\033[;96mimporting existing configuration values from ${DEV_DATA_DIR}/env_reset\033[;39m"
. ${DEV_DATA_DIR}/env_reset
fi
else
>&2 echo -e "\033[;33mGenerating scratch configuration\033[;39m"
confini-dump --schema-dir ./config --prefix export > ${DEV_DATA_DIR}/env_reset
fi
# Handle wallet
@ -31,9 +36,6 @@ export CIC_DEFAULT_TOKEN_SYMBOL=$TOKEN_SYMBOL
export TOKEN_SINK_ADDRESS=${TOKEN_SINK_ADDRESS:-$DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER}
# Legacy variable defaults
# Migration variable processing
confini-dump --schema-dir ./config --prefix export > ${DEV_DATA_DIR}/env_reset
echo "export CIC_TRUST_ADDRESS=$CIC_TRUST_ADDRESS
@ -41,6 +43,4 @@ export CIC_DEFAULT_TOKEN_SYMBOL=$CIC_DEFAULT_TOKEN_SYMBOL
export WALLET_KEY_FILE=$WALLET_KEY_FILE
" >> ${DEV_DATA_DIR}/env_reset
cat ${DEV_DATA_DIR}/env_reset
set +a

View File

@ -1,13 +1,23 @@
[dev]
eth_account_contract_deployer =
eth_account_reserve_minter =
eth_account_accounts_index_writer =
reserve_amount = 10000000000000000000000000000000000
#eth_account_reserve_minter =
#eth_account_accounts_index_writer =
token_mint_amount = 10000000000000000000000000000000000
default_token_symbol = GFT
faucet_amount = 0
gas_amount = 100000000000000000000000
token_amount = 100000000000000000000000
eth_gas_price =
data_dir =
pip_extra_index_url =
eth_provider_host =
eth_provider_port =
#pip_extra_index_url =
address_declarator =
declarator_description = 0x546869732069732074686520434943206e6574776f726b000000000000000000
[rpc]
provider = http://localhost:8545
[chain]
spec =
[cic]
registry_address =

View File

@ -19,8 +19,6 @@ if [ -z "${RPC_PROVIDER}" ]; then
exit 1
fi
unset CONFINI_DIR
if [ ! -z "$DEV_USE_DOCKER_WAIT_SCRIPT" ]; then
IFS=: read -a p <<< "$RPC_PROVIDER"
read -i "/" rpc_provider_port <<< "${p[2]}"

View File

@ -1,31 +1,54 @@
#! /bin/bash
>&2 echo -e "\033[;96mRUNNING\033[;39m configurations"
./config.sh
. ./util.sh
set -a
DEV_DEBUG_FLAG=""
DEV_DEBUG_LEVEL=${DEV_DEBUG_LEVEL=0}
if [ $DEV_DEBUG_LEVEL -eq 1 ]; then
DEV_DEBUG_FLAG="-v"
elif [ $DEV_DEBUG_LEVEL -gt 1 ]; then
DEV_DEBUG_FLAG="-vv"
fi
# disable override of config schema directory
unset CONFINI_DIR
set +a
LAST_BIT_POS=4
files=(deploy_contract_root deploy_contract_instance deploy_token)
description=("global contracts" "instance specific contracts" "token deployment")
>&2 echo -e "\033[;96mRUNNING configurations\033[;39m"
source ./config.sh
if [ $? -ne "0" ]; then
>&2 echo -e "\033[;31mFAILED\033[;39m configurations"
>&2 echo -e "\033[;31mFAILED configurations\033[;39m"
exit 1;
fi
>&2 echo -e "\033[;32mSUCCEEDED\033[;39m configurations"
>&2 echo -e "\033[;32mSUCCEEDED configurations\033[;39m"
if [[ $((RUN_MASK & 1)) -eq 1 ]]
then
>&2 echo -e "\033[;96mRUNNING\033[;39m RUN_MASK 1 - contract deployment"
./reset.sh
if [ $? -ne "0" ]; then
>&2 echo -e "\033[;31mFAILED\033[;39m RUN_MASK 1 - contract deployment"
exit 1;
fi
>&2 echo -e "\033[;32mSUCCEEDED\033[;39m RUN_MASK 1 - contract deployment"
fi
>&2 echo -e "\033[;96mInitial configuration state\033[;39m"
if [[ $((RUN_MASK & 2)) -eq 2 ]]
then
>&2 echo -e "\033[;96mRUNNING\033[;39m RUN_MASK 2 - custodial service initialization"
./seed_cic_eth.sh
if [ $? -ne "0" ]; then
>&2 echo -e "\033[;31mFAILED\033[;39m RUN_MASK 2 - custodial service initialization"
exit 1;
confini-dump --schema-dir ./config
clear_pending_tx_hashes
bit=1
for ((i=0; i<$LAST_BIT_POS; i++)); do
runlevel="RUNLEVEL $bit"
if [[ $((RUN_MASK & $bit)) -eq ${bit} ]]; then
s="$runlevel - ${description[$i]}"
>&2 echo -e "\033[;96mRUNNING $s\033[;39m"
source $((i+1))_${files[$i]}.sh
if [ $? -ne "0" ]; then
>&2 echo -e "\033[;31mFAILED $s\033[;39m"
exit 1;
fi
>&2 echo -e "\033[;32mSUCCEEDED $s\033[;39m"
echo -e "\033[;96mConfiguration state after $runlevel execution\033[;39m"
confini-dump --schema-dir ./config
fi
>&2 echo -e "\033[;32mSUCCEEDED\033[;39m RUN_MASK 2 - custodial service initialization"
fi
bit=$((bit*2))
done

View File

@ -0,0 +1,42 @@
function must_address() {
if [[ ! "$1" =~ ^(0x)?[0-9a-fA-F]{40}$ ]]; then
>&2 echo -e "\033[;31mvalue '$1' for $2 is not an address\033[;39m"
exit 1
fi
}
function must_hash_256() {
if [[ ! "$1" =~ ^(0x)?[0-9a-fA-F]{64}$ ]]; then
>&2 echo -e "\033[;31mvalue '$1' for $2 is not a 256-bit digest\033[;39m"
exit 1
fi
}
function must_eth_rpc() {
if [ -z "${RPC_PROVIDER}" ]; then
echo "\$RPC_PROVIDER not set!"
exit 1
fi
# Wait for the backend to be up, if we know where it is.
if [ ! -z "$DEV_USE_DOCKER_WAIT_SCRIPT" ]; then
WAIT_FOR_TIMEOUT=${WAIT_FOR_TIMEOUT:-60}
IFS=: read -a p <<< "$RPC_PROVIDER"
read -i "/" rpc_provider_port <<< "${p[2]}"
rpc_provider_host=${p[1]:2}
echo "waiting for provider host $rpc_provider_host port $rpc_provider_port..."
./wait-for-it.sh "$rpc_provider_host:$rpc_provider_port" -t $WAIT_FOR_TIMEOUT
fi
}
function clear_pending_tx_hashes() {
truncate -s 0 $DEV_DATA_DIR/hashes
}
function add_pending_tx_hash() {
must_hash_256 $1
echo $1 >> $DEV_DATA_DIR/hashes
}