Skip to content

Commit

Permalink
refactor: remove config parsing in favor of envvars
Browse files Browse the repository at this point in the history
  • Loading branch information
nadir-akhtar committed Oct 29, 2024
1 parent 1da8e52 commit a223cb2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 297 deletions.
8 changes: 2 additions & 6 deletions src/release-template/1-eoa.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Addresses, Environment, Params, EOADeployer} from "../templates/EOADeployer.sol";
import {EOADeployer} from "../templates/EOADeployer.sol";

contract Deploy is EOADeployer {
Deployment[] private _deployments;

function _deploy(Addresses memory, Environment memory, Params memory)
internal
override
returns (Deployment[] memory)
{
function _deploy() internal override returns (Deployment[] memory) {
vm.startBroadcast();

//////////////////////////
Expand Down
9 changes: 1 addition & 8 deletions src/release-template/2-multisig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
pragma solidity ^0.8.12;

import {
Addresses,
Environment,
Params,
MultisigCall,
MultisigCallUtils,
OpsTimelockBuilder
Expand All @@ -15,11 +12,7 @@ contract Queue is OpsTimelockBuilder {

MultisigCall[] internal _executorCalls;

function queue(Addresses memory addrs, Environment memory env, Params memory params)
public
override
returns (MultisigCall[] memory)
{
function queue() public override returns (MultisigCall[] memory) {
//////////////////////////
// construct executor data here
//////////////////////////
Expand Down
26 changes: 9 additions & 17 deletions src/release-template/3-multisig.s.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {
Addresses,
Environment,
Params,
MultisigCall,
MultisigCallUtils,
MultisigBuilder
} from "../templates/MultisigBuilder.sol";
import {MultisigCall, MultisigCallUtils, MultisigBuilder} from "../templates/MultisigBuilder.sol";
import {SafeTx, SafeTxUtils} from "../utils/SafeTxUtils.sol";
import {ITimelock} from "../interfaces/ITimelock.sol";
import {Queue} from "./2-multisig.s.sol";
Expand All @@ -19,21 +12,20 @@ contract Execute is MultisigBuilder {

MultisigCall[] internal _opsCalls;

function _execute(Addresses memory addrs, Environment memory env, Params memory params)
internal
override
returns (MultisigCall[] memory)
{
function _execute() internal override returns (MultisigCall[] memory) {
Queue queue = new Queue();

MultisigCall[] memory _executorCalls = queue.queue(addrs, env, params);
MultisigCall[] memory _executorCalls = queue.queue();

bytes memory executorCalldata =
queue.makeExecutorCalldata(_executorCalls, params.multiSendCallOnly, addrs.timelock);
address multiSendCallOnly = vm.envAddress("ZEUS_DEPLOYED_MultiSendCallOnly");

address timelock = vm.envAddress("ZEUS_DEPLOYED_Timelock");

bytes memory executorCalldata = queue.makeExecutorCalldata(_executorCalls, multiSendCallOnly, timelock);

// execute queued transaction
_opsCalls.append({
to: addrs.timelock,
to: timelock,
value: 0,
data: abi.encodeWithSelector(ITimelock.executeTransaction.selector, executorCalldata)
});
Expand Down
20 changes: 5 additions & 15 deletions src/templates/EOADeployer.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Addresses, Environment, Params, ConfigParser} from "../utils/ConfigParser.sol";
import {Script} from "forge-std/Script.sol";

/**
* @title EOADeployer
* @notice Template for an Externally Owned Account (EOA) deploy script.
*/
abstract contract EOADeployer is ConfigParser {
abstract contract EOADeployer is Script {
/**
* @notice Struct for deployment information.
* @param deployedTo The address where the contract is deployed.
Expand All @@ -22,26 +22,16 @@ abstract contract EOADeployer is ConfigParser {

/**
* @notice Deploys contracts based on the configuration specified in the provided environment file.
* @param envPath The file path to the environment configuration file.
* @return An array of Deployment structs containing information about the deployed contracts.
*/
function deploy(string memory envPath) public returns (Deployment[] memory) {
// read in config file for environment
(Addresses memory addrs, Environment memory env, Params memory params) = _readConfigFile(envPath);

function deploy() public returns (Deployment[] memory) {
// return deployment info
return _deploy(addrs, env, params);
return _deploy();
}

/**
* @dev Internal function to deploy contracts based on the provided addresses, environment, and parameters.
* @param addrs Struct containing the addresses required for deployment.
* @param env Struct containing the environment settings for deployment.
* @param params Struct containing additional parameters for deployment.
* @return An array of Deployment structs representing the deployed contracts.
*/
function _deploy(Addresses memory addrs, Environment memory env, Params memory params)
internal
virtual
returns (Deployment[] memory);
function _deploy() internal virtual returns (Deployment[] memory);
}
29 changes: 8 additions & 21 deletions src/templates/MultisigBuilder.sol
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Addresses, Environment, Params, ConfigParser} from "../utils/ConfigParser.sol";
import {Script} from "forge-std/Script.sol";
import {MultisigCall, MultisigCallUtils} from "../utils/MultisigCallUtils.sol";
import {SafeTx, EncGnosisSafe} from "../utils/SafeTxUtils.sol";

/**
* @title MultisigBuilder
* @dev Abstract contract for building arbitrary multisig scripts.
*/
abstract contract MultisigBuilder is ConfigParser {
abstract contract MultisigBuilder is Script {
using MultisigCallUtils for MultisigCall[];

/**
* @dev To be used in _execute() to craft multisig calls.
*/
MultisigCall[] internal _multisigCalls;

/**
* @notice Constructs a SafeTx object for a Gnosis Safe to ingest.
* @param envPath The path to the relevant environment configuration file.
* @return A SafeTx struct containing the transaction data to post to the Safe API.
*/
function execute(string memory envPath) public returns (SafeTx memory) {
// read in config file for relevant environment
(Addresses memory addrs, Environment memory env, Params memory params) = _readConfigFile(envPath);

function execute() public returns (SafeTx memory) {
// get calls for Multisig from inheriting script
MultisigCall[] memory calls = _execute(addrs, env, params);
MultisigCall[] memory calls = _execute();

// encode calls as MultiSend data
bytes memory data = calls.encodeMultisendTxs();

// creates and return SafeTx object
// assumes 0 value (ETH) being sent to multisig
return SafeTx({to: params.multiSendCallOnly, value: 0, data: data, op: EncGnosisSafe.Operation.DelegateCall});

address multiSendCallOnly = vm.envAddress("ZEUS_DEPLOYED_MultiSendCallOnly");
return SafeTx({to: multiSendCallOnly, value: 0, data: data, op: EncGnosisSafe.Operation.DelegateCall});
}

/**
* @notice To be implemented by inheriting contract.
* @param addrs A struct containing the addresses involved in the multisig call.
* @param env A struct containing the environment settings for the multisig call.
* @param params A struct containing the parameters for the multisig call.
* @return An array of MultisigCall objects.
*/
function _execute(Addresses memory addrs, Environment memory env, Params memory params)
internal
virtual
returns (MultisigCall[] memory);
function _execute() internal virtual returns (MultisigCall[] memory);
}
32 changes: 12 additions & 20 deletions src/templates/OpsTimelockBuilder.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Addresses, Environment, Params, ConfigParser} from "../utils/ConfigParser.sol";
import {MultisigCall, MultisigCallUtils} from "../utils/MultisigCallUtils.sol";
import {SafeTx, SafeTxUtils, EncGnosisSafe} from "../utils/SafeTxUtils.sol";

Expand All @@ -22,28 +21,27 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {

/**
* @notice Overrides the parent _execute() function to call queue() and prepare transactions for the Timelock.
* @param addrs A struct containing environment addresses.
* @param env A struct containing environment configuration values.
* @param params A struct containing environment parameters.
* @return A MultisigCall array representing the SafeTx object for the Gnosis Safe to process.
*/
function _execute(Addresses memory addrs, Environment memory env, Params memory params)
internal
override
returns (MultisigCall[] memory)
{
function _execute() internal override returns (MultisigCall[] memory) {
// get the queue data
MultisigCall[] memory calls = queue(addrs, env, params);
MultisigCall[] memory calls = queue();

address multiSendCallOnly = vm.envAddress("ZEUS_DEPLOYED_MultiSendCallOnly");

address timelock = vm.envAddress("ZEUS_DEPLOYED_Timelock");

// encode calls for executor
bytes memory executorCalldata = makeExecutorCalldata(calls, params.multiSendCallOnly, addrs.timelock);
bytes memory executorCalldata = makeExecutorCalldata(calls, multiSendCallOnly, timelock);

address executorMultisig = vm.envAddress("ZEUS_DEPLOYED_ExecutorMultisig");

// encode executor data for timelock
bytes memory timelockCalldata = abi.encodeWithSelector(
ITimelock.queueTransaction.selector, addrs.executorMultisig, 0, "", executorCalldata, type(uint256).max
ITimelock.queueTransaction.selector, executorMultisig, 0, "", executorCalldata, type(uint256).max
);

_opsCalls.append(addrs.timelock, timelockCalldata);
_opsCalls.append(timelock, timelockCalldata);

// encode timelock data for ops multisig
return _opsCalls;
Expand Down Expand Up @@ -77,13 +75,7 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {
/**
* @notice Queues a set of operations to be executed later.
* @dev This abstract function is to be overridden by the inheriting contract, where calls are written from the POV of the Executor Multisig.
* @param addrs A struct containing environment addresses.
* @param env A struct containing environment configuration values.
* @param params A struct containing environment parameters.
* @return An array of MultisigCall structs representing the operations to queue.
*/
function queue(Addresses memory addrs, Environment memory env, Params memory params)
public
virtual
returns (MultisigCall[] memory);
function queue() public virtual returns (MultisigCall[] memory);
}
Loading

0 comments on commit a223cb2

Please sign in to comment.