diff --git a/foundry.toml b/foundry.toml index b289ba2..06c721a 100644 --- a/foundry.toml +++ b/foundry.toml @@ -11,6 +11,7 @@ optimizer = true optimizer_runs = 1000 via_ir = true gas_limit = 1_000_000_000 # ETH is 30M, but we use a higher value. +always_use_create_2_factory = true remappings = [ "murky=lib/murky", "dn404/=lib/dn404/src", diff --git a/script/Delegate7702.s.sol b/script/Delegate7702.s.sol index 3e1feeb..f87e87a 100644 --- a/script/Delegate7702.s.sol +++ b/script/Delegate7702.s.sol @@ -8,37 +8,27 @@ contract Delegate7702Script is Script { function run() external { uint256 privateKey = uint256(vm.envBytes32("PRIVATE_KEY")); - address gasbackImplementation = _deployWithNicks(type(Gasback).creationCode); + address nicks = 0x4e59b44847b379578588920cA78FbF26c0B4956C; + address gasbackImplementation = + _predictDeterministicAddress(keccak256(type(Gasback).creationCode), 0, nicks); + if (gasbackImplementation.code.length == 0) { + vm.startBroadcast(privateKey); + gasbackImplementation = address(new Gasback{salt: 0}()); + vm.stopBroadcast(); + } + address deployer = vm.addr(privateKey); vm.signAndAttachDelegation(gasbackImplementation, privateKey); - bytes memory code = deployer.code; - require(code.length > 0, "Not delegation detected"); vm.startBroadcast(privateKey); + Gasback(payable(deployer)).noop(); Gasback(payable(deployer)).setGasbackRatioNumerator(900000000000000000); - vm.stopBroadcast(); - - vm.startBroadcast(privateKey); Gasback(payable(deployer)).setGasbackMaxBaseFee(type(uint256).max); - vm.stopBroadcast(); - - vm.startBroadcast(privateKey); Gasback(payable(deployer)).setBaseFeeVault(0x4200000000000000000000000000000000000019); vm.stopBroadcast(); } - /// @dev Returns the address deployed via Nick's factory with salt `bytes32(0)`. - /// If the contract has already been deployed, skips deploying it. - function _deployWithNicks(bytes memory code) internal returns (address) { - address nicks = 0x4e59b44847b379578588920cA78FbF26c0B4956C; - address instance = _predictDeterministicAddress(keccak256(code), 0, nicks); - if (instance.code.length != 0) return instance; - (bool success,) = nicks.call(abi.encodePacked(bytes32(0), code)); - require(success && instance.code.length != 0, "Deployment via Nick's failed."); - return instance; - } - /// @dev Returns the address when a contract with initialization code hash, /// `hash`, is deployed with `salt`, by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. diff --git a/src/Gasback.sol b/src/Gasback.sol index 6962189..45c4859 100644 --- a/src/Gasback.sol +++ b/src/Gasback.sol @@ -104,6 +104,11 @@ contract Gasback { return true; } + /// @dev A noop function. + function noop() public payable returns (bool) { + return true; + } + /// @dev Guards the function such that it can only be called either by /// the system contract, or by the contract itself (as an EIP-7702 delegated EOA). modifier onlySystemOrThis() {