Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: rename msca -> ma, remove token receiver plugin usage #129

Merged
merged 4 commits into from
Jan 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REQUIRED_STAKE_AMOUNT=1
UNSTAKE_DELAY_SEC=86400

ENTRYPOINT=
# MSCA_IMPL=
# MA_IMPL=
# OWNER_FACTORY=
# OWNER_TOKEN_RECEIVER_FACTORY=

Expand Down
1,359 changes: 907 additions & 452 deletions .gasestimates.md

Large diffs are not rendered by default.

51 changes: 21 additions & 30 deletions .storagelayout.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,43 @@ Generated via `bash utils/inspect.sh`.
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

`forge inspect --pretty src/account/PluginManagerInternals.sol:PluginManagerInternals storage-layout`
`forge inspect --pretty src/account/AccountStorageV1.sol:AccountStorageV1 storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

`forge inspect --pretty src/account/UpgradeableModularAccount.sol:UpgradeableModularAccount storage-layout`
`forge inspect --pretty src/account/PluginManagerInternals.sol:PluginManagerInternals storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

`forge inspect --pretty src/factory/MultiOwnerMSCAFactory.sol:MultiOwnerMSCAFactory storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|--------|---------|------|--------|-------|-------------------------------------------------------------|
| _owner | address | 0 | 0 | 20 | src/factory/MultiOwnerMSCAFactory.sol:MultiOwnerMSCAFactory |

`forge inspect --pretty src/factory/MultiOwnerTokenReceiverMSCAFactory.sol:MultiOwnerTokenReceiverMSCAFactory storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|--------|---------|------|--------|-------|---------------------------------------------------------------------------------------|
| _owner | address | 0 | 0 | 20 | src/factory/MultiOwnerTokenReceiverMSCAFactory.sol:MultiOwnerTokenReceiverMSCAFactory |

`forge inspect --pretty src/libraries/AccountStorageV1.sol:AccountStorageV1 storage-layout`
`forge inspect --pretty src/account/UpgradeableModularAccount.sol:UpgradeableModularAccount storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

`forge inspect --pretty src/plugins/BasePlugin.sol:BasePlugin storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|
`forge inspect --pretty src/factory/MultiOwnerModularAccountFactory.sol:MultiOwnerModularAccountFactory storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|---------|------|--------|-------|---------------------------------------------------------------------------------|
| _owner | address | 0 | 0 | 20 | src/factory/MultiOwnerModularAccountFactory.sol:MultiOwnerModularAccountFactory |
| _pendingOwner | address | 1 | 0 | 20 | src/factory/MultiOwnerModularAccountFactory.sol:MultiOwnerModularAccountFactory |

`forge inspect --pretty src/plugins/TokenReceiverPlugin.sol:TokenReceiverPlugin storage-layout`
`forge inspect --pretty src/plugins/BasePlugin.sol:BasePlugin storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------|------|------|--------|-------|----------|

`forge inspect --pretty src/plugins/owner/MultiOwnerPlugin.sol:MultiOwnerPlugin storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|------------------|--------------------------------|------|--------|-------|---------------------------------------------------------|
| _nameFallback | string | 0 | 0 | 32 | src/plugins/owner/MultiOwnerPlugin.sol:MultiOwnerPlugin |
| _versionFallback | string | 1 | 0 | 32 | src/plugins/owner/MultiOwnerPlugin.sol:MultiOwnerPlugin |
| _owners | struct AssociatedLinkedListSet | 2 | 0 | 32 | src/plugins/owner/MultiOwnerPlugin.sol:MultiOwnerPlugin |
| Name | Type | Slot | Offset | Bytes | Contract |
|---------|--------------------------------|------|--------|-------|---------------------------------------------------------|
| _owners | struct AssociatedLinkedListSet | 0 | 0 | 32 | src/plugins/owner/MultiOwnerPlugin.sol:MultiOwnerPlugin |

`forge inspect --pretty src/plugins/session/SessionKeyPlugin.sol:SessionKeyPlugin storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|--------------|--------------------------------|------|--------|-------|-----------------------------------------------------------|
| _sessionKeys | struct AssociatedLinkedListSet | 0 | 0 | 32 | src/plugins/session/SessionKeyPlugin.sol:SessionKeyPlugin |
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|--------------------------------|------|--------|-------|-----------------------------------------------------------|
| _keyIdCounter | mapping(address => uint256) | 0 | 0 | 32 | src/plugins/session/SessionKeyPlugin.sol:SessionKeyPlugin |
| _sessionKeys | struct AssociatedLinkedListSet | 1 | 0 | 32 | src/plugins/session/SessionKeyPlugin.sol:SessionKeyPlugin |

`forge inspect --pretty src/plugins/session/permissions/SessionKeyPermissions.sol:SessionKeyPermissions storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|-----------------------------|------|--------|-------|---------------------------------------------------------------------------------|
| _keyIdCounter | mapping(address => uint256) | 0 | 0 | 32 | src/plugins/session/permissions/SessionKeyPermissions.sol:SessionKeyPermissions |

`forge inspect --pretty src/plugins/session/permissions/SessionKeyPermissionsBase.sol:SessionKeyPermissionsBase storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
Expand All @@ -67,8 +63,3 @@ Generated via `bash utils/inspect.sh`.
|---------------|-----------------------------|------|--------|-------|-------------------------------------------------------------------------------------------|
| _keyIdCounter | mapping(address => uint256) | 0 | 0 | 32 | src/plugins/session/permissions/SessionKeyPermissionsLoupe.sol:SessionKeyPermissionsLoupe |

`forge inspect --pretty src/plugins/session/permissions/SessionKeyPermissionsPlugin.sol:SessionKeyPermissionsPlugin storage-layout`
| Name | Type | Slot | Offset | Bytes | Contract |
|---------------|-----------------------------|------|--------|-------|---------------------------------------------------------------------------------------------|
| _keyIdCounter | mapping(address => uint256) | 0 | 0 | 32 | src/plugins/session/permissions/SessionKeyPermissionsPlugin.sol:SessionKeyPermissionsPlugin |

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast

## Security and Audits

We have done 2 audits from Spearbit and Quantstamp and will upload the reports shortly.
We have done 2 audits from Spearbit and Quantstamp and will upload the reports shortly. Note that these audit reports may contain references to "MSCA". This was the name we used for Modular Account previously.

## License

Expand Down
47 changes: 24 additions & 23 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,27 @@ pragma solidity ^0.8.22;
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/Test.sol";

import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {IEntryPoint as I4337EntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";

import {UpgradeableModularAccount} from "../src/account/UpgradeableModularAccount.sol";
import {MultiOwnerMSCAFactory} from "../src/factory/MultiOwnerMSCAFactory.sol";
import {IEntryPoint as IMSCAEntryPoint} from "../src/interfaces/erc4337/IEntryPoint.sol";
import {MultiOwnerModularAccountFactory} from "../src/factory/MultiOwnerModularAccountFactory.sol";
import {IEntryPoint} from "../src/interfaces/erc4337/IEntryPoint.sol";
import {BasePlugin} from "../src/plugins/BasePlugin.sol";
import {MultiOwnerPlugin} from "../src/plugins/owner/MultiOwnerPlugin.sol";
import {SessionKeyPlugin} from "../src/plugins/session/SessionKeyPlugin.sol";

contract Deploy is Script {
// Load entrypoint from env
address public entryPointAddr = vm.envAddress("ENTRYPOINT");
IMSCAEntryPoint public entryPoint = IMSCAEntryPoint(payable(entryPointAddr));
IEntryPoint public entryPoint = IEntryPoint(payable(entryPointAddr));

// Load factory owner from env
address public owner = vm.envAddress("OWNER");

// Load core contract, if not in env, deploy new contract
address public mscaImpl = vm.envOr("MSCA_IMPL", address(0));
address public maImpl = vm.envOr("MA_IMPL", address(0));
address public ownerFactoryAddr = vm.envOr("OWNER_FACTORY", address(0));
address public ownerAndTokenReceiverFactoryAddr = vm.envOr("OWNER_TOKEN_RECEIVER_FACTORY", address(0));
MultiOwnerMSCAFactory ownerFactory;
MultiOwnerModularAccountFactory ownerFactory;

// Load plugins contract, if not in env, deploy new contract
address public multiOwnerPlugin = vm.envOr("OWNER_PLUGIN", address(0));
Expand All @@ -57,13 +56,13 @@ contract Deploy is Script {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Deploy msca impl
if (mscaImpl == address(0)) {
UpgradeableModularAccount msca = new UpgradeableModularAccount(entryPoint);
mscaImpl = address(msca);
console.log("New MSCA impl: ", mscaImpl);
// Deploy ma impl
if (maImpl == address(0)) {
UpgradeableModularAccount ma = new UpgradeableModularAccount(entryPoint);
maImpl = address(ma);
console.log("New MA impl: ", maImpl);
} else {
console.log("Exist MSCA impl: ", mscaImpl);
console.log("Exist MA impl: ", maImpl);
}

// Deploy multi owner plugin, and set plugin hash
Expand All @@ -76,17 +75,17 @@ contract Deploy is Script {
}
multiOwnerPluginManifestHash = keccak256(abi.encode(BasePlugin(multiOwnerPlugin).pluginManifest()));

// Deploy MultiOwnerMSCAFactory, and add stake with EP
// Deploy MultiOwnerModularAccountFactory, and add stake with EP

if (ownerFactoryAddr == address(0)) {
ownerFactory = new MultiOwnerMSCAFactory(
owner, multiOwnerPlugin, mscaImpl, multiOwnerPluginManifestHash, entryPoint
ownerFactory = new MultiOwnerModularAccountFactory(
owner, multiOwnerPlugin, maImpl, multiOwnerPluginManifestHash, entryPoint
);

ownerFactoryAddr = address(ownerFactory);
console.log("New MultiOwnerMSCAFactory: ", ownerFactoryAddr);
console.log("New MultiOwnerModularAccountFactory: ", ownerFactoryAddr);
} else {
console.log("Exist MultiOwnerMSCAFactory: ", ownerFactoryAddr);
console.log("Exist MultiOwnerModularAccountFactory: ", ownerFactoryAddr);
}
_addStakeForFactory(ownerFactoryAddr, entryPoint);

Expand All @@ -103,19 +102,21 @@ contract Deploy is Script {
vm.stopBroadcast();
}

function _addStakeForFactory(address factoryAddr, IMSCAEntryPoint anEntryPoint) internal {
function _addStakeForFactory(address factoryAddr, IEntryPoint anEntryPoint) internal {
uint32 unstakeDelaySec = uint32(vm.envOr("UNSTAKE_DELAY_SEC", uint32(60)));
uint256 requiredStakeAmount = vm.envUint("REQUIRED_STAKE_AMOUNT") * 1 ether;
uint256 currentStakedAmount = IEntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).stake;
uint256 currentStakedAmount = I4337EntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).stake;
uint256 stakeAmount = requiredStakeAmount - currentStakedAmount;
// since all factory share the same addStake method, it does not matter which contract we use to cast the
// address
MultiOwnerMSCAFactory(payable(factoryAddr)).addStake{value: stakeAmount}(unstakeDelaySec, stakeAmount);
MultiOwnerModularAccountFactory(payable(factoryAddr)).addStake{value: stakeAmount}(
unstakeDelaySec, stakeAmount
);
console.log("******** Add Stake Verify *********");
console.log("Staked factory: ", factoryAddr);
console.log("Stake amount: ", IEntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).stake);
console.log("Stake amount: ", I4337EntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).stake);
console.log(
"Unstake delay: ", IEntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).unstakeDelaySec
"Unstake delay: ", I4337EntryPoint(address(anEntryPoint)).getDepositInfo(factoryAddr).unstakeDelaySec
);
console.log("******** Stake Verify Done *********");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import {FactoryHelpers} from "../helpers/FactoryHelpers.sol";
import {IEntryPoint} from "../interfaces/erc4337/IEntryPoint.sol";
import {IAccountInitializable} from "../interfaces/IAccountInitializable.sol";

/// @title Multi Owner Plugin MSCA (Modular Smart Contract Account) Factory
/// @title Multi Owner Plugin Modular Account Factory
/// @author Alchemy
/// @notice Factory for upgradeable modular accounts with MultiOwnerPlugin installed.
/// @dev There is a reliance on the assumption that the plugin manifest will remain static, following ERC-6900. If
/// this assumption is broken then account deployments would be bricked.
contract MultiOwnerMSCAFactory is Ownable2Step {
contract MultiOwnerModularAccountFactory is Ownable2Step {
IEntryPoint public immutable ENTRYPOINT;
address public immutable MULTI_OWNER_PLUGIN;
address public immutable IMPL;
Expand Down
6 changes: 3 additions & 3 deletions test/account/AccountExecHooks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import {PluginManagerInternals} from "../../src/account/PluginManagerInternals.sol";
import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
import {MultiOwnerMSCAFactory} from "../../src/factory/MultiOwnerMSCAFactory.sol";
import {MultiOwnerModularAccountFactory} from "../../src/factory/MultiOwnerModularAccountFactory.sol";
import {FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol";
import {IEntryPoint} from "../../src/interfaces/erc4337/IEntryPoint.sol";
import {
Expand All @@ -44,7 +44,7 @@ contract UpgradeableModularAccountExecHooksTest is Test {

IEntryPoint public entryPoint;
MultiOwnerPlugin public multiOwnerPlugin;
MultiOwnerMSCAFactory public factory;
MultiOwnerModularAccountFactory public factory;
MockPlugin public mockPlugin1;
MockPlugin public mockPlugin2;
bytes32 public manifestHash1;
Expand Down Expand Up @@ -73,7 +73,7 @@ contract UpgradeableModularAccountExecHooksTest is Test {
(owner1, owner1Key) = makeAddrAndKey("owner1");
address impl = address(new UpgradeableModularAccount(IEntryPoint(address(entryPoint))));

factory = new MultiOwnerMSCAFactory(
factory = new MultiOwnerModularAccountFactory(
address(this),
address(multiOwnerPlugin),
impl,
Expand Down
6 changes: 3 additions & 3 deletions test/account/AccountLoupe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {EntryPoint} from "@eth-infinitism/account-abstraction/core/EntryPoint.so
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
import {MultiOwnerMSCAFactory} from "../../src/factory/MultiOwnerMSCAFactory.sol";
import {MultiOwnerModularAccountFactory} from "../../src/factory/MultiOwnerModularAccountFactory.sol";
import {FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol";
import {IEntryPoint} from "../../src/interfaces/erc4337/IEntryPoint.sol";
import {IAccountLoupe} from "../../src/interfaces/IAccountLoupe.sol";
Expand All @@ -43,7 +43,7 @@ import {ComprehensivePlugin} from "../mocks/plugins/ComprehensivePlugin.sol";
contract AccountLoupeTest is Test {
IEntryPoint public entryPoint;
MultiOwnerPlugin public multiOwnerPlugin;
MultiOwnerMSCAFactory public factory;
MultiOwnerModularAccountFactory public factory;
ComprehensivePlugin public comprehensivePlugin;

UpgradeableModularAccount public account1;
Expand All @@ -58,7 +58,7 @@ contract AccountLoupeTest is Test {

multiOwnerPlugin = new MultiOwnerPlugin();
address impl = address(new UpgradeableModularAccount(entryPoint));
factory = new MultiOwnerMSCAFactory(
factory = new MultiOwnerModularAccountFactory(
address(this),
address(multiOwnerPlugin),
impl,
Expand Down
6 changes: 3 additions & 3 deletions test/account/AccountPreValidationHooks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import {PluginManagerInternals} from "../../src/account/PluginManagerInternals.sol";
import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
import {MultiOwnerMSCAFactory} from "../../src/factory/MultiOwnerMSCAFactory.sol";
import {MultiOwnerModularAccountFactory} from "../../src/factory/MultiOwnerModularAccountFactory.sol";
import {FunctionReferenceLib} from "../../src/helpers/FunctionReferenceLib.sol";
import {IEntryPoint} from "../../src/interfaces/erc4337/IEntryPoint.sol";
import {UserOperation} from "../../src/interfaces/erc4337/UserOperation.sol";
Expand All @@ -46,7 +46,7 @@ contract UpgradeableModularAccountPreValidationHooksTest is Test {
IEntryPoint public entryPoint;
address payable public beneficiary;
MultiOwnerPlugin public multiOwnerPlugin;
MultiOwnerMSCAFactory public factory;
MultiOwnerModularAccountFactory public factory;
MockPlugin public mockPlugin1;
MockPlugin public mockPlugin2;
bytes32 public manifestHash1;
Expand Down Expand Up @@ -77,7 +77,7 @@ contract UpgradeableModularAccountPreValidationHooksTest is Test {

address impl = address(new UpgradeableModularAccount(entryPoint));

factory = new MultiOwnerMSCAFactory(
factory = new MultiOwnerModularAccountFactory(
address(this),
address(multiOwnerPlugin),
impl,
Expand Down
6 changes: 3 additions & 3 deletions test/account/AccountReturnData.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {Test} from "forge-std/Test.sol";
import {EntryPoint} from "@eth-infinitism/account-abstraction/core/EntryPoint.sol";

import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
import {MultiOwnerMSCAFactory} from "../../src/factory/MultiOwnerMSCAFactory.sol";
import {MultiOwnerModularAccountFactory} from "../../src/factory/MultiOwnerModularAccountFactory.sol";
import {IEntryPoint} from "../../src/interfaces/erc4337/IEntryPoint.sol";
import {FunctionReference} from "../../src/interfaces/IPluginManager.sol";
import {Call} from "../../src/interfaces/IStandardExecutor.sol";
Expand All @@ -37,7 +37,7 @@ import {
contract AccountReturnDataTest is Test {
IEntryPoint public entryPoint; // Just to be able to construct the factory
MultiOwnerPlugin public multiOwnerPlugin;
MultiOwnerMSCAFactory public factory;
MultiOwnerModularAccountFactory public factory;

RegularResultContract public regularResultContract;
ResultCreatorPlugin public resultCreatorPlugin;
Expand All @@ -50,7 +50,7 @@ contract AccountReturnDataTest is Test {
multiOwnerPlugin = new MultiOwnerPlugin();
address impl = address(new UpgradeableModularAccount(entryPoint));

factory = new MultiOwnerMSCAFactory(
factory = new MultiOwnerModularAccountFactory(
address(this),
address(multiOwnerPlugin),
impl,
Expand Down
Loading
Loading