Skip to content
Draft
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
39 changes: 33 additions & 6 deletions contracts/SmartAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,15 +61,19 @@ 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);
}

/// @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);
}
Expand All @@ -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");
}

Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
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 = ["*"]
fuzz = { runs = 1_000 }
auto_detect_solc = false
extra_output_files = [ "metadata" ]
viaIR = true
evm_version = "cancun"

# Soldeer configuration
[soldeer]
Expand All @@ -39,5 +40,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" }
account-abstraction = { version = "0.8.0", git = "https://github.com/eth-infinitism/account-abstraction", rev="v0.8.0" }
51 changes: 28 additions & 23 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ 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,
},
evmVersion: "cancun",
},
},
networks: {
hardhat: {
hardfork: "cancun",
},
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;
4 changes: 2 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -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/
hardhat/=node_modules/hardhat/
4 changes: 2 additions & 2 deletions soldeer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions soldeer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
account-abstraction = { version = "0.8.0", git = "https://github.com/eth-infinitism/account-abstraction", rev="v0.8.0" }
Loading