Skip to content

Commit

Permalink
userOp working. predicting address for userop.sender not working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Mar 8, 2024
1 parent b14fc84 commit 8987bde
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 428 deletions.
29 changes: 25 additions & 4 deletions accounts/safe7579/src/SafeERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ import {
} from "@ERC4337/account-abstraction/contracts/core/UserOperationLib.sol";
import { _packValidationData } from "@ERC4337/account-abstraction/contracts/core/Helpers.sol";

import "forge-std/console2.sol";
/**
* @title ERC7579 Adapter for Safe accounts.
* By using Safe's Fallback and Execution modules,
* this contract creates full ERC7579 compliance to Safe accounts
* @author zeroknots.eth | rhinestone.wtf
*/

contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManager {
using UserOperationLib for PackedUserOperation;
using ModeLib for ModeCode;
using ExecutionLib for bytes;

error Unsupported();

event Safe7579Initialized(address indexed safe);

bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH =
0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218;

Expand Down Expand Up @@ -151,6 +155,7 @@ contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManag

// pay prefund
if (missingAccountFunds != 0) {
console2.log("missingAccountFunds", missingAccountFunds);
_execute({
safe: userOp.getSender(),
target: entryPoint(),
Expand Down Expand Up @@ -368,12 +373,28 @@ contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManag
return keccak256(abi.encode(DOMAIN_SEPARATOR_TYPEHASH, block.chainid, this));
}

function initializeAccount(bytes calldata data) external payable {
function initializeAccount(bytes calldata initCode) external payable {
_initModuleManager();

(address bootstrap, bytes memory bootstrapCall) = abi.decode(data, (address, bytes));
(
address[] memory validator,
bytes[] memory validatorInitcode,
address[] memory executors,
bytes[] memory executorsInitcode
) = abi.decode(initCode, (address[], bytes[], address[], bytes[]));

uint256 length = validator.length;
if (length != validatorInitcode.length) revert("Invalid input");
for (uint256 i; i < length; i++) {
_installValidator(validator[i], validatorInitcode[i]);
}

length = executors.length;
if (length != executorsInitcode.length) revert("Invalid input");
for (uint256 i; i < length; i++) {
_installExecutor(executors[i], executorsInitcode[i]);
}

(bool success,) = bootstrap.delegatecall(bootstrapCall);
if (!success) revert AccountInitializationFailed();
emit Safe7579Initialized(msg.sender);
}
}
8 changes: 8 additions & 0 deletions accounts/safe7579/src/utils/Launchpad.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "../SafeERC7579.sol";

contract Launchpad {
function initSafe7579(address safe7579, bytes calldata safe7579InitCode) public {
ISafe(address(this)).enableModule(safe7579);
SafeERC7579(payable(safe7579)).initializeAccount(safe7579InitCode);
}
}
Loading

0 comments on commit 8987bde

Please sign in to comment.