Skip to content

Commit

Permalink
Some more DRY from #273
Browse files Browse the repository at this point in the history
  • Loading branch information
duncancmt committed Dec 18, 2024
1 parent 240bc91 commit 8f7aab2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 156 deletions.
1 change: 0 additions & 1 deletion sh/common_safe.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

declare safe_url
safe_url="$(get_config safe.apiUrl)"
declare -r safe_url
Expand Down
66 changes: 2 additions & 64 deletions sh/confirm_new_feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,70 +207,8 @@ declare struct_json
struct_json="$(eip712_json "$new_feature_calldata" 1)"
declare -r struct_json

# sign the message
declare signature
if [[ $wallet_type = 'frame' ]] ; then
declare typedDataRPC
typedDataRPC="$(
jq -Mc \
'
{
"jsonrpc": "2.0",
"method": "eth_signTypedData",
"params": [
$signer,
.
],
"id": 1
}
' \
--arg signer "$signer" \
<<<"$struct_json"
)"
declare -r typedDataRPC
signature="$(curl --fail -s -X POST --url 'http://127.0.0.1:1248' --data "$typedDataRPC")"
if [[ $signature = *error* ]] ; then
echo "$signature" >&2
exit 1
fi
signature="$(jq -Mr .result <<<"$signature")"
else
signature="$(cast wallet sign "${wallet_args[@]}" --from "$signer" --data "$struct_json")"
fi
signature="$(sign_call "$struct_json")"
declare -r signature

declare signing_hash
signing_hash="$(eip712_hash "$new_feature_calldata" 1)"
declare -r signing_hash

declare multicall_address
multicall_address="$(get_config safe.multiCall)"
declare -r multicall_address

# encode the Safe Transaction Service API call
declare safe_multisig_transaction
safe_multisig_transaction="$(
jq -Mc \
"$eip712_message_json_template"',
"contractTransactionHash": $signing_hash,
"sender": $sender,
"signature": $signature,
"origin": "0xSettlerCLI"
}
' \
--arg to "$multicall_address" \
--arg data "$new_feature_calldata" \
--arg operation 1 \
--arg nonce "$nonce" \
--arg signing_hash "$signing_hash" \
--arg sender "$signer" \
--arg signature "$signature" \
--arg safe_address "$safe_address" \
<<<'{}'
)"
declare -r safe_multisig_transaction

# call the API
curl --fail -s "$(get_config safe.apiUrl)"'/v1/safes/'"$safe_address"'/multisig-transactions/' -X POST -H 'Content-Type: application/json' --data "$safe_multisig_transaction"

echo 'Signature submitted' >&2
save_signature new_feature "$new_feature_calldata" "$signature" 1
24 changes: 6 additions & 18 deletions sh/submit_deployer_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ safe_address="$(get_config governance.upgradeSafe)"
declare -r safe_address

. "$project_root"/sh/common_safe.sh
. "$project_root"/sh/common_safe_deployer.sh

if [[ $(get_config safe.apiUrl) != 'NOT SUPPORTED' ]] ; then
if [[ $safe_url != 'NOT SUPPORTED' ]] ; then
echo 'Just use the safe dApp' >&2
echo 'Why are you running this script?' >&2
exit 1
Expand All @@ -142,26 +143,13 @@ new_implementation="$1"
declare -r new_implementation
shift

declare -a signatures=()
set +f
for confirmation in "$project_root"/deployer_upgrade_"$(get_config displayName)"_"$(git rev-parse --short=8 HEAD)"_"$new_implementation"_*_"$(nonce)".txt ; do
signatures+=("$(<"$confirmation")")
done
set -f
declare -r -a signatures

if (( ${#signatures[@]} != 2 )) ; then
echo 'Bad number of signatures' >&2
exit 1
fi

declare packed_signatures
packed_signatures="$(cast concat-hex "${signatures[@]}")"
declare -r packed_signatures

declare upgrade_calldata
upgrade_calldata="$(cast calldata 'upgradeAndCall(address,bytes)' "$new_implementation" "$(cast calldata 'initialize(address)' "$(cast address-zero)")")"
declare -r upgrade_calldata

declare packed_signatures
packed_signatures="$(retrieve_signatures deployer_upgrade "$upgrade_calldata")"
declare -r packed_signatures

cast send --rpc-url 'http://127.0.0.1:1248' --chain $chainid --confirmations 10 --from 0xEf37aD2BACD70119F141140f7B5E46Cd53a65fc4 --unlocked $(get_config extraFlags) "$safe_address" \
"$execTransaction_sig" "$deployer_address" 0 "$upgrade_calldata" 0 0 0 0 "$(cast address-zero)" "$(cast address-zero)" "$packed_signatures"
75 changes: 2 additions & 73 deletions sh/upgrade_deployer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,80 +223,9 @@ if [[ ${1:-unset} = 'confirm' ]] ; then
struct_json="$(eip712_json "$upgrade_calldata")"
declare -r struct_json

# sign the message
declare signature
if [[ $wallet_type = 'frame' ]] ; then
declare typedDataRPC
typedDataRPC="$(
jq -Mc \
'
{
"jsonrpc": "2.0",
"method": "eth_signTypedData",
"params": [
$signer,
.
],
"id": 1
}
' \
--arg signer "$signer" \
<<<"$struct_json"
)"
declare -r typedDataRPC
signature="$(curl --fail -s -X POST --url 'http://127.0.0.1:1248' --data "$typedDataRPC")"
if [[ $signature = *error* ]] ; then
echo "$signature" >&2
exit 1
fi
signature="$(jq -Mr .result <<<"$signature")"
else
signature="$(cast wallet sign "${wallet_args[@]}" --from "$signer" --data "$struct_json")"
fi
signature="$(sign_call "$struct_json")"
declare -r signature

declare safe_url
safe_url="$(get_config safe.apiUrl)"
declare -r safe_url

if [[ $safe_url = 'NOT SUPPORTED' ]] ; then
declare signature_file
signature_file="$project_root"/deployer_upgrade_"$(get_config displayName)"_"$(git rev-parse --short=8 HEAD)"_"$deployed_address"_"$(tr '[:upper:]' '[:lower:]' <<<"$signer")"_"$(nonce)".txt
declare -r signature_file
echo "$signature" >"$signature_file"
echo "Signature saved to '$signature_file'" >&2
exit 0
fi

declare signing_hash
signing_hash="$(eip712_hash "$upgrade_calldata")"
declare -r signing_hash

# encode the Safe Transaction Service API call
declare safe_multisig_transaction
safe_multisig_transaction="$(
jq -Mc \
"$eip712_message_json_template"',
"contractTransactionHash": $signing_hash,
"sender": $sender,
"signature": $signature,
"origin": "0xSettlerCLI"
}
' \
--arg to "$deployer_address" \
--arg data "$upgrade_calldata" \
--arg operation 0 \
--arg nonce "$(nonce)" \
--arg signing_hash "$signing_hash" \
--arg sender "$signer" \
--arg signature "$signature" \
--arg safe_address "$safe_address" \
<<<'{}'
)"
declare -r safe_multisig_transaction

# call the API
curl --fail -s "$safe_url"'/v1/safes/'"$safe_address"'/multisig-transactions/' -X POST -H 'Content-Type: application/json' --data "$safe_multisig_transaction"

echo 'Signature submitted' >&2
save_signature deployer_upgrade "$upgrade_calldata" "$signature"
fi

0 comments on commit 8f7aab2

Please sign in to comment.