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

feat: add fork activation based on env variables - getting started script update #11500

Merged
merged 9 commits into from
Aug 19, 2024
59 changes: 45 additions & 14 deletions packages/contracts-bedrock/scripts/getting-started/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ reqenv() {
fi
}

append_with_default() {
json_key="$1"
env_var_name="$2"
default_value="$3"
var_value="${!env_var_name}"

if [ -z "$var_value" ] || [ "$var_value" == "None" ]; then
var_value="$default_value"
fi

echo " \"$json_key\": \"$var_value\"," >> tmp_config.json
}

# Check required environment variables
reqenv "GS_ADMIN_ADDRESS"
reqenv "GS_BATCHER_ADDRESS"
Expand All @@ -31,10 +44,12 @@ block=$(cast block finalized --rpc-url "$L1_RPC_URL")
timestamp=$(echo "$block" | awk '/timestamp/ { print $2 }')
blockhash=$(echo "$block" | awk '/hash/ { print $2 }')

# Generate the config file
config=$(cat << EOL
# Start generating the config file in a temporary file

cat << EOL > tmp_config.json
{
"l1StartingBlockTag": "$blockhash",

"l1StartingBlockTag": "$blockhash",

"l1ChainID": $L1_CHAIN_ID,
"l2ChainID": $L2_CHAIN_ID,
Expand Down Expand Up @@ -82,19 +97,36 @@ config=$(cat << EOL

"l2GenesisBlockGasLimit": "0x1c9c380",
"l2GenesisBlockBaseFeePerGas": "0x3b9aca00",
"l2GenesisRegolithTimeOffset": "0x0",
"l2GenesisCanyonTimeOffset": "0x0",
"l2GenesisDeltaTimeOffset": "0x0",
"l2GenesisEcotoneTimeOffset": "0x0",

"eip1559Denominator": 50,
"eip1559DenominatorCanyon": 250,
"eip1559Elasticity": 6,
EOL

"l2GenesisEcotoneTimeOffset": "0x0",
"l2GenesisDeltaTimeOffset": "0x0",
"l2GenesisCanyonTimeOffset": "0x0",

# Append conditional environment variables with their corresponding default values
# Activate granite fork
if [ -n "${GRANITE_TIME_OFFSET}" ]; then
append_with_default "l2GenesisGraniteTimeOffset" "GRANITE_TIME_OFFSET" "0x0"
fi
# Activate holocene fork
if [ -n "${HOLOCENE_TIME_OFFSET}" ]; then
append_with_default "l2GenesisHoloceneTimeOffset" "HOLOCENE_TIME_OFFSET" "0x0"
fi

# Activate the interop fork
if [ -n "${INTEROP_TIME_OFFSET}" ]; then
append_with_default "l2GenesisInteropTimeOffset" "INTEROP_TIME_OFFSET" "0x0"
fi

# Already forked updates
append_with_default "l2GenesisFjordTimeOffset" "FJORD_TIME_OFFSET" "0x0"
append_with_default "l2GenesisRegolithTimeOffset" "REGOLITH_TIME_OFFSET" "0x0"
append_with_default "l2GenesisEcotoneTimeOffset" "ECOTONE_TIME_OFFSET" "0x0"
append_with_default "l2GenesisDeltaTimeOffset" "DELTA_TIME_OFFSET" "0x0"
append_with_default "l2GenesisCanyonTimeOffset" "CANYON_TIME_OFFSET" "0x0"

# Continue generating the config file
cat << EOL >> tmp_config.json
"systemConfigStartBlock": 0,

"requiredProtocolVersion": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand All @@ -113,7 +145,6 @@ config=$(cat << EOL
"preimageOracleChallengePeriod": 86400
}
EOL
)

# Write the config file
echo "$config" > "$CONTRACTS_BASE/deploy-config/getting-started.json"
# Write the final config file
mv tmp_config.json "$CONTRACTS_BASE/deploy-config/getting-started.json"