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

chore:rename verifying singelton paymaster to sponsorship paymaster #55

Merged
merged 6 commits into from
Dec 4, 2023
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PAYMASTER_OWNER_ADDRESS_DEV=
PAYMASTER_OWNER_ADDRESS_PROD=
PAYMASTER_SIGNER_ADDRESS_DEV=
PAYMASTER_SIGNER_ADDRESS_PROD=
SPONSORSHIP_FEE_COLLECTOR_ADDRESS_PROD=
TOKEN_PAYMASTER_OWNER_ADDRESS_DEV=
TOKEN_PAYMASTER_OWNER_ADDRESS_PROD=
TOKEN_PAYMASTER_SIGNER_ADDRESS_DEV=
Expand Down
12 changes: 11 additions & 1 deletion contracts/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract BasePaymasterErrors {
error CallerIsNotAnEntryPoint(address caller);
}

contract VerifyingPaymasterErrors {
contract SponsorshipPaymasterErrors {
/**
* @notice Throws when the Entrypoint address provided is address(0)
*/
Expand All @@ -20,6 +20,16 @@ contract VerifyingPaymasterErrors {
*/
error VerifyingSignerCannotBeZero();

/**
* @notice Throws when the paymaster id provided is a deployed contract
*/
error PaymasterIdCannotBeContract();

/**
* @notice Throws when the fee collector address provided is a deployed contract
*/
error FeeCollectorCannotBeContract();

/**
* @notice Throws when the fee collector address provided is address(0)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IVerifyingSingletonPaymaster {
interface ISponsorshipPaymaster {
event EPGasOverheadChanged(
uint256 indexed _oldValue,
uint256 indexed _newValue
Expand Down
30 changes: 30 additions & 0 deletions contracts/libs/AddressUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


/**
* Utility library of inline functions on addresses
*/
library AddressUtils {

/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param _addr address to check
* @return whether the target address is a contract
*/
function isContract(address _addr) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(_addr) }
return size > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {UserOperation, UserOperationLib} from "@account-abstraction/contracts/interfaces/UserOperation.sol";
import "../BasePaymaster.sol";
import {VerifyingPaymasterErrors} from "../common/Errors.sol";
import {SponsorshipPaymasterErrors} from "../common/Errors.sol";
import {MathLib} from "../libs/MathLib.sol";
import {IVerifyingSingletonPaymaster} from "../interfaces/paymasters/IVerifyingSingletonPaymaster.sol";

contract VerifyingSingletonPaymasterV2 is
import {AddressUtils} from "../libs/AddressUtils.sol";
import {ISponsorshipPaymaster} from "../interfaces/paymasters/ISponsorshipPaymaster.sol";

/**
* @title SponsorshipPaymaster
* @author livingrockrises<[email protected]>
* @notice Based on Infinitism 'VerifyingPaymaster' contract
* @dev This contract is used to sponsor the transaction fees of the user operations
* Uses a verifying signer to provide the signature if predetermined conditions are met
* regarding the user operation calldata. Also this paymaster is Singleton in nature which
* means multiple Dapps/Wallet clients willing to sponsor the transactions can share this paymaster.
* Maintains it's own accounting of the gas balance for each Dapp/Wallet client
* and Manages it's own deposit on the EntryPoint.
*/
contract SponsorshipPaymaster is
BasePaymaster,
ReentrancyGuard,
VerifyingPaymasterErrors,
IVerifyingSingletonPaymaster
SponsorshipPaymasterErrors,
ISponsorshipPaymaster
{
using ECDSA for bytes32;
using AddressUtils for address;
using UserOperationLib for UserOperation;

uint32 private constant PRICE_DENOMINATOR = 1e6;
Expand Down Expand Up @@ -61,11 +74,10 @@ contract VerifyingSingletonPaymasterV2 is
* @param paymasterId dapp identifier for which deposit is being made
*/
function depositFor(address paymasterId) external payable nonReentrant {
if(paymasterId.isContract()) revert PaymasterIdCannotBeContract();
if (paymasterId == address(0)) revert PaymasterIdCannotBeZero();
if (msg.value == 0) revert DepositCanNotBeZero();
paymasterIdBalances[paymasterId] =
paymasterIdBalances[paymasterId] +
msg.value;
paymasterIdBalances[paymasterId] += msg.value;
entryPoint.depositTo{value: msg.value}(address(this));
emit GasDeposited(paymasterId, msg.value);
}
Expand Down Expand Up @@ -99,6 +111,7 @@ contract VerifyingSingletonPaymasterV2 is
function setFeeCollector(
address _newFeeCollector
) external payable onlyOwner {
if(_newFeeCollector.isContract()) revert FeeCollectorCannotBeContract();
if (_newFeeCollector == address(0)) revert FeeCollectorCannotBeZero();
address oldFeeCollector = feeCollector;
assembly {
Expand Down Expand Up @@ -313,7 +326,6 @@ contract VerifyingSingletonPaymasterV2 is
require(priceMarkup <= 2e6, "Verifying PM:high markup %");

uint32 dynamicMarkup = MathLib.maxuint32(priceMarkup, fixedPriceMarkup);
require(dynamicMarkup >= 1e6, "Verifying PM:low markup %");

uint256 effectiveCost = (requiredPreFund * dynamicMarkup) /
PRICE_DENOMINATOR;
Expand Down
Loading
Loading