-
Notifications
You must be signed in to change notification settings - Fork 720
/
register-and-delegate-script-staking-address.sh
executable file
·237 lines (185 loc) · 7.77 KB
/
register-and-delegate-script-staking-address.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
set -e
# Unofficial bash strict mode.
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -u
set -o pipefail
export WORK="${WORK:-example/work}"
export CARDANO_NODE_SOCKET_PATH="${CARDANO_NODE_SOCKET_PATH:-example/main.sock}"
export TESTNET_MAGIC="${TESTNET_MAGIC:-42}"
export UTXO_VKEY1="${UTXO_VKEY1:-example/utxo-keys/utxo1.vkey}"
export UTXO_SKEY1="${UTXO_SKEY1:-example/utxo-keys/utxo1.skey}"
export UTXO_VKEY2="${UTXO_VKEY2:-example/utxo-keys/utxo2.vkey}"
export UTXO_STAKING_VKEY2="${UTXO_STAKING_VKEY2:=example/utxo-keys/utxo2-stake.vkey}"
export PV=v2 # Plutus Script Version
mkdir -p "$WORK"
nodepool1dir=example/node-spo1
# Pool 1 related
poolownerstakekey="example/pools/staking-reward1.vkey"
# Generate stake keys
cardano-cli stake-address key-gen \
--verification-key-file example/utxo-keys/utxo-stake.vkey \
--signing-key-file example/utxo-keys/utxo-stake.skey
cardano-cli stake-address key-gen \
--verification-key-file example/utxo-keys/utxo2-stake.vkey \
--signing-key-file example/utxo-keys/utxo2-stake.skey
# We want to delegagate the stake from UTXO_STAKING_VKEY2 to node pool 1
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)
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[]' "$WORK/utxo-1.json")
lovelaceattxin=$(jq -r ".[\"$txin\"].value.lovelace" "$WORK/utxo-1.json")
lovelaceattxindiv3=$((lovelaceattxin / 3))
certifyingscript="scripts/plutus/scripts/v2/stake-script.plutus"
scriptpaymentaddrwithstakecred=$(cardano-cli address build --payment-verification-key-file "$UTXO_VKEY1" --stake-script-file $certifyingscript --testnet-magic 42)
dummyaddress=addr_test1vpqgspvmh6m2m5pwangvdg499srfzre2dd96qq57nlnw6yctpasy4
# Node Pool 1
poolcoldkey="example/pools/cold1.vkey"
# Delegate Plutus staking script address to stake pool.
cardano-cli query protocol-parameters --testnet-magic "$TESTNET_MAGIC" --out-file "$WORK/pparams.json"
# Step 1: Create certifying reference script at tx out
cardano-cli transaction build \
--babbage-era \
--cardano-mode \
--testnet-magic "$TESTNET_MAGIC" \
--change-address "$utxoaddr" \
--tx-in "$txin" \
--tx-out "$scriptpaymentaddrwithstakecred+999978" \
--tx-out "$dummyaddress+$lovelaceattxindiv3" \
--tx-out-reference-script-file "$certifyingscript" \
--protocol-params-file "$WORK/pparams.json" \
--out-file "$WORK/create-stake-reference-script.body"
cardano-cli transaction sign \
--tx-body-file "$WORK/create-stake-reference-script.body" \
--testnet-magic "$TESTNET_MAGIC" \
--signing-key-file "$UTXO_SKEY1" \
--out-file "$WORK/create-stake-reference-script.tx"
cardano-cli transaction submit \
--tx-file "$WORK/create-stake-reference-script.tx" \
--testnet-magic "$TESTNET_MAGIC"
echo ""
echo "Wait 5 seconds..."
echo ""
sleep 5
# Step 2: Create and submit registration certificate for the staking script
cardano-cli query utxo \
--address "$utxoaddr" \
--cardano-mode \
--testnet-magic "$TESTNET_MAGIC" \
--out-file "$WORK/utxo-2.json"
cat "$WORK/utxo-2.json"
# We also create collateral.
txin2=$(jq -r 'keys[0]' "$WORK/utxo-2.json")
lovelaceattxin2=$(jq -r ".[\"$txin2\"].value.lovelace" "$WORK/utxo-2.json")
lovelaceattxin2div3=$(($lovelaceattxin2 / 3))
cardano-cli stake-address registration-certificate \
--stake-script-file "$certifyingscript" \
--out-file "$WORK/script.regcert"
cardano-cli transaction build \
--babbage-era \
--testnet-magic "$TESTNET_MAGIC" \
--change-address "$utxoaddr" \
--tx-in "$txin2" \
--tx-out "$utxoaddr+$lovelaceattxin2div3" \
--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 $certifyingscript --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
# Retrieve plutus reference script tx in
cardano-cli query utxo --address "$dummyaddress" --cardano-mode --testnet-magic "$TESTNET_MAGIC" --out-file $WORK/dummy-address-ref-script.json
cat $WORK/dummy-address-ref-script.json
# Get reference script txin
plutusreferencescripttxin=$(jq -r 'keys[0]' $WORK/dummy-address-ref-script.json)
cardano-cli stake-address delegation-certificate \
--stake-script-file "$certifyingscript" \
--cold-verification-key-file "$poolcoldkey" \
--out-file "$WORK/script.delegcert"
# 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: $txinupdated3"
cardano-cli transaction build \
--babbage-era \
--testnet-magic "$TESTNET_MAGIC" \
--change-address "$utxoaddr" \
--tx-in "$txinupdated3" \
--tx-in-collateral "$txincollateral" \
--tx-out "$scriptpaymentaddrwithstakecred+999978" \
--witness-override 3 \
--certificate-file "$WORK/script.delegcert" \
--certificate-tx-in-reference "$plutusreferencescripttxin" \
--certificate-plutus-script-v2 \
--certificate-reference-tx-in-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 ""
echo "!!!!!!!!!!!!"
echo "You need to wait 2 epochs after the current epoch for rewards"
cardano-cli query tip --testnet-magic 42
echo "!!!!!!!!!!!!"
echo ""
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 "Staking script payment address"
echo "$scriptpaymentaddrwithstakecred"
echo ""
echo "If a staking script address is displayed after this message, the registration of the Plutus staking script was successful"
echo "$stakingscriptaddr"
echo ""
echo "Use the following command to check when rewards have been paid to the staking script address"
echo ""
echo "cardano-cli query stake-address-info --testnet-magic 42 --address $stakingscriptaddr"