2021-10-20 17:02:36 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
. util.sh
|
|
|
|
|
|
|
|
set -a
|
|
|
|
|
|
|
|
. ${DEV_DATA_DIR}/env_reset
|
|
|
|
|
|
|
|
WAIT_FOR_TIMEOUT=${WAIT_FOR_TIMEOUT:-60}
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
if [ ! -z $DEV_FEE_PRICE ]; then
|
|
|
|
gas_price_arg="--gas-price $DEV_FEE_PRICE"
|
|
|
|
fee_price_arg="--fee-price $DEV_FEE_PRICE"
|
2021-10-20 17:02:36 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
have_default_token=1
|
|
|
|
token_feedback_display_string='token'
|
|
|
|
|
|
|
|
must_address "$DEV_ADDRESS_DECLARATOR" "address declarator"
|
|
|
|
must_address "$CIC_REGISTRY_ADDRESS" "registry"
|
|
|
|
must_eth_rpc
|
|
|
|
|
|
|
|
|
|
|
|
function _deploy_token_defaults {
|
|
|
|
if [ -z "$TOKEN_SYMBOL" ]; then
|
2021-10-29 11:36:14 +02:00
|
|
|
>&2 echo -e "\033[;33mToken symbol not set, setting defaults for type $TOKEN_TYPE\033[;39m"
|
2021-10-20 17:02:36 +02:00
|
|
|
TOKEN_SYMBOL=$1
|
|
|
|
TOKEN_NAME=$2
|
|
|
|
elif [ -z "$TOKEN_NAME" ]; then
|
2021-10-29 11:36:14 +02:00
|
|
|
>&2 echo -e "\033[;33mToken name not set, setting same as symbol for type $TOKEN_TYPE\033[;39m"
|
2021-10-20 17:02:36 +02:00
|
|
|
TOKEN_NAME=$TOKEN_SYMBOL
|
|
|
|
fi
|
|
|
|
TOKEN_DECIMALS=${TOKEN_DECIMALS:-6}
|
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
debug_rpc
|
|
|
|
default_token_registered=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw DefaultToken --fee-limit 8000000`
|
2021-10-20 17:02:36 +02:00
|
|
|
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"
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
|
|
|
TOKEN_ADDRESS=`giftable-token-deploy --nonce $nonce $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`
|
2021-10-20 17:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function deploy_token_erc20_demurrage_token() {
|
|
|
|
_deploy_token_defaults "DET" "Demurrage Token"
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
|
|
|
TOKEN_ADDRESS=`erc20-demurrage-token-deploy --nonce $nonce $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL $DEV_DEBUG_FLAG -ww -s`
|
2021-10-20 17:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deploy_accounts_index() {
|
|
|
|
# Deploy accounts index contact
|
|
|
|
>&2 echo -e "\033[;96mDeploy accounts index contract for token $TOKEN_SYMBOL\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
|
|
|
DEV_ACCOUNTS_INDEX_ADDRESS=`okota-accounts-index-deploy --nonce $nonce $fee_price_arg -u -s -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --address-declarator $DEV_ADDRESS_DECLARATOR --token-address $1`
|
2021-10-20 17:02:36 +02:00
|
|
|
|
|
|
|
if [ -z "$have_default_token" ]; then
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mAdd acccounts index record for default token to contract registry\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`eth-contract-registry-set --nonce $nonce $DEV_WAIT_FLAG $fee_price_arg -s -u -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier AccountRegistry $DEV_ACCOUNTS_INDEX_ADDRESS`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function deploy_minter_faucet() {
|
|
|
|
FAUCET_AMOUNT=${FAUCET_AMOUNT:-0}
|
|
|
|
|
|
|
|
# Token faucet contract
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mDeploy token faucet contract for token $TOKEN_SYMBOL\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
accounts_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw AccountRegistry --fee-limit 8000000`
|
|
|
|
faucet_address=`sarafu-faucet-deploy --nonce $nonce $fee_price_arg -s -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --account-index-address $accounts_index_address $1`
|
2021-10-20 17:02:36 +02:00
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
# sarafu-faucet-deploy consumes TWO nonces
|
|
|
|
advance_nonce
|
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mSet token faucet amount to $FAUCET_AMOUNT\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`sarafu-faucet-set --nonce $nonce $fee_price_arg $DEV_WAIT_FLAG -s -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -e $faucet_address $DEV_DEBUG_FLAG --fee-limit 100000 $FAUCET_AMOUNT`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
|
|
|
|
if [ -z $have_default_token ]; then
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mRegister faucet in registry\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`eth-contract-registry-set --nonce $nonce $DEV_WAIT_FLAG -s -u $fee_price_arg -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier Faucet $faucet_address`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
fi
|
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mSet faucet as token minter\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`giftable-token-minter $DEV_WAIT_FLAG --nonce $nonce -s -u $fee_price_arg -y $WALLET_KEY_FILE -e $TOKEN_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG $faucet_address`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TOKEN_TYPE=${TOKEN_TYPE:-giftable_erc20_token}
|
|
|
|
deploy_token_${TOKEN_TYPE}
|
|
|
|
|
|
|
|
if [ -z "$have_default_token" ]; then
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mAdd default token to contract registry\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`eth-contract-registry-set $DEV_WAIT_FLAG --nonce $nonce $fee_price_arg -s -u -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier DefaultToken $TOKEN_ADDRESS`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
fi
|
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mAdd token symbol $TOKEN_SYMBOL to token address $TOKEN_ADDRESS mapping 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`
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`eth-token-index-add --nonce $nonce $fee_price_arg -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG -e $token_index_address $TOKEN_ADDRESS`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
|
|
|
|
|
|
|
|
TOKEN_MINT_AMOUNT=${TOKEN_MINT_AMOUNT:-${DEV_TOKEN_MINT_AMOUNT}}
|
2021-10-29 11:36:14 +02:00
|
|
|
advance_nonce
|
|
|
|
debug_rpc
|
2021-10-20 17:02:36 +02:00
|
|
|
>&2 echo -e "\033[;96mMinting $TOKEN_MINT_AMOUNT tokens\033[;39m"
|
2021-10-29 11:36:14 +02:00
|
|
|
r=`giftable-token-gift $DEV_WAIT_FLAG --nonce $nonce $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC -u $DEV_DEBUG_FLAG -s -e $TOKEN_ADDRESS "$DEV_TOKEN_MINT_AMOUNT"`
|
2021-10-20 17:02:36 +02:00
|
|
|
add_pending_tx_hash $r
|
|
|
|
|
|
|
|
|
|
|
|
# Create accounts index for default token
|
|
|
|
deploy_accounts_index $TOKEN_ADDRESS
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2021-10-29 11:36:14 +02:00
|
|
|
check_wait 3
|
2021-10-20 17:02:36 +02:00
|
|
|
|
|
|
|
>&2 echo -e "\033[;96mWriting env_reset file\033[;39m"
|
|
|
|
confini-dump --schema-dir ./config > ${DEV_DATA_DIR}/env_reset
|
|
|
|
|
|
|
|
set +e
|
|
|
|
set +a
|