diff --git a/scripts/byron-to-alonzo/mkfiles.sh b/scripts/byron-to-alonzo/mkfiles.sh index 2e447da2e90..f6e565e527a 100755 --- a/scripts/byron-to-alonzo/mkfiles.sh +++ b/scripts/byron-to-alonzo/mkfiles.sh @@ -310,13 +310,15 @@ cardano-cli genesis create --testnet-magic 42 --genesis-dir shelley # and K=10, but we'll keep long KES periods so we don't have to bother # cycling KES keys sed -i shelley/genesis.spec.json \ - -e 's/"slotLength": 1/"slotLength": 0.2/' \ + -e 's/"slotLength": 1/"slotLength": 0.1/' \ -e 's/"activeSlotsCoeff": 5.0e-2/"activeSlotsCoeff": 0.1/' \ -e 's/"securityParam": 2160/"securityParam": 10/' \ - -e 's/"epochLength": 432000/"epochLength": 1500/' \ + -e 's/"epochLength": 432000/"epochLength": 500/' \ -e 's/"maxLovelaceSupply": 0/"maxLovelaceSupply": 1000000000000/' \ -e 's/"decentralisationParam": 1.0/"decentralisationParam": 0.7/' \ - -e 's/"major": 0/"major": 2/' \ + -e 's/"major": 0/"major": 5/' \ + -e 's/"rho": 0.0/"rho": 0.1/' \ + -e 's/"tau": 0.0/"tau": 0.1/' \ -e 's/"updateQuorum": 5/"updateQuorum": 2/' # Now generate for real: @@ -327,6 +329,18 @@ cardano-cli genesis create \ --gen-genesis-keys ${NUM_BFT_NODES} \ --gen-utxo-keys 1 +cardano-cli stake-address key-gen \ + --verification-key-file shelley/utxo-keys/utxo-stake.vkey \ + --signing-key-file shelley/utxo-keys/utxo-stake.skey + +cardano-cli address key-gen \ + --verification-key-file shelley/utxo-keys/utxo2.vkey \ + --signing-key-file shelley/utxo-keys/utxo2.skey + +cardano-cli stake-address key-gen \ + --verification-key-file shelley/utxo-keys/utxo2-stake.vkey \ + --signing-key-file shelley/utxo-keys/utxo2-stake.skey + echo "=====================================================================" echo "Generated genesis keys and genesis files:" echo diff --git a/scripts/plutus/scripts/guess-42-stake.plutus b/scripts/plutus/scripts/guess-42-stake.plutus new file mode 100644 index 00000000000..0d73c4735e5 --- /dev/null +++ b/scripts/plutus/scripts/guess-42-stake.plutus @@ -0,0 +1,5 @@ +{ + "type": "PlutusScriptV1", + "description": "", + "cborHex": "587a58780100003233322232323233223232225335300a333500900800233500700d4815040184d400d2411d496e636f727265637420646174756d2e2045787065637465642034322e001235002353003335738002008930930900090008900091199ab9a3375e00400200c00a24002244004244002400246ea00041" +} diff --git a/scripts/plutus/staking-example/claim-script-staking-rewards.sh b/scripts/plutus/staking-example/claim-script-staking-rewards.sh new file mode 100755 index 00000000000..f4511ec4ed6 --- /dev/null +++ b/scripts/plutus/staking-example/claim-script-staking-rewards.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +set -e +# Unoffiical bash strict mode. +# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -u +set -o pipefail + + +export BASE="${BASE:-.}" +export WORK="${WORK:-example/work}" +export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" +export TESTNET_MAGIC="${TESTNET_MAGIC:-42}" +export UTXO_VKEY1="${UTXO_VKEY1:-example/shelley/utxo-keys/utxo1.vkey}" +export UTXO_SKEY1="${UTXO_SKEY1:-example/shelley/utxo-keys/utxo1.skey}" +export UTXO_VKEY2="${UTXO_VKEY1:-example/shelley/utxo-keys/utxo2.vkey}" +export UTXO_SKEY2="${UTXO_SKEY1:-example/shelley/utxo-keys/utxo2.skey}" +export UTXO_STAKING_VKEY1="${UTXO_STAKING_VKEY1:=example/shelley/utxo-keys/utxo-stake.vkey}" +export UTXO_STAKING_SKEY1="${UTXO_STAKING_SKEY1:=example/shelley/utxo-keys/utxo-stake.skey}" +export UTXO_STAKING_VKEY2="${UTXO_STAKING_VKEY2:=example/shelley/utxo-keys/utxo2-stake.vkey}" +export UTXO_STAKING_SKEY2="${UTXO_STAKING_SKEY2:=example/shelley/utxo-keys/utxo2-stake.skey}" + +utxoaddr=$(cardano-cli address build --testnet-magic "$TESTNET_MAGIC" --payment-verification-key-file "$UTXO_VKEY1") + + +cardano-cli query utxo \ + --address "$utxoaddr" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/utxo-1.json" + +echo "UTxO" +cat "$WORK/utxo-1.json" +echo "" + +txin=$(jq -r 'keys[0]' $WORK/utxo-1.json) +txinlovelace=$(jq -r ".[\"$txin\"].value.lovelace" $WORK/utxo-1.json) +txincollateral=$(jq -r 'keys[1]' $WORK/utxo-1.json) +scriptpaymentaddrwithstakecred=$(cardano-cli address build --payment-verification-key-file $UTXO_VKEY1 --stake-script-file "scripts/plutus/scripts/guess-42-stake.plutus" --testnet-magic 42) +stakingscriptaddr=$(cardano-cli stake-address build --stake-script-file scripts/plutus/scripts/guess-42-stake.plutus --testnet-magic 42) + +# STEP 1 - Get reward account balance + +cardano-cli query stake-address-info \ + --address "$stakingscriptaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/scriptdelegationstatusrewards.json" + +rewardamt=$(jq -r '.[0].rewardAccountBalance' $WORK/scriptdelegationstatusrewards.json) + +totalspendable=$(expr $rewardamt + $txinlovelace - 289563) +echo "Lovelace at utxo: $txinlovelace" +echo "Rewards: $rewardamt" +echo "Combined: $totalspendable" + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddr" \ + --tx-in "$txin" \ + --tx-in-collateral "$txincollateral" \ + --tx-out "$scriptpaymentaddrwithstakecred+$totalspendable" \ + --withdrawal "$stakingscriptaddr+$rewardamt" \ + --withdrawal-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ + --withdrawal-redeemer-file "scripts/plutus/data/42.redeemer" \ + --protocol-params-file "$WORK/pparams.json" \ + --out-file "$WORK/script-withdrawal.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/script-withdrawal.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY1" \ + --out-file "$WORK/script-withdrawal.tx" + +echo "Submitting withdrawal..." + +cardano-cli transaction submit \ + --tx-file "$WORK/script-withdrawal.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +echo "Waiting 5 seconds...." +sleep 5 + +cardano-cli query stake-address-info \ + --address "$stakingscriptaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/scriptrewardscheck.json" + +scriptrewardscheck=$(jq -r '.[0]' $WORK/scriptrewardscheck.json) +echo "Checking if script rewards withdrawal was successful..." +echo "$scriptrewardscheck" diff --git a/scripts/plutus/staking-example/register-stake-pool.sh b/scripts/plutus/staking-example/register-stake-pool.sh new file mode 100755 index 00000000000..6a5f90d007f --- /dev/null +++ b/scripts/plutus/staking-example/register-stake-pool.sh @@ -0,0 +1,507 @@ +#!/usr/bin/env bash + +set -e +# Unoffiical bash strict mode. +# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -u +set -o pipefail + + +export BASE="${BASE:-.}" +export WORK="${WORK:-example/work}" +export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" +export TESTNET_MAGIC="${TESTNET_MAGIC:-42}" +export UTXO_VKEY1="${UTXO_VKEY1:-example/shelley/utxo-keys/utxo1.vkey}" +export UTXO_SKEY1="${UTXO_SKEY1:-example/shelley/utxo-keys/utxo1.skey}" +export UTXO_VKEY2="${UTXO_VKEY1:-example/shelley/utxo-keys/utxo2.vkey}" +export UTXO_SKEY2="${UTXO_SKEY1:-example/shelley/utxo-keys/utxo2.skey}" +export UTXO_STAKING_VKEY1="${UTXO_STAKING_VKEY1:=example/shelley/utxo-keys/utxo-stake.vkey}" +export UTXO_STAKING_SKEY1="${UTXO_STAKING_SKEY1:=example/shelley/utxo-keys/utxo-stake.skey}" +export UTXO_STAKING_VKEY2="${UTXO_STAKING_VKEY2:=example/shelley/utxo-keys/utxo2-stake.vkey}" +export UTXO_STAKING_SKEY2="${UTXO_STAKING_SKEY2:=example/shelley/utxo-keys/utxo2-stake.skey}" + +# TODO: Left off here. You should try a staking key address to see if you are the problem! +mkdir -p "$WORK" + +utxoaddr=$(cardano-cli address build --testnet-magic "$TESTNET_MAGIC" --payment-verification-key-file "$UTXO_VKEY1") +nodepool1dir=example/node-pool1 +utxoaddrwithstaking=$(cardano-cli address build --payment-verification-key-file "$UTXO_VKEY2" --stake-verification-key-file "$UTXO_STAKING_VKEY2" --testnet-magic 42) +keystakeaddress=$(cardano-cli stake-address build --stake-verification-key-file "$UTXO_STAKING_VKEY2" --testnet-magic 42) + + +cardano-cli query utxo \ + --address "$utxoaddr" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/utxo-1.json" + +echo "UTxO" +cat "$WORK/utxo-1.json" +echo "" + +txin=$(jq -r 'keys[]' $WORK/utxo-1.json) +lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" $WORK/utxo-1.json) +lovelaceattxindiv3=$(expr $lovelaceattxin / 3) +scriptpaymentaddrwithstakecred=$(cardano-cli address build --payment-verification-key-file $UTXO_VKEY1 --stake-script-file "scripts/plutus/scripts/guess-42-stake.plutus" --testnet-magic 42) +#TODO: Look at stake-distbution cmd +poolownerstakekey="example/addresses/pool-owner1-stake.vkey" +poolowneraddresswstakecred=$(cardano-cli address build --payment-verification-key-file example/addresses/pool-owner1.vkey --stake-verification-key-file example/addresses/pool-owner1-stake.vkey --testnet-magic 42) +poolcoldkey="example/node-pool1/shelley/operator.vkey" + +#Register stake pool + +# We need to submit the stake pool registration certificate and +# also submit the delegation certificate of the pledger + +# STEP 1 +# Create registration certificate of pledger AND FUND THE POOL OWNER'S ADDRESS + +cardano-cli stake-address registration-certificate \ + --stake-verification-key-file "$poolownerstakekey" \ + --out-file "$WORK/pledger.regcert" + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddr" \ + --tx-in "$txin" \ + --tx-out "$scriptpaymentaddrwithstakecred+5000000" \ + --tx-out "$poolowneraddresswstakecred+5000000" \ + --tx-out "$utxoaddrwithstaking+5000000" \ + --witness-override 3 \ + --certificate-file "$WORK/pledger.regcert" \ + --out-file "$WORK/pledge-registration-cert.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/pledge-registration-cert.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY1" \ + --out-file "$WORK/pledge-registration-cert.tx" + +echo "Submitting pool owner/pledge stake registration cert and funding stake pool owner address..." + +cardano-cli transaction submit \ + --tx-file "$WORK/pledge-registration-cert.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +poolownerstakeaddr=$(cardano-cli stake-address build --stake-verification-key-file $poolownerstakekey --testnet-magic 42) + +echo "" +echo "Pool owner/pledger stake address" +echo "$poolownerstakeaddr" +echo "Waiting 10 seconds..." + +sleep 10 + +# Check the stake address was registered +cardano-cli query stake-address-info \ + --address "$poolownerstakeaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/pledgeownerregistration.json" +registered=$(jq -r '.[0]' $WORK/pledgeownerregistration.json) + +echo "" +echo "Registered pool owner/pledger address. If null it was not successfully registered" +echo "$registered" +sleep 2 + +#Register key staking address +echo "" +echo "Register key staking address" +echo "$poolownerstakeaddr" +echo "" + +cardano-cli query utxo \ + --address "$utxoaddrwithstaking" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/staking-key-utxo-1.json" + +echo "Staking key UTxO" +cat "$WORK/staking-key-utxo-1.json" +echo "" + +keytxin=$(jq -r 'keys[]' $WORK/staking-key-utxo-1.json) + +cardano-cli stake-address registration-certificate \ + --stake-verification-key-file "$UTXO_STAKING_VKEY2" \ + --out-file "$WORK/stakekey.regcert" + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddrwithstaking" \ + --tx-in "$keytxin" \ + --tx-out "$utxoaddrwithstaking+1000" \ + --witness-override 3 \ + --certificate-file "$WORK/stakekey.regcert" \ + --out-file "$WORK/key-registration-cert.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/key-registration-cert.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY2" \ + --signing-key-file "$UTXO_STAKING_SKEY2" \ + --out-file "$WORK/key-registration-cert.tx" + +echo "Submitting key stake registration cert..." + +cardano-cli transaction submit \ + --tx-file "$WORK/key-registration-cert.tx" \ + --testnet-magic "$TESTNET_MAGIC" +echo "Wait 10 seconds..." +sleep 10 + +echo "Check to see if it was registered..." +cardano-cli query stake-address-info \ + --address "$keystakeaddress" \ + --testnet-magic 42 \ + --out-file "$WORK/keyregistration.json" + +registeredkey=$(jq -r '.[0]' $WORK/keyregistration.json) +echo "" +echo "Registered key staking address. If null it was not successfully registered" +echo "$registeredkey" + + +# Update UTxO + +cardano-cli query utxo \ + --address "$utxoaddr" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/utxo-1.json" + +cat "$WORK/utxo-1.json" + +txinupdated=$(jq -r 'keys[0]' $WORK/utxo-1.json) + + +# STEP 2 +# Create delegation certificate of pledger + +cardano-cli stake-address delegation-certificate \ + --stake-verification-key-file "$poolownerstakekey" \ + --cold-verification-key-file "$poolcoldkey" \ + --out-file "$WORK/pledger.delegcert" + +# TODO: We use witness override because the build command does not take certificates +# into account and underestimates the tx fee. + +# STEP 3 +# REGISTER STAKE POOL AND DELEGATE THE PLEDGER TO THE STAKE POOL IN ONE TX + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddr" \ + --tx-in "$txinupdated" \ + --tx-out "$scriptpaymentaddrwithstakecred+500" \ + --witness-override 3 \ + --certificate-file "example/node-pool1/registration.cert" \ + --certificate-file "$WORK/pledger.delegcert" \ + --out-file "$WORK/register-stake-pool.txbody" + +# UTxO Payment key +# Staking key +# Cold key +cardano-cli transaction sign \ + --tx-body-file "$WORK/register-stake-pool.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY1" \ + --signing-key-file "$nodepool1dir/shelley/operator.skey" \ + --signing-key-file "$nodepool1dir/owner.skey" \ + --out-file "$WORK/register-stake-pool.tx" + +echo "Registering stake pool and delegating to said stake pool" + +cardano-cli transaction submit \ + --tx-file "$WORK/register-stake-pool.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +echo "Wait 5 seconds for UTxO to update..." +sleep 5 +currentstakepools=$(cardano-cli query stake-pools --testnet-magic 42) + +# Check the stake address was delegated +cardano-cli query stake-address-info \ + --address "$poolownerstakeaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/pledgeownerregistration.json" +delegated=$(jq -r '.[0]' $WORK/pledgeownerregistration.json) + +echo "" +echo "Currently registered stake pools" +echo "$currentstakepools" +echo "" +echo "We check if the pool owner/pledger has successfully delegated" +echo "$delegated" + + +echo "" +echo "Delegate staking key to stake pool" +echo "" + +cardano-cli stake-address delegation-certificate \ + --stake-verification-key-file "$UTXO_STAKING_VKEY2" \ + --cold-verification-key-file "$poolcoldkey" \ + --out-file "$WORK/stakekey.delegcert" + +cardano-cli query utxo \ + --address "$utxoaddrwithstaking" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/staking-key-utxo-2.json" + +echo "Staking key UTxO" +cat "$WORK/staking-key-utxo-2.json" +echo "" + +keytxin2=$(jq -r 'keys[0]' $WORK/staking-key-utxo-2.json) + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddrwithstaking" \ + --tx-in "$keytxin2" \ + --tx-out "$utxoaddrwithstaking+1000" \ + --witness-override 3 \ + --certificate-file "$WORK/stakekey.delegcert" \ + --out-file "$WORK/key-deleg-cert.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/key-deleg-cert.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY2" \ + --signing-key-file "$UTXO_STAKING_SKEY2" \ + --out-file "$WORK/key-deleg-cert.tx" + +echo "Submitting key stake delegation cert" + +cardano-cli transaction submit \ + --tx-file "$WORK/key-deleg-cert.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +echo "Wait 10 seconds..." +sleep 10 + +echo "Check to see if it was delegated..." +cardano-cli query stake-address-info \ + --address "$keystakeaddress" \ + --testnet-magic 42 \ + --out-file "$WORK/keydelegation.json" + +delegatedkey=$(jq -r '.[0]' $WORK/keydelegation.json) +echo "" +echo "Delegating key staking address. If null it was not successfully registered" +echo "$delegatedkey" + + + +# UP TO HERE IN THEORY WE ARE FINE. THE POOL GETS REGISTERED AND THE PLEDGE IS DELEGATED TO THE POOL +# Delegate Plutus staking script address to stake pool + +# Update UTxO again + +cardano-cli query utxo \ + --address "$utxoaddr" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/utxo-2.json" + +cat "$WORK/utxo-2.json" + +txinupdated2=$(jq -r 'keys[0]' $WORK/utxo-2.json) +echo "" +echo "Selected txin: $txinupdated2" +# Step 1: Create registration certificate for the staking script + +# We also create collateral. + +txin=$(jq -r 'keys[]' $WORK/utxo-2.json) +lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" $WORK/utxo-2.json) +lovelaceattxindiv3=$(expr $lovelaceattxin / 3) + +cardano-cli stake-address registration-certificate \ + --stake-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ + --out-file "$WORK/script.regcert" + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddr" \ + --tx-in "$txinupdated2" \ + --tx-out "$scriptpaymentaddrwithstakecred+500" \ + --tx-out "$utxoaddr+$lovelaceattxindiv3" \ + --witness-override 3 \ + --certificate-file "$WORK/script.regcert" \ + --out-file "$WORK/script-registration-cert.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/script-registration-cert.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY1" \ + --out-file "$WORK/script-registration-cert.tx" + +cardano-cli transaction submit \ + --tx-file "$WORK/script-registration-cert.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +stakingscriptaddr=$(cardano-cli stake-address build --stake-script-file scripts/plutus/scripts/guess-42-stake.plutus --testnet-magic 42) + +echo "" +echo "Staking script address" +echo "$stakingscriptaddr" +echo "Waiting 10 seconds..." +sleep 10 +echo "Check to see if the SCRIPT staking address was successfully REGISTERED" + +cardano-cli query stake-address-info \ + --address "$stakingscriptaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/scriptregistration.json" + +registeredscr=$(jq -r '.[0]' $WORK/scriptregistration.json) +echo "$registeredscr" + +# We have successfully registered our script staking address. + +# We need to delegate the script staking address + +cardano-cli stake-address delegation-certificate \ + --stake-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ + --cold-verification-key-file "$poolcoldkey" \ + --out-file "$WORK/script.delegcert" + +cardano-cli query protocol-parameters --testnet-magic "$TESTNET_MAGIC" --out-file $WORK/pparams.json + +# We also need collateral + +cardano-cli query utxo \ + --address "$utxoaddr" \ + --cardano-mode \ + --testnet-magic "$TESTNET_MAGIC" \ + --out-file "$WORK/utxo-2.json" + +cat "$WORK/utxo-2.json" + +txinupdated3=$(jq -r 'keys[0]' $WORK/utxo-2.json) +txincollateral=$(jq -r 'keys[1]' $WORK/utxo-2.json) +echo "" +echo "Selected txin: $txinupdated2" + +cardano-cli transaction build \ + --alonzo-era \ + --testnet-magic "$TESTNET_MAGIC" \ + --change-address "$utxoaddr" \ + --tx-in "$txinupdated3" \ + --tx-in-collateral "$txincollateral" \ + --tx-out "$scriptpaymentaddrwithstakecred+500" \ + --witness-override 3 \ + --certificate-file "$WORK/script.delegcert" \ + --certificate-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ + --certificate-redeemer-file "scripts/plutus/data/42.redeemer" \ + --protocol-params-file "$WORK/pparams.json" \ + --out-file "$WORK/script-delegation-cert.txbody" + +cardano-cli transaction sign \ + --tx-body-file "$WORK/script-delegation-cert.txbody" \ + --testnet-magic "$TESTNET_MAGIC" \ + --signing-key-file "$UTXO_SKEY1" \ + --out-file "$WORK/script-delegation-cert.tx" + +echo "Submitting staking script delegation certificate..." + +cardano-cli transaction submit \ + --tx-file "$WORK/script-delegation-cert.tx" \ + --testnet-magic "$TESTNET_MAGIC" + +echo "Waiting 10 seconds..." +sleep 10 +echo "Check to see if staking script was successfully delegated..." + + +cardano-cli query stake-address-info \ + --address "$stakingscriptaddr" \ + --testnet-magic 42 \ + --out-file "$WORK/scriptdelegation.json" + +delegatedscript=$(jq -r '.[0]' $WORK/scriptdelegation.json) +echo "$delegatedscript" +echo "" +echo "Stake payment address" +echo "$scriptpaymentaddrwithstakecred" +# We have two scenarios to test, deregistration and rewards withdrawal +# SCENARIO 1: WITHDRAWAL + + +# SCENARIO 2: DEREGISTRATION -- THIS WORKS + +# Update UTxO again +#echo "" +#echo "Script staking address deregistration" +#echo "" +#cardano-cli query utxo \ +# --address "$utxoaddr" \ +# --cardano-mode \ +# --testnet-magic "$TESTNET_MAGIC" \ +# --out-file "$WORK/utxo-2.json" +# +#cat "$WORK/utxo-2.json" +# +#txinupdated3=$(jq -r 'keys[0]' $WORK/utxo-2.json) +#txincollateral=$(jq -r 'keys[1]' $WORK/utxo-2.json) +#echo "" +#echo "Selected txin: $txinupdated2" +# +## Create deregistration certificate +#cardano-cli stake-address deregistration-certificate \ +# --stake-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ +# --out-file "$WORK/script.deregcert" +# +# +## TODO: Then figure out why rewards aren't being dispersed. +# +## Get PParams +# +#cardano-cli query protocol-parameters --testnet-magic "$TESTNET_MAGIC" --out-file $WORK/pparams.json +# +#cardano-cli transaction build \ +# --alonzo-era \ +# --testnet-magic "$TESTNET_MAGIC" \ +# --change-address "$utxoaddr" \ +# --tx-in "$txinupdated3" \ +# --tx-in-collateral "$txincollateral" \ +# --tx-out "$scriptpaymentaddrwithstakecred+500" \ +# --witness-override 3 \ +# --certificate-file "$WORK/script.deregcert" \ +# --certificate-script-file "scripts/plutus/scripts/guess-42-stake.plutus" \ +# --certificate-redeemer-file "scripts/plutus/data/42.redeemer" \ +# --protocol-params-file "$WORK/pparams.json" \ +# --out-file "$WORK/script-deregistration-cert.txbody" +# +#cardano-cli transaction sign \ +# --tx-body-file "$WORK/script-deregistration-cert.txbody" \ +# --testnet-magic "$TESTNET_MAGIC" \ +# --signing-key-file "$UTXO_SKEY1" \ +# --out-file "$WORK/script-deregistration-cert.tx" +# +#cardano-cli transaction submit \ +# --tx-file "$WORK/script-deregistration-cert.tx" \ +# --testnet-magic "$TESTNET_MAGIC" +# +#echo "Staking script adress" +#echo "$stakingscriptaddr" +#echo "Waiting 5 seconds..." +#sleep 5 +#echo "Check to see if the script staking address was successfully deregistered" +# +#cardano-cli query stake-address-info \ +# --address "$stakingscriptaddr" \ +# --testnet-magic 42 \ +# --out-file "$WORK/scriptderegistration.json" +# +#deregistered=$(jq -r '.[0]' $WORK/scriptderegistration.json) +#echo "$deregistered" + + diff --git a/scripts/test-stake-cred-script/create-collateral.sh b/scripts/test-stake-cred-script/create-collateral.sh new file mode 100755 index 00000000000..8796aeb3686 --- /dev/null +++ b/scripts/test-stake-cred-script/create-collateral.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -e +# Unoffiical bash strict mode. +# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -u +set -o pipefail + +export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/node-bft1/node.sock}" + + +# query the UTxO +cardano-cli query utxo \ + --address "$(cat addresses/address.addr)" \ + --cardano-mode \ + --testnet-magic ${TESTNET_MAGIC} \ + --out-file queries/utxo.json + +# cardano-cli transaction build-raw +TXIN=$(jq -r 'keys[0]' queries/utxo.json) +LOVELACE=$(jq -r ".[\"$TXIN\"].value.lovelace" queries/utxo.json) + +mkdir -p txs + +cardano-cli transaction build \ + --alonzo-era \ + --cardano-mode \ + --testnet-magic ${TESTNET_MAGIC} \ + --tx-in ${TXIN} \ + --tx-out "$(cat addresses/address.addr)+1000000" \ + --change-address $(cat addresses/address-script.addr) \ + --out-file txs/create-collateral.txraw + +cardano-cli transaction sign \ + --tx-body-file txs/create-collateral.txraw \ + --signing-key-file addresses/payment-addr.skey \ + --testnet-magic ${TESTNET_MAGIC} \ + --out-file txs/create-collateral + +cardano-cli transaction submit \ + --cardano-mode \ + --testnet-magic ${TESTNET_MAGIC} \ + --tx-file txs/create-collateral