Skip to content

Commit

Permalink
feat: contracts v3 (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas authored Oct 12, 2023
1 parent 3f252a5 commit d27860b
Show file tree
Hide file tree
Showing 28 changed files with 444 additions and 1,825 deletions.
8 changes: 5 additions & 3 deletions contracts/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"rules": {
"code-complexity": ["error", 18],
"compiler-version": ["error", ">=0.8.0"],
"max-line-length": ["warn", 100],
"no-console": "warn",
"max-line-length": ["off", 100],
"no-console": "off",
"var-name-mixedcase": "off",
"func-name-mixedcase": "off",
"avoid-low-level-calls": "off",
"no-inline-assembly": "off"
"no-inline-assembly": "off",
"no-global-import": "off",
"no-empty-blocks": "off"
}
}
7 changes: 7 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./"}]

# https://book.getfoundry.sh/reference/config/formatter#line_length
[fmt]
line_length = 100
tab_width = 4
func_attrs_with_params_multiline = true
ignore = ["lib/**"]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
18 changes: 9 additions & 9 deletions contracts/script/deploy/FunctionGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
pragma solidity ^0.8.16;

import "forge-std/console.sol";
import {BaseScript} from "script/misc/Base.s.sol";
import {FunctionGateway} from "src/FunctionGateway.sol";
import {Proxy} from "src/upgrades/Proxy.sol";
import {BaseScript} from "../misc/Base.s.sol";
import {FunctionGateway} from "../../src/FunctionGateway.sol";
import {Proxy} from "../../src/upgrades/Proxy.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract DeployFunctionGateway is BaseScript {
function run() external broadcaster {
console.log("Deploying FunctionGateway contract on chain %s", Strings.toString(block.chainid));
console.log(
"Deploying FunctionGateway contract on chain %s", Strings.toString(block.chainid)
);

// Check inputs
uint256 SCALAR = envUint256("SCALAR");
address SUCCINCT_FEE_VAULT = envAddress("SUCCINCT_FEE_VAULT", block.chainid);
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
bytes32 CREATE2_SALT = envBytes32("CREATE2_SALT");
Expand All @@ -23,8 +22,9 @@ contract DeployFunctionGateway is BaseScript {
FunctionGateway gatewayImpl = new FunctionGateway{salt: CREATE2_SALT}();
FunctionGateway gateway;
if (!UPGRADE) {
gateway = FunctionGateway(address(new Proxy{salt: CREATE2_SALT}(address(gatewayImpl), "")));
gateway.initialize(SCALAR, SUCCINCT_FEE_VAULT, TIMELOCK, GUARDIAN);
gateway =
FunctionGateway(address(new Proxy{salt: CREATE2_SALT}(address(gatewayImpl), "")));
gateway.initialize(TIMELOCK, GUARDIAN);
} else {
gateway = FunctionGateway(envAddress("FUNCTION_GATEWAY", block.chainid));
gateway.upgradeTo(address(gatewayImpl));
Expand Down
12 changes: 10 additions & 2 deletions contracts/script/deploy/Guardian.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
// "Guardian" refers to a Gnosis Safe proxy.
contract DeployGuardian is BaseScript {
function run() external broadcaster {
console.log("Deploying Guardian (Safe) contract on chain %s", Strings.toString(block.chainid));
console.log(
"Deploying Guardian (Safe) contract on chain %s", Strings.toString(block.chainid)
);

// Check inputs

Expand Down Expand Up @@ -48,6 +50,12 @@ contract DeployGuardian is BaseScript {
address(0)
);

return Safe(payable(_safeFactory.createProxyWithNonce(address(_safeSingleton), initializer, uint256(_salt))));
return Safe(
payable(
_safeFactory.createProxyWithNonce(
address(_safeSingleton), initializer, uint256(_salt)
)
)
);
}
}
37 changes: 0 additions & 37 deletions contracts/script/deploy/StorageOracle.s.sol

This file was deleted.

27 changes: 0 additions & 27 deletions contracts/script/deploy/StorageVerifier.sol

This file was deleted.

4 changes: 3 additions & 1 deletion contracts/script/deploy/SuccinctFeeVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract DeploySuccinctFeeVault is BaseScript {
function run() external broadcaster {
console.log("Deploying SuccinctFeeVault contract on chain %s", Strings.toString(block.chainid));
console.log(
"Deploying SuccinctFeeVault contract on chain %s", Strings.toString(block.chainid)
);

// Check inputs
bytes32 CREATE2_SALT = envBytes32("CREATE2_SALT");
Expand Down
20 changes: 15 additions & 5 deletions contracts/script/misc/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ abstract contract BaseScript is Script {
return value;
}

function envUint32s(string memory name, string memory delimiter) internal returns (uint32[] memory) {
function envUint32s(string memory name, string memory delimiter)
internal
returns (uint32[] memory)
{
uint256[] memory values = new uint256[](0);
values = vm.envOr(name, delimiter, values);
if (values.length == 0) {
Expand Down Expand Up @@ -167,9 +170,12 @@ abstract contract BaseScript is Script {
console.log(string.concat(string.concat(addrVar, "="), Strings.toHexString(value)));
}

function writeEnvAddresses(string memory file, string memory name, address[] memory values, string memory delimiter)
internal
{
function writeEnvAddresses(
string memory file,
string memory name,
address[] memory values,
string memory delimiter
) internal {
string memory addrVar = string.concat(name, "_", Strings.toString(block.chainid));
string memory line = string.concat(addrVar, "=");
string memory addrs;
Expand Down Expand Up @@ -243,7 +249,11 @@ abstract contract BaseScript is Script {
return _b;
}

function buildSignaturesFromArray(bytes[] memory _signatures) internal pure returns (bytes memory) {
function buildSignaturesFromArray(bytes[] memory _signatures)
internal
pure
returns (bytes memory)
{
bytes memory signatures;
for (uint256 i = 0; i < _signatures.length; i++) {
signatures = bytes.concat(signatures, bytes(_signatures[i]));
Expand Down
83 changes: 62 additions & 21 deletions contracts/script/misc/Upgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
// );
//
contract UpgradeSignSchedule is BaseScript {
function run(address PROXY, address IMPL) external returns (address signer, bytes memory signature) {
function run(address PROXY, address IMPL)
external
returns (address signer, bytes memory signature)
{
// Check inputs
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
Expand All @@ -36,9 +39,12 @@ contract UpgradeSignSchedule is BaseScript {
bytes[] memory payloads = new bytes[](1);
payloads[0] = abi.encodeWithSelector(IProxy.upgradeTo.selector, IMPL);

bytes32 id = ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
bytes32 id =
ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
if (ITimelock(TIMELOCK).isOperation(id)) {
revert("operation already exists in Timelock, change CREATE2_SALT to schedule a new one");
revert(
"operation already exists in Timelock, change CREATE2_SALT to schedule a new one"
);
}

scheduleBatchData = abi.encodeWithSelector(
Expand Down Expand Up @@ -82,7 +88,11 @@ contract UpgradeSignSchedule is BaseScript {
// After enough signatures have been collected, a call to Safe.execTransaction(..., signatures) is
// made which schedules the call on the Timelock.
contract UpgradeSendSchedule is BaseScript {
function run(address PROXY, address IMPL, bytes memory _signatures) external broadcaster returns (bool success) {
function run(address PROXY, address IMPL, bytes memory _signatures)
external
broadcaster
returns (bool success)
{
// Check inputs
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
Expand All @@ -103,9 +113,12 @@ contract UpgradeSendSchedule is BaseScript {
bytes[] memory payloads = new bytes[](1);
payloads[0] = abi.encodeWithSelector(IProxy.upgradeTo.selector, IMPL);

bytes32 id = ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
bytes32 id =
ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
if (ITimelock(TIMELOCK).isOperation(id)) {
revert("operation already exists in Timelock, change CREATE2_SALT to schedule a new one");
revert(
"operation already exists in Timelock, change CREATE2_SALT to schedule a new one"
);
}

scheduleBatchData = abi.encodeWithSelector(
Expand All @@ -122,7 +135,9 @@ contract UpgradeSendSchedule is BaseScript {
{
if (ISafe(GUARDIAN).getThreshold() * 65 > _signatures.length) {
console.log(
"not enough signatures, need %d have %d", ISafe(GUARDIAN).getThreshold(), _signatures.length / 65
"not enough signatures, need %d have %d",
ISafe(GUARDIAN).getThreshold(),
_signatures.length / 65
);
return false;
}
Expand All @@ -147,7 +162,10 @@ contract UpgradeSendSchedule is BaseScript {

// After MINIMUM_DELAY has passed, the call to Timelock.execute() can be made.
contract UpgradeSignExecute is BaseScript {
function run(address PROXY, address IMPL) external returns (address signer, bytes memory signature) {
function run(address PROXY, address IMPL)
external
returns (address signer, bytes memory signature)
{
// Check inputs
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
Expand All @@ -168,7 +186,8 @@ contract UpgradeSignExecute is BaseScript {
bytes[] memory payloads = new bytes[](1);
payloads[0] = abi.encodeWithSelector(IProxy.upgradeTo.selector, IMPL);

bytes32 id = ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
bytes32 id =
ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
if (ITimelock(TIMELOCK).isOperationDone(id)) {
console.log("operation already executed in Timelock");
return (address(0), "");
Expand Down Expand Up @@ -212,7 +231,11 @@ contract UpgradeSignExecute is BaseScript {
}

contract UpgradeSendExecute is BaseScript {
function run(address PROXY, address IMPL, bytes memory _signatures) external broadcaster returns (bool success) {
function run(address PROXY, address IMPL, bytes memory _signatures)
external
broadcaster
returns (bool success)
{
// Check inputs
address TIMELOCK = envAddress("TIMELOCK", block.chainid);
address GUARDIAN = envAddress("GUARDIAN", block.chainid);
Expand All @@ -233,7 +256,8 @@ contract UpgradeSendExecute is BaseScript {
bytes[] memory payloads = new bytes[](1);
payloads[0] = abi.encodeWithSelector(IProxy.upgradeTo.selector, IMPL);

bytes32 id = ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
bytes32 id =
ITimelock(TIMELOCK).hashOperationBatch(targets, values, payloads, 0, CREATE2_SALT);
if (ITimelock(TIMELOCK).isOperationDone(id)) {
console.log("operation already executed in Timelock");
return true;
Expand All @@ -253,7 +277,9 @@ contract UpgradeSendExecute is BaseScript {
{
if (ISafe(GUARDIAN).getThreshold() * 65 > _signatures.length) {
console.log(
"not enough signatures, need %d have %d", ISafe(GUARDIAN).getThreshold(), _signatures.length / 65
"not enough signatures, need %d have %d",
ISafe(GUARDIAN).getThreshold(),
_signatures.length / 65
);
return false;
}
Expand Down Expand Up @@ -338,7 +364,11 @@ interface ISafe {
event RemovedOwner(address owner);
event SafeReceived(address indexed sender, uint256 value);
event SafeSetup(
address indexed initiator, address[] owners, uint256 threshold, address initializer, address fallbackHandler
address indexed initiator,
address[] owners,
uint256 threshold,
address initializer,
address fallbackHandler
);
event SignMsg(bytes32 indexed msgHash);

Expand All @@ -347,10 +377,15 @@ interface ISafe {
function approveHash(bytes32 hashToApprove) external;
function approvedHashes(address, bytes32) external view returns (uint256);
function changeThreshold(uint256 _threshold) external;
function checkNSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures, uint256 requiredSignatures)
function checkNSignatures(
bytes32 dataHash,
bytes memory data,
bytes memory signatures,
uint256 requiredSignatures
) external view;
function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures)
external
view;
function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures) external view;
function disableModule(address prevModule, address module) external;
function domainSeparator() external view returns (bytes32);
function enableModule(address module) external;
Expand Down Expand Up @@ -378,12 +413,18 @@ interface ISafe {
address refundReceiver,
bytes memory signatures
) external payable returns (bool success);
function execTransactionFromModule(address to, uint256 value, bytes memory data, Enum.Operation operation)
external
returns (bool success);
function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, Enum.Operation operation)
external
returns (bool success, bytes memory returnData);
function execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) external returns (bool success);
function execTransactionFromModuleReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) external returns (bool success, bytes memory returnData);
function getChainId() external view returns (uint256);
function getModulesPaginated(address start, uint256 pageSize)
external
Expand Down
Loading

0 comments on commit d27860b

Please sign in to comment.