Skip to content

Commit

Permalink
Merge branch 'master' into dcmt/sonic-amms
Browse files Browse the repository at this point in the history
  • Loading branch information
duncancmt committed Dec 18, 2024
2 parents c02c5db + 240bc91 commit f63ad92
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 129 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ Master list of UniV3 forks:
* Add SolidlyV3 UniV3 fork to Sonic
* Add Wagmi UniV3 fork to Sonic

## 2024-12-18

### Breaking changes

### Non-breaking changes

* Deploy Settler to Ink chain
* Add UniswapV3 UniV3 fork to Ink

## 2024-12-14

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ your integration.

* `0x0000000000001fF3684f28c67538d4D072C22734` on chains supporting the Cancun
hardfork (Ethereum Mainnet, Ethereum Sepolia, Polygon, Base, Optimism,
Arbitrum, Blast, Bnb, Mode, World Chain, Gnosis, Fantom Sonic)
Arbitrum, Blast, Bnb, Mode, World Chain, Gnosis, Fantom Sonic, Ink)
* `0x0000000000005E88410CcDFaDe4a5EfaE4b49562` on chains supporting the Shanghai
hardfork (Avalanche, Scroll, Mantle, Taiko)
* `0x000000000000175a8b9bC6d539B3708EEd92EA6c` on chains supporting the London
Expand Down
3 changes: 3 additions & 0 deletions api_secrets.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
"sonic": {
"etherscanKey": "",
"rpcUrl": ""
},
"ink": {
"rpcUrl": ""
}
}
26 changes: 26 additions & 0 deletions chain_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,31 @@
"deployer": "0x00000000000004533Fe15556B1E086BB1A72cEae"
},
"etherscanApi": "https://api.sonicscan.org/api"
},
"ink": {
"chainId": 57073,
"displayName": "Ink",
"isShanghai": true,
"isCancun": true,
"extraFlags": "--legacy",
"gasMultiplierPercent": 200,
"minGasPriceGwei": 1,
"safe": {
"singleton": "0xfb1bffC9d739B8D520DaF37dF666da4C687191EA",
"factory": "0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC",
"fallback": "0x017062a1dE2FE6b99BE3d9d37841FeD19F573804",
"multiCall": "0xA1dabEF33b3B82c7814B6D82A79e50F4AC44102B",
"apiUrl": "https://safe-transaction-ink.safe.global/api"
},
"governance": {
"upgradeSafe": "0xf36b9f50E59870A24F42F9Ba43b2aD0A4b8f2F51",
"deploymentSafe": "0x8E5DE7118a596E99B0563D3022039c11927f4827",
"pause": "0x1CeC01DC0fFEE5eB5aF47DbEc1809F2A7c601C30"
},
"deployment": {
"deployer": "0x00000000000004533Fe15556B1E086BB1A72cEae",
"allowanceHolder": "0x0000000000001fF3684f28c67538d4D072C22734"
},
"blockscoutApi": "https://explorer.inkonchain.com/api"
}
}
4 changes: 3 additions & 1 deletion script/SafeConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ library SafeConfig {
|| block.chainid == 34443 // mode
|| block.chainid == 42161 // arbitrum
|| block.chainid == 43114 // avalanche
|| block.chainid == 57073 // ink
|| block.chainid == 59144 // linea
|| block.chainid == 81457 // blast
|| block.chainid == 167000 // taiko
Expand All @@ -49,6 +50,7 @@ library SafeConfig {
|| block.chainid == 34443 // mode
|| block.chainid == 42161 // arbitrum
|| block.chainid == 43114 // avalanche
|| block.chainid == 57073 // ink
|| block.chainid == 59144 // linea
|| block.chainid == 81457 // blast
|| block.chainid == 167000 // taiko
Expand Down Expand Up @@ -86,7 +88,7 @@ library SafeConfig {
result[0] = 0x24420bC8C760787F3eEF3b809e81f44d31a9c5A2; // Jacob
result[1] = 0x000000c397124D0375555F435e201F83B636C26C; // Kyu
result[2] = 0x6879fAb591ed0d62537A3Cac9D7cd41218445a84; // Sav
result[3] = 0x755588A2422E4779aC30cBD3774BBB12521d2c15; // Josh
result[3] = 0x052809d05DC83F317b2f578710411e6cbF88AC5a; // Josh
result[4] = 0xDCa4ee0070b4aa44b30D8af22F3CBbb2cC859dAf; // Kevin
result[5] = 0xD6B66609E5C05210BE0A690aB3b9788BA97aFa60; // Duncan
result[6] = 0xEC3E1F7aC9Df42c31570b02068f2e7500915e557; // Andy
Expand Down
24 changes: 15 additions & 9 deletions sh/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,26 @@ function get_config {
jq -Mr ."$chain_name"."$1" < "$project_root"/chain_config.json
}

if [[ $(get_config isShanghai) != [Tt]rue ]] ; then
echo 'Chains without the Shanghai hardfork (PUSH0) are not supported' >&2
exit 1
fi
if [[ ${IGNORE_HARDFORK-no} != [Yy]es ]] ; then
if [[ $(get_config isShanghai) != [Tt]rue ]] ; then
echo 'Chains without the Shanghai hardfork (PUSH0) are not supported' >&2
exit 1
fi

if [[ $(get_config isCancun) != [Tt]rue ]] ; then
echo 'You are on the wrong branch' >&2
exit 1
if [[ $(get_config isCancun) != [Tt]rue ]] ; then
echo 'You are on the wrong branch' >&2
exit 1
fi
fi

declare -i chainid
chainid="$(get_config chainId)"
declare -r -i chainid

declare chain_display_name
chain_display_name="$(get_config displayName)"
declare -r chain_display_name

declare rpc_url
rpc_url="$(get_api_secret rpcUrl)"
declare -r rpc_url
Expand All @@ -81,12 +87,12 @@ function verify_contract {
declare -r _verify_source_path="$1"
shift

if (( chainid == 34443 )) ; then # Mode uses Blockscout, not Etherscan
if (( chainid == 34443 )) || (( chainid == 57073 )) ; then # Mode and Ink use Blockscout, not Etherscan
forge verify-contract --watch --chain $chainid --verifier blockscout --verifier-url "$(get_config blockscoutApi)" --constructor-args "$_verify_constructor_args" "$_verify_deployed_address" "$_verify_source_path"
else
forge verify-contract --watch --chain $chainid --verifier custom --verifier-api-key "$(get_api_secret etherscanKey)" --verifier-url "$(get_config etherscanApi)" --constructor-args "$_verify_constructor_args" "$_verify_deployed_address" "$_verify_source_path"
fi
if (( chainid != 146 )) && (( chainid != 480 )) && (( chainid != 81457 )) && (( chainid != 167000 )); then # Sourcify doesn't support Sonic, World Chain, Blast, or Taiko
if (( chainid != 146 )) && (( chainid != 480 )) && (( chainid != 57073 )) && (( chainid != 81457 )) && (( chainid != 167000 )); then # Sourcify doesn't support Sonic, World Chain, Blast, Taiko, or Ink
forge verify-contract --watch --chain $chainid --verifier sourcify --constructor-args "$_verify_constructor_args" "$_verify_deployed_address" "$_verify_source_path"
fi
}
8 changes: 0 additions & 8 deletions sh/common_deploy_settler.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
declare chain_display_name
chain_display_name="$(get_config displayName)"
declare -r chain_display_name

forge clean
declare flat_taker_source
flat_taker_source="$project_root"/src/flat/"$chain_display_name"TakerSubmittedFlat.sol
Expand Down Expand Up @@ -84,7 +80,3 @@ if [[ -n "${deployer_address-}" ]] ; then
)
fi
fi

declare safe_url
safe_url="$(get_config safe.apiUrl)"
declare -r safe_url
74 changes: 71 additions & 3 deletions sh/common_safe.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

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

declare multicall_address
multicall_address="$(get_config safe.multiCall)"
declare -r multicall_address
Expand All @@ -13,6 +18,42 @@ nonce() {
echo $((${SAFE_NONCE_INCREMENT:-0} + current_safe_nonce))
}

declare -r get_owners_sig='getOwners()(address[])'
declare owners
owners="$(cast call --rpc-url "$rpc_url" "$safe_address" "$get_owners_sig")"
owners="${owners:1:$((${#owners} - 2))}"
owners="${owners//, /;}"
declare -r owners

declare -a owners_array
IFS=';' read -r -a owners_array <<<"$owners"
declare -r -a owners_array

prev_owner() {
declare inp="$1"
shift
inp="$(cast to-checksum "$inp")"
declare -r inp

declare result=0x0000000000000000000000000000000000000001
declare owner_i
for i in ${!owners_array[@]} ; do
owner_i="$(cast to-checksum "${owners_array[$i]}")"
if [[ $owner_i = "$inp" ]] ; then
break
fi
result="$owner_i"
done
declare -r result

if [[ $result = "$(cast to-checksum "${owners_array[$((${#owners_array} - 1))]}")" ]] ; then
echo 'Old owner "'"$inp"'" not found' >&2
return 1
fi

echo "$result"
}

target() {
declare -i operation
if (( $# > 0 )) ; then
Expand Down Expand Up @@ -64,6 +105,15 @@ eip712_json() {
fi
declare -r -i operation

declare to
if (( $# > 0 )) ; then
to="$1"
shift
else
to="$(target $operation)"
fi
declare -r to

jq -Mc \
'
{
Expand Down Expand Up @@ -132,7 +182,7 @@ eip712_json() {
' \
--arg verifyingContract "$safe_address" \
--arg chainId "$chainid" \
--arg to "$(target $operation)" \
--arg to "$to" \
--arg data "$calldata" \
--arg operation $operation \
--arg nonce $(nonce) \
Expand All @@ -152,7 +202,16 @@ eip712_struct_hash() {
fi
declare -r -i operation

cast keccak "$(cast abi-encode 'foo(bytes32,address,uint256,bytes32,uint8,uint256,uint256,uint256,address,address,uint256)' "$type_hash" "$(target $operation)" 0 "$(cast keccak "$calldata")" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" $(nonce))"
declare to
if (( $# > 0 )) ; then
to="$1"
shift
else
to="$(target $operation)"
fi
declare -r to

cast keccak "$(cast abi-encode 'foo(bytes32,address,uint256,bytes32,uint8,uint256,uint256,uint256,address,address,uint256)' "$type_hash" "$to" 0 "$(cast keccak "$calldata")" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" $(nonce))"
}

eip712_hash() {
Expand All @@ -168,8 +227,17 @@ eip712_hash() {
fi
declare -r -i operation

declare to
if (( $# > 0 )) ; then
to="$1"
shift
else
to="$(target $operation)"
fi
declare -r to

declare struct_hash
struct_hash="$(eip712_struct_hash "$calldata" $operation)"
struct_hash="$(eip712_struct_hash "$calldata" $operation "$to")"

cast keccak "$(cast concat-hex '0x1901' "$domain_separator" "$struct_hash")"
}
Expand Down
63 changes: 63 additions & 0 deletions sh/common_safe_deployer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
retrieve_signatures() {
declare -r _retrieve_signatures_prefix="$1"
shift

declare -r _retrieve_signatures_call="$1"
shift

declare -i _retrieve_signatures_operation
if (( $# > 0 )) ; then
_retrieve_signatures_operation="$1"
shift
else
_retrieve_signatures_operation=0
fi
declare -r -i _retrieve_signatures_operation

declare _retrieve_signatures_to
if (( $# > 0 )) ; then
_retrieve_signatures_to="$1"
shift
else
_retrieve_signatures_to="$(target $_retrieve_signatures_operation)"
fi
declare -r _retrieve_signatures_to

declare signing_hash
signing_hash="$(eip712_hash "$_retrieve_signatures_call" $_retrieve_signatures_operation "$_retrieve_signatures_to")"
declare -r signing_hash

declare -a _retrieve_signatures_result
if [[ $safe_url = 'NOT SUPPORTED' ]] ; then
set +f
declare confirmation
for confirmation in "$project_root"/"$_retrieve_signatures_prefix"_"$chain_display_name"_"$(git rev-parse --short=8 HEAD)"_*_$(nonce).txt ; do
signatures+=("$(<"$confirmation")")
done
set -f

if (( ${#signatures[@]} != 2 )) ; then
echo 'Bad number of signatures' >&2
return 1
fi
else
declare signatures_json
signatures_json="$(curl --fail -s "$safe_url"'/v1/multisig-transactions/'"$signing_hash"'/confirmations/?executed=false' -X GET)"
declare -r signatures_json

if (( $(jq -Mr .count <<<"$signatures_json") != 2 )) ; then
echo 'Bad number of signatures' >&2
return 1
fi

if [ "$(jq -Mr '.results[1].owner' <<<"$signatures_json" | tr '[:upper:]' '[:lower:]')" \< "$(jq -Mr '.results[0].owner' <<<"$signatures_json" | tr '[:upper:]' '[:lower:]')" ] ; then
signatures+=( "$(jq -Mr '.results[1].signature' <<<"$signatures_json")" )
signatures+=( "$(jq -Mr '.results[0].signature' <<<"$signatures_json")" )
else
signatures+=( "$(jq -Mr '.results[0].signature' <<<"$signatures_json")" )
signatures+=( "$(jq -Mr '.results[1].signature' <<<"$signatures_json")" )
fi
fi

cast concat-hex "${signatures[@]}"
}
Loading

0 comments on commit f63ad92

Please sign in to comment.