From 1aa1b0f104ac8ed10f73186fc18878cd0782f71e Mon Sep 17 00:00:00 2001 From: Jem <0x0xjem@gmail.com> Date: Thu, 11 Jul 2024 13:16:20 +0400 Subject: [PATCH] Amend salt scripts to work without AtomicAuctionHouse deployment --- script/salts/allowlist/AllowlistSalts.s.sol | 19 ++++----- script/salts/allowlist/allowlist_salts.sh | 41 ++++++++++++++----- .../salts/dtl-uniswap/UniswapDTLSalts.s.sol | 21 ++++++---- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/script/salts/allowlist/AllowlistSalts.s.sol b/script/salts/allowlist/AllowlistSalts.s.sol index 2826dc0e..f10dc13a 100644 --- a/script/salts/allowlist/AllowlistSalts.s.sol +++ b/script/salts/allowlist/AllowlistSalts.s.sol @@ -15,24 +15,23 @@ import {Callbacks} from "src/lib/Callbacks.sol"; contract AllowlistSalts is Script, WithEnvironment, WithSalts { string internal constant _ADDRESS_PREFIX = "98"; - address internal _envAtomicAuctionHouse; - address internal _envBatchAuctionHouse; - function _setUp(string calldata chain_) internal { _loadEnv(chain_); _createBytecodeDirectory(); - - // Cache auction houses - _envAtomicAuctionHouse = _envAddress("deployments.AtomicAuctionHouse"); - console2.log("AtomicAuctionHouse:", _envAtomicAuctionHouse); - _envBatchAuctionHouse = _envAddress("deployments.BatchAuctionHouse"); - console2.log("BatchAuctionHouse:", _envBatchAuctionHouse); } function generate(string calldata chain_, bool atomic_) public { _setUp(chain_); - address auctionHouse = atomic_ ? _envAtomicAuctionHouse : _envBatchAuctionHouse; + address auctionHouse; + if (atomic_) { + auctionHouse = _envAddress("deployments.AtomicAuctionHouse"); + console2.log("AtomicAuctionHouse:", auctionHouse); + } + else { + auctionHouse = _envAddress("deployments.BatchAuctionHouse"); + console2.log("BatchAuctionHouse:", auctionHouse); + } // All of these allowlists have the same permissions and constructor args string memory prefix = "98"; diff --git a/script/salts/allowlist/allowlist_salts.sh b/script/salts/allowlist/allowlist_salts.sh index 7262aad1..d2dfbe0c 100755 --- a/script/salts/allowlist/allowlist_salts.sh +++ b/script/salts/allowlist/allowlist_salts.sh @@ -1,31 +1,50 @@ #!/bin/bash # Usage: -# ./allowlist_salts.sh +# ./allowlist_salts.sh --type --envFile <.env> # # Expects the following environment variables: # CHAIN: The chain to deploy to, based on values from the ./script/env.json file. -# Load environment variables, but respect overrides -curenv=$(declare -p -x) -source .env -eval "$curenv" +# Iterate through named arguments +# Source: https://unix.stackexchange.com/a/388038 +while [ $# -gt 0 ]; do + if [[ $1 == *"--"* ]]; then + v="${1/--/}" + declare $v="$2" + fi -# Get command-line arguments -MODE=$1 + shift +done + +# Get the name of the .env file or use the default +ENV_FILE=${envFile:-".env"} +echo "Sourcing environment variables from $ENV_FILE" + +# Load environment file +set -a # Automatically export all variables +source $ENV_FILE +set +a # Disable automatic export + +# Check that the CHAIN environment variable is set +if [ -z "$CHAIN" ] +then + echo "CHAIN environment variable is not set. Please set it in the .env file or provide it as an environment variable." + exit 1 +fi # Check that the mode is "atomic" or "batch" -if [ "$MODE" != "atomic" ] && [ "$MODE" != "batch" ] +if [ "$type" != "atomic" ] && [ "$type" != "batch" ] then - echo "Invalid mode specified. Provide 'atomic' or 'batch' after the command as argument 2." + echo "Invalid type specified. Provide 'atomic' or 'batch' after the --type flag." exit 1 fi # Set flag for atomic or batch auction -ATOMIC=$( if [ "$MODE" == "atomic" ]; then echo "true"; else echo "false"; fi ) +ATOMIC=$( if [ "$type" == "atomic" ]; then echo "true"; else echo "false"; fi ) echo "Using RPC at URL: $RPC_URL" echo "Using chain: $CHAIN" -echo "Using variant: $MODE" +echo "Using type: $type" forge script ./script/salts/allowlist/AllowListSalts.s.sol:AllowlistSalts --sig "generate(string,bool)()" $CHAIN $ATOMIC diff --git a/script/salts/dtl-uniswap/UniswapDTLSalts.s.sol b/script/salts/dtl-uniswap/UniswapDTLSalts.s.sol index 0121229d..1eec7b8d 100644 --- a/script/salts/dtl-uniswap/UniswapDTLSalts.s.sol +++ b/script/salts/dtl-uniswap/UniswapDTLSalts.s.sol @@ -17,9 +17,6 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { address internal _envUniswapV3Factory; address internal _envGUniFactory; - address internal _envAtomicAuctionHouse; - address internal _envBatchAuctionHouse; - function _setUp(string calldata chain_) internal { _loadEnv(chain_); _createBytecodeDirectory(); @@ -33,12 +30,6 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { console2.log("UniswapV3Factory:", _envUniswapV3Factory); _envGUniFactory = _envAddressNotZero("constants.gUni.factory"); console2.log("GUniFactory:", _envGUniFactory); - - // Cache auction houses - _envAtomicAuctionHouse = _envAddress("deployments.AtomicAuctionHouse"); - console2.log("AtomicAuctionHouse:", _envAtomicAuctionHouse); - _envBatchAuctionHouse = _envAddress("deployments.BatchAuctionHouse"); - console2.log("BatchAuctionHouse:", _envBatchAuctionHouse); } function generate( @@ -60,6 +51,9 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { function _generateV2(bool atomic_) internal { if (atomic_) { + address _envAtomicAuctionHouse = _envAddressNotZero("deployments.AtomicAuctionHouse"); + console2.log("AtomicAuctionHouse:", _envAtomicAuctionHouse); + // Calculate salt for the UniswapV2DirectToLiquidity bytes memory contractCode = type(UniswapV2DirectToLiquidity).creationCode; (string memory bytecodePath, bytes32 bytecodeHash) = _writeBytecode( @@ -69,6 +63,9 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { ); _setSalt(bytecodePath, _ADDRESS_PREFIX, "UniswapV2DirectToLiquidity", bytecodeHash); } else { + address _envBatchAuctionHouse = _envAddressNotZero("deployments.BatchAuctionHouse"); + console2.log("BatchAuctionHouse:", _envBatchAuctionHouse); + // Calculate salt for the UniswapV2DirectToLiquidity bytes memory contractCode = type(UniswapV2DirectToLiquidity).creationCode; (string memory bytecodePath, bytes32 bytecodeHash) = _writeBytecode( @@ -82,6 +79,9 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { function _generateV3(bool atomic_) internal { if (atomic_) { + address _envAtomicAuctionHouse = _envAddressNotZero("deployments.AtomicAuctionHouse"); + console2.log("AtomicAuctionHouse:", _envAtomicAuctionHouse); + // Calculate salt for the UniswapV3DirectToLiquidity bytes memory contractCode = type(UniswapV3DirectToLiquidity).creationCode; (string memory bytecodePath, bytes32 bytecodeHash) = _writeBytecode( @@ -91,6 +91,9 @@ contract UniswapDTLSalts is Script, WithEnvironment, WithSalts { ); _setSalt(bytecodePath, _ADDRESS_PREFIX, "UniswapV3DirectToLiquidity", bytecodeHash); } else { + address _envBatchAuctionHouse = _envAddressNotZero("deployments.BatchAuctionHouse"); + console2.log("BatchAuctionHouse:", _envBatchAuctionHouse); + // Calculate salt for the UniswapV3DirectToLiquidity bytes memory contractCode = type(UniswapV3DirectToLiquidity).creationCode; (string memory bytecodePath, bytes32 bytecodeHash) = _writeBytecode(