-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: stakable factories #47
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.23; | ||
|
||
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {IEntryPoint} from "account-abstraction/interfaces/IEntryPoint.sol"; | ||
|
||
abstract contract BaseLightAccountFactory is Ownable2Step { | ||
IEntryPoint public immutable ENTRY_POINT; | ||
|
||
error InvalidAction(); | ||
error TransferFailed(); | ||
|
||
/// @notice Allow contract to receive native currency. | ||
receive() external payable {} | ||
|
||
/// @notice Add stake to an entry point. | ||
/// @dev Only callable by owner. | ||
/// @param unstakeDelay Unstake delay for the stake. | ||
/// @param amount Amount of native currency to stake. | ||
function addStake(uint32 unstakeDelay, uint256 amount) external payable onlyOwner { | ||
ENTRY_POINT.addStake{value: amount}(unstakeDelay); | ||
} | ||
|
||
/// @notice Start unlocking stake for an entry point. | ||
/// @dev Only callable by owner. | ||
function unlockStake() external onlyOwner { | ||
ENTRY_POINT.unlockStake(); | ||
} | ||
|
||
/// @notice Withdraw stake from an entry point. | ||
/// @dev Only callable by owner. | ||
/// @param to Address to send native currency to. | ||
function withdrawStake(address payable to) external onlyOwner { | ||
ENTRY_POINT.withdrawStake(to); | ||
} | ||
|
||
/// @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. | ||
function withdraw(address payable to, address token, uint256 amount) external onlyOwner { | ||
if (token == address(0)) { | ||
(bool success,) = to.call{value: address(this).balance}(""); | ||
if (!success) { | ||
revert TransferFailed(); | ||
} | ||
} else { | ||
SafeERC20.safeTransfer(IERC20(token), to, amount); | ||
} | ||
} | ||
|
||
/// @notice Overriding to disable renounce ownership in Ownable. | ||
function renounceOwnership() public view override onlyOwner { | ||
revert InvalidAction(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hypothetically, we could add a withdraw function to withdraw from the EntryPoint's deposit for this factory, but that should never happen unless we make a mistake. So I'm ok leaving that out.