From b1946265a1ef0e084987f6845fe04ece0d8731b7 Mon Sep 17 00:00:00 2001 From: Daan Poron Date: Fri, 4 Apr 2025 14:43:13 +0200 Subject: [PATCH 1/4] feat: update to AA 0.8.0 --- contracts/SmartAccount.sol | 39 ++++++++++++++++++++++++++++++++------ foundry.toml | 9 +-------- remappings.txt | 4 ++-- soldeer.lock | 4 ++-- soldeer.toml | 3 +-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/contracts/SmartAccount.sol b/contracts/SmartAccount.sol index c8ccee7..58904f6 100644 --- a/contracts/SmartAccount.sol +++ b/contracts/SmartAccount.sol @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; import "account-abstraction/core/BaseAccount.sol"; import "account-abstraction/core/Helpers.sol"; -import "account-abstraction/samples/callback/TokenCallbackHandler.sol"; +import "account-abstraction/accounts/callback/TokenCallbackHandler.sol"; /** * @title SmartAccount @@ -61,8 +61,8 @@ contract SmartAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, Ini /// @param dest The destination address for the transaction /// @param value The amount of ETH to send /// @param func The calldata for the transaction - function execute(address dest, uint256 value, bytes calldata func) external { - _requireFromEntryPointOrOwner(); + function execute(address dest, uint256 value, bytes calldata func) external override { + _requireForExecute(); _call(dest, value, func); emit TransactionExecuted(dest, value, func); } @@ -70,6 +70,10 @@ contract SmartAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, Ini /// @notice Initializes the account with an owner - can only be called once /// @param anOwner The owner's address function initialize(address anOwner) public virtual initializer { + _initialize(anOwner); + } + + function _initialize(address anOwner) internal virtual { owner = anOwner; emit SmartAccountInitialized(_entryPoint, owner); } @@ -84,15 +88,15 @@ contract SmartAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, Ini override returns (uint256 validationData) { - bytes32 hash = MessageHashUtils.toEthSignedMessageHash(userOpHash); - if (owner != ECDSA.recover(hash, userOp.signature)) { + // UserOpHash can be generated using eth_signTypedData_v4 + if (owner != ECDSA.recover(userOpHash, userOp.signature)) { return SIG_VALIDATION_FAILED; } return SIG_VALIDATION_SUCCESS; } /// @notice Ensures the caller is either the EntryPoint or the owner - function _requireFromEntryPointOrOwner() internal view { + function _requireForExecute() internal view virtual override { require(msg.sender == address(entryPoint()) || msg.sender == owner, "account: not Owner or EntryPoint"); } @@ -117,4 +121,27 @@ contract SmartAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, Ini /// @notice Required for receiving ETH receive() external payable { } + + /** + * check current account deposit in the entryPoint + */ + function getDeposit() public view returns (uint256) { + return entryPoint().balanceOf(address(this)); + } + + /** + * deposit more funds for this account in the entryPoint + */ + function addDeposit() public payable { + entryPoint().depositTo{ value: msg.value }(address(this)); + } + + /** + * withdraw value from the account's deposit + * @param withdrawAddress target to send to + * @param amount to withdraw + */ + function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public onlyOwner { + entryPoint().withdrawTo(withdrawAddress, amount); + } } diff --git a/foundry.toml b/foundry.toml index 6fe0313..0bd3970 100644 --- a/foundry.toml +++ b/foundry.toml @@ -22,7 +22,7 @@ libs = ['node_modules', 'dependencies'] test = 'test' cache_path = 'cache_forge' - solc = "0.8.27" + solc = "0.8.28" optimizer = true optimizer_runs = 10_000 gas_reports = ["*"] @@ -34,10 +34,3 @@ # Soldeer configuration [soldeer] remappings_version = false - -[dependencies] - # Core dependencies - forge-std = "1.9.5" - "@openzeppelin-contracts" = "5.2.0" - # Pinned to specific commit to avoid breaking changes, https://github.com/eth-infinitism/account-abstraction/commit/b3bae63bd9bc0ed394dfca8668008213127adb62 doesn't work on Paris (TransientSlot.sol) - account-abstraction = { version = "0.7.0", git = "https://github.com/eth-infinitism/account-abstraction", rev = "4b9a3ecfb63c3342218f2ba0226e19be16e022ac" } \ No newline at end of file diff --git a/remappings.txt b/remappings.txt index ccee858..d741855 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,4 +1,4 @@ @openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.2.0 -account-abstraction/=dependencies/account-abstraction-0.7.0/contracts +account-abstraction/=dependencies/account-abstraction-0.8.0/contracts forge-std/=dependencies/forge-std-1.9.5/src/ -hardhat/=node_modules/hardhat/ \ No newline at end of file +hardhat/=node_modules/hardhat/ diff --git a/soldeer.lock b/soldeer.lock index 7804dc3..dd9e4fb 100644 --- a/soldeer.lock +++ b/soldeer.lock @@ -7,9 +7,9 @@ integrity = "4cb7f3777f67fdf4b7d0e2f94d2f93f198b2e5dce718b7062ac7c2c83e1183bd" [[dependencies]] name = "account-abstraction" -version = "0.7.0" +version = "0.8.0" git = "https://github.com/eth-infinitism/account-abstraction" -rev = "4b9a3ecfb63c3342218f2ba0226e19be16e022ac" +rev = "4cbc06072cdc19fd60f285c5997f4f7f57a588de" [[dependencies]] name = "forge-std" diff --git a/soldeer.toml b/soldeer.toml index d6b71d8..8fac622 100644 --- a/soldeer.toml +++ b/soldeer.toml @@ -5,5 +5,4 @@ # Core dependencies forge-std = "1.9.5" "@openzeppelin-contracts" = "5.2.0" - # Pinned to specific commit to avoid breaking changes, https://github.com/eth-infinitism/account-abstraction/commit/b3bae63bd9bc0ed394dfca8668008213127adb62 doesn't work on Paris (TransientSlot.sol) - account-abstraction = { version = "0.7.0", git = "https://github.com/eth-infinitism/account-abstraction", rev = "4b9a3ecfb63c3342218f2ba0226e19be16e022ac" } \ No newline at end of file + account-abstraction = { version = "0.8.0", git = "https://github.com/eth-infinitism/account-abstraction", rev="v0.8.0" } \ No newline at end of file From 194d9dff2f99f40a4e7d17b6683fa05ac9bb01c7 Mon Sep 17 00:00:00 2001 From: Daan Poron Date: Fri, 4 Apr 2025 14:48:00 +0200 Subject: [PATCH 2/4] fix foundry toml --- foundry.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/foundry.toml b/foundry.toml index 0bd3970..c7eed2f 100644 --- a/foundry.toml +++ b/foundry.toml @@ -34,3 +34,9 @@ # Soldeer configuration [soldeer] remappings_version = false + +[dependencies] + # Core dependencies + forge-std = "1.9.5" + "@openzeppelin-contracts" = "5.2.0" + account-abstraction = { version = "0.8.0", git = "https://github.com/eth-infinitism/account-abstraction", rev="v0.8.0" } From fc8e4311c6065e0df84efa74e3cd02d90d65ce99 Mon Sep 17 00:00:00 2001 From: Daan Poron Date: Fri, 4 Apr 2025 14:53:47 +0200 Subject: [PATCH 3/4] bump hardhat solidity versiona s well --- hardhat.config.ts | 48 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 6c3c0b8..88627ab 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -4,29 +4,31 @@ import "@nomiclabs/hardhat-solhint"; import type { HardhatUserConfig } from "hardhat/config"; const config: HardhatUserConfig = { - solidity: { - version: "0.8.27", - settings: { - viaIR: true, - optimizer: { - enabled: true, - runs: 10_000, - }, - }, - }, - networks: { - hardhat: {}, - btp: { - url: process.env.BTP_RPC_URL || "", - gasPrice: process.env.BTP_GAS_PRICE ? parseInt(process.env.BTP_GAS_PRICE) : "auto", - }, - }, - etherscan: { - apiKey: process.env.ETHERSCAN_API_KEY, - }, - sourcify: { - enabled: true, - } + solidity: { + version: "0.8.28", + settings: { + viaIR: true, + optimizer: { + enabled: true, + runs: 10_000, + }, + }, + }, + networks: { + hardhat: {}, + btp: { + url: process.env.BTP_RPC_URL || "", + gasPrice: process.env.BTP_GAS_PRICE + ? Number.parseInt(process.env.BTP_GAS_PRICE) + : "auto", + }, + }, + etherscan: { + apiKey: process.env.ETHERSCAN_API_KEY, + }, + sourcify: { + enabled: true, + }, }; export default config; From 61843ad0dc2c58e326a402fcd2fe3c207d82097a Mon Sep 17 00:00:00 2001 From: Daan Poron Date: Fri, 4 Apr 2025 16:12:49 +0200 Subject: [PATCH 4/4] we need to use cancun for compiling because of the transient storage --- foundry.toml | 1 + hardhat.config.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/foundry.toml b/foundry.toml index c7eed2f..47ffdde 100644 --- a/foundry.toml +++ b/foundry.toml @@ -30,6 +30,7 @@ auto_detect_solc = false extra_output_files = [ "metadata" ] viaIR = true + evm_version = "cancun" # Soldeer configuration [soldeer] diff --git a/hardhat.config.ts b/hardhat.config.ts index 88627ab..3153f26 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -12,10 +12,13 @@ const config: HardhatUserConfig = { enabled: true, runs: 10_000, }, + evmVersion: "cancun", }, }, networks: { - hardhat: {}, + hardhat: { + hardfork: "cancun", + }, btp: { url: process.env.BTP_RPC_URL || "", gasPrice: process.env.BTP_GAS_PRICE