Skip to content

Commit

Permalink
Amend salt scripts to work without AtomicAuctionHouse deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJem committed Jul 11, 2024
1 parent 2159201 commit 1aa1b0f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
19 changes: 9 additions & 10 deletions script/salts/allowlist/AllowlistSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
41 changes: 30 additions & 11 deletions script/salts/allowlist/allowlist_salts.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
#!/bin/bash

# Usage:
# ./allowlist_salts.sh <atomic | batch>
# ./allowlist_salts.sh --type <atomic | batch> --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
21 changes: 12 additions & 9 deletions script/salts/dtl-uniswap/UniswapDTLSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 1aa1b0f

Please sign in to comment.