Skip to content

Commit

Permalink
fix: natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik committed Nov 12, 2024
1 parent 0108dd6 commit 4544b2a
Showing 1 changed file with 55 additions and 48 deletions.
103 changes: 55 additions & 48 deletions src/factory/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ contract AccountFactory is Ownable {
/// @dev Returns the address even if the account is already deployed.
/// Note that during user operation execution, this method is called only if the account is not deployed.
/// This method returns an existing account address so that entryPoint.getSenderAddress() would work even after
/// account creation
/// @param owner The owner of the account
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The address of the created account
/// account creation.
/// @param owner The owner of the account.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The address of the created account.
function createAccount(address owner, uint256 salt, uint32 entityId) external returns (ModularAccount) {
bytes32 combinedSalt = getSalt(owner, salt, entityId);

Expand All @@ -77,12 +77,12 @@ contract AccountFactory is Ownable {
return ModularAccount(payable(instance));
}

/// @notice Create a semi modular account and return its address.
/// @dev This only ever deploys semi-modular accounts with added bytecode, since this is much less
/// @notice Create a semi-modular account and return its address.
/// @dev This only ever deploys semi-modular accounts with added bytecode since this is much less
/// expensive than the storage-only variant, which should only be used for upgrades.
/// @param owner The owner of the account
/// @param salt The salt to use for the account creation
/// @return The address of the created account
/// @param owner The owner of the account.
/// @param salt The salt to use for the account creation.
/// @return The address of the created account.
function createSemiModularAccount(address owner, uint256 salt) external returns (SemiModularAccountBytecode) {
// both module address and entityId for fallback validations are hardcoded at the maximum value.
bytes32 fullSalt = getSalt(owner, salt, type(uint32).max);
Expand All @@ -104,12 +104,12 @@ contract AccountFactory is Ownable {
/// @dev Returns the address even if the account is already deployed.
/// Note that during user operation execution, this method is called only if the account is not deployed.
/// This method returns an existing account address so that entryPoint.getSenderAddress() would work even after
/// account creation
/// @param ownerX The x coordinate of the owner's public key
/// @param ownerY The y coordinate of the owner's public key
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The address of the created account
/// account creation.
/// @param ownerX The x coordinate of the owner's public key.
/// @param ownerY The y coordinate of the owner's public key.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The address of the created account.
function createWebAuthnAccount(uint256 ownerX, uint256 ownerY, uint256 salt, uint32 entityId)
external
returns (ModularAccount)
Expand All @@ -136,23 +136,28 @@ contract AccountFactory is Ownable {
return ModularAccount(payable(instance));
}

/// @notice Add stake to the entry point contract.
/// @param unstakeDelay The delay in seconds before the stake can be withdrawn.
function addStake(uint32 unstakeDelay) external payable onlyOwner {
ENTRY_POINT.addStake{value: msg.value}(unstakeDelay);
}

/// @notice Unlock the stake in the entry point contract.
function unlockStake() external onlyOwner {
ENTRY_POINT.unlockStake();
}

/// @notice Withdraw the stake from the entry point contract.
/// @param withdrawAddress The address to withdraw the stake to.
function withdrawStake(address payable withdrawAddress) external onlyOwner {
ENTRY_POINT.withdrawStake(withdrawAddress);
}

/// @notice Withdraw funds from this contract
/// @dev can withdraw stuck erc20s or native currency
/// @param to address to send erc20s or native currency to
/// @param token address of the token to withdraw, 0 address for native currency
/// @param amount amount of the token to withdraw in case of rebasing tokens
/// @notice Withdraw funds from this contract.
/// @dev Can be used to withdraw native currency or ERC-20 tokens.
/// @param to The address to withdraw the funds to.
/// @param token The address of the token to withdraw, or the zero address for native currency.
/// @param amount The amount to withdraw.
function withdraw(address payable to, address token, uint256 amount) external onlyOwner {
if (token == address(0)) {
(bool success,) = to.call{value: address(this).balance}("");
Expand All @@ -164,33 +169,35 @@ contract AccountFactory is Ownable {
}
}

/// @notice Calculate the counterfactual address of this account as it would be returned by createAccount()
/// @param owner The owner of the account
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The address of the account
/// @notice Calculate the counterfactual address of this account as it would be returned by createAccount.
/// @param owner The owner of the account.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The address of the account.
function getAddress(address owner, uint256 salt, uint32 entityId) external view returns (address) {
return LibClone.predictDeterministicAddressERC1967(
address(ACCOUNT_IMPL), getSalt(owner, salt, entityId), address(this)
);
}

/// @notice Gets the deployed address of a semi modular account given the owner and salt
/// @param owner The owner of the account
/// @param salt The salt to use for the account creation
/// @return The address of the account
/// @notice Calculate the counterfactual address of a semi-modular account as it would be returned by
/// createSemiModularAccount.
/// @param owner The owner of the account.
/// @param salt The salt to use for the account creation.
/// @return The address of the account.
function getAddressSemiModular(address owner, uint256 salt) public view returns (address) {
bytes32 fullSalt = getSalt(owner, salt, type(uint32).max);
bytes memory immutables = _getImmutableArgs(owner);
return _getAddressSemiModular(immutables, fullSalt);
}

/// @notice Gets the deployed address of a modular account with the WebAuthn module given the owner and salt
/// @param ownerX The x coordinate of the owner's public key
/// @param ownerY The y coordinate of the owner's public key
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The address of the account
/// @notice Calculate the counterfactual address of a webauthn account as it would be returned by
/// createWebAuthnAccount.
/// @param ownerX The x coordinate of the owner's public key.
/// @param ownerY The y coordinate of the owner's public key.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The address of the account.
function getAddressWebAuthn(uint256 ownerX, uint256 ownerY, uint256 salt, uint32 entityId)
public
view
Expand All @@ -201,22 +208,22 @@ contract AccountFactory is Ownable {
);
}

/// @notice Gets the deployed address of a modular account given the owner, salt and entityId
/// @param owner The owner of the account
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The create2 salt used to deploy
/// @notice Get the full salt used for account creation.
/// @dev To get the full salt used in createSemiModularAccount, use type(uint32).max for entityId.
/// @param owner The owner of the account.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The full salt.
function getSalt(address owner, uint256 salt, uint32 entityId) public pure returns (bytes32) {
return keccak256(abi.encodePacked(owner, salt, entityId));
}

/// @notice Gets the deployed address of a modular account deployed with the webauthn module given the owner
/// and salt
/// @param ownerX The x coordinate of the owner's public key
/// @param ownerY The y coordinate of the owner's public key
/// @param salt The salt to use for the account creation
/// @param entityId The entity ID to use for the account creation
/// @return The create2 salt used to deploy
/// @notice Get the full salt used for account creation using WebAuthn.
/// @param ownerX The x coordinate of the owner's public key.
/// @param ownerY The y coordinate of the owner's public key.
/// @param salt The salt to use for the account creation.
/// @param entityId The entity ID to use for the account creation.
/// @return The full salt.
function getSaltWebAuthn(uint256 ownerX, uint256 ownerY, uint256 salt, uint32 entityId)
public
pure
Expand Down

0 comments on commit 4544b2a

Please sign in to comment.