Skip to content

Commit

Permalink
Merge branch 'develop' into chainlight-SPM-001-002-004
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 11, 2024
2 parents ca4515e + 4062a45 commit e811e45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion contracts/common/BiconomySponsorshipPaymasterErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract BiconomySponsorshipPaymasterErrors {
/**
* @notice Throws when insufficient funds to withdraw
*/
error InsufficientFundsInGasTank();
error InsufficientFunds();

/**
* @notice Throws when invalid signature length in paymasterAndData
Expand All @@ -67,6 +67,11 @@ contract BiconomySponsorshipPaymasterErrors {
*/
error CanNotWithdrawToZeroAddress();

/**
* @notice Throws when trying to withdraw zero amount
*/
error CanNotWithdrawZeroAmount();

/**
* @notice Throws when trying unaccountedGas is too high
*/
Expand Down
7 changes: 4 additions & 3 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ contract BiconomySponsorshipPaymaster is
}

/**
* @dev Set a new unaccountedEPGasOverhead value.
* @param value The new value to be set as the unaccountedEPGasOverhead.
* @dev Set a new unaccountedGas value.
* @param value The new value to be set as the unaccountedGas.
* @notice only to be called by the owner of the contract.
*/
function setUnaccountedGas(uint256 value) external payable onlyOwner {
Expand Down Expand Up @@ -160,9 +160,10 @@ contract BiconomySponsorshipPaymaster is
*/
function withdrawTo(address payable withdrawAddress, uint256 amount) external override nonReentrant {
if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress();
if (amount == 0) revert CanNotWithdrawZeroAmount();
uint256 currentBalance = paymasterIdBalances[msg.sender];
if (amount > currentBalance) {
revert InsufficientFundsInGasTank();
revert InsufficientFunds();
}
paymasterIdBalances[msg.sender] = currentBalance - amount;
entryPoint.withdrawTo(withdrawAddress, amount);
Expand Down
7 changes: 6 additions & 1 deletion test/unit/concrete/TestSponsorshipPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase {
bicoPaymaster.withdrawTo(payable(address(0)), 0 ether);
}

function test_RevertIf_WithdrawZeroAmount() external prankModifier(DAPP_ACCOUNT.addr) {
vm.expectRevert(abi.encodeWithSelector(CanNotWithdrawZeroAmount.selector));
bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 0 ether);
}

function test_RevertIf_WithdrawToExceedsBalance() external prankModifier(DAPP_ACCOUNT.addr) {
vm.expectRevert(abi.encodeWithSelector(InsufficientFundsInGasTank.selector));
vm.expectRevert(abi.encodeWithSelector(InsufficientFunds.selector));
bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 1 ether);
}

Expand Down

0 comments on commit e811e45

Please sign in to comment.