Skip to content

Commit

Permalink
style: run prettier write
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielstoica committed Nov 7, 2024
1 parent a256e78 commit 61b4ad7
Show file tree
Hide file tree
Showing 30 changed files with 220 additions and 175 deletions.
2 changes: 1 addition & 1 deletion script/Base.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.20;
pragma solidity ^0.8.22;

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

Expand Down
8 changes: 6 additions & 2 deletions script/DeployDeterministicInvoiceModule.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ contract DeployDeterministicInvoiceModule is BaseScript {
bytes32 salt = bytes32(abi.encodePacked(create2Salt));

// Deterministically deploy the {InvoiceModule} contracts
invoiceModule =
new InvoiceModule{ salt: salt }(sablierLockupLinear, sablierLockupTranched, brokerAdmin, baseURI);
invoiceModule = new InvoiceModule{ salt: salt }(
sablierLockupLinear,
sablierLockupTranched,
brokerAdmin,
baseURI
);
}
}
2 changes: 1 addition & 1 deletion src/ModuleKeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract ModuleKeeper is IModuleKeeper, Ownable {
//////////////////////////////////////////////////////////////////////////*/

/// @dev Initializes the initial owner of the {ModuleKeeper}
constructor(address _initialOwner) Ownable(_initialOwner) { }
constructor(address _initialOwner) Ownable(_initialOwner) {}

/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
Expand Down
54 changes: 28 additions & 26 deletions src/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
//////////////////////////////////////////////////////////////////////////*/

/// @dev Initializes the address of the EIP 4337 factory and EntryPoint contract
constructor(IEntryPoint _entrypoint, address _factory) AccountCore(_entrypoint, _factory) { }
constructor(IEntryPoint _entrypoint, address _factory) AccountCore(_entrypoint, _factory) {}

/// @notice Initializes the {ModuleKeeper}, enables initial modules and configures the {Space} smart account
function initialize(address _defaultAdmin, bytes calldata _data) public override {
(,, address[] memory initialModules) = abi.decode(_data, (uint256, uint256, address[]));
(, , address[] memory initialModules) = abi.decode(_data, (uint256, uint256, address[]));

// Enable the initial module(s)
ModuleKeeper moduleKeeper = StationRegistry(factory).moduleKeeper();
Expand Down Expand Up @@ -153,24 +153,34 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
// therefore the `onERC1155Received` hook must be implemented
// - depending on the length of the `ids` array, we're using `safeBatchTransferFrom` or `safeTransferFrom`
if (ids.length > 1) {
collection.safeBatchTransferFrom({ from: address(this), to: msg.sender, ids: ids, values: amounts, data: "" });
collection.safeBatchTransferFrom({
from: address(this),
to: msg.sender,
ids: ids,
values: amounts,
data: ""
});
} else {
collection.safeTransferFrom({ from: address(this), to: msg.sender, id: ids[0], value: amounts[0], data: "" });
collection.safeTransferFrom({
from: address(this),
to: msg.sender,
id: ids[0],
value: amounts[0],
data: ""
});
}

// Log the successful ERC-1155 token withdrawal
emit ERC1155Withdrawn(msg.sender, address(collection), ids, amounts);
}

/// @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();

// Interactions: withdraw by transferring the amount to the sender
(bool success,) = msg.sender.call{ value: amount }("");
(bool success, ) = msg.sender.call{ value: amount }("");
// Revert if the call failed
if (!success) revert Errors.NativeWithdrawFailed();

Expand All @@ -179,9 +189,7 @@ 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 @@ -190,9 +198,7 @@ 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 All @@ -202,10 +208,7 @@ contract Space is ISpace, AccountCore, ERC1271, ModuleManager {
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc ERC1271
function isValidSignature(
bytes32 _hash,
bytes memory _signature
) public view override returns (bytes4 magicValue) {
function isValidSignature(bytes32 _hash, bytes memory _signature) public view override returns (bytes4 magicValue) {
// Compute the hash of message the should be signed
bytes32 targetDigest = getMessageHash(_hash);

Expand All @@ -230,20 +233,19 @@ 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) {
return interfaceId == type(ISpace).interfaceId || interfaceId == type(IERC1155Receiver).interfaceId
|| interfaceId == type(IERC721Receiver).interfaceId || interfaceId == type(IERC165).interfaceId;
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;
}

/// @inheritdoc IERC721Receiver
Expand Down
8 changes: 2 additions & 6 deletions src/StationRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ 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 @@ -126,9 +124,7 @@ 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
16 changes: 4 additions & 12 deletions src/utils/BaseAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ abstract contract BaseAccountFactory is IAccountFactory, Multicall {
//////////////////////////////////////////////////////////////*/

/// @notice Callback function for an Account to register itself on the factory.
function onRegister(
bytes32 _salt
) external {
function onRegister(bytes32 _salt) external {
address account = msg.sender;
require(_isAccountOfFactory(account, _salt), "AccountFactory: not an account.");

Expand Down Expand Up @@ -112,9 +110,7 @@ abstract contract BaseAccountFactory is IAccountFactory, Multicall {
//////////////////////////////////////////////////////////////*/

/// @notice Returns whether an account is registered on this factory.
function isRegistered(
address _account
) external view returns (bool) {
function isRegistered(address _account) external view returns (bool) {
return allAccounts.contains(_account);
}

Expand Down Expand Up @@ -147,9 +143,7 @@ abstract contract BaseAccountFactory is IAccountFactory, Multicall {
}

/// @notice Returns all accounts that the given address is a signer of.
function getAccountsOfSigner(
address signer
) external view returns (address[] memory accounts) {
function getAccountsOfSigner(address signer) external view returns (address[] memory accounts) {
return accountsOfSigner[signer].values();
}

Expand All @@ -163,9 +157,7 @@ abstract contract BaseAccountFactory is IAccountFactory, Multicall {
return _account == predicted;
}

function _getImplementation(
address cloneAddress
) internal view returns (address) {
function _getImplementation(address cloneAddress) internal view returns (address) {
bytes memory code = cloneAddress.code;
return BytesLib.toAddress(code, 10);
}
Expand Down
31 changes: 18 additions & 13 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
pragma solidity ^0.8.22;

import { Events } from "./utils/Events.sol";
import { Users } from "./utils/Types.sol";
Expand Down Expand Up @@ -98,8 +98,11 @@ abstract contract Base_Test is Test, Events {
}
vm.stopPrank();

bytes memory data =
computeCreateAccountCalldata({ deployer: _owner, stationId: _spaceId, initialModules: _initialModules });
bytes memory data = computeCreateAccountCalldata({
deployer: _owner,
stationId: _spaceId,
initialModules: _initialModules
});

vm.prank({ msgSender: _owner });
_container = Space(payable(stationRegistry.createAccount({ _admin: _owner, _data: data })));
Expand All @@ -118,17 +121,18 @@ abstract contract Base_Test is Test, Events {
}
vm.stopPrank();

bytes memory data =
computeCreateAccountCalldata({ deployer: _owner, stationId: _spaceId, initialModules: _initialModules });
bytes memory data = computeCreateAccountCalldata({
deployer: _owner,
stationId: _spaceId,
initialModules: _initialModules
});

vm.prank({ msgSender: _owner });
_badSpace = MockBadSpace(payable(stationRegistry.createAccount({ _admin: _owner, _data: data })));
vm.stopPrank();
}

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

Expand All @@ -137,9 +141,7 @@ 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 All @@ -160,8 +162,11 @@ abstract contract Base_Test is Test, Events {
bytes32 salt = keccak256(abi.encode(deployer, data));

// Use {Clones} library to predict the smart account address based on the smart account implementation, salt and account factory
expectedAddress =
Clones.predictDeterministicAddress(stationRegistry.accountImplementation(), salt, address(stationRegistry));
expectedAddress = Clones.predictDeterministicAddress(
stationRegistry.accountImplementation(),
salt,
address(stationRegistry)
);
}

/// @dev Constructs the calldata passed to the {StationRegistry}.createAccount method
Expand Down
6 changes: 4 additions & 2 deletions test/integration/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ abstract contract Integration_Test is Base_Test {
/// @dev Deploys the {InvoiceModule} module by initializing the Sablier v2-required contracts first
function deployInvoiceModule() internal {
mockNFTDescriptor = new MockNFTDescriptor();
sablierV2LockupLinear =
new SablierV2LockupLinear({ initialAdmin: users.admin, initialNFTDescriptor: mockNFTDescriptor });
sablierV2LockupLinear = new SablierV2LockupLinear({
initialAdmin: users.admin,
initialNFTDescriptor: mockNFTDescriptor
});
sablierV2LockupTranched = new SablierV2LockupTranched({
initialAdmin: users.admin,
initialNFTDescriptor: mockNFTDescriptor,
Expand Down
Loading

0 comments on commit 61b4ad7

Please sign in to comment.