Skip to content

Commit

Permalink
fix: replace 'EntryPoint' import with 'IEntryPoint' to avoid versions…
Browse files Browse the repository at this point in the history
… incompatibility
  • Loading branch information
gabrielstoica committed Nov 4, 2024
1 parent b9f9c53 commit 77e98a1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions script/DeployDeterministicStationRegistry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.26;
import { BaseScript } from "./Base.s.sol";
import { StationRegistry } from "./../src/StationRegistry.sol";
import { ModuleKeeper } from "./../src/ModuleKeeper.sol";
import { EntryPoint } from "@thirdweb/contracts/prebuilts/account/utils/Entrypoint.sol";
import { IEntryPoint } from "@thirdweb/contracts/prebuilts/account/interface/IEntrypoint.sol";

/// @notice Deploys at deterministic addresses across chains an instance of {StationRegistry}
/// @dev Reverts if any contract has already been deployed
Expand All @@ -14,7 +14,7 @@ contract DeployDeterministicStationRegistry is BaseScript {
function run(
string memory create2Salt,
address initialAdmin,
EntryPoint entrypoint,
IEntryPoint entrypoint,
ModuleKeeper moduleKeeper
) public virtual broadcast returns (StationRegistry stationRegistry) {
bytes32 salt = bytes32(abi.encodePacked(create2Salt));
Expand Down
20 changes: 15 additions & 5 deletions src/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
}

/// @inheritdoc ISpace
function withdrawNative(uint256 amount) public onlyAdminOrEntrypoint {
function withdrawNative(
uint256 amount
) public onlyAdminOrEntrypoint {
// Checks: the native balance of the space minus the amount locked for operations is greater than the requested amount
if (amount > address(this).balance) revert Errors.InsufficientNativeToWithdraw();

Expand All @@ -177,7 +179,9 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
}

/// @inheritdoc IModuleManager
function enableModule(address module) public override onlyAdminOrEntrypoint {
function enableModule(
address module
) public override onlyAdminOrEntrypoint {
// Retrieve the address of the {ModuleKeeper}
ModuleKeeper moduleKeeper = StationRegistry(factory).moduleKeeper();

Expand All @@ -186,7 +190,9 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
}

/// @inheritdoc IModuleManager
function disableModule(address module) public override onlyAdminOrEntrypoint {
function disableModule(
address module
) public override onlyAdminOrEntrypoint {
// Effects: disable the module
_disableModule(module);
}
Expand Down Expand Up @@ -224,14 +230,18 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
}

/// @inheritdoc ISpace
function getMessageHash(bytes32 _hash) public view returns (bytes32) {
function getMessageHash(
bytes32 _hash
) public view returns (bytes32) {
bytes32 messageHash = keccak256(abi.encode(_hash));
bytes32 typedDataHash = keccak256(abi.encode(MSG_TYPEHASH, messageHash));
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), typedDataHash));
}

/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
function supportsInterface(
bytes4 interfaceId
) public pure returns (bool) {
return interfaceId == type(ISpace).interfaceId || interfaceId == type(IERC1155Receiver).interfaceId
|| interfaceId == type(IERC721Receiver).interfaceId || interfaceId == type(IERC165).interfaceId;
}
Expand Down
8 changes: 6 additions & 2 deletions src/StationRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ contract StationRegistry is IStationRegistry, BaseAccountFactory, PermissionsEnu
}

/// @inheritdoc IStationRegistry
function updateModuleKeeper(ModuleKeeper newModuleKeeper) external onlyRole(DEFAULT_ADMIN_ROLE) {
function updateModuleKeeper(
ModuleKeeper newModuleKeeper
) external onlyRole(DEFAULT_ADMIN_ROLE) {
// Effects: update the {ModuleKeeper} address
moduleKeeper = newModuleKeeper;

Expand All @@ -124,7 +126,9 @@ contract StationRegistry is IStationRegistry, BaseAccountFactory, PermissionsEnu
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IStationRegistry
function totalAccountsOfSigner(address signer) public view returns (uint256) {
function totalAccountsOfSigner(
address signer
) public view returns (uint256) {
return accountsOfSigner[signer].length();
}

Expand Down
18 changes: 11 additions & 7 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { MockBadReceiver } from "./mocks/MockBadReceiver.sol";
import { Space } from "./../src/Space.sol";
import { ModuleKeeper } from "./../src/ModuleKeeper.sol";
import { StationRegistry } from "./../src/StationRegistry.sol";
import { EntryPoint } from "@thirdweb/contracts/prebuilts/account/utils/Entrypoint.sol";
import { MockERC721Collection } from "./mocks/MockERC721Collection.sol";
import { MockERC1155Collection } from "./mocks/MockERC1155Collection.sol";
import { MockBadSpace } from "./mocks/MockBadSpace.sol";
import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol";
import { IEntryPoint } from "@thirdweb/contracts/prebuilts/account/interface/IEntrypoint.sol";

abstract contract Base_Test is Test, Events {
/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -28,7 +28,7 @@ abstract contract Base_Test is Test, Events {
TEST CONTRACTS
//////////////////////////////////////////////////////////////////////////*/

EntryPoint internal entrypoint;
address internal entrypoint;
StationRegistry internal stationRegistry;
Space internal space;
ModuleKeeper internal moduleKeeper;
Expand Down Expand Up @@ -58,11 +58,11 @@ abstract contract Base_Test is Test, Events {
users = Users({ admin: createUser("admin"), eve: createUser("eve"), bob: createUser("bob") });

// Deploy test contracts
entrypoint = new EntryPoint();
//entrypoint = new EntryPoint();
moduleKeeper = new ModuleKeeper({ _initialOwner: users.admin });

stationRegistry = new StationRegistry(users.admin, entrypoint, moduleKeeper);
containerImplementation = address(new Space(entrypoint, address(stationRegistry)));
stationRegistry = new StationRegistry(users.admin, IEntryPoint(entrypoint), moduleKeeper);
containerImplementation = address(new Space(IEntryPoint(entrypoint), address(stationRegistry)));

mockModule = new MockModule();
mockNonCompliantSpace = new MockNonCompliantSpace({ _owner: users.admin });
Expand Down Expand Up @@ -126,7 +126,9 @@ abstract contract Base_Test is Test, Events {
vm.stopPrank();
}

function allowlistModule(address _module) internal {
function allowlistModule(
address _module
) internal {
moduleKeeper.addToAllowlist({ module: _module });
}

Expand All @@ -135,7 +137,9 @@ abstract contract Base_Test is Test, Events {
//////////////////////////////////////////////////////////////////////////*/

/// @dev Generates a user, labels its address, and funds it with test assets
function createUser(string memory name) internal returns (address payable) {
function createUser(
string memory name
) internal returns (address payable) {
address payable user = payable(makeAddr(name));
vm.deal({ account: user, newBalance: 100 ether });
deal({ token: address(usdt), to: user, give: 10_000_000e18 });
Expand Down
7 changes: 6 additions & 1 deletion test/unit/concrete/station-registry/constructor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.26;
import { StationRegistry } from "./../../../../src/StationRegistry.sol";
import { Base_Test } from "../../../Base.t.sol";
import { Constants } from "../../../utils/Constants.sol";
import { IEntryPoint } from "@thirdweb/contracts/prebuilts/account/interface/IEntrypoint.sol";

contract Constructor_StationRegistry_Test is Base_Test {
function setUp() public virtual override {
Expand All @@ -12,7 +13,11 @@ contract Constructor_StationRegistry_Test is Base_Test {

function test_Constructor() external {
// Run the test
new StationRegistry({ _initialAdmin: users.admin, _entrypoint: entrypoint, _moduleKeeper: moduleKeeper });
new StationRegistry({
_initialAdmin: users.admin,
_entrypoint: IEntryPoint(entrypoint),
_moduleKeeper: moduleKeeper
});

// Assert the actual and expected {ModuleKeeper} address
address actualModuleKeeper = address(stationRegistry.moduleKeeper());
Expand Down

0 comments on commit 77e98a1

Please sign in to comment.