Commit 82500aa5 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: cleanup

parent a05054d0
...@@ -4,6 +4,7 @@ pragma solidity 0.8.15; ...@@ -4,6 +4,7 @@ pragma solidity 0.8.15;
import { Script } from "forge-std/Script.sol"; import { Script } from "forge-std/Script.sol";
import { console2 as console } from "forge-std/console2.sol"; import { console2 as console } from "forge-std/console2.sol";
import { stdJson } from "forge-std/StdJson.sol"; import { stdJson } from "forge-std/StdJson.sol";
import { Executables } from "./Executables.sol";
/// @title DeployConfig /// @title DeployConfig
/// @notice Represents the configuration required to deploy the system. It is expected /// @notice Represents the configuration required to deploy the system. It is expected
...@@ -92,21 +93,19 @@ contract DeployConfig is Script { ...@@ -92,21 +93,19 @@ contract DeployConfig is Script {
} catch { } catch {
try vm.parseJsonUint(_json, "$.l1StartingBlockTag") returns (uint256 tag) { try vm.parseJsonUint(_json, "$.l1StartingBlockTag") returns (uint256 tag) {
return _getBlockByTag(vm.toString(tag)); return _getBlockByTag(vm.toString(tag));
} catch { } catch {}
revert("cannot fetch l1StartingBlockTag");
}
} }
} }
revert("l1StartingBlockTag must be a bytes32, string or uint256"); revert("l1StartingBlockTag must be a bytes32, string or uint256 or cannot fetch l1StartingBlockTag");
} }
function l2OutputOracleStartingTimestamp() public returns (uint256) { function l2OutputOracleStartingTimestamp() public returns (uint256) {
if (_l2OutputOracleStartingTimestamp < 0) { if (_l2OutputOracleStartingTimestamp < 0) {
bytes32 tag = l1StartingBlockTag(); bytes32 tag = l1StartingBlockTag();
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("cast block ", vm.toString(tag), " --json | jq .timestamp"); cmd[2] = string.concat("cast block ", vm.toString(tag), " --json | ", Executables.jq, " .timestamp");
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return stdJson.readUint(string(res), ""); return stdJson.readUint(string(res), "");
} }
...@@ -115,9 +114,9 @@ contract DeployConfig is Script { ...@@ -115,9 +114,9 @@ contract DeployConfig is Script {
function _getBlockByTag(string memory _tag) internal returns (bytes32) { function _getBlockByTag(string memory _tag) internal returns (bytes32) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("cast block ", _tag, " --json | jq -r .hash"); cmd[2] = string.concat("cast block ", _tag, " --json | ", Executables.jq, " -r .hash");
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return abi.decode(res, (bytes32)); return abi.decode(res, (bytes32));
} }
......
...@@ -4,6 +4,7 @@ pragma solidity 0.8.15; ...@@ -4,6 +4,7 @@ pragma solidity 0.8.15;
import { Script } from "forge-std/Script.sol"; import { Script } from "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol"; import { stdJson } from "forge-std/StdJson.sol";
import { console2 as console } from "forge-std/console2.sol"; import { console2 as console } from "forge-std/console2.sol";
import { Executables } from "./Executables.sol";
/// @notice store the new deployment to be saved /// @notice store the new deployment to be saved
struct Deployment { struct Deployment {
...@@ -232,9 +233,9 @@ abstract contract Deployer is Script { ...@@ -232,9 +233,9 @@ abstract contract Deployer is Script {
function _getTempDeployments() internal returns (Deployment[] memory) { function _getTempDeployments() internal returns (Deployment[] memory) {
string memory json = vm.readFile(tempDeploymentsPath); string memory json = vm.readFile(tempDeploymentsPath);
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq 'keys' <<< '", json, "'"); cmd[2] = string.concat(Executables.jq, " 'keys' <<< '", json, "'");
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
string[] memory names = stdJson.readStringArray(string(res), ""); string[] memory names = stdJson.readStringArray(string(res), "");
...@@ -253,9 +254,9 @@ abstract contract Deployer is Script { ...@@ -253,9 +254,9 @@ abstract contract Deployer is Script {
/// @notice Returns the json of the deployment transaction given a contract address. /// @notice Returns the json of the deployment transaction given a contract address.
function _getDeployTransactionByContractAddress(address _addr) internal returns (string memory) { function _getDeployTransactionByContractAddress(address _addr) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.transactions[] | select(.contractAddress == ", '"', vm.toString(_addr), '"', ") | select(.transactionType == ", '"CREATE"', ")' < ", deployPath); cmd[2] = string.concat(Executables.jq, " -r '.transactions[] | select(.contractAddress == ", '"', vm.toString(_addr), '"', ") | select(.transactionType == ", '"CREATE"', ")' < ", deployPath);
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
...@@ -263,9 +264,9 @@ abstract contract Deployer is Script { ...@@ -263,9 +264,9 @@ abstract contract Deployer is Script {
/// @notice Returns the constructor arguent of a deployment transaction given a transaction json. /// @notice Returns the constructor arguent of a deployment transaction given a transaction json.
function getDeployTransactionConstructorArguments(string memory _transaction) internal returns (string[] memory) { function getDeployTransactionConstructorArguments(string memory _transaction) internal returns (string[] memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.arguments' <<< '", _transaction, "'"); cmd[2] = string.concat(Executables.jq, " -r '.arguments' <<< '", _transaction, "'");
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
string[] memory args = new string[](0); string[] memory args = new string[](0);
...@@ -285,9 +286,9 @@ abstract contract Deployer is Script { ...@@ -285,9 +286,9 @@ abstract contract Deployer is Script {
/// file matches the name of the contract. /// file matches the name of the contract.
function _getForgeArtifactPath(string memory _name) internal returns (string memory) { function _getForgeArtifactPath(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = "forge config --json | jq -r .out"; cmd[2] = string.concat(Executables.forge, " config --json | ", Executables.jq, "-r .out");
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
string memory forgeArtifactPath = string.concat(vm.projectRoot(), "/", string(res), "/", _name, ".sol/", _name, ".json"); string memory forgeArtifactPath = string.concat(vm.projectRoot(), "/", string(res), "/", _name, ".sol/", _name, ".json");
return forgeArtifactPath; return forgeArtifactPath;
...@@ -303,9 +304,9 @@ abstract contract Deployer is Script { ...@@ -303,9 +304,9 @@ abstract contract Deployer is Script {
/// @notice Returns the receipt of a deployment transaction. /// @notice Returns the receipt of a deployment transaction.
function _getDeployReceiptByContractAddress(address addr) internal returns (string memory) { function _getDeployReceiptByContractAddress(address addr) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.receipts[] | select(.contractAddress == ", '"', vm.toString(addr), '"', ")' < ", deployPath); cmd[2] = string.concat(Executables.jq, " -r '.receipts[] | select(.contractAddress == ", '"', vm.toString(addr), '"', ")' < ", deployPath);
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
string memory receipt = string(res); string memory receipt = string(res);
return receipt; return receipt;
...@@ -314,9 +315,9 @@ abstract contract Deployer is Script { ...@@ -314,9 +315,9 @@ abstract contract Deployer is Script {
/// @notice Returns the devdoc for a deployed contract. /// @notice Returns the devdoc for a deployed contract.
function getDevDoc(string memory _name) internal returns (string memory) { function getDevDoc(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.devdoc' < ", _getForgeArtifactPath(_name)); cmd[2] = string.concat(Executables.jq, " -r '.devdoc' < ", _getForgeArtifactPath(_name));
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
...@@ -324,9 +325,9 @@ abstract contract Deployer is Script { ...@@ -324,9 +325,9 @@ abstract contract Deployer is Script {
/// @notice Returns the storage layout for a deployed contract. /// @notice Returns the storage layout for a deployed contract.
function getStorageLayout(string memory _name) internal returns (string memory) { function getStorageLayout(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.storageLayout' < ", _getForgeArtifactPath(_name)); cmd[2] = string.concat(Executables.jq, " -r '.storageLayout' < ", _getForgeArtifactPath(_name));
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
...@@ -334,9 +335,9 @@ abstract contract Deployer is Script { ...@@ -334,9 +335,9 @@ abstract contract Deployer is Script {
/// @notice Returns the abi for a deployed contract. /// @notice Returns the abi for a deployed contract.
function getAbi(string memory _name) internal returns (string memory) { function getAbi(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.abi' < ", _getForgeArtifactPath(_name)); cmd[2] = string.concat(Executables.jq, " -r '.abi' < ", _getForgeArtifactPath(_name));
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
...@@ -344,9 +345,9 @@ abstract contract Deployer is Script { ...@@ -344,9 +345,9 @@ abstract contract Deployer is Script {
/// @notice Returns the userdoc for a deployed contract. /// @notice Returns the userdoc for a deployed contract.
function getUserDoc(string memory _name) internal returns (string memory) { function getUserDoc(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq -r '.userdoc' < ", _getForgeArtifactPath(_name)); cmd[2] = string.concat(Executables.jq, " -r '.userdoc' < ", _getForgeArtifactPath(_name));
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
...@@ -354,9 +355,9 @@ abstract contract Deployer is Script { ...@@ -354,9 +355,9 @@ abstract contract Deployer is Script {
/// @notice /// @notice
function getMetadata(string memory _name) internal returns (string memory) { function getMetadata(string memory _name) internal returns (string memory) {
string[] memory cmd = new string[](3); string[] memory cmd = new string[](3);
cmd[0] = "/usr/bin/bash"; cmd[0] = Executables.bash;
cmd[1] = "-c"; cmd[1] = "-c";
cmd[2] = string.concat("jq '.metadata | tostring' < ", _getForgeArtifactPath(_name)); cmd[2] = string.concat(Executables.jq, " '.metadata | tostring' < ", _getForgeArtifactPath(_name));
bytes memory res = vm.ffi(cmd); bytes memory res = vm.ffi(cmd);
return string(res); return string(res);
} }
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice The executables used in ffi commands. These are set here
/// to have a single source of truth in case absolute paths
/// need to be used.
library Executables {
string internal constant bash = "bash";
string internal constant jq = "jq";
string internal constant forge = "forge";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment