-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b48dfb
commit a73ccb8
Showing
10 changed files
with
229 additions
and
54 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -10,6 +10,16 @@ import { BasePaymaster } from "../base/BasePaymaster.sol"; | |
import { BiconomyTokenPaymasterErrors } from "../common/BiconomyTokenPaymasterErrors.sol"; | ||
import { IBiconomyTokenPaymaster } from "../interfaces/IBiconomyTokenPaymaster.sol"; | ||
|
||
/** | ||
* @title BiconomyTokenPaymaster | ||
* @author ShivaanshK<[email protected]> | ||
* @author livingrockrises<[email protected]> | ||
* @notice Token Paymaster for v0.7 Entry Point | ||
* @dev A paymaster that allows user to pay gas fee in ERC20 tokens. The paymaster owner chooses which tokens to | ||
* accept. The payment manager (usually the owner) first deposits native gas into the EntryPoint. Then, for each | ||
* transaction, it takes the gas fee from the user's ERC20 token balance. The exchange rate between ETH and the token is | ||
* calculated using 1 of three methods: external price source, off-chain oracle, or a TWAP oracle. | ||
*/ | ||
contract BiconomyTokenPaymaster is | ||
BasePaymaster, | ||
ReentrancyGuard, | ||
|
@@ -19,12 +29,86 @@ contract BiconomyTokenPaymaster is | |
using UserOperationLib for PackedUserOperation; | ||
using SignatureCheckerLib for address; | ||
|
||
address public verifyingSigner; | ||
address public feeCollector; | ||
uint16 public unaccountedGas; | ||
|
||
// Limit for unaccounted gas cost | ||
uint16 private constant UNACCOUNTED_GAS_LIMIT = 50_000; | ||
|
||
constructor( | ||
address _owner, | ||
IEntryPoint _entryPoint | ||
IEntryPoint _entryPoint, | ||
address _verifyingSigner, | ||
address _feeCollector, | ||
uint16 _unaccountedGas | ||
) | ||
BasePaymaster(_owner, _entryPoint) | ||
{ } | ||
{ | ||
_checkConstructorArgs(_verifyingSigner, _feeCollector, _unaccountedGas); | ||
assembly ("memory-safe") { | ||
sstore(verifyingSigner.slot, _verifyingSigner) | ||
} | ||
verifyingSigner = _verifyingSigner; | ||
feeCollector = _feeCollector; | ||
unaccountedGas = _unaccountedGas; | ||
} | ||
|
||
/** | ||
* @dev Set a new verifying signer address. | ||
* Can only be called by the owner of the contract. | ||
* @param _newVerifyingSigner The new address to be set as the verifying signer. | ||
* @notice If _newVerifyingSigner is set to zero address, it will revert with an error. | ||
* After setting the new signer address, it will emit an event VerifyingSignerChanged. | ||
*/ | ||
function setSigner(address _newVerifyingSigner) external payable override onlyOwner { | ||
if (_isContract(_newVerifyingSigner)) revert VerifyingSignerCanNotBeContract(); | ||
if (_newVerifyingSigner == address(0)) { | ||
revert VerifyingSignerCanNotBeZero(); | ||
} | ||
address oldSigner = verifyingSigner; | ||
assembly ("memory-safe") { | ||
sstore(verifyingSigner.slot, _newVerifyingSigner) | ||
} | ||
emit VerifyingSignerChanged(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 (_isContract(_newFeeCollector)) revert FeeCollectorCanNotBeContract(); | ||
if (_newFeeCollector == address(0)) revert FeeCollectorCanNotBeZero(); | ||
address oldFeeCollector = feeCollector; | ||
feeCollector = _newFeeCollector; | ||
emit FeeCollectorChanged(oldFeeCollector, _newFeeCollector, msg.sender); | ||
} | ||
|
||
/** | ||
* @dev Set a new unaccountedEPGasOverhead value. | ||
* @param value The new value to be set as the unaccountedEPGasOverhead. | ||
* @notice only to be called by the owner of the contract. | ||
*/ | ||
function setUnaccountedGas(uint16 value) external payable override onlyOwner { | ||
if (value > UNACCOUNTED_GAS_LIMIT) { | ||
revert UnaccountedGasTooHigh(); | ||
} | ||
uint16 oldValue = unaccountedGas; | ||
unaccountedGas = value; | ||
emit UnaccountedGasChanged(oldValue, value); | ||
} | ||
|
||
/** | ||
* Add a deposit in native currency for this paymaster, used for paying for transaction fees. | ||
* This is ideally done by the entity who is managing the received ERC20 gas tokens. | ||
*/ | ||
function deposit() public payable virtual override nonReentrant { | ||
entryPoint.depositTo{ value: msg.value }(address(this)); | ||
} | ||
|
||
/** | ||
* @dev Validate a user operation. | ||
|
@@ -64,4 +148,25 @@ contract BiconomyTokenPaymaster is | |
{ | ||
// Implementation of post-operation logic | ||
} | ||
|
||
function _checkConstructorArgs( | ||
address _verifyingSigner, | ||
address _feeCollector, | ||
uint16 _unaccountedGas | ||
) | ||
internal | ||
view | ||
{ | ||
if (_verifyingSigner == address(0)) { | ||
revert VerifyingSignerCanNotBeZero(); | ||
} else if (_isContract(_verifyingSigner)) { | ||
revert VerifyingSignerCanNotBeContract(); | ||
} else if (_feeCollector == address(0)) { | ||
revert FeeCollectorCanNotBeZero(); | ||
} else if (_isContract(_feeCollector)) { | ||
revert FeeCollectorCanNotBeContract(); | ||
} else if (_unaccountedGas > UNACCOUNTED_GAS_LIMIT) { | ||
revert UnaccountedGasTooHigh(); | ||
} | ||
} | ||
} |
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.