Skip to content

Commit

Permalink
flag added to allow zeroAddress (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEnYO authored Feb 11, 2025
1 parent 9c1a481 commit 038d342
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 18 deletions.
1 change: 1 addition & 0 deletions script/deploy/facets/DeployArbitrumBridgeFacet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract DeployScript is DeployScriptBase {
path,
string.concat(".", network, ".gatewayRouter")
);

address inbox = _getConfigContractAddress(
path,
string.concat(".", network, ".inbox")
Expand Down
1 change: 1 addition & 0 deletions script/deploy/facets/DeployCelerCircleBridgeFacet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract DeployScript is DeployScriptBase {
path,
string.concat(".", network, ".circleBridgeProxy")
);

address usdc = _getConfigContractAddress(
path,
string.concat(".", network, ".usdc")
Expand Down
4 changes: 2 additions & 2 deletions script/deploy/facets/DeployGenericSwapFacetV3.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ contract DeployScript is DeployScriptBase {
function getConstructorArgs() internal override returns (bytes memory) {
// get path of global config file
string memory path = string.concat(root, "/config/networks.json");
string memory json = vm.readFile(path);

// extract network's native address
address nativeAddress = _getConfigContractAddress(
path,
address nativeAddress = json.readAddress(
string.concat(".", network, ".nativeAddress")
);

Expand Down
12 changes: 6 additions & 6 deletions script/deploy/facets/DeployReceiver.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ contract DeployScript is DeployScriptBase {
".refundWallet"
);

// obtain address of Stargate router in current network from config file
// obtain address of Stargate router in current network from config file (may be address(0), if stargate is not available on this chain)
string memory path = string.concat(root, "/config/stargate.json");

address stargateRouter = _getConfigContractAddress(
path,
string.concat(".composers.", network)
string.concat(".composers.", network),
true
);

// obtain address of Amarok router in current network from config file
// obtain address of Amarok router in current network from config file (may be address(0), if amarok is not available on this chain)
path = string.concat(root, "/config/amarok.json");

address amarokRouter = _getConfigContractAddress(
path,
string.concat(".", network, ".connextHandler")
string.concat(".", network, ".connextHandler"),
true
);

path = string.concat(
Expand Down
6 changes: 4 additions & 2 deletions script/deploy/facets/DeployRelayFacet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ contract DeployScript is DeployScriptBase {

function getConstructorArgs() internal override returns (bytes memory) {
string memory path = string.concat(root, "/config/relay.json");
string memory json = vm.readFile(path);

address relayReceiver = _getConfigContractAddress(
path,
string.concat(".", network, ".relayReceiver")
);
address relaySolver = _getConfigContractAddress(
path,

// the relaySolver address is the same address on all mainnets (and it's not a contract)
address relaySolver = json.readAddress(
string.concat(".", network, ".relaySolver")
);

Expand Down
25 changes: 24 additions & 1 deletion script/deploy/facets/utils/ScriptBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,40 @@ contract ScriptBase is Script, DSTest {
fileSuffix = vm.envString("FILE_SUFFIX");
}

// reads an address from a config file and makes sure that the address contains code
// reads an address from a config file and makes sure that the address contains code, it will not check for contract and still return the address
function _getConfigContractAddress(
string memory path,
string memory key
) internal returns (address contractAddress) {
return _getConfigContractAddress(path, key, false);
}

// reads an address from a config file and makes sure that the address contains code
function _getConfigContractAddress(
string memory path,
string memory key,
bool allowZeroAddress // if zeroAddress is found, it will not check for contract and still return the address
) internal returns (address contractAddress) {
// load json file
string memory json = vm.readFile(path);

// read address
contractAddress = json.readAddress(key);

// only allow address(0) values if flag is set accordingly, otherwise revert
if (contractAddress == address(0))
if (allowZeroAddress) return contractAddress;
else
revert(
string.concat(
"Found address(0) for key ",
key,
" in file ",
path,
" which is not allowed here"
)
);

// check if address contains code
if (!LibAsset.isContract(contractAddress))
revert(
Expand Down
4 changes: 2 additions & 2 deletions script/deploy/zksync/DeployGenericSwapFacetV3.zksync.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ contract DeployScript is DeployScriptBase {
function getConstructorArgs() internal override returns (bytes memory) {
// get path of global config file
string memory path = string.concat(root, "/config/networks.json");
string memory json = vm.readFile(path);

// extract network's native address
address nativeAddress = _getConfigContractAddress(
path,
address nativeAddress = json.readAddress(
string.concat(".", network, ".nativeAddress")
);

Expand Down
6 changes: 4 additions & 2 deletions script/deploy/zksync/DeployReceiver.zksync.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ contract DeployScript is DeployScriptBase {

address stargateRouter = _getConfigContractAddress(
path,
string.concat(".composers.", network)
string.concat(".composers.", network),
true
);

// obtain address of Amarok router in current network from config file
path = string.concat(root, "/config/amarok.json");

address amarokRouter = _getConfigContractAddress(
path,
string.concat(".", network, ".connextHandler")
string.concat(".", network, ".connextHandler"),
true
);

path = string.concat(
Expand Down
6 changes: 4 additions & 2 deletions script/deploy/zksync/DeployRelayFacet.zksync.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ contract DeployScript is DeployScriptBase {

function getConstructorArgs() internal override returns (bytes memory) {
string memory path = string.concat(root, "/config/relay.json");
string memory json = vm.readFile(path);

address relayReceiver = _getConfigContractAddress(
path,
string.concat(".", network, ".relayReceiver")
);
address relaySolver = _getConfigContractAddress(
path,

// the relaySolver address is the same address on all mainnets (and it's not a contract)
address relaySolver = json.readAddress(
string.concat(".", network, ".relaySolver")
);

Expand Down
2 changes: 1 addition & 1 deletion templates/facetDeployScript.template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract DeployScript is DeployScriptBase {
string memory json = vm.readFile(path);

// If you need to read an address from your config file or from a network deploy log that is supposed to be a contract, use the
// following helper function which makes sure that the address contains code:
// following helper function which makes sure that the address contains code (and has a optional flag for allowing address(0)):
//
// address example = _getConfigContractAddress(json,string.concat(".", network, ".example"));
//
Expand Down

0 comments on commit 038d342

Please sign in to comment.