Add Account framework docs and guides (#5660)

This commit is contained in:
Ernesto García
2025-07-09 09:10:48 -06:00
committed by GitHub
parent a95d01c30d
commit 6ef73e3386
11 changed files with 977 additions and 7 deletions

View File

@ -0,0 +1,20 @@
// contracts/MyAccountERC7702.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Account} from "../../../account/Account.sol";
import {ERC721Holder} from "../../../token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "../../../token/ERC1155/utils/ERC1155Holder.sol";
import {ERC7821} from "../../../account/extensions/draft-ERC7821.sol";
import {SignerERC7702} from "../../../utils/cryptography/signers/SignerERC7702.sol";
contract MyAccountERC7702 is Account, SignerERC7702, ERC7821, ERC721Holder, ERC1155Holder {
/// @dev Allows the entry point as an authorized executor.
function _erc7821AuthorizedExecutor(
address caller,
bytes32 mode,
bytes calldata executionData
) internal view virtual override returns (bool) {
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
}
}

View File

@ -0,0 +1,37 @@
// contracts/MyFactoryAccount.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Clones} from "../../../proxy/Clones.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @dev A factory contract to create accounts on demand.
*/
contract MyFactoryAccount {
using Clones for address;
using Address for address;
address private immutable _impl;
constructor(address impl_) {
require(impl_.code.length > 0);
_impl = impl_;
}
/// @dev Predict the address of the account
function predictAddress(bytes calldata callData) public view returns (address) {
return _impl.predictDeterministicAddress(keccak256(callData), address(this));
}
/// @dev Create clone accounts on demand
function cloneAndInitialize(bytes calldata callData) public returns (address) {
address predicted = predictAddress(callData);
if (predicted.code.length == 0) {
_impl.cloneDeterministic(keccak256(callData));
predicted.functionCall(callData);
}
return predicted;
}
}