Skip to content

Commit

Permalink
Merge branch 'develop' into fix/remediations-chainlight-BTPMQ4-005
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Nov 18, 2024
2 parents 6f1c353 + 2439053 commit 716e8f1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
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 @@ contract BiconomyTokenPaymasterErrors {
* @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)
}
22 changes: 20 additions & 2 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/Reentran
import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol";
import { PackedUserOperation, UserOperationLib } from "account-abstraction/core/UserOperationLib.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

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

View workflow job for this annotation

GitHub Actions / Lint sources

imported name SafeERC20 is not used
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { BasePaymaster } from "../base/BasePaymaster.sol";
Expand Down Expand Up @@ -125,6 +126,10 @@ contract BiconomyTokenPaymaster is
}
}

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 @@ -135,6 +140,19 @@ contract BiconomyTokenPaymaster is
_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 @@ -497,7 +515,7 @@ contract BiconomyTokenPaymaster is

// deduct max penalty from the token amount we pass to the postOp
// so we don't refund it at postOp
context = abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice)/_NATIVE_TOKEN_DECIMALS), tokenPrice, externalPriceMarkup, userOpHash);
context = abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*externalPriceMarkup)/(1e18*_PRICE_DENOMINATOR)), tokenPrice, externalPriceMarkup, userOpHash);
validationData = _packValidationData(false, validUntil, validAfter);
} else if (mode == PaymasterMode.INDEPENDENT) {
// Use only oracles for the token specified in modeSpecificData
Expand Down Expand Up @@ -525,7 +543,7 @@ contract BiconomyTokenPaymaster is
SafeTransferLib.safeTransferFrom(tokenAddress, userOp.sender, address(this), tokenAmount);

context =
abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice)/_NATIVE_TOKEN_DECIMALS), tokenPrice, independentPriceMarkup, userOpHash);
abi.encode(userOp.sender, tokenAddress, tokenAmount-((maxPenalty*tokenPrice*independentPriceMarkup)/(1e18*_PRICE_DENOMINATOR)), tokenPrice, independentPriceMarkup, userOpHash);
validationData = 0; // Validation success and price is valid indefinetly
}
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/token/swaps/Uniswapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.27;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/interfaces/IPeripheryPayments.sol";

Expand Down Expand Up @@ -46,7 +47,7 @@ abstract contract Uniswapper {
}

function _setTokenPool(address token, uint24 poolFeeTier) internal {
IERC20(token).approve(address(uniswapRouter), type(uint256).max); // one time max approval
SafeERC20.forceApprove(IERC20(token), address(uniswapRouter), type(uint256).max); // one time max approval
tokenToPools[token] = poolFeeTier; // set mapping of token to uniswap pool to use for swap
}

Expand Down

0 comments on commit 716e8f1

Please sign in to comment.