Skip to content

Commit

Permalink
refine setup
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Mar 8, 2024
1 parent ccaa93c commit 3e5f10c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 7 additions & 4 deletions accounts/safe7579/src/SafeERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ import {
UserOperationLib
} from "@ERC4337/account-abstraction/contracts/core/UserOperationLib.sol";
import { _packValidationData } from "@ERC4337/account-abstraction/contracts/core/Helpers.sol";
import { IEntryPoint } from "@ERC4337/account-abstraction/contracts/interfaces/IEntryPoint.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;
Expand Down Expand Up @@ -155,7 +154,6 @@ 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 @@ -245,6 +243,7 @@ contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManag
CallType callType = encodedMode.getCallType();
if (callType == CALLTYPE_BATCH) return true;
else if (callType == CALLTYPE_SINGLE) return true;
else if (callType == CALLTYPE_DELEGATECALL) return true;
else return false;
}

Expand Down Expand Up @@ -283,7 +282,6 @@ contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManag
* @inheritdoc IERC7579Account
*/
function accountId() external view override returns (string memory accountImplementationId) {
// TODO: concat safe version
string memory safeVersion = ISafe(_msgSender()).VERSION();
return string(abi.encodePacked(safeVersion, "erc7579.v0.0.0"));
}
Expand Down Expand Up @@ -397,4 +395,9 @@ contract SafeERC7579 is ISafeOp, IERC7579Account, AccessControl, IMSA, HookManag

emit Safe7579Initialized(msg.sender);
}

function getNonce(address safe, address validator) external view returns (uint256 nonce) {
uint192 key = uint192(bytes24(bytes20(address(validator))));
nonce = IEntryPoint(entryPoint()).getNonce(safe, key);
}
}
10 changes: 3 additions & 7 deletions accounts/safe7579/test/Launchpad.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ contract SafeLaunchPadTest is Test {
uint256 salt = 0;

address account = _predictAddress(bytes32(salt), initializer);
vm.deal(account, 1 ether);
PackedUserOperation memory userOp = getDefaultUserOp(account);
userOp.initCode = abi.encodePacked(
address(safeProxyFactory),
Expand All @@ -116,8 +117,6 @@ contract SafeLaunchPadTest is Test {
)
);

console.log("accountPredict", _predictAddress(bytes32(0), initializer));

PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

Expand All @@ -126,15 +125,12 @@ contract SafeLaunchPadTest is Test {

function getDefaultUserOp(address account)
internal
view
returns (PackedUserOperation memory userOp)
{
// console.log("accountPredict", _predictAddress(bytes32(0)));
vm.deal(account, 1 ether);
uint192 key = uint192(bytes24(bytes20(address(defaultValidator))));
uint256 nonce = entrypoint.getNonce(address(account), key);
userOp = PackedUserOperation({
sender: account,
nonce: nonce,
nonce: safe7579.getNonce(address(account), address(defaultValidator)),
initCode: "",
callData: "",
accountGasLimits: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))),
Expand Down

0 comments on commit 3e5f10c

Please sign in to comment.