Skip to content

Commit

Permalink
Account factory: update constructor params (#556)
Browse files Browse the repository at this point in the history
* update constructor params

* fix tests
  • Loading branch information
kumaryash90 authored Oct 26, 2023
1 parent e315dbe commit cb0f1da
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 23 deletions.
11 changes: 8 additions & 3 deletions contracts/prebuilts/account/dynamic/DynamicAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ import { DynamicAccount, IEntryPoint } from "./DynamicAccount.sol";
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

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

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

constructor(IEntryPoint _entrypoint, IExtension.Extension[] memory _defaultExtensions)
BaseAccountFactory(payable(address(new DynamicAccount(_entrypoint, _defaultExtensions))), address(_entrypoint))
constructor(address _defaultAdmin, IExtension.Extension[] memory _defaultExtensions)
BaseAccountFactory(
payable(address(new DynamicAccount(IEntryPoint(ENTRYPOINT_ADDRESS), _defaultExtensions))),
ENTRYPOINT_ADDRESS
)
{
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
}

/*///////////////////////////////////////////////////////////////
Expand Down
10 changes: 7 additions & 3 deletions contracts/prebuilts/account/managed/ManagedAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, Permissi
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint, Extension[] memory _defaultExtensions)
constructor(
address _defaultAdmin,
IEntryPoint _entrypoint,
Extension[] memory _defaultExtensions
)
BaseRouter(_defaultExtensions)
BaseAccountFactory(payable(address(new ManagedAccount(_entrypoint, address(this)))), address(_entrypoint))
{
__BaseRouter_init();
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);

bytes32 _extensionRole = keccak256("EXTENSION_ROLE");
_setupRole(_extensionRole, msg.sender);
_setupRole(_extensionRole, _defaultAdmin);
_setRoleAdmin(_extensionRole, _extensionRole);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ contract AccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnum
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint)
constructor(address _defaultAdmin, IEntryPoint _entrypoint)
BaseAccountFactory(address(new Account(_entrypoint, address(this))), address(_entrypoint))
{
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
}

/*///////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/test/benchmark/AccountBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ contract AccountBenchmarkTest is BaseTest {
// Setup contracts
entrypoint = new EntryPoint();
// deploy account factory
accountFactory = new AccountFactory(IEntryPoint(payable(address(entrypoint))));
accountFactory = new AccountFactory(deployer, IEntryPoint(payable(address(entrypoint))));
// deploy dummy contract
numberContract = new Number();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/smart-wallet/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ contract SimpleAccountTest is BaseTest {
// Setup contracts
entrypoint = new EntryPoint();
// deploy account factory
accountFactory = new AccountFactory(IEntryPoint(payable(address(entrypoint))));
accountFactory = new AccountFactory(deployer, IEntryPoint(payable(address(entrypoint))));
// deploy dummy contract
numberContract = new Number();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/smart-wallet/AccountVulnPOC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ contract SimpleAccountVulnPOCTest is BaseTest {
// Setup contracts
entrypoint = new EntryPoint();
// deploy account factory
accountFactory = new AccountFactory(IEntryPoint(payable(address(entrypoint))));
accountFactory = new AccountFactory(deployer, IEntryPoint(payable(address(entrypoint))));
// deploy dummy contract
numberContract = new Number();
}
Expand Down
12 changes: 5 additions & 7 deletions src/test/smart-wallet/DynamicAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract NFTRejector {

contract DynamicAccountTest is BaseTest {
// Target contracts
EntryPoint private entrypoint;
EntryPoint private constant entrypoint = EntryPoint(payable(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789));
DynamicAccountFactory private accountFactory;

// Mocks
Expand Down Expand Up @@ -202,7 +202,8 @@ contract DynamicAccountTest is BaseTest {
nonSigner = vm.addr(nonSignerPKey);

// Setup contracts
entrypoint = new EntryPoint();
address _deployedEntrypoint = address(new EntryPoint());
vm.etch(address(entrypoint), bytes(_deployedEntrypoint.code));

// Setting up default extension.
IExtension.Extension memory defaultExtension;
Expand Down Expand Up @@ -248,7 +249,7 @@ contract DynamicAccountTest is BaseTest {
extensions[0] = defaultExtension;

// deploy account factory
accountFactory = new DynamicAccountFactory(IEntryPoint(payable(address(entrypoint))), extensions);
accountFactory = new DynamicAccountFactory(deployer, extensions);
// deploy dummy contract
numberContract = new Number();
}
Expand Down Expand Up @@ -303,10 +304,7 @@ contract DynamicAccountTest is BaseTest {
extensions[0] = defaultExtension;

// deploy account factory
DynamicAccountFactory factory = new DynamicAccountFactory(
IEntryPoint(payable(address(entrypoint))),
extensions
);
DynamicAccountFactory factory = new DynamicAccountFactory(deployer, extensions);
}

/// @dev Create an account by directly calling the factory.
Expand Down
7 changes: 6 additions & 1 deletion src/test/smart-wallet/ManagedAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ contract ManagedAccountTest is BaseTest {

// deploy account factory
vm.prank(factoryDeployer);
accountFactory = new ManagedAccountFactory(IEntryPoint(payable(address(entrypoint))), extensions);
accountFactory = new ManagedAccountFactory(
factoryDeployer,
IEntryPoint(payable(address(entrypoint))),
extensions
);
// deploy dummy contract
numberContract = new Number();
}
Expand Down Expand Up @@ -303,6 +307,7 @@ contract ManagedAccountTest is BaseTest {
// deploy account factory
vm.prank(factoryDeployer);
ManagedAccountFactory factory = new ManagedAccountFactory(
factoryDeployer,
IEntryPoint(payable(address(entrypoint))),
extensions
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/smart-wallet/account-core/isValidSigner.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ contract AccountCoreTest_isValidSigner is BaseTest {
IExtension.Extension[] memory extensions;

// deploy account factory
accountFactory = new DynamicAccountFactory(IEntryPoint(payable(address(entrypoint))), extensions);
accountFactory = new DynamicAccountFactory(deployer, extensions);
// deploy dummy contract
numberContract = new Number();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract AccountPermissionsTest_setPermissionsForSigner is BaseTest {
);

// Target contracts
EntryPoint private entrypoint;
EntryPoint private constant entrypoint = EntryPoint(payable(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789));
DynamicAccountFactory private accountFactory;

// Mocks
Expand Down Expand Up @@ -220,7 +220,8 @@ contract AccountPermissionsTest_setPermissionsForSigner is BaseTest {
nonSigner = vm.addr(nonSignerPKey);

// Setup contracts
entrypoint = new EntryPoint();
address _deployedEntrypoint = address(new EntryPoint());
vm.etch(address(entrypoint), bytes(_deployedEntrypoint.code));

// Setting up default extension.
IExtension.Extension memory defaultExtension;
Expand Down Expand Up @@ -266,7 +267,7 @@ contract AccountPermissionsTest_setPermissionsForSigner is BaseTest {
extensions[0] = defaultExtension;

// deploy account factory
accountFactory = new DynamicAccountFactory(IEntryPoint(payable(address(entrypoint))), extensions);
accountFactory = new DynamicAccountFactory(deployer, extensions);
// deploy dummy contract
numberContract = new Number();
}
Expand Down

0 comments on commit cb0f1da

Please sign in to comment.