Skip to content

Commit

Permalink
feat: add deploy account script
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Jul 24, 2024
1 parent 8ab1626 commit e0e51b9
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions script/DeployAccount.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Script } from "forge-std/Script.sol";
import "src/MSAFactory.sol";

Check warning on line 5 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

global import of path src/MSAFactory.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import { Bootstrap, BootstrapConfig } from "src/utils/Bootstrap.sol";
import { PackedUserOperation } from "account-abstraction/interfaces/PackedUserOperation.sol";
import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol";
import {
ModeLib,
ModeCode,

Check warning on line 11 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name ModeCode is not used
CallType,

Check warning on line 12 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name CallType is not used
ExecType,

Check warning on line 13 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name ExecType is not used
ModeSelector,

Check warning on line 14 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name ModeSelector is not used
ModePayload,

Check warning on line 15 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name ModePayload is not used
CALLTYPE_DELEGATECALL,

Check warning on line 16 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name CALLTYPE_DELEGATECALL is not used
EXECTYPE_DEFAULT,

Check warning on line 17 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name EXECTYPE_DEFAULT is not used
MODE_DEFAULT
} from "src/lib/ModeLib.sol";
import "src/interfaces/IERC7579Account.sol";
import { ExecutionLib } from "src/lib/ExecutionLib.sol";

import "forge-std/console2.sol";

Check failure on line 23 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected import of console file

/**
* @title DeployAccount
* @author @kopy-kat
*/
contract DeployAccountScript is Script {
function run() public {
MSAFactory factory = MSAFactory(address(0xeffF0157a29286b1B66f59184E1Cc8C95bb69327));
Bootstrap bootstrap =
Bootstrap(payable(address(0xC33673E6a02ac64B90f2b8FaC58f88309DB6238B)));
address initialValidator = address(0x11D02847245Df7cF19f48C8907ace59289D8aCEe);

bytes32 salt = bytes32(uint256(1));

// Create config for initial modules
BootstrapConfig[] memory validators = new BootstrapConfig[](1);
validators[0] = BootstrapConfig({ module: initialValidator, data: "" });
BootstrapConfig[] memory executors = new BootstrapConfig[](0);
BootstrapConfig memory hook;
BootstrapConfig[] memory fallbacks = new BootstrapConfig[](1);

// Create initcode and salt to be sent to Factory
bytes memory _initCode =
bootstrap._getInitMSACalldata(validators, executors, hook, fallbacks);

// Get address of new account
address account = factory.getAddress(salt, _initCode);

// Pack the initcode to include in the userOp
bytes memory initCode = abi.encodePacked(
address(factory),
abi.encodeWithSelector(factory.createAccount.selector, salt, _initCode)
);

IEntryPoint entryPoint = IEntryPoint(address(0x0000000071727De22E5E9d8BAf0edAc6f37da032));

// Create the userOp and add the data
PackedUserOperation memory userOp = getDefaultUserOp();
userOp.sender = address(account);

uint192 key = uint192(bytes24(bytes20(address(initialValidator))));
userOp.nonce = entryPoint.getNonce(address(account), key);

userOp.initCode = initCode;
userOp.callData = abi.encodeCall(
IERC7579Account.execute,
(ModeLib.encodeSimpleSingle(), ExecutionLib.encodeSingle(address(0), uint256(1), ""))
);

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

console2.log(account);

Check failure on line 77 in script/DeployAccount.s.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Unexpected console statement

vm.startBroadcast(vm.envUint("PK"));

entryPoint.handleOps(userOps, payable(address(0x69)));

vm.stopBroadcast();
}

function getDefaultUserOp() internal view returns (PackedUserOperation memory userOp) {
userOp = PackedUserOperation({
sender: address(0),
nonce: 0,
initCode: "",
callData: "",
accountGasLimits: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))),
preVerificationGas: 2e6,
gasFees: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))),
paymasterAndData: bytes(""),
signature: abi.encodePacked(hex"41414141")
});
}
}

0 comments on commit e0e51b9

Please sign in to comment.