Skip to content

Commit

Permalink
refactor: Refactor to use modular-account-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0dot committed May 10, 2024
1 parent 1cff070 commit fd8aa73
Show file tree
Hide file tree
Showing 76 changed files with 201 additions and 3,418 deletions.
4 changes: 2 additions & 2 deletions src/account/AccountExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pragma solidity ^0.8.22;

import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";

import {UserOperation} from "../interfaces/erc4337/UserOperation.sol";
import {IPlugin} from "../interfaces/IPlugin.sol";
import {UserOperation} from "modular-account-libs/interfaces/UserOperation.sol";
import {IPlugin} from "modular-account-libs/interfaces/IPlugin.sol";

/// @title Account Executor
/// @author Alchemy
Expand Down
8 changes: 4 additions & 4 deletions src/account/AccountLoupe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pragma solidity ^0.8.22;
import {AccountStorageV1} from "../account/AccountStorageV1.sol";
import {CastLib} from "../helpers/CastLib.sol";
import {KnownSelectors} from "../helpers/KnownSelectors.sol";
import {IAccountLoupe} from "../interfaces/IAccountLoupe.sol";
import {FunctionReference} from "../interfaces/IPluginManager.sol";
import {CountableLinkedListSetLib} from "../libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol";
import {IAccountLoupe} from "modular-account-libs/interfaces/IAccountLoupe.sol";
import {FunctionReference} from "modular-account-libs/interfaces/IPluginManager.sol";
import {CountableLinkedListSetLib} from "modular-account-libs/libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "modular-account-libs/libraries/LinkedListSetLib.sol";

/// @title Account Loupe
/// @author Alchemy
Expand Down
6 changes: 3 additions & 3 deletions src/account/AccountStorageV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

pragma solidity ^0.8.22;

import {IPlugin} from "../interfaces/IPlugin.sol";
import {FunctionReference} from "../interfaces/IPluginManager.sol";
import {LinkedListSet} from "../libraries/LinkedListSetLib.sol";
import {IPlugin} from "modular-account-libs/interfaces/IPlugin.sol";
import {FunctionReference} from "modular-account-libs/interfaces/IPluginManager.sol";
import {LinkedListSet} from "modular-account-libs/libraries/LinkedListSetLib.sol";

/// @title Account Storage V1
/// @author Alchemy
Expand Down
28 changes: 15 additions & 13 deletions src/account/PluginManagerInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ pragma solidity ^0.8.22;

import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";

import {AccountStorageV1} from "../account/AccountStorageV1.sol";
import {CastLib} from "../helpers/CastLib.sol";
import {FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
import {KnownSelectors} from "../helpers/KnownSelectors.sol";
import {FunctionReferenceLib} from "modular-account-libs/libraries/FunctionReferenceLib.sol";
import {
IPlugin,
ManifestAssociatedFunction,
Expand All @@ -31,10 +28,15 @@ import {
ManifestExternalCallPermission,
ManifestFunction,
PluginManifest
} from "../interfaces/IPlugin.sol";
import {FunctionReference, IPluginManager} from "../interfaces/IPluginManager.sol";
import {CountableLinkedListSetLib} from "../libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol";
} from "modular-account-libs/interfaces/IPlugin.sol";
import {FunctionReference, IPluginManager} from "modular-account-libs/interfaces/IPluginManager.sol";
import {CountableLinkedListSetLib} from "modular-account-libs/libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "modular-account-libs/libraries/LinkedListSetLib.sol";

import {KnownSelectors} from "../helpers/KnownSelectors.sol";
import {AccountStorageV1} from "../account/AccountStorageV1.sol";
import {CastLib} from "../helpers/CastLib.sol";
import {FunctionReferenceHelpers} from "../helpers/FunctionReferenceHelpers.sol";

/// @title Plugin Manager Internals
/// @author Alchemy
Expand Down Expand Up @@ -574,15 +576,15 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {
for (uint256 i = 0; i < length; ++i) {
bytes4 executionSelector = args.manifest.runtimeValidationFunctions[i].executionSelector;
storage_.selectorData[executionSelector].runtimeValidation =
FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE;
FunctionReferenceLib.EMPTY_FUNCTION_REFERENCE;
}

// Remove user op validation function hooks
length = args.manifest.userOpValidationFunctions.length;
for (uint256 i = 0; i < length; ++i) {
bytes4 executionSelector = args.manifest.userOpValidationFunctions[i].executionSelector;
storage_.selectorData[executionSelector].userOpValidation =
FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE;
FunctionReferenceLib.EMPTY_FUNCTION_REFERENCE;
}

// Remove permitted external call permissions, anyExternalAddressPermitted is cleared when pluginData being
Expand Down Expand Up @@ -672,17 +674,17 @@ abstract contract PluginManagerInternals is IPluginManager, AccountStorageV1 {
}
if (manifestFunction.functionType == ManifestAssociatedFunctionType.RUNTIME_VALIDATION_ALWAYS_ALLOW) {
if (allowedMagicValue == ManifestAssociatedFunctionType.RUNTIME_VALIDATION_ALWAYS_ALLOW) {
return FunctionReferenceLib._RUNTIME_VALIDATION_ALWAYS_ALLOW;
return FunctionReferenceHelpers._RUNTIME_VALIDATION_ALWAYS_ALLOW;
}
revert InvalidPluginManifest();
}
if (manifestFunction.functionType == ManifestAssociatedFunctionType.PRE_HOOK_ALWAYS_DENY) {
if (allowedMagicValue == ManifestAssociatedFunctionType.PRE_HOOK_ALWAYS_DENY) {
return FunctionReferenceLib._PRE_HOOK_ALWAYS_DENY;
return FunctionReferenceHelpers._PRE_HOOK_ALWAYS_DENY;
}
revert InvalidPluginManifest();
}
return FunctionReferenceLib._EMPTY_FUNCTION_REFERENCE; // Empty checks are done elsewhere
return FunctionReferenceLib.EMPTY_FUNCTION_REFERENCE; // Empty checks are done elsewhere
}

function _assertNotNullFunction(FunctionReference functionReference) internal pure {
Expand Down
21 changes: 12 additions & 9 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@ import {IERC777Recipient} from "@openzeppelin/contracts/interfaces/IERC777Recipi
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {IAccount} from "modular-account-libs/interfaces/IAccount.sol";
import {UserOperation} from "modular-account-libs/interfaces/UserOperation.sol";
import {IPlugin, PluginManifest} from "modular-account-libs/interfaces/IPlugin.sol";
import {FunctionReferenceLib} from "modular-account-libs/libraries/FunctionReferenceLib.sol";
import {IPluginExecutor} from "modular-account-libs/interfaces/IPluginExecutor.sol";
import {Call, IStandardExecutor} from "modular-account-libs/interfaces/IStandardExecutor.sol";
import {CountableLinkedListSetLib} from "modular-account-libs/libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "modular-account-libs/libraries/LinkedListSetLib.sol";
import {FunctionReference, IPluginManager} from "modular-account-libs/interfaces/IPluginManager.sol";

import {UUPSUpgradeable} from "../../ext/UUPSUpgradeable.sol";
import {CastLib} from "../helpers/CastLib.sol";
import {FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol";
import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationDataHelpers.sol";
import {IAccount} from "../interfaces/erc4337/IAccount.sol";
import {IEntryPoint} from "../interfaces/erc4337/IEntryPoint.sol";
import {UserOperation} from "../interfaces/erc4337/UserOperation.sol";
import {IAccountInitializable} from "../interfaces/IAccountInitializable.sol";
import {IAccountView} from "../interfaces/IAccountView.sol";
import {IPlugin, PluginManifest} from "../interfaces/IPlugin.sol";
import {IPluginExecutor} from "../interfaces/IPluginExecutor.sol";
import {FunctionReference, IPluginManager} from "../interfaces/IPluginManager.sol";
import {Call, IStandardExecutor} from "../interfaces/IStandardExecutor.sol";
import {CountableLinkedListSetLib} from "../libraries/CountableLinkedListSetLib.sol";
import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol";
import {AccountExecutor} from "./AccountExecutor.sol";
import {AccountLoupe} from "./AccountLoupe.sol";
import {AccountStorageInitializable} from "./AccountStorageInitializable.sol";
import {PluginManagerInternals} from "./PluginManagerInternals.sol";
import {FunctionReferenceHelpers} from "../helpers/FunctionReferenceHelpers.sol";

/// @title Upgradeable Modular Account
/// @author Alchemy
Expand All @@ -64,6 +66,7 @@ contract UpgradeableModularAccount is
using CountableLinkedListSetLib for LinkedListSet;
using LinkedListSetLib for LinkedListSet;
using FunctionReferenceLib for FunctionReference;
using FunctionReferenceHelpers for FunctionReference;

/// @dev Struct to hold optional configuration data for uninstalling a plugin. This should be encoded and
/// passed to the `config` parameter of `uninstallPlugin`.
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/CastLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

pragma solidity ^0.8.22;

import {SetValue} from "../libraries/Constants.sol";
import {FunctionReference} from "./FunctionReferenceLib.sol";
import {SetValue} from "modular-account-libs/libraries/Constants.sol";
import {FunctionReference} from "modular-account-libs/libraries/FunctionReferenceLib.sol";

/// @title Cast Library
/// @author Alchemy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,18 @@

pragma solidity ^0.8.22;

import {FunctionReference} from "../interfaces/IPluginManager.sol";
import {FunctionReference} from "modular-account-libs/interfaces/IPluginManager.sol";

/// @title Function Reference Lib
/// @title Function Reference Helpers
/// @author Alchemy
library FunctionReferenceLib {
// Empty or unset function reference.
FunctionReference internal constant _EMPTY_FUNCTION_REFERENCE = FunctionReference.wrap(bytes21(0));
library FunctionReferenceHelpers {
// Magic value for runtime validation functions that always allow access.
FunctionReference internal constant _RUNTIME_VALIDATION_ALWAYS_ALLOW =
FunctionReference.wrap(bytes21(uint168(1)));
// Magic value for hooks that should always revert.
FunctionReference internal constant _PRE_HOOK_ALWAYS_DENY = FunctionReference.wrap(bytes21(uint168(2)));

function pack(address addr, uint8 functionId) internal pure returns (FunctionReference) {
return FunctionReference.wrap(bytes21(bytes20(addr)) | bytes21(uint168(functionId)));
}

function unpack(FunctionReference fr) internal pure returns (address addr, uint8 functionId) {
bytes21 underlying = FunctionReference.unwrap(fr);
addr = address(bytes20(underlying));
functionId = uint8(bytes1(underlying << 160));
}

function isEmptyOrMagicValue(FunctionReference fr) internal pure returns (bool) {
return FunctionReference.unwrap(fr) <= bytes21(uint168(2));
}

function isEmpty(FunctionReference fr) internal pure returns (bool) {
return FunctionReference.unwrap(fr) == bytes21(0);
}

function eq(FunctionReference a, FunctionReference b) internal pure returns (bool) {
return FunctionReference.unwrap(a) == FunctionReference.unwrap(b);
}

function notEq(FunctionReference a, FunctionReference b) internal pure returns (bool) {
return FunctionReference.unwrap(a) != FunctionReference.unwrap(b);
}
}
12 changes: 6 additions & 6 deletions src/helpers/KnownSelectors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import {IERC777Recipient} from "@openzeppelin/contracts/interfaces/IERC777Recipi
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {IAccount} from "../../src/interfaces/erc4337/IAccount.sol";
import {IAccount} from "modular-account-libs/interfaces/IAccount.sol";
import {IAggregator} from "../../src/interfaces/erc4337/IAggregator.sol";
import {IPaymaster} from "../../src/interfaces/erc4337/IPaymaster.sol";
import {IAccountLoupe} from "../../src/interfaces/IAccountLoupe.sol";
import {IAccountLoupe} from "modular-account-libs/interfaces/IAccountLoupe.sol";
import {IAccountView} from "../../src/interfaces/IAccountView.sol";
import {IPluginManager} from "../../src/interfaces/IPluginManager.sol";
import {IPluginManager} from "modular-account-libs/interfaces/IPluginManager.sol";
import {IAccountInitializable} from "../interfaces/IAccountInitializable.sol";
import {IPlugin} from "../interfaces/IPlugin.sol";
import {IPluginExecutor} from "../interfaces/IPluginExecutor.sol";
import {IStandardExecutor} from "../interfaces/IStandardExecutor.sol";
import {IPlugin} from "modular-account-libs/interfaces/IPlugin.sol";
import {IPluginExecutor} from "modular-account-libs/interfaces/IPluginExecutor.sol";
import {IStandardExecutor} from "modular-account-libs/interfaces/IStandardExecutor.sol";

/// @title Known Selectors
/// @author Alchemy
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ValidationDataHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

pragma solidity ^0.8.22;

import {SIG_VALIDATION_FAILED} from "../libraries/Constants.sol";
import {SIG_VALIDATION_FAILED} from "modular-account-libs/libraries/Constants.sol";

/// @dev This helper function assumes that uint160(validationData1) and uint160(validationData2) can only be 0 or 1
// solhint-disable-next-line private-vars-leading-underscore
Expand Down
53 changes: 0 additions & 53 deletions src/interfaces/IAccountLoupe.sol

This file was deleted.

Loading

0 comments on commit fd8aa73

Please sign in to comment.