Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy SettlerIntent #312

Merged
merged 13 commits into from
Mar 11, 2025
106 changes: 91 additions & 15 deletions sh/common_deploy_settler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ trap 'trap - EXIT; set +e; rm -f '"$(_escape "$flat_taker_source")"' '"$(_escape
forge flatten -o "$flat_metatx_source" src/chains/"$chain_display_name"/MetaTxn.sol >/dev/null
forge build "$flat_metatx_source"

declare flat_intent_source
flat_intent_source="$project_root"/src/flat/"$chain_display_name"IntentFlat.sol
declare -r flat_intent_source
trap 'trap - EXIT; set +e; rm -f '"$(_escape "$flat_taker_source")"' '"$(_escape "$flat_metatx_source")"' '"$(_escape "$flat_intent_source")" EXIT
forge flatten -o "$flat_intent_source" src/chains/"$chain_display_name"/Intent.sol >/dev/null
forge build "$flat_intent_source"

declare taker_artifact
taker_artifact="$project_root"/out/"$chain_display_name"TakerSubmittedFlat.sol/"$chain_display_name"Settler.json
declare -r taker_artifact
Expand All @@ -21,7 +28,11 @@ declare metatx_artifact
metatx_artifact="$project_root"/out/"$chain_display_name"MetaTxnFlat.sol/"$chain_display_name"SettlerMetaTxn.json
declare -r metatx_artifact

if [ ! -f "$taker_artifact" ] || [ ! -f "$metatx_artifact" ] ; then
declare intent_artifact
intent_artifact="$project_root"/out/"$chain_display_name"IntentFlat.sol/"$chain_display_name"SettlerIntent.json
declare -r intent_artifact

if [ ! -f "$taker_artifact" ] || [ ! -f "$metatx_artifact" ] || [ ! -f "$intent_artifact" ] ; then
echo 'Cannot find '"$chain_display_name"'Settler.json' >&2
exit 1
fi
Expand All @@ -38,6 +49,10 @@ declare metatx_initcode
metatx_initcode="$(cast concat-hex "$(jq -Mr .bytecode.object < "$metatx_artifact")" "$constructor_args")"
declare -r metatx_initcode

declare intent_initcode
intent_initcode="$(cast concat-hex "$(jq -Mr .bytecode.object < "$intent_artifact")" "$constructor_args")"
declare -r intent_initcode

declare -r deploy_sig='deploy(uint128,bytes)(address,uint32)'

declare deploy_taker_calldata
Expand All @@ -48,35 +63,96 @@ declare deploy_metatx_calldata
deploy_metatx_calldata="$(cast calldata "$deploy_sig" 3 "$metatx_initcode")"
declare -r deploy_metatx_calldata

declare deploy_intent_calldata
deploy_intent_calldata="$(cast calldata "$deploy_sig" 4 "$intent_initcode")"
declare -r deploy_intent_calldata

declare next_intent_settler_address
next_intent_settler_address="$(cast call --rpc-url "$rpc_url" "$deployer_address" 'next(uint128)(address)' 4)"
declare -r next_intent_settler_address

declare -a solvers
readarray -t solvers < "$project_root"/sh/solvers.txt
declare -r -a solvers

declare -a setsolver_calldatas
declare setsolver_calldata
declare prev_solver=0x0000000000000000000000000000000000000001
declare solver
for solver in "${solvers[@]}" ; do
setsolver_calldata="$(cast calldata 'setSolver(address,address,bool)' "$prev_solver" "$solver" true)"
setsolver_calldatas+=("$setsolver_calldata")
prev_solver="$solver"
done
unset -v solver
unset -v prev_solver
unset -v setsolver_calldata

if [[ -n "${deployer_address-}" ]] ; then
declare -a deploy_calldatas
if (( chainid == 534352 )) ; then
declare setsolver_calldata
for setsolver_calldata in "${setsolver_calldatas[@]}" ; do
deploy_calldatas+=(
"$(
cast concat-hex \
0x00 \
"$next_intent_settler_address" \
"$(cast to-uint256 0)" \
"$(cast to-uint256 $(( (${#setsolver_calldata} - 2) / 2 )) )" \
"$setsolver_calldata"
)"
)
done
deploy_calldatas=(
0 "$deploy_taker_calldata"
0 "$deploy_metatx_calldata"
# 0 "$deploy_taker_calldata" "$deployer_address"
# 0 "$deploy_metatx_calldata" "$deployer_address"
0 "$deploy_intent_calldata" "$deployer_address"
1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")" "$multicall_address"
)
else
deploy_calldatas=(
"$(
cast concat-hex \
0x00 \
"$deployer_address" \
"$(cast to-uint256 0)" \
"$(cast to-uint256 $(( (${#deploy_taker_calldata} - 2) / 2 )) )" \
"$deploy_taker_calldata"
)"
deploy_calldatas+=(
# "$(
# cast concat-hex \
# 0x00 \
# "$deployer_address" \
# "$(cast to-uint256 0)" \
# "$(cast to-uint256 $(( (${#deploy_taker_calldata} - 2) / 2 )) )" \
# "$deploy_taker_calldata"
# )"
#
# "$(
# cast concat-hex \
# 0x00 \
# "$deployer_address" \
# "$(cast to-uint256 0)" \
# "$(cast to-uint256 $(( (${#deploy_metatx_calldata} - 2) / 2 )) )" \
# "$deploy_metatx_calldata"
# )"

"$(
cast concat-hex \
0x00 \
"$deployer_address" \
"$(cast to-uint256 0)" \
"$(cast to-uint256 $(( (${#deploy_metatx_calldata} - 2) / 2 )) )" \
"$deploy_metatx_calldata"
"$(cast to-uint256 $(( (${#deploy_intent_calldata} - 2) / 2 )) )" \
"$deploy_intent_calldata"
)"
)
for setsolver_calldata in "${setsolver_calldatas[@]}" ; do
deploy_calldatas+=(
"$(
cast concat-hex \
0x00 \
"$next_intent_settler_address" \
"$(cast to-uint256 0)" \
"$(cast to-uint256 $(( (${#setsolver_calldata} - 2) / 2 )) )" \
"$setsolver_calldata"
)"
)
done
deploy_calldatas=(
1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")"
1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")" "$multicall_address"
)
fi
fi
9 changes: 5 additions & 4 deletions sh/confirm_new_settler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ declare -r safe_address
. "$project_root"/sh/common_wallet_type.sh
. "$project_root"/sh/common_deploy_settler.sh

while (( ${#deploy_calldatas[@]} >= 2 )) ; do
while (( ${#deploy_calldatas[@]} >= 3 )) ; do
declare -i operation="${deploy_calldatas[0]}"
declare deploy_calldata="${deploy_calldatas[1]}"
deploy_calldatas=( "${deploy_calldatas[@]:2:$((${#deploy_calldatas[@]}-2))}" )
declare target="${deploy_calldatas[2]}"
deploy_calldatas=( "${deploy_calldatas[@]:3:$((${#deploy_calldatas[@]}-3))}" )

declare struct_json
struct_json="$(eip712_json "$deploy_calldata" $operation)"
struct_json="$(eip712_json "$deploy_calldata" $operation "$target")"

declare signature
signature="$(sign_call "$struct_json")"

save_signature settler_confirmation "$deploy_calldata" "$signature" $operation
save_signature settler_confirmation "$deploy_calldata" "$signature" $operation "$target"

SAFE_NONCE_INCREMENT=$((${SAFE_NONCE_INCREMENT:-0} + 1))
done
12 changes: 5 additions & 7 deletions sh/deploy_new_settler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,20 @@ declare -i gas_estimate_multiplier
gas_estimate_multiplier="$(get_config gasMultiplierPercent)"
declare -r -i gas_estimate_multiplier

while (( ${#deploy_calldatas[@]} >= 2 )) ; do
while (( ${#deploy_calldatas[@]} >= 3 )) ; do
declare -i operation="${deploy_calldatas[0]}"
declare deploy_calldata="${deploy_calldatas[1]}"
deploy_calldatas=( "${deploy_calldatas[@]:2:$((${#deploy_calldatas[@]}-2))}" )

declare signing_hash
signing_hash="$(eip712_hash "$deploy_calldata" $operation)"
declare target="${deploy_calldatas[2]}"
deploy_calldatas=( "${deploy_calldatas[@]:3:$((${#deploy_calldatas[@]}-3))}" )

declare packed_signatures
packed_signatures="$(retrieve_signatures settler_confirmation "$deploy_calldata" $operation)"
packed_signatures="$(retrieve_signatures settler_confirmation "$deploy_calldata" $operation "$target")"

# configure gas limit
declare -a args=(
"$safe_address" "$execTransaction_sig"
# to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, signatures
"$(target $operation)" 0 "$deploy_calldata" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" "$packed_signatures"
"$target" 0 "$deploy_calldata" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" "$packed_signatures"
)

# set gas limit and add multiplier/headroom (again mostly for Arbitrum)
Expand Down
163 changes: 163 additions & 0 deletions sh/generate_solvers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env bash

## POSIX Bash implementation of realpath
## Copied and modified from https://github.com/mkropat/sh-realpath and https://github.com/AsymLabs/realpath-lib/
## Copyright (c) 2014 Michael Kropat - MIT License
## Copyright (c) 2013 Asymmetry Laboratories - MIT License

function realpath {
_resolve_symlinks "$(_canonicalize "$1")"
}

function _directory {
local out slsh
slsh=/
out="$1"
out="${out//$slsh$slsh/$slsh}"
if [ "$out" = / ]; then
echo /
return
fi
out="${out%/}"
case "$out" in
*/*)
out="${out%/*}"
;;
*)
out=.
;;
esac
if [ "$out" ]; then
printf '%s\n' "$out"
else
echo /
fi
}

function _file {
local out slsh
slsh=/
out="$1"
out="${out//$slsh$slsh/$slsh}"
if [ "$out" = / ]; then
echo /
return
fi
out="${out%/}"
out="${out##*/}"
printf '%s\n' "$out"
}

function _resolve_symlinks {
local path pattern context
while [ -L "$1" ]; do
context="$(_directory "$1")"
path="$(POSIXLY_CORRECT=y ls -ld -- "$1" 2>/dev/null)"
pattern='*'"$(_escape "$1")"' -> '
path="${path#$pattern}"
set -- "$(_canonicalize "$(_prepend_context "$context" "$path")")" "$@"
_assert_no_path_cycles "$@" || return 1
done
printf '%s\n' "$1"
}

function _escape {
local out
out=''
local -i i
for ((i=0; i < ${#1}; i+=1)); do
out+='\'"${1:$i:1}"
done
printf '%s\n' "$out"
}

function _prepend_context {
if [ "$1" = . ]; then
printf '%s\n' "$2"
else
case "$2" in
/* ) printf '%s\n' "$2" ;;
* ) printf '%s\n' "$1/$2" ;;
esac
fi
}

function _assert_no_path_cycles {
local target path

if [ $# -gt 16 ]; then
return 1
fi

target="$1"
shift

for path in "$@"; do
if [ "$path" = "$target" ]; then
return 1
fi
done
}

function _canonicalize {
local d f
if [ -d "$1" ]; then
(CDPATH= cd -P "$1" 2>/dev/null && pwd -P)
else
d="$(_directory "$1")"
f="$(_file "$1")"
(CDPATH= cd -P "$d" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$f")
fi
}

## end POSIX Bash implementation of realpath

set -Eeufo pipefail -o posix

declare project_root
project_root="$(_directory "$(_directory "$(realpath "${BASH_SOURCE[0]}")")")"
declare -r project_root
cd "$project_root"

echo "This script is mostly for Duncan's use in generating the file solvers.txt ." >&2
echo "You probably don't need to run this script." >&2
echo "The only reason you'd need to run this script is if the production or staging" >&2
echo 'chain worker mnemonics have been rotated.' >&2
echo '' >&2

. "$project_root"/sh/common.sh
. "$project_root"/sh/common_secrets.sh

declare -i num_production_addresses
num_production_addresses="$(get_secret intentWorkers limit.production)"
declare -r -i num_production_addresses

declare production_mnemonic
production_mnemonic="$(get_secret intentWorkers mnemonic.production)"
declare -r production_mnemonic

declare -i num_staging_addresses
num_staging_addresses="$(get_secret intentWorkers limit.staging)"
declare -r -i num_staging_addresses

declare staging_mnemonic
staging_mnemonic="$(get_secret intentWorkers mnemonic.staging)"
declare -r staging_mnemonic

declare -a solvers=()
declare privkey
declare solver

for (( i = 0 ; i < $num_production_addresses ; i++ )) ; do
privkey="$(cast wallet private-key "$production_mnemonic" "m/44'/60'/0'/0/$i")"
solver="$(cast wallet address "$privkey")"
solvers+=("$solver")
done

for (( i = 0 ; i < $num_staging_addresses ; i++ )) ; do
privkey="$(cast wallet private-key "$staging_mnemonic" "m/44'/60'/0'/0/$i")"
solver="$(cast wallet address "$privkey")"
solvers+=("$solver")
done

printf '%s\n' "${solvers[@]}"
Loading