Skip to content

Commit

Permalink
Revert account factory proxy deploy back to direct deploy (#578)
Browse files Browse the repository at this point in the history
* Revert proxy deployable factory -> direct deploy factory

* Re-add EIP-1271 udpated sig to Account
  • Loading branch information
nkrishang authored Nov 20, 2023
1 parent 85874e3 commit 791e8df
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 268 deletions.
11 changes: 2 additions & 9 deletions contracts/prebuilts/account/dynamic/DynamicAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,16 @@ contract DynamicAccount is AccountCore, BaseRouter {
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint, Extension[] memory _defaultExtensions)
AccountCore(_entrypoint)
AccountCore(_entrypoint, msg.sender)
BaseRouter(_defaultExtensions)
{
_disableInitializers();
}

/// @notice Initializes the smart contract wallet.
function initialize(
address _defaultAdmin,
address _factory,
bytes calldata _data
) public override initializer {
function initialize(address _defaultAdmin, bytes calldata _data) public override initializer {
__BaseRouter_init();

// This is passed as data in the `_registerOnFactory()` call in `AccountExtension` / `Account`.
AccountCoreStorage.data().creationSalt = _generateSalt(_defaultAdmin, _data);
AccountCoreStorage.data().factory = _factory;
_setAdmin(_defaultAdmin, true);
}

Expand Down
19 changes: 6 additions & 13 deletions contracts/prebuilts/account/dynamic/DynamicAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ pragma solidity ^0.8.12;
// Utils
import "../utils/BaseAccountFactory.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IExtension.sol";
import "../../../extension/upgradeable/Initializable.sol";

// Extensions
import "../../../extension/upgradeable/PermissionsEnumerable.sol";
import "../../../extension/upgradeable/ContractMetadata.sol";
import "../../../extension/upgradeable//PermissionsEnumerable.sol";
import "../../../extension/upgradeable//ContractMetadata.sol";

// Smart wallet implementation
import { DynamicAccount, IEntryPoint } from "./DynamicAccount.sol";
Expand All @@ -22,26 +21,20 @@ import { DynamicAccount, IEntryPoint } from "./DynamicAccount.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract DynamicAccountFactory is Initializable, BaseAccountFactory, ContractMetadata, PermissionsEnumerable {
contract DynamicAccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable {
address public constant ENTRYPOINT_ADDRESS = 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789;

/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IExtension.Extension[] memory _defaultExtensions)
constructor(address _defaultAdmin, IExtension.Extension[] memory _defaultExtensions)
BaseAccountFactory(
address(new DynamicAccount(IEntryPoint(ENTRYPOINT_ADDRESS), _defaultExtensions)),
payable(address(new DynamicAccount(IEntryPoint(ENTRYPOINT_ADDRESS), _defaultExtensions))),
ENTRYPOINT_ADDRESS
)
{
_disableInitializers();
}

/// @notice Initializes the factory contract.
function initialize(address _defaultAdmin, string memory _contractURI) external initializer {
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
_setupContractURI(_contractURI);
}

/*///////////////////////////////////////////////////////////////
Expand All @@ -54,7 +47,7 @@ contract DynamicAccountFactory is Initializable, BaseAccountFactory, ContractMet
address _admin,
bytes calldata _data
) internal override {
DynamicAccount(payable(_account)).initialize(_admin, address(this), _data);
DynamicAccount(payable(_account)).initialize(_admin, _data);
}

/// @dev Returns whether contract metadata can be set in the given execution context.
Expand Down
6 changes: 3 additions & 3 deletions contracts/prebuilts/account/managed/ManagedAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import "@thirdweb-dev/dynamic-contracts/src/core/Router.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IRouterState.sol";

contract ManagedAccount is AccountCore, Router, IRouterState {
constructor(IEntryPoint _entrypoint) AccountCore(_entrypoint) {}
constructor(IEntryPoint _entrypoint, address _factory) AccountCore(_entrypoint, _factory) {}

/// @notice Returns the implementation contract address for a given function signature.
function getImplementationForFunction(bytes4 _functionSelector) public view virtual override returns (address) {
return Router(payable(AccountCoreStorage.data().factory)).getImplementationForFunction(_functionSelector);
return Router(payable(factory)).getImplementationForFunction(_functionSelector);
}

/// @notice Returns all extensions of the Router.
function getAllExtensions() external view returns (Extension[] memory) {
return IRouterState(payable(AccountCoreStorage.data().factory)).getAllExtensions();
return IRouterState(payable(factory)).getAllExtensions();
}
}
27 changes: 8 additions & 19 deletions contracts/prebuilts/account/managed/ManagedAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.12;
// Utils
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouter.sol";
import "../utils/BaseAccountFactory.sol";
import "../../../extension/upgradeable/Initializable.sol";

// Extensions
import "../../../extension/upgradeable//PermissionsEnumerable.sol";
Expand All @@ -22,35 +21,25 @@ import { ManagedAccount, IEntryPoint } from "./ManagedAccount.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract ManagedAccountFactory is
Initializable,
BaseAccountFactory,
ContractMetadata,
PermissionsEnumerable,
BaseRouter
{
contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable, BaseRouter {
/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint, Extension[] memory _defaultExtensions)
constructor(
address _defaultAdmin,
IEntryPoint _entrypoint,
Extension[] memory _defaultExtensions
)
BaseRouter(_defaultExtensions)
BaseAccountFactory(address(new ManagedAccount(_entrypoint)), address(_entrypoint))
BaseAccountFactory(payable(address(new ManagedAccount(_entrypoint, address(this)))), address(_entrypoint))
{
_disableInitializers();
}

/// @notice Initializes the factory contract.
function initialize(address _defaultAdmin, string memory _contractURI) external initializer {
__BaseRouter_init();

_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);

bytes32 _extensionRole = keccak256("EXTENSION_ROLE");
_setupRole(_extensionRole, _defaultAdmin);
_setRoleAdmin(_extensionRole, _extensionRole);

_setupContractURI(_contractURI);
}

/*///////////////////////////////////////////////////////////////
Expand All @@ -63,7 +52,7 @@ contract ManagedAccountFactory is
address _admin,
bytes calldata _data
) internal override {
ManagedAccount(payable(_account)).initialize(_admin, address(this), _data);
ManagedAccount(payable(_account)).initialize(_admin, _data);
}

/// @dev Returns whether all relevant permission and other checks are met before any upgrade.
Expand Down
4 changes: 2 additions & 2 deletions contracts/prebuilts/account/non-upgradeable/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115
Constructor, Initializer, Modifiers
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint) AccountCore(_entrypoint) {}
constructor(IEntryPoint _entrypoint, address _factory) AccountCore(_entrypoint, _factory) {}

/// @notice Checks whether the caller is the EntryPoint contract or the admin.
modifier onlyAdminOrEntrypoint() virtual {
Expand Down Expand Up @@ -145,7 +145,7 @@ contract Account is AccountCore, ContractMetadata, ERC1271, ERC721Holder, ERC115

/// @dev Registers the account on the factory if it hasn't been registered yet.
function _registerOnFactory() internal virtual {
BaseAccountFactory factoryContract = BaseAccountFactory(AccountCoreStorage.data().factory);
BaseAccountFactory factoryContract = BaseAccountFactory(factory);
if (!factoryContract.isRegistered(address(this))) {
factoryContract.onRegister(AccountCoreStorage.data().creationSalt);
}
Expand Down
15 changes: 5 additions & 10 deletions contracts/prebuilts/account/non-upgradeable/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.12;
import "../utils/BaseAccountFactory.sol";
import "../utils/BaseAccount.sol";
import "../../../external-deps/openzeppelin/proxy/Clones.sol";
import "../../../extension/upgradeable/Initializable.sol";

// Extensions
import "../../../extension/upgradeable//PermissionsEnumerable.sol";
Expand All @@ -26,19 +25,15 @@ import { Account } from "./Account.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract AccountFactory is Initializable, BaseAccountFactory, ContractMetadata, PermissionsEnumerable {
contract AccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable {
/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint) BaseAccountFactory(address(new Account(_entrypoint)), address(_entrypoint)) {
_disableInitializers();
}

/// @notice Initializes the factory contract.
function initialize(address _defaultAdmin, string memory _contractURI) external initializer {
constructor(address _defaultAdmin, IEntryPoint _entrypoint)
BaseAccountFactory(address(new Account(_entrypoint, address(this))), address(_entrypoint))
{
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
_setupContractURI(_contractURI);
}

/*///////////////////////////////////////////////////////////////
Expand All @@ -51,7 +46,7 @@ contract AccountFactory is Initializable, BaseAccountFactory, ContractMetadata,
address _admin,
bytes calldata _data
) internal override {
Account(payable(_account)).initialize(_admin, address(this), _data);
Account(payable(_account)).initialize(_admin, _data);
}

/// @dev Returns whether contract metadata can be set in the given execution context.
Expand Down
31 changes: 11 additions & 20 deletions contracts/prebuilts/account/utils/AccountCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,33 @@ contract AccountCore is IAccountCore, Initializable, Multicall, BaseAccount, Acc
State
//////////////////////////////////////////////////////////////*/

/// @notice EIP 4337 factory for this contract.
address public immutable factory;

/// @notice EIP 4337 Entrypoint contract.
IEntryPoint private immutable entrypointContract;

/*///////////////////////////////////////////////////////////////
Constructor, Initializer, Modifiers
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint) EIP712("Account", "1") {
constructor(IEntryPoint _entrypoint, address _factory) EIP712("Account", "1") {
_disableInitializers();
factory = _factory;
entrypointContract = _entrypoint;
}

/// @notice Initializes the smart contract wallet.
function initialize(
address _defaultAdmin,
address _factory,
bytes calldata _data
) public virtual initializer {
function initialize(address _defaultAdmin, bytes calldata _data) public virtual initializer {
// This is passed as data in the `_registerOnFactory()` call in `AccountExtension` / `Account`.
AccountCoreStorage.data().creationSalt = _generateSalt(_defaultAdmin, _data);
AccountCoreStorage.data().factory = _factory;
_setAdmin(_defaultAdmin, true);
}

/*///////////////////////////////////////////////////////////////
View functions
//////////////////////////////////////////////////////////////*/

/// @notice Returns the address of the account factory.
function factory() public view virtual override returns (address) {
return AccountCoreStorage.data().factory;
}

/// @notice Returns the EIP 4337 entrypoint contract.
function entryPoint() public view virtual override returns (IEntryPoint) {
address entrypointOverride = AccountCoreStorage.data().entrypointOverride;
Expand Down Expand Up @@ -241,22 +235,19 @@ contract AccountCore is IAccountCore, Initializable, Multicall, BaseAccount, Acc
/// @notice Makes the given account an admin.
function _setAdmin(address _account, bool _isAdmin) internal virtual override {
super._setAdmin(_account, _isAdmin);

address factoryAddr = factory();
if (factoryAddr.code.length > 0) {
if (factory.code.length > 0) {
if (_isAdmin) {
BaseAccountFactory(factoryAddr).onSignerAdded(_account, AccountCoreStorage.data().creationSalt);
BaseAccountFactory(factory).onSignerAdded(_account, AccountCoreStorage.data().creationSalt);
} else {
BaseAccountFactory(factoryAddr).onSignerRemoved(_account, AccountCoreStorage.data().creationSalt);
BaseAccountFactory(factory).onSignerRemoved(_account, AccountCoreStorage.data().creationSalt);
}
}
}

/// @notice Runs after every `changeRole` run.
function _afterSignerPermissionsUpdate(SignerPermissionRequest calldata _req) internal virtual override {
address factoryAddr = factory();
if (factoryAddr.code.length > 0) {
BaseAccountFactory(factoryAddr).onSignerAdded(_req.signer, AccountCoreStorage.data().creationSalt);
if (factory.code.length > 0) {
BaseAccountFactory(factory).onSignerAdded(_req.signer, AccountCoreStorage.data().creationSalt);
}
}
}
1 change: 0 additions & 1 deletion contracts/prebuilts/account/utils/AccountCoreStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ library AccountCoreStorage {

struct Data {
address entrypointOverride;
address factory;
bytes32 creationSalt;
}

Expand Down
Loading

0 comments on commit 791e8df

Please sign in to comment.