Add Account framework docs and guides (#5660)
This commit is contained in:
20
contracts/mocks/docs/account/MyAccountERC7702.sol
Normal file
20
contracts/mocks/docs/account/MyAccountERC7702.sol
Normal 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);
|
||||
}
|
||||
}
|
||||
37
contracts/mocks/docs/account/MyFactoryAccount.sol
Normal file
37
contracts/mocks/docs/account/MyFactoryAccount.sol
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user