Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 10 additions & 20 deletions script/Delegate7702.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/Gasback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down