Skip to content

Commit

Permalink
get rid of feeCollector (will always be contract)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaanshK committed Sep 11, 2024
1 parent 3a97ec1 commit 3611b12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
13 changes: 9 additions & 4 deletions contracts/interfaces/IBiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ interface IBiconomyTokenPaymaster {
event UpdatedVerifyingSigner(address indexed oldSigner, address indexed newSigner, address indexed actor);
event UpdatedFeeCollector(address indexed oldFeeCollector, address indexed newFeeCollector, address indexed actor);
event UpdatedPriceExpiryDuration(uint256 indexed oldValue, uint256 indexed newValue);
event TokensRefunded(address indexed userOpSender, address indexed token, uint256 refundAmount, bytes32 indexed userOpHash);
event TokensRefunded(
address indexed userOpSender, address indexed token, uint256 refundAmount, bytes32 indexed userOpHash
);
event PaidGasInTokens(
address indexed userOpSender, address indexed token, uint256 nativeCharge, uint256 tokenCharge, uint256 dynamicAdjustment, bytes32 indexed userOpHash
address indexed userOpSender,
address indexed token,
uint256 nativeCharge,
uint256 tokenCharge,
uint256 dynamicAdjustment,
bytes32 indexed userOpHash
);
event Received(address indexed sender, uint256 value);
event TokensWithdrawn(address indexed token, address indexed to, uint256 indexed amount, address actor);
Expand All @@ -33,8 +40,6 @@ interface IBiconomyTokenPaymaster {

function setSigner(address _newVerifyingSigner) external payable;

function setFeeCollector(address _newFeeCollector) external payable;

function setUnaccountedGas(uint256 value) external payable;

function setDynamicAdjustment(uint256 _newUnaccountedGas) external payable;
Expand Down
21 changes: 1 addition & 20 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ contract BiconomyTokenPaymaster is
using SignatureCheckerLib for address;

// State variables
address public feeCollector;
address public verifyingSigner;
uint256 public unaccountedGas;
uint256 public dynamicAdjustment;
Expand Down Expand Up @@ -93,7 +92,6 @@ contract BiconomyTokenPaymaster is
// Set state variables
assembly ("memory-safe") {
sstore(verifyingSigner.slot, _verifyingSigner)
sstore(feeCollector.slot, address()) // initialize fee collector to this contract
sstore(unaccountedGas.slot, _unaccountedGas)
sstore(dynamicAdjustment.slot, _dynamicAdjustment)
sstore(priceExpiryDuration.slot, _priceExpiryDuration)
Expand Down Expand Up @@ -218,22 +216,6 @@ contract BiconomyTokenPaymaster is
emit UpdatedVerifyingSigner(oldSigner, _newVerifyingSigner, msg.sender);
}

/**
* @dev Set a new fee collector address.
* Can only be called by the owner of the contract.
* @param _newFeeCollector The new address to be set as the fee collector.
* @notice If _newFeeCollector is set to zero address, it will revert with an error.
* After setting the new fee collector address, it will emit an event FeeCollectorChanged.
*/
function setFeeCollector(address _newFeeCollector) external payable override onlyOwner {
if (_newFeeCollector == address(0)) revert FeeCollectorCanNotBeZero();
address oldFeeCollector = feeCollector;
assembly ("memory-safe") {
sstore(feeCollector.slot, _newFeeCollector)
}
emit UpdatedFeeCollector(oldFeeCollector, _newFeeCollector, msg.sender);
}

/**
* @dev Set a new unaccountedEPGasOverhead value.
* @param _newUnaccountedGas The new value to be set as the unaccounted gas value
Expand Down Expand Up @@ -483,14 +465,13 @@ contract BiconomyTokenPaymaster is
(actualGasCost + (unaccountedGas) * actualUserOpFeePerGas) * appliedDynamicAdjustment * tokenPrice
) / (1e18 * PRICE_DENOMINATOR);

// If the user was overcharged, refund the excess tokens
if (prechargedAmount > actualTokenAmount) {
// If the user was overcharged, refund the excess tokens
uint256 refundAmount = prechargedAmount - actualTokenAmount;
SafeTransferLib.safeTransfer(tokenAddress, userOpSender, refundAmount);
emit TokensRefunded(userOpSender, tokenAddress, refundAmount, userOpHash);
}

// Emit an event for post-operation completion (optional)
emit PaidGasInTokens(
userOpSender, tokenAddress, actualGasCost, actualTokenAmount, appliedDynamicAdjustment, userOpHash
);
Expand Down
12 changes: 0 additions & 12 deletions test/unit/concrete/TestTokenPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,6 @@ contract TestTokenPaymaster is TestBase {
tokenPaymaster.setSigner(address(0));
}

function test_SetFeeCollector() external prankModifier(PAYMASTER_OWNER.addr) {
// Set the expected fee collector change and expect the event to be emitted
vm.expectEmit(true, true, true, true, address(tokenPaymaster));
emit IBiconomyTokenPaymaster.UpdatedFeeCollector(address(tokenPaymaster), BOB_ADDRESS, PAYMASTER_OWNER.addr);

// Call the function to set the fee collector
tokenPaymaster.setFeeCollector(BOB_ADDRESS);

// Assert the change has been applied correctly
assertEq(tokenPaymaster.feeCollector(), BOB_ADDRESS);
}

function test_Deposit() external prankModifier(PAYMASTER_OWNER.addr) {
uint256 depositAmount = 10 ether;
assertEq(tokenPaymaster.getDeposit(), 0);
Expand Down

0 comments on commit 3611b12

Please sign in to comment.