Skip to content

Commit

Permalink
refactor: use reference-implementation's libraries (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik authored Oct 10, 2024
1 parent 77c4dde commit 4998901
Show file tree
Hide file tree
Showing 46 changed files with 154 additions and 730 deletions.
4 changes: 3 additions & 1 deletion gas/modular-account/ModularAccount.gas.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

import {Vm} from "forge-std/src/Vm.sol";

import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol";
import {AccountFactory} from "../../src/factory/AccountFactory.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol";

import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol";

Expand Down
11 changes: 8 additions & 3 deletions gas/modular-account/ModularAccountBenchmarkBase.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {
HookConfig,
ModuleEntity,
ValidationConfig
} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {ValidationDataView} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol";
import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";

Expand All @@ -10,9 +18,6 @@ import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol";
import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBytecode.sol";
import {AccountFactory} from "../../src/factory/AccountFactory.sol";
import {FALLBACK_VALIDATION} from "../../src/helpers/Constants.sol";
import {HookConfig, HookConfigLib} from "../../src/libraries/HookConfigLib.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol";
import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol";
import {AllowlistModule} from "../../src/modules/permissions/AllowlistModule.sol";
import {ERC20TokenLimitModule} from "../../src/modules/permissions/ERC20TokenLimitModule.sol";
import {TimeRangeModule} from "../../src/modules/permissions/TimeRangeModule.sol";
Expand Down
3 changes: 2 additions & 1 deletion gas/modular-account/SemiModularAccount.gas.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {Vm} from "forge-std/src/Vm.sol";

import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol";
import {AccountFactory} from "../../src/factory/AccountFactory.sol";
import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol";

import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol";

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"version": "v1.0.1",
"dependencies": {
"account-abstraction": "github:eth-infinitism/account-abstraction#v0.7.0",
"@erc6900/modular-account-libs": "github:erc6900/modular-account-libs#v0.8.0-rc.1",
"@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0-rc.3",
"@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0-rc.4",
"solady": "github:Vectorized/solady#v0.0.237"
},
"devDependencies": {
Expand Down
21 changes: 6 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ds-test/=lib/forge-std/lib/ds-test/src/
@erc6900/modular-account-libs/=node_modules/@erc6900/modular-account-libs/src/
@eth-infinitism/account-abstraction/=node_modules/account-abstraction/contracts/
account-abstraction/=node_modules/account-abstraction/contracts/
@openzeppelin/=lib/openzeppelin-contracts/
Expand All @@ -10,4 +9,4 @@ forge-gas-snapshot/=lib/forge-gas-snapshot/src/
forge-std/=lib/forge-std/
webauthn-sol/=lib/webauthn-sol/
FreshCryptoLib/=lib/webauthn-sol/lib/FreshCryptoLib/solidity/src/
openzeppelin-contracts/=lib/webauthn-sol/lib/openzeppelin-contracts/
openzeppelin-contracts/=lib/webauthn-sol/lib/openzeppelin-contracts/
29 changes: 13 additions & 16 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

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

import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";

import {IExecutionHookModule} from "@erc6900/reference-implementation/interfaces/IExecutionHookModule.sol";
import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol";
import {
Call,
HookConfig,
IModularAccount,
ModuleEntity,
ValidationConfig
} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {IValidationHookModule} from "@erc6900/reference-implementation/interfaces/IValidationHookModule.sol";
import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol";
import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol";
import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";

import {DIRECT_CALL_VALIDATION_ENTITYID} from "../helpers/Constants.sol";
import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationResHelpers.sol";

import {ExecutionLib} from "../libraries/ExecutionLib.sol";
import {HookConfig, HookConfigLib} from "../libraries/HookConfigLib.sol";
import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol";
import {MemManagementLib} from "../libraries/MemManagementLib.sol";
import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol";
import {SparseCalldataSegmentLib} from "../libraries/SparseCalldataSegmentLib.sol";
import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol";
import {AccountStorage, getAccountStorage, toSetValue} from "./AccountStorage.sol";
import {AccountStorageInitializable} from "./AccountStorageInitializable.sol";
import {BaseAccount} from "./BaseAccount.sol";
Expand Down
9 changes: 4 additions & 5 deletions src/account/ModuleManagerInternals.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

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

import {IExecutionHookModule} from "@erc6900/reference-implementation/interfaces/IExecutionHookModule.sol";
import {
ExecutionManifest,
Expand All @@ -17,15 +15,16 @@ import {
import {IModule} from "@erc6900/reference-implementation/interfaces/IModule.sol";
import {IValidationHookModule} from "@erc6900/reference-implementation/interfaces/IValidationHookModule.sol";
import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol";
import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol";
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";

import {MAX_PRE_VALIDATION_HOOKS} from "../helpers/Constants.sol";
import {ExecutionLib} from "../libraries/ExecutionLib.sol";
import {HookConfigLib} from "../libraries/HookConfigLib.sol";
import {KnownSelectorsLib} from "../libraries/KnownSelectorsLib.sol";
import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol";
import {MemManagementLib} from "../libraries/MemManagementLib.sol";
import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol";
import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol";
import {AccountStorage, ExecutionData, ValidationData, getAccountStorage, toSetValue} from "./AccountStorage.sol";

abstract contract ModuleManagerInternals is IModularAccount {
Expand Down
8 changes: 2 additions & 6 deletions src/account/SemiModularAccountBase.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";

import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

import {DIRECT_CALL_VALIDATION_ENTITYID, FALLBACK_VALIDATION} from "../helpers/Constants.sol";

import {SignatureType} from "../helpers/SignatureType.sol";
import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol";

import {SemiModularKnownSelectorsLib} from "../libraries/SemiModularKnownSelectorsLib.sol";
import {ModularAccountBase} from "./ModularAccountBase.sol";

Expand Down
6 changes: 2 additions & 4 deletions src/factory/AccountFactory.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {LibClone} from "solady/utils/LibClone.sol";

import {ModularAccount} from "../account/ModularAccount.sol";
import {SemiModularAccountBytecode} from "../account/SemiModularAccountBytecode.sol";
import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol";

import {LibClone} from "solady/utils/LibClone.sol";

contract AccountFactory is Ownable {
ModularAccount public immutable ACCOUNT_IMPL;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Constants.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;

import {ModuleEntity} from "../libraries/ModuleEntityLib.sol";
import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";

// Index marking the start of the data for the validation function.
uint8 constant RESERVED_VALIDATION_DATA_INDEX = type(uint8).max;
Expand Down
Loading

0 comments on commit 4998901

Please sign in to comment.