Skip to content

Commit

Permalink
Test OZ Defender WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGuilding committed Oct 24, 2024
1 parent c11459a commit b2bfa08
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ SIGNER=0x69bec2dd161d6bbcc91ec32aa44d9333ebc864c0 # Signer for the dkim oracle o
ETHERSCAN_API_KEY=
# CHAIN_NAME="base_sepolia"

PROXY_BYTECODE_HASH=0x0000000000000000000000000000000000000000000000000000000000000000
PROXY_BYTECODE_HASH=0x0000000000000000000000000000000000000000000000000000000000000000

DEFENDER_KEY="<<YOUR_KEY>>"
DEFENDER_SECRET="<<YOUR_SECRET>>"
3 changes: 3 additions & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ fs_permissions = [
{ access = "read", path = "./artifacts/WETH9.sol/WETH9.json" },
{ access = "read", path = "./test/build_integration" },
{ access = "read", path = "./zkout/ERC1967Proxy.sol/ERC1967Proxy.json" },
{ access = "read", path = "./artifacts" },
]

solc = "0.8.26"

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

# OpenZeppelin
ffi = true
ast = true
build_info = true
extra_output = ["storageLayout"]

Expand Down
4 changes: 3 additions & 1 deletion packages/contracts/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
forge-std/=../../node_modules/forge-std/src
ds-test/=../../node_modules/ds-test/src
solady/=../../node_modules/solady/src/
accountabstraction/=../../node_modules/accountabstraction/
accountabstraction/=../../node_modules/accountabstraction/
openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/
openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/
43 changes: 25 additions & 18 deletions packages/contracts/script/DeploySimpleWallet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@ pragma solidity ^0.8.13;
import "forge-std/Script.sol";

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Defender, ApprovalProcessResponse} from "openzeppelin-foundry-upgrades/Defender.sol";
import {Upgrades, Options} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import "../test/helpers/SimpleWallet.sol";

contract Deploy is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}
address initOwner = vm.addr(deployerPrivateKey);
address controller = vm.envAddress("CONTROLLER");
address simpleWalletImpl = vm.envAddress("SIMPLE_WALLET_IMPL");
if (simpleWalletImpl == address(0)) {
console.log("SIMPLE_WALLET_IMPL env var not set");
return;
ApprovalProcessResponse memory upgradeApprovalProcess = Defender
.getUpgradeApprovalProcess();

if (upgradeApprovalProcess.via == address(0)) {
revert(
string.concat(
"Upgrade approval process with id ",
upgradeApprovalProcess.approvalProcessId,
" has no assigned address"
)
);
}

vm.startBroadcast(deployerPrivateKey);
bytes memory data = abi.encodeWithSelector(
SimpleWallet(payable(simpleWalletImpl)).initialize.selector,
initOwner,
controller
Options memory opts;
opts.defender.useDefenderDeploy = true;

address initOwner = upgradeApprovalProcess.via;
// address controller = vm.envAddress("CONTROLLER");
address controller = address(1);

address proxyAddress = Upgrades.deployUUPSProxy(
"SimpleWallet.sol",
abi.encodeCall(SimpleWallet.initialize, (initOwner, controller)),
opts
);
ERC1967Proxy proxy = new ERC1967Proxy(address(simpleWalletImpl), data);
ERC1967Proxy proxy = ERC1967Proxy(payable(proxyAddress));
console.log("SimpleWallet deployed at: %s", address(proxy));
vm.stopBroadcast();
}
}
6 changes: 3 additions & 3 deletions packages/contracts/test/helpers/SimpleWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ contract SimpleWallet is OwnableUpgradeable, IERC1271 {
) public initializer {
__Ownable_init(_initialOwner);
recoveryController = _recoveryController;
RecoveryController(_recoveryController).configureTimelockPeriod(
RecoveryController(_recoveryController).DEFAULT_TIMELOCK_PERIOD()
);
// RecoveryController(_recoveryController).configureTimelockPeriod(
// RecoveryController(_recoveryController).DEFAULT_TIMELOCK_PERIOD()
// );
}

function transfer(address to, uint256 amount) public onlyOwner {
Expand Down

0 comments on commit b2bfa08

Please sign in to comment.