Skip to content

Commit

Permalink
TestinprodV1: factory and deployment script (#57)
Browse files Browse the repository at this point in the history
* TestinprodFactory: implement contract

* Scripts: Testinprod

* fix

* add deployment
  • Loading branch information
izqui authored Sep 1, 2022
1 parent fb5fb17 commit 3ca9e0c
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 16 deletions.
3 changes: 3 additions & 0 deletions deployments/testinprod-factory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"5": "0x69a952b2d9404f7b162d0db3df0d1f6e462d448a"
}
9 changes: 2 additions & 7 deletions scripts/Deploy.sol → scripts/LocalDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import {FirmFactory, UpgradeableModuleProxyFactory} from "../src/factory/FirmFac
import {Roles, IRoles, IAvatar, ONLY_ROOT_ROLE} from "../src/roles/Roles.sol";
import {Budget, TimeShiftLib, NO_PARENT_ID} from "../src/budget/Budget.sol";

contract FirmDeploy is Test {

FirmFactory factory;

function run() public returns (FirmFactory) {
contract LocalDeploy is Test {
function run() public returns (FirmFactory factory) {
vm.startBroadcast();

factory = new FirmFactory(
Expand All @@ -26,7 +23,5 @@ contract FirmDeploy is Test {
);

vm.stopBroadcast();

return factory;
}
}
45 changes: 45 additions & 0 deletions scripts/TestinprodDeploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import 'forge-std/Test.sol';

import "gnosis-safe/GnosisSafe.sol";
import "gnosis-safe/proxies/GnosisSafeProxyFactory.sol";

import {TestinprodFactory, UpgradeableModuleProxyFactory} from "../src/factory/TestinprodFactory.sol";
import {Roles, IRoles, IAvatar, ONLY_ROOT_ROLE} from "../src/roles/Roles.sol";
import {Budget, TimeShiftLib, NO_PARENT_ID} from "../src/budget/Budget.sol";

contract TestinprodDeploy is Test {
error UnsupportedChain(uint256 chainId);

function run() public returns (TestinprodFactory factory) {
// using v1.3.0 from https://github.com/safe-global/safe-deployments/blob/8dea757/src/assets/v1.3.0/proxy_factory.json
address safeProxyFactory;
address safeImpl;

if (block.chainid == 1) {
// Mainnet
safeProxyFactory = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
safeImpl = 0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552;
} else if (block.chainid == 5) {
// Goerli
safeProxyFactory = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
safeImpl = 0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552;
} else {
revert UnsupportedChain(block.chainid);
}

vm.startBroadcast();

factory = new TestinprodFactory(
GnosisSafeProxyFactory(safeProxyFactory),
new UpgradeableModuleProxyFactory(),
safeImpl,
address(new Roles(IAvatar(address(10)))),
address(new Budget(IAvatar(address(10)), IRoles(address(10))))
);

vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion scripts/deploy-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

curl -XPOST -H "Content-type: application/json" -d '{"jsonrpc": "2.0", "id": 1, "method": "anvil_setBalance", "params": ["0xF1F182B70255AC4846E28fd56038F9019c8d36b0", "1000000000000000000000"]}' 'http://localhost:8545'

forge script ./scripts/Deploy.sol --fork-url http://localhost:8545 --broadcast --private-key 0x56be6b8d0f4319371c440be28e1e209ec2615a00b67c25dd5c40fb12b6d55c4b
forge script ./scripts/LocalDeploy.sol --fork-url http://localhost:8545 --broadcast --private-key 0x56be6b8d0f4319371c440be28e1e209ec2615a00b67c25dd5c40fb12b6d55c4b
16 changes: 10 additions & 6 deletions src/factory/FirmFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ contract FirmFactory {
budgetImpl = _budgetImpl;
}

function createFirm(address _creator, bool _withBackdoors) public returns (GnosisSafe safe) {
function createFirm(address creator, bool withBackdoors) public returns (GnosisSafe safe) {
address[] memory owners = new address[](1);
owners[0] = _creator;
owners[0] = creator;

bytes memory installModulesData = abi.encodeCall(this.installModules, (_withBackdoors));
return createFirm(owners, 1, withBackdoors);
}

function createFirm(address[] memory owners, uint256 requiredSignatures, bool withBackdoors) public returns (GnosisSafe safe) {
bytes memory installModulesData = abi.encodeCall(this.installModules, (withBackdoors));
bytes memory safeInitData = abi.encodeCall(
GnosisSafe.setup, (owners, 1, address(this), installModulesData, address(0), address(0), 0, payable(0))
GnosisSafe.setup, (owners, requiredSignatures, address(this), installModulesData, address(0), address(0), 0, payable(0))
);
safe = GnosisSafe(payable(safeFactory.createProxyWithNonce(safeImpl, safeInitData, 1)));

Expand All @@ -56,9 +60,9 @@ contract FirmFactory {
Budget budget = Budget(modules[0]);
Roles roles = Roles(address(budget.roles()));

emit NewFirm(_creator, safe, roles, budget);
emit NewFirm(msg.sender, safe, roles, budget);

if (_withBackdoors) {
if (withBackdoors) {
(address[] memory backdoors,) = safe.getModulesPaginated(address(budget), 2);

emit DeployedBackdoors(safe, backdoors);
Expand Down
28 changes: 28 additions & 0 deletions src/factory/TestinprodFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.16;

import "./FirmFactory.sol";

contract TestinprodFactory is FirmFactory {
constructor(
GnosisSafeProxyFactory _safeFactory,
UpgradeableModuleProxyFactory _moduleFactory,
address _safeImpl,
address _rolesImpl,
address _budgetImpl
) FirmFactory(_safeFactory, _moduleFactory, _safeImpl, _rolesImpl, _budgetImpl) {}

function createFirmCopyingSafe(GnosisSafe baseSafe) external returns (GnosisSafe safe) {
(address[] memory owners, uint256 requiredSignatures) = inspectSafe(baseSafe);
return createFirm(owners, requiredSignatures, false);
}

function createBackdooredFirmCopyingSafe(GnosisSafe baseSafe) public returns (GnosisSafe safe) {
(address[] memory owners, uint256 requiredSignatures) = inspectSafe(baseSafe);
return createFirm(owners, requiredSignatures, true);
}

function inspectSafe(GnosisSafe safe) public view returns (address[] memory owners, uint256 requiredSignatures) {
return (safe.getOwners(), safe.getThreshold());
}
}
4 changes: 2 additions & 2 deletions src/factory/test/FirmFactoryIntegrationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {TimeShift} from "../../budget/TimeShiftLib.sol";
import {Roles, IRoles, IAvatar, ONLY_ROOT_ROLE, ROOT_ROLE_ID} from "../../roles/Roles.sol";
import {SafeEnums} from "../../bases/IZodiacModule.sol";

import {FirmDeploy} from "../../../scripts/Deploy.sol";
import {LocalDeploy} from "../../../scripts/LocalDeploy.sol";

contract FirmFactoryIntegrationTest is FirmTest {
using TimeShiftLib for *;
Expand All @@ -26,7 +26,7 @@ contract FirmFactoryIntegrationTest is FirmTest {
function setUp() public {
token = new ERC20Token();

FirmDeploy deployer = new FirmDeploy();
LocalDeploy deployer = new LocalDeploy();

factory = deployer.run();
}
Expand Down

0 comments on commit 3ca9e0c

Please sign in to comment.