Skip to content
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

fix: remediations. allow receive eth and withdraw stuck eth #36

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/common/BiconomyTokenPaymasterErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@
* @notice Throws when external signer's signature has invalid length
*/
error InvalidSignatureLength();

/**
* @notice Throws when ETH withdrawal fails
*/
error WithdrawalFailed();

/**
* @notice Emitted when ETH is withdrawn from the paymaster
*/
event EthWithdrawn(address indexed recipient, uint256 indexed amount);

Check failure on line 87 in contracts/common/BiconomyTokenPaymasterErrors.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Function order is incorrect, event definition can not go after custom error definition (line 82)
}
17 changes: 17 additions & 0 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import "account-abstraction/core/Helpers.sol";
import "./swaps/Uniswapper.sol";
// Todo: marked for removal
import "forge-std/console2.sol";

Check failure on line 20 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Unexpected import of console file

/**
* @title BiconomyTokenPaymaster
Expand Down Expand Up @@ -133,6 +133,10 @@
}
}

receive() external payable {
// no need to emit an event here
}

/**
* @dev pull tokens out of paymaster in case they were sent to the paymaster at any point.
* @param token the token deposit to withdraw
Expand All @@ -143,6 +147,19 @@
_withdrawERC20(token, target, amount);
}

/**
* @dev Withdraw ETH from the paymaster
* @param recipient The address to send the ETH to
* @param amount The amount of ETH to withdraw
*/
function withdrawEth(address payable recipient, uint256 amount) external payable onlyOwner nonReentrant {
(bool success,) = recipient.call{ value: amount }("");
if (!success) {
revert WithdrawalFailed();
}
emit EthWithdrawn(recipient, amount);
}

/**
* @dev pull tokens out of paymaster in case they were sent to the paymaster at any point.
* @param token the token deposit to withdraw
Expand Down Expand Up @@ -422,7 +439,7 @@
* @param userOpHash The hash of the user operation.
* @param maxCost The maximum cost of the user operation.
*/
function _validatePaymasterUserOp(

Check failure on line 442 in contracts/token/BiconomyTokenPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Function body contains 98 lines but allowed no more than 90 lines
PackedUserOperation calldata userOp,
bytes32 userOpHash,
uint256 maxCost
Expand Down
Loading