Skip to content

Commit

Permalink
Add base contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
nadir-akhtar committed Oct 15, 2024
1 parent 7e7f339 commit 981d174
Show file tree
Hide file tree
Showing 13 changed files with 571 additions and 57 deletions.
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

6 changes: 6 additions & 0 deletions src/interfaces/IMultisend.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

interface IMultiSend {
function multiSend(bytes memory transactions) external payable;
}
29 changes: 29 additions & 0 deletions src/interfaces/ISafe.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;

interface ISafe {
/// @dev Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction.
/// Note: The fees are always transferred, even if the user transaction fails.
/// @param to Destination address of Safe transaction.
/// @param value Ether value of Safe transaction.
/// @param data Data payload of Safe transaction.
/// @param operation Operation type of Safe transaction.
/// @param safeTxGas Gas that should be used for the Safe transaction.
/// @param baseGas Gas costs that are independent of the transaction execution(e.g. base transaction fee, signature check, payment of the refund)
/// @param gasPrice Gas price that should be used for the payment calculation.
/// @param gasToken Token address (or 0 if ETH) that is used for the payment.
/// @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).
/// @param signatures Packed signature data ({bytes32 r}{bytes32 s}{uint8 v})
function execTransaction(
address to,
uint256 value,
bytes calldata data,
uint8 operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address payable refundReceiver,
bytes memory signatures
) external;
}
30 changes: 30 additions & 0 deletions src/interfaces/ITimelock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: BUSL-1.1
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 executeTransaction(
address target,
uint value,
string memory signature,
bytes memory data,
uint eta
) external payable returns (bytes memory);

function cancelTransaction(
address target,
uint value,
string memory signature,
bytes memory data,
uint eta
) external;
}
52 changes: 52 additions & 0 deletions src/templates/EOADeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

import {Addresses, Environment, Params, ConfigParser} from "src/utils/ConfigParser.sol";

/**
* @notice Struct for deployment information.
* @param name The name of the deployed contract.
* @param deployedTo The address where the contract is deployed.
*/
struct Deployment {
string name;
address deployedTo;
}

/**
* @title EOADeployer
* @notice Template for an Externally Owned Account (EOA) deploy script.
*/
abstract contract EOADeployer is ConfigParser {
/**
* @dev Internal array to store deployment information.
* Intended to be populated by inheriting contracts.
*/
Deployment[] internal _deployments;

/**
* @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);

// return deployment info
return _deploy(addrs, env, params);
}

/**
* @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);
}
58 changes: 58 additions & 0 deletions src/templates/MultisigBuilder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.12;

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

/**
* @title MultisigBuilder
* @dev Abstract contract for building arbitrary multisig scripts.
*/
abstract contract MultisigBuilder is ConfigParser {

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);

// get calls for Multisig from inheriting script
MultisigCall[] memory calls = _execute(addrs, env, params);

// 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
});
}

/**
* @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);
}
Loading

0 comments on commit 981d174

Please sign in to comment.