Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nadir-akhtar committed Oct 16, 2024
1 parent e44ab96 commit 92826e7
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/IMultisend.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pragma solidity ^0.8.12;

interface IMultiSend {
function multiSend(bytes memory transactions) external payable;
}
}
30 changes: 9 additions & 21 deletions src/interfaces/ITimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@ pragma solidity ^0.8.12;
interface ITimelock {
function queuedTransactions(bytes32) external view returns (bool);

function queueTransaction(
address target,
uint value,
string memory signature,
bytes memory data,
uint eta
) external returns (bytes32);
function queueTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
external
returns (bytes32);

function executeTransaction(
address target,
uint value,
string memory signature,
bytes memory data,
uint eta
) external payable returns (bytes memory);
function executeTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
external
payable
returns (bytes memory);

function cancelTransaction(
address target,
uint value,
string memory signature,
bytes memory data,
uint eta
) external;
function cancelTransaction(address target, uint256 value, string memory signature, bytes memory data, uint256 eta)
external;
}
13 changes: 6 additions & 7 deletions src/templates/EOADeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ abstract contract EOADeployer is ConfigParser {
*/
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);
(Addresses memory addrs, Environment memory env, Params memory params) = _readConfigFile(envPath);

// return deployment info
return _deploy(addrs, env, params);
Expand All @@ -48,5 +44,8 @@ abstract contract EOADeployer is ConfigParser {
* @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(Addresses memory addrs, Environment memory env, Params memory params)
internal
virtual
returns (Deployment[] memory);
}
21 changes: 7 additions & 14 deletions src/templates/MultisigBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {SafeTx, EncGnosisSafe} from "src/utils/SafeTxUtils.sol";
* @dev Abstract contract for building arbitrary multisig scripts.
*/
abstract contract MultisigBuilder is ConfigParser {

using MultisigCallUtils for MultisigCall[];

/**
Expand All @@ -25,11 +24,7 @@ abstract contract MultisigBuilder is ConfigParser {
*/
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);
(Addresses memory addrs, Environment memory env, Params memory params) = _readConfigFile(envPath);

// get calls for Multisig from inheriting script
MultisigCall[] memory calls = _execute(addrs, env, params);
Expand All @@ -39,12 +34,7 @@ abstract contract MultisigBuilder is ConfigParser {

// 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
});
return SafeTx({to: params.multiSendCallOnly, value: 0, data: data, op: EncGnosisSafe.Operation.DelegateCall});
}

/**
Expand All @@ -54,5 +44,8 @@ abstract contract MultisigBuilder is ConfigParser {
* @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(Addresses memory addrs, Environment memory env, Params memory params)
internal
virtual
returns (MultisigCall[] memory);
}
32 changes: 17 additions & 15 deletions src/templates/OpsTimelockBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {ITimelock} from "src/interfaces/ITimelock.sol";
* @dev Writing a script is done from the perspective of the OpsMultisig.
*/
abstract contract OpsTimelockBuilder is MultisigBuilder {

using MultisigCallUtils for MultisigCall[];
using SafeTxUtils for SafeTx;

Expand All @@ -28,7 +27,11 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {
* @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(Addresses memory addrs, Environment memory env, Params memory params)
internal
override
returns (MultisigCall[] memory)
{
// get the queue data
MultisigCall[] memory calls = queue(addrs, env, params);

Expand All @@ -37,18 +40,10 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {

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

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

// encode timelock data for ops multisig
return _opsCalls;
Expand All @@ -62,7 +57,11 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {
* @param timelock The address of the timelock contract.
* @return A bytes array representing the calldata for the executor to be sent to the Timelock.
*/
function makeExecutorCalldata(MultisigCall[] memory calls, address multiSendCallOnly, address timelock) public pure returns (bytes memory) {
function makeExecutorCalldata(MultisigCall[] memory calls, address multiSendCallOnly, address timelock)
public
pure
returns (bytes memory)
{
bytes memory data = calls.encodeMultisendTxs();

bytes memory executorCalldata = SafeTx({
Expand All @@ -83,5 +82,8 @@ abstract contract OpsTimelockBuilder is MultisigBuilder {
* @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(Addresses memory addrs, Environment memory env, Params memory params)
public
virtual
returns (MultisigCall[] memory);
}
22 changes: 9 additions & 13 deletions src/utils/ConfigParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "forge-std/Test.sol";
import "./StringUtils.sol";

struct Environment {
uint chainid;
uint256 chainid;
string name;
string lastUpdated;
}
Expand Down Expand Up @@ -78,13 +78,15 @@ struct Addresses {
}

contract ConfigParser is Script, Test {

using StringUtils for *;

string private _configPath;
string private _configData;

function _readConfigFile(string memory configPath) internal returns (Addresses memory, Environment memory, Params memory) {
function _readConfigFile(string memory configPath)
internal
returns (Addresses memory, Environment memory, Params memory)
{
_configPath = configPath;
_configData = vm.readFile(_configPath);
emit log_named_string("Reading from config file", _configPath);
Expand All @@ -96,13 +98,11 @@ contract ConfigParser is Script, Test {
return (addrs, env, params);
}


/**
*
* READS
*
*/

function _readEnvironment() private view returns (Environment memory) {
return Environment({
chainid: _readUint(".config.environment.chainid"),
Expand Down Expand Up @@ -180,12 +180,8 @@ contract ConfigParser is Script, Test {

TUPInfo[] memory strategyInfos = new TUPInfo[](strategyProxies.length);

for (uint i = 0; i < strategyInfos.length; i++) {
strategyInfos[i] = TUPInfo({
proxy: strategyProxies[i],
impl: strategyImpl,
pendingImpl: address(0)
});
for (uint256 i = 0; i < strategyInfos.length; i++) {
strategyInfos[i] = TUPInfo({proxy: strategyProxies[i], impl: strategyImpl, pendingImpl: address(0)});
}

return strategyInfos;
Expand All @@ -204,11 +200,11 @@ contract ConfigParser is Script, Test {
return stdJson.readAddress(_configData, jsonLocation);
}

function _readUint(string memory jsonLocation) private view returns (uint) {
function _readUint(string memory jsonLocation) private view returns (uint256) {
return stdJson.readUint(_configData, jsonLocation);
}

function _readString(string memory jsonLocation) private view returns (string memory) {
return stdJson.readString(_configData, jsonLocation);
}
}
}
47 changes: 21 additions & 26 deletions src/utils/EncGnosisSafe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,45 @@ pragma solidity ^0.8.12;
import {ISafe} from "src/interfaces/ISafe.sol";

library EncGnosisSafe {

enum Operation {
Call,
DelegateCall
}

uint constant SAFE_TX_GAS = 0;
uint constant BASE_GAS = 0;
uint constant GAS_PRICE = 0;
uint256 constant SAFE_TX_GAS = 0;
uint256 constant BASE_GAS = 0;
uint256 constant GAS_PRICE = 0;
address constant GAS_TOKEN = address(uint160(0));
address constant REFUND_RECEIVER = payable(address(uint160(0)));

function execTransaction(
address from,
address to,
bytes memory data,
Operation op
) internal pure returns (bytes memory) {
function execTransaction(address from, address to, bytes memory data, Operation op)
internal
pure
returns (bytes memory)
{
return encodeForExecutor(from, to, 0, data, op);
}

function execTransaction(
address from,
address to,
uint value,
bytes memory data,
Operation op
) internal pure returns (bytes memory) {
function execTransaction(address from, address to, uint256 value, bytes memory data, Operation op)
internal
pure
returns (bytes memory)
{
return encodeForExecutor(from, to, value, data, op);
}

function encodeForExecutor(
address from,
address to,
uint value,
bytes memory data,
Operation op
) internal pure returns (bytes memory) {
function encodeForExecutor(address from, address to, uint256 value, bytes memory data, Operation op)
internal
pure
returns (bytes memory)
{
bytes1 v = bytes1(uint8(1));
bytes32 r = bytes32(uint256(uint160(from)));
bytes32 s;
bytes memory sig = abi.encodePacked(r,s,v);
bytes memory sig = abi.encodePacked(r, s, v);

bytes memory final_calldata_to_executor_multisig = abi.encodeWithSelector(ISafe.execTransaction.selector,
bytes memory final_calldata_to_executor_multisig = abi.encodeWithSelector(
ISafe.execTransaction.selector,
to,
value,
data,
Expand Down
43 changes: 12 additions & 31 deletions src/utils/MultisigCallUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,21 @@ struct MultisigCall {
}

library MultisigCallUtils {

function append(
MultisigCall[] storage multisigCalls,
address to,
uint256 value,
bytes memory data
) internal returns (MultisigCall[] storage) {
multisigCalls.push(MultisigCall({
to: to,
value: value,
data: data
}));
function append(MultisigCall[] storage multisigCalls, address to, uint256 value, bytes memory data)
internal
returns (MultisigCall[] storage)
{
multisigCalls.push(MultisigCall({to: to, value: value, data: data}));

return multisigCalls;
}

/// @notice appends a multisig call with a value of 0
function append(
MultisigCall[] storage multisigCalls,
address to,
bytes memory data
) internal returns (MultisigCall[] storage) {
multisigCalls.push(MultisigCall({
to: to,
value: 0,
data: data
}));
function append(MultisigCall[] storage multisigCalls, address to, bytes memory data)
internal
returns (MultisigCall[] storage)
{
multisigCalls.push(MultisigCall({to: to, value: 0, data: data}));

return multisigCalls;
}
Expand All @@ -46,17 +34,10 @@ library MultisigCallUtils {
bytes memory ret = new bytes(0);
for (uint256 i = 0; i < txs.length; i++) {
ret = abi.encodePacked(
ret,
abi.encodePacked(
uint8(0),
txs[i].to,
txs[i].value,
uint256(txs[i].data.length),
txs[i].data
)
ret, abi.encodePacked(uint8(0), txs[i].to, txs[i].value, uint256(txs[i].data.length), txs[i].data)
);
}

return abi.encodeWithSelector(IMultiSend.multiSend.selector, ret);
}
}
}
Loading

0 comments on commit 92826e7

Please sign in to comment.