Skip to content

Commit

Permalink
Automatically determine the CREATE3 Factory address (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 authored Jul 8, 2024
1 parent 0d0e931 commit b9dcf9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/global.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"create3Factory": {
"default": "0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1",
"linea": "0x8437A5fE47A4Df14700c96DF1870824e72FA8499",
"metis": "0x763f212f355433C59d734C71247d16fCE74D8785"
},
"refundWallet": "0x156CeBba59DEB2cB23742F70dCb0a11cC775591F",
"withdrawWallet": "0x08647cc950813966142A416D40C382e2c5DB73bB",
"lifuelRebalanceWallet": "0xC71284231A726A18ac85c94D75f9fe17A185BeAF",
Expand Down
7 changes: 5 additions & 2 deletions script/deploy/deploySingleContract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ deploySingleContract() {
# prepare bytecode
BYTECODE=$(getBytecodeFromArtifact "$CONTRACT")

# if selected contract is "LiFiDiamondImmutable" then use an adjusted salt for deployment to prevent clashes due to same bytecode
# get CREATE3_FACTORY_ADDRESS
CREATE3_FACTORY_ADDRESS=$(getCreate3FactoryAddress "$NETWORK")

echo $CREATE3_FACTORY_ADDRESS # if selected contract is "LiFiDiamondImmutable" then use an adjusted salt for deployment to prevent clashes due to same bytecode
if [[ $CONTRACT == "LiFiDiamondImmutable" ]]; then
# adds a string to the end of the bytecode to alter the salt but always produce deterministic results based on bytecode
BYTECODE="$BYTECODE""ffffffffffffffffffffffffffffffffffffff"
Expand Down Expand Up @@ -189,7 +192,7 @@ deploySingleContract() {
doNotContinueUnlessGasIsBelowThreshold "$NETWORK"

# try to execute call
RAW_RETURN_DATA=$(DEPLOYSALT=$DEPLOYSALT NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX DEFAULT_DIAMOND_ADDRESS_DEPLOYSALT=$DEFAULT_DIAMOND_ADDRESS_DEPLOYSALT DEPLOY_TO_DEFAULT_DIAMOND_ADDRESS=$DEPLOY_TO_DEFAULT_DIAMOND_ADDRESS PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") DIAMOND_TYPE=$DIAMOND_TYPE forge script "$FULL_SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy)
RAW_RETURN_DATA=$(DEPLOYSALT=$DEPLOYSALT CREATE3_FACTORY_ADDRESS=$CREATE3_FACTORY_ADDRESS NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX DEFAULT_DIAMOND_ADDRESS_DEPLOYSALT=$DEFAULT_DIAMOND_ADDRESS_DEPLOYSALT DEPLOY_TO_DEFAULT_DIAMOND_ADDRESS=$DEPLOY_TO_DEFAULT_DIAMOND_ADDRESS PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") DIAMOND_TYPE=$DIAMOND_TYPE forge script "$FULL_SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy)
RETURN_CODE=$?

# print return data only if debug mode is activated
Expand Down
13 changes: 13 additions & 0 deletions script/helperFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source .env
# load script
source script/config.sh



ZERO_ADDRESS=0x0000000000000000000000000000000000000000
RED='\033[0;31m' # Red color
GREEN='\033[0;32m' # Green color
Expand Down Expand Up @@ -2871,6 +2873,17 @@ function getChainId() {
esac

}

function getCreate3FactoryAddress() {
NETWORK="$1"
local CONFIG="config/global.json"

CREATE3_FACTORY=$(jq --arg NETWORK "$NETWORK" -r '.create3Factory[$NETWORK] // .create3Factory["default"]' $CONFIG)

echo $CREATE3_FACTORY
}


function printDeploymentsStatus() {
# read function arguments into variables
ENVIRONMENT="$1"
Expand Down

0 comments on commit b9dcf9d

Please sign in to comment.