Source Code
Overview
S Balance
0 S
More Info
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
BiconomySponsorshipPaymaster
Compiler Version
v0.8.27+commit.40a35a09
Optimization Enabled:
Yes with 800 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.27; /* solhint-disable reason-string */ import "../base/BasePaymaster.sol"; import "account-abstraction/core/UserOperationLib.sol"; import "account-abstraction/core/Helpers.sol"; import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; import { ECDSA as ECDSA_solady } from "solady/utils/ECDSA.sol"; import { BiconomySponsorshipPaymasterErrors } from "../common/BiconomySponsorshipPaymasterErrors.sol"; import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; import { IBiconomySponsorshipPaymaster } from "../interfaces/IBiconomySponsorshipPaymaster.sol"; /** * @title BiconomySponsorshipPaymaster * @author livingrockrises<[email protected]> * @author ShivaanshK<[email protected]> * @notice Based on Infinitism's '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 BiconomySponsorshipPaymaster is BasePaymaster, ReentrancyGuardTransient, BiconomySponsorshipPaymasterErrors, IBiconomySponsorshipPaymaster { using UserOperationLib for PackedUserOperation; using SignatureCheckerLib for address; using ECDSA_solady for bytes32; address public verifyingSigner; address public feeCollector; uint256 public unaccountedGas; uint256 public paymasterIdWithdrawalDelay; uint256 public minDeposit; // Denominator to prevent precision errors when applying price markup uint256 private constant _PRICE_DENOMINATOR = 1e6; // Offset in PaymasterAndData to get to PAYMASTER_ID_OFFSET uint256 private constant _PAYMASTER_ID_OFFSET = _PAYMASTER_DATA_OFFSET; // Limit for unaccounted gas cost uint256 private constant _UNACCOUNTED_GAS_LIMIT = 100_000; mapping(address => uint256) public paymasterIdBalances; mapping(address => bool) internal _trustedPaymasterIds; mapping(address paymasterId => WithdrawalRequest request) internal _requests; constructor( address owner, IEntryPoint entryPointArg, address verifyingSignerArg, address feeCollectorArg, uint256 unaccountedGasArg, uint256 paymasterIdWithdrawalDelayArg, uint256 minDepositArg ) BasePaymaster(owner, entryPointArg) { _checkConstructorArgs(verifyingSignerArg, feeCollectorArg, unaccountedGasArg); assembly ("memory-safe") { sstore(verifyingSigner.slot, verifyingSignerArg) } feeCollector = feeCollectorArg; unaccountedGas = unaccountedGasArg; paymasterIdWithdrawalDelay = paymasterIdWithdrawalDelayArg; minDeposit = minDepositArg; } receive() external payable { emit Received(msg.sender, msg.value); } /** * @dev Add a deposit for this paymaster and given paymasterId (Dapp Depositor address), used for paying for * transaction fees * @param paymasterId dapp identifier for which deposit is being made */ function depositFor(address paymasterId) external payable nonReentrant { if (paymasterId == address(0)) revert PaymasterIdCanNotBeZero(); if (msg.value == 0) revert DepositCanNotBeZero(); if (paymasterIdBalances[paymasterId] + msg.value < minDeposit) revert LowDeposit(); paymasterIdBalances[paymasterId] += msg.value; entryPoint.depositTo{ value: msg.value }(address(this)); emit GasDeposited(paymasterId, msg.value); } /** * @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 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 Refund balances for multiple paymasterIds * PM charges more than it should to protect itself. * This function is used to refund the extra amount * when the real consumption is known. * @param paymasterIds The paymasterIds to refund * @param amounts The amounts to refund */ function refundBalances(address[] calldata paymasterIds, uint256[] calldata amounts) external payable onlyOwner { if (paymasterIds.length != amounts.length) revert InvalidArrayLengths(); for (uint256 i; i < paymasterIds.length; i++) { paymasterIdBalances[paymasterIds[i]] += amounts[i]; } } /** * @dev Set a new trusted paymasterId. * Can only be called by the owner of the contract. * @param paymasterId The paymasterId to be set as trusted. * @param isTrusted Whether the paymasterId is trusted or not. */ function setTrustedPaymasterId(address paymasterId, bool isTrusted) external payable onlyOwner { if (paymasterId == address(0)) revert PaymasterIdCanNotBeZero(); if (_trustedPaymasterIds[paymasterId] != isTrusted) { _trustedPaymasterIds[paymasterId] = isTrusted; emit TrustedPaymasterIdSet(paymasterId, isTrusted); } } /** * @dev Set a new minimum deposit value. * Can only be called by the owner of the contract. * @param newMinDeposit The new minimum deposit value to be set. */ function setMinDeposit(uint256 newMinDeposit) external payable onlyOwner { emit MinDepositChanged(minDeposit, newMinDeposit); minDeposit = newMinDeposit; } /** * @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 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 { if (value > _UNACCOUNTED_GAS_LIMIT) { revert UnaccountedGasTooHigh(); } uint256 oldValue = unaccountedGas; unaccountedGas = value; emit UnaccountedGasChanged(oldValue, value); } /** * @dev Override the default implementation. */ function deposit() external payable virtual override { revert UseDepositForInstead(); } /** * @dev pull tokens out of paymaster in case they were sent to the paymaster at any point. * @param token the token deposit to withdraw * @param target address to send to * @param amount amount to withdraw */ function withdrawERC20(IERC20 token, address target, uint256 amount) external onlyOwner nonReentrant { _withdrawERC20(token, target, amount); } /** * @dev Submit a withdrawal request for the paymasterId (Dapp Depositor address) * @param withdrawAddress address to send the funds to * @param amount amount to withdraw */ function submitWithdrawalRequest(address withdrawAddress, uint256 amount) external { if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress(); if (amount == 0) revert CanNotWithdrawZeroAmount(); uint256 currentBalance = paymasterIdBalances[msg.sender]; if (amount > currentBalance) revert InsufficientFundsInGasTank(); _requests[msg.sender] = WithdrawalRequest({ amount: amount, to: withdrawAddress, requestSubmittedTimestamp: block.timestamp }); emit WithdrawalRequestSubmitted(withdrawAddress, amount); } /** * @dev Execute a withdrawal request for the paymasterId (Dapp Depositor address) * Request must be cleared by the withdrawal delay period * @param paymasterId paymasterId (Dapp Depositor address) */ function executeWithdrawalRequest(address paymasterId) external nonReentrant { WithdrawalRequest memory req = _requests[paymasterId]; if (req.requestSubmittedTimestamp == 0) revert NoRequestSubmitted(); uint256 clearanceTimestamp = req.requestSubmittedTimestamp + _getDelay(paymasterId); if (block.timestamp < clearanceTimestamp) revert RequestNotClearedYet(clearanceTimestamp); uint256 currentBalance = paymasterIdBalances[paymasterId]; req.amount = req.amount > currentBalance ? currentBalance : req.amount; if(req.amount == 0) revert CanNotWithdrawZeroAmount(); paymasterIdBalances[paymasterId] = currentBalance - req.amount; delete _requests[paymasterId]; entryPoint.withdrawTo(payable(req.to), req.amount); emit GasWithdrawn(paymasterId, req.to, req.amount); } /** * @dev Cancel a withdrawal request for the paymasterId (Dapp Depositor address) */ function cancelWithdrawalRequest() external { delete _requests[msg.sender]; emit WithdrawalRequestCancelledFor(msg.sender); } 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); } function withdrawTo(address payable withdrawAddress, uint256 amount) external virtual override { (withdrawAddress, amount); revert SubmitRequestInstead(); } /** * @dev get the current deposit for paymasterId (Dapp Depositor address) * @param paymasterId dapp identifier */ function getBalance(address paymasterId) external view returns (uint256 balance) { balance = paymasterIdBalances[paymasterId]; } /** * return the hash we're going to sign off-chain (and validate on-chain) * this method is called by the off-chain service, to sign the request. * it is called on-chain from the validatePaymasterUserOp, to validate the signature. * note that this signature covers all fields of the UserOperation, except the "paymasterAndData", * which will carry the signature itself. */ function getHash( PackedUserOperation calldata userOp, address paymasterId, uint48 validUntil, uint48 validAfter, uint32 priceMarkup ) public view returns (bytes32) { //can't use userOp.hash(), since it contains also the paymasterAndData itself. address sender = userOp.getSender(); return keccak256( abi.encode( sender, userOp.nonce, keccak256(userOp.initCode), keccak256(userOp.callData), userOp.accountGasLimits, uint256(bytes32(userOp.paymasterAndData[_PAYMASTER_VALIDATION_GAS_OFFSET:_PAYMASTER_DATA_OFFSET])), userOp.preVerificationGas, userOp.gasFees, block.chainid, address(this), paymasterId, validUntil, validAfter, priceMarkup ) ); } function parsePaymasterAndData( bytes calldata paymasterAndData ) public pure returns ( address paymasterId, uint48 validUntil, uint48 validAfter, uint32 priceMarkup, uint128 paymasterValidationGasLimit, uint128 paymasterPostOpGasLimit, bytes calldata signature ) { unchecked { paymasterId = address(bytes20(paymasterAndData[_PAYMASTER_ID_OFFSET:_PAYMASTER_ID_OFFSET + 20])); validUntil = uint48(bytes6(paymasterAndData[_PAYMASTER_ID_OFFSET + 20:_PAYMASTER_ID_OFFSET + 26])); validAfter = uint48(bytes6(paymasterAndData[_PAYMASTER_ID_OFFSET + 26:_PAYMASTER_ID_OFFSET + 32])); priceMarkup = uint32(bytes4(paymasterAndData[_PAYMASTER_ID_OFFSET + 32:_PAYMASTER_ID_OFFSET + 36])); paymasterValidationGasLimit = uint128(bytes16(paymasterAndData[_PAYMASTER_VALIDATION_GAS_OFFSET:_PAYMASTER_POSTOP_GAS_OFFSET])); paymasterPostOpGasLimit = uint128(bytes16(paymasterAndData[_PAYMASTER_POSTOP_GAS_OFFSET:_PAYMASTER_DATA_OFFSET])); signature = paymasterAndData[_PAYMASTER_ID_OFFSET + 36:]; } } /// @notice Performs post-operation tasks, such as deducting the sponsored gas cost from the paymasterId's balance /// @dev This function is called after a user operation has been executed or reverted. /// @param context The context containing the token amount and user sender address. /// @param actualGasCost The actual gas cost of the transaction. function _postOp( PostOpMode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas ) internal override { (address paymasterId, uint32 priceMarkup, uint256 prechargedAmount) = abi.decode(context, (address, uint32, uint256)); // Include unaccountedGas since EP doesn't include this in actualGasCost // unaccountedGas = postOpGas + EP overhead gas actualGasCost = actualGasCost + (unaccountedGas * actualUserOpFeePerGas); // Apply the price markup uint256 adjustedGasCost = (actualGasCost * priceMarkup) / _PRICE_DENOMINATOR; uint256 premium = adjustedGasCost - actualGasCost; // Add priceMarkup to fee collector balance paymasterIdBalances[feeCollector] += premium; if (prechargedAmount > adjustedGasCost) { // If overcharged refund the excess paymasterIdBalances[paymasterId] += (prechargedAmount - adjustedGasCost); } else { // deduct what needs to be deducted from paymasterId paymasterIdBalances[paymasterId] -= (adjustedGasCost - prechargedAmount); } // here adjustedGasCost does not account for gasPenalty. prechargedAmount accounts for penalty with maxGasPenalty emit GasBalanceDeducted(paymasterId, adjustedGasCost, premium); } /** * @dev verify our external signer signed this request. * Adds maxPenalty to the effectiveCost to protect PM. * The "paymasterAndData" is expected to be the paymaster and a signature over the entire request params. * paymasterAndData[:20] : address(this) * paymasterAndData[52:72] : paymasterId (dappDepositor) * paymasterAndData[72:78] : validUntil * paymasterAndData[78:84] : validAfter * paymasterAndData[84:88] : priceMarkup * paymasterAndData[88:] : signature * @param userOp The user operation to validate. * @param userOpHash The hash of the user operation. * @param requiredPreFund The required pre-fund amount. * @return context The context for the paymaster. * @return validationData The validation data as per ERC-4337. */ function _validatePaymasterUserOp( PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 requiredPreFund ) internal override returns (bytes memory context, uint256 validationData) { (userOpHash); ( address paymasterId, uint48 validUntil, uint48 validAfter, uint32 priceMarkup, uint128 paymasterValidationGasLimit, uint128 paymasterPostOpGasLimit, bytes calldata signature ) = parsePaymasterAndData(userOp.paymasterAndData); (paymasterValidationGasLimit, paymasterPostOpGasLimit); //ECDSA library supports both 64 and 65-byte long signatures. // we only "require" it here so that the revert reason on invalid signature will be of "VerifyingPaymaster", and // not "ECDSA" if (signature.length != 64 && signature.length != 65) { revert InvalidSignatureLength(); } if (unaccountedGas > userOp.unpackPostOpGasLimit()) { revert PostOpGasLimitTooLow(); } bool validSig = ( (getHash(userOp, paymasterId, validUntil, validAfter, priceMarkup).toEthSignedMessageHash()).tryRecover( signature ) ) == verifyingSigner ? true : false; //don't revert on signature failure: return SIG_VALIDATION_FAILED if (!validSig) { return ("", _packValidationData(true, validUntil, validAfter)); } // Send 1e6 for No markup if (priceMarkup > 2e6 || priceMarkup < 1e6) { revert InvalidPriceMarkup(); } // callGasLimit + paymasterPostOpGas uint256 maxPenalty = ( ( uint128(uint256(userOp.accountGasLimits)) + uint128(bytes16(userOp.paymasterAndData[_PAYMASTER_POSTOP_GAS_OFFSET:_PAYMASTER_DATA_OFFSET])) ) * 10 * userOp.unpackMaxFeePerGas() ) / 100; // Deduct the max gas cost. uint256 effectiveCost = (((requiredPreFund + unaccountedGas * userOp.unpackMaxFeePerGas()) * priceMarkup) / _PRICE_DENOMINATOR); if (effectiveCost + maxPenalty > paymasterIdBalances[paymasterId]) { revert InsufficientFundsForPaymasterId(); } paymasterIdBalances[paymasterId] -= (effectiveCost + maxPenalty); context = abi.encode(paymasterId, priceMarkup, effectiveCost); // no need for other on-chain validation: entire UserOp should have been checked // by the external service prior to signing it. return (context, _packValidationData(false, validUntil, validAfter)); } function _checkConstructorArgs( address verifyingSignerArg, address feeCollectorArg, uint256 unaccountedGasArg ) internal view { if (verifyingSignerArg == address(0)) { revert VerifyingSignerCanNotBeZero(); } else if (_isContract(verifyingSignerArg)) { revert VerifyingSignerCanNotBeContract(); } else if (feeCollectorArg == address(0)) { revert FeeCollectorCanNotBeZero(); } else if (_isContract(feeCollectorArg)) { revert FeeCollectorCanNotBeContract(); } else if (unaccountedGasArg > _UNACCOUNTED_GAS_LIMIT) { revert UnaccountedGasTooHigh(); } } function _getDelay(address paymasterId) internal view returns (uint256) { if (_trustedPaymasterIds[paymasterId]) return 0; return paymasterIdWithdrawalDelay; } function _withdrawERC20(IERC20 token, address target, uint256 amount) private { if (target == address(0)) revert CanNotWithdrawToZeroAddress(); SafeTransferLib.safeTransfer(address(token), target, amount); emit TokensWithdrawn(address(token), target, amount, msg.sender); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.27; /* solhint-disable reason-string */ import { SoladyOwnable } from "../utils/SoladyOwnable.sol"; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import { IPaymaster } from "account-abstraction/interfaces/IPaymaster.sol"; import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol"; import "account-abstraction/core/UserOperationLib.sol"; /** * Helper class for creating a paymaster. * provides helper methods for staking. * Validates that the postOp is called only by the entryPoint. */ abstract contract BasePaymaster is IPaymaster, SoladyOwnable { IEntryPoint public immutable entryPoint; uint256 internal constant _PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET; uint256 internal constant _PAYMASTER_POSTOP_GAS_OFFSET = UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET; uint256 internal constant _PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET; constructor(address owner, IEntryPoint entryPointArg) SoladyOwnable(owner) { _validateEntryPointInterface(entryPointArg); entryPoint = entryPointArg; } /** * Add stake for this paymaster. * This method can also carry eth value to add to the current stake. * @param unstakeDelaySec - The unstake delay for this paymaster. Can only be increased. */ function addStake(uint32 unstakeDelaySec) external payable onlyOwner { entryPoint.addStake{ value: msg.value }(unstakeDelaySec); } /** * Unlock the stake, in order to withdraw it. * The paymaster can't serve requests once unlocked, until it calls addStake again */ function unlockStake() external onlyOwner { entryPoint.unlockStake(); } /** * Withdraw the entire paymaster's stake. * stake must be unlocked first (and then wait for the unstakeDelay to be over) * @param withdrawAddress - The address to send withdrawn value. */ function withdrawStake(address payable withdrawAddress) external onlyOwner { entryPoint.withdrawStake(withdrawAddress); } /// @inheritdoc IPaymaster function postOp( PostOpMode mode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas ) external override { _requireFromEntryPoint(); _postOp(mode, context, actualGasCost, actualUserOpFeePerGas); } /// @inheritdoc IPaymaster function validatePaymasterUserOp( PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost ) external override returns (bytes memory context, uint256 validationData) { _requireFromEntryPoint(); return _validatePaymasterUserOp(userOp, userOpHash, maxCost); } /** * Add a deposit for this paymaster, used for paying for transaction fees. */ function deposit() external payable virtual { entryPoint.depositTo{ value: msg.value }(address(this)); } /** * Withdraw value from the deposit. * @param withdrawAddress - Target to send to. * @param amount - Amount to withdraw. */ function withdrawTo(address payable withdrawAddress, uint256 amount) external virtual onlyOwner { entryPoint.withdrawTo(withdrawAddress, amount); } /** * Return current paymaster's deposit on the entryPoint. */ function getDeposit() public view returns (uint256) { return entryPoint.balanceOf(address(this)); } //sanity check: make sure this EntryPoint was compiled against the same // IEntryPoint of this paymaster function _validateEntryPointInterface(IEntryPoint entryPointArg) internal virtual { require( IERC165(address(entryPointArg)).supportsInterface(type(IEntryPoint).interfaceId), "IEntryPoint interface mismatch" ); } /** * Validate a user operation. * @param userOp - The user operation. * @param userOpHash - The hash of the user operation. * @param maxCost - The maximum cost of the user operation. */ function _validatePaymasterUserOp( PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost ) internal virtual returns (bytes memory context, uint256 validationData); /** * Post-operation handler. * (verified to be called only through the entryPoint) * @dev If subclass returns a non-empty context from validatePaymasterUserOp, * it must also implement this method. * @param mode - Enum with the following options: * opSucceeded - User operation succeeded. * opReverted - User op reverted. The paymaster still has to pay for gas. * postOpReverted - never passed in a call to postOp(). * @param context - The context value returned by validatePaymasterUserOp * @param actualGasCost - Actual gas used so far (without this postOp call). * @param actualUserOpFeePerGas - the gas price this UserOp pays. This value is based on the UserOp's maxFeePerGas * and maxPriorityFee (and basefee) * It is not the same as tx.gasprice, which is what the bundler pays. */ function _postOp( PostOpMode mode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas ) internal virtual { (mode, context, actualGasCost, actualUserOpFeePerGas); // unused params // subclass must override this method if validatePaymasterUserOp returns a context revert("must override"); } /** * Validate the call is made from a valid entrypoint */ function _requireFromEntryPoint() internal virtual { require(msg.sender == address(entryPoint), "Sender not EntryPoint"); } /** * Check if address is a contract */ function _isContract(address addr) internal view returns (bool) { uint256 size; assembly ("memory-safe") { size := extcodesize(addr) } return size > 0; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.23; /* solhint-disable no-inline-assembly */ import "../interfaces/PackedUserOperation.sol"; import {calldataKeccak, min} from "./Helpers.sol"; /** * Utility functions helpful when working with UserOperation structs. */ library UserOperationLib { uint256 public constant PAYMASTER_VALIDATION_GAS_OFFSET = 20; uint256 public constant PAYMASTER_POSTOP_GAS_OFFSET = 36; uint256 public constant PAYMASTER_DATA_OFFSET = 52; /** * Get sender from user operation data. * @param userOp - The user operation data. */ function getSender( PackedUserOperation calldata userOp ) internal pure returns (address) { address data; //read sender from userOp, which is first userOp member (saves 800 gas...) assembly { data := calldataload(userOp) } return address(uint160(data)); } /** * Relayer/block builder might submit the TX with higher priorityFee, * but the user should not pay above what he signed for. * @param userOp - The user operation data. */ function gasPrice( PackedUserOperation calldata userOp ) internal view returns (uint256) { unchecked { (uint256 maxPriorityFeePerGas, uint256 maxFeePerGas) = unpackUints(userOp.gasFees); if (maxFeePerGas == maxPriorityFeePerGas) { //legacy mode (for networks that don't support basefee opcode) return maxFeePerGas; } return min(maxFeePerGas, maxPriorityFeePerGas + block.basefee); } } /** * Pack the user operation data into bytes for hashing. * @param userOp - The user operation data. */ function encode( PackedUserOperation calldata userOp ) internal pure returns (bytes memory ret) { address sender = getSender(userOp); uint256 nonce = userOp.nonce; bytes32 hashInitCode = calldataKeccak(userOp.initCode); bytes32 hashCallData = calldataKeccak(userOp.callData); bytes32 accountGasLimits = userOp.accountGasLimits; uint256 preVerificationGas = userOp.preVerificationGas; bytes32 gasFees = userOp.gasFees; bytes32 hashPaymasterAndData = calldataKeccak(userOp.paymasterAndData); return abi.encode( sender, nonce, hashInitCode, hashCallData, accountGasLimits, preVerificationGas, gasFees, hashPaymasterAndData ); } function unpackUints( bytes32 packed ) internal pure returns (uint256 high128, uint256 low128) { return (uint128(bytes16(packed)), uint128(uint256(packed))); } //unpack just the high 128-bits from a packed value function unpackHigh128(bytes32 packed) internal pure returns (uint256) { return uint256(packed) >> 128; } // unpack just the low 128-bits from a packed value function unpackLow128(bytes32 packed) internal pure returns (uint256) { return uint128(uint256(packed)); } function unpackMaxPriorityFeePerGas(PackedUserOperation calldata userOp) internal pure returns (uint256) { return unpackHigh128(userOp.gasFees); } function unpackMaxFeePerGas(PackedUserOperation calldata userOp) internal pure returns (uint256) { return unpackLow128(userOp.gasFees); } function unpackVerificationGasLimit(PackedUserOperation calldata userOp) internal pure returns (uint256) { return unpackHigh128(userOp.accountGasLimits); } function unpackCallGasLimit(PackedUserOperation calldata userOp) internal pure returns (uint256) { return unpackLow128(userOp.accountGasLimits); } function unpackPaymasterVerificationGasLimit(PackedUserOperation calldata userOp) internal pure returns (uint256) { return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET])); } function unpackPostOpGasLimit(PackedUserOperation calldata userOp) internal pure returns (uint256) { return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET])); } function unpackPaymasterStaticFields( bytes calldata paymasterAndData ) internal pure returns (address paymaster, uint256 validationGasLimit, uint256 postOpGasLimit) { return ( address(bytes20(paymasterAndData[: PAYMASTER_VALIDATION_GAS_OFFSET])), uint128(bytes16(paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET])), uint128(bytes16(paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET])) ); } /** * Hash the user operation data. * @param userOp - The user operation data. */ function hash( PackedUserOperation calldata userOp ) internal pure returns (bytes32) { return keccak256(encode(userOp)); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.23; /* solhint-disable no-inline-assembly */ /* * For simulation purposes, validateUserOp (and validatePaymasterUserOp) * must return this value in case of signature failure, instead of revert. */ uint256 constant SIG_VALIDATION_FAILED = 1; /* * For simulation purposes, validateUserOp (and validatePaymasterUserOp) * return this value on success. */ uint256 constant SIG_VALIDATION_SUCCESS = 0; /** * Returned data from validateUserOp. * validateUserOp returns a uint256, which is created by `_packedValidationData` and * parsed by `_parseValidationData`. * @param aggregator - address(0) - The account validated the signature by itself. * address(1) - The account failed to validate the signature. * otherwise - This is an address of a signature aggregator that must * be used to validate the signature. * @param validAfter - This UserOp is valid only after this timestamp. * @param validaUntil - This UserOp is valid only up to this timestamp. */ struct ValidationData { address aggregator; uint48 validAfter; uint48 validUntil; } /** * Extract sigFailed, validAfter, validUntil. * Also convert zero validUntil to type(uint48).max. * @param validationData - The packed validation data. */ function _parseValidationData( uint256 validationData ) pure returns (ValidationData memory data) { address aggregator = address(uint160(validationData)); uint48 validUntil = uint48(validationData >> 160); if (validUntil == 0) { validUntil = type(uint48).max; } uint48 validAfter = uint48(validationData >> (48 + 160)); return ValidationData(aggregator, validAfter, validUntil); } /** * Helper to pack the return value for validateUserOp. * @param data - The ValidationData to pack. */ function _packValidationData( ValidationData memory data ) pure returns (uint256) { return uint160(data.aggregator) | (uint256(data.validUntil) << 160) | (uint256(data.validAfter) << (160 + 48)); } /** * Helper to pack the return value for validateUserOp, when not using an aggregator. * @param sigFailed - True for signature failure, false for success. * @param validUntil - Last timestamp this UserOperation is valid (or zero for infinite). * @param validAfter - First timestamp this UserOperation is valid. */ function _packValidationData( bool sigFailed, uint48 validUntil, uint48 validAfter ) pure returns (uint256) { return (sigFailed ? 1 : 0) | (uint256(validUntil) << 160) | (uint256(validAfter) << (160 + 48)); } /** * keccak function over calldata. * @dev copy calldata into memory, do keccak and drop allocated memory. Strangely, this is more efficient than letting solidity do it. */ function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) { assembly ("memory-safe") { let mem := mload(0x40) let len := data.length calldatacopy(mem, data.offset, len) ret := keccak256(mem, len) } } /** * The minimum of two numbers. * @param a - First number. * @param b - Second number. */ function min(uint256 a, uint256 b) pure returns (uint256) { return a < b ? a : b; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Signature verification helper that supports both ECDSA signatures from EOAs /// and ERC1271 signatures from smart contract wallets like Argent and Gnosis safe. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SignatureCheckerLib.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/SignatureChecker.sol) /// /// @dev Note: /// - The signature checking functions use the ecrecover precompile (0x1). /// - The `bytes memory signature` variants use the identity precompile (0x4) /// to copy memory internally. /// - Unlike ECDSA signatures, contract signatures are revocable. /// - As of Solady version 0.0.134, all `bytes signature` variants accept both /// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures. /// See: https://eips.ethereum.org/EIPS/eip-2098 /// This is for calldata efficiency on smart accounts prevalent on L2s. /// /// WARNING! Do NOT use signatures as unique identifiers: /// - Use a nonce in the digest to prevent replay attacks on the same contract. /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts. /// EIP-712 also enables readable signing of typed data for better user safety. /// This implementation does NOT check if a signature is non-malleable. library SignatureCheckerLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* SIGNATURE CHECKING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns whether `signature` is valid for `signer` and `hash`. /// First, it will try to validate with `ecrecover`, and if the validation fails, /// it will try to validate with ERC1271 on `signer`. function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool isValid) { if (signer == address(0)) return isValid; /// @solidity memory-safe-assembly assembly { let m := mload(0x40) for {} 1 {} { switch mload(signature) case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { break } mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. break } if iszero(isValid) { let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. // Copy the `signature` over. let n := add(0x20, mload(signature)) pop(staticcall(gas(), 4, signature, n, add(m, 0x44), n)) isValid := staticcall(gas(), signer, m, add(returndatasize(), 0x44), d, 0x20) isValid := and(eq(mload(d), f), isValid) } } } /// @dev Returns whether `signature` is valid for `signer` and `hash`. /// First, it will try to validate with `ecrecover`, and if the validation fails, /// it will try to validate with ERC1271 on `signer`. function isValidSignatureNowCalldata(address signer, bytes32 hash, bytes calldata signature) internal view returns (bool isValid) { if (signer == address(0)) return isValid; /// @solidity memory-safe-assembly assembly { let m := mload(0x40) for {} 1 {} { switch signature.length case 64 { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // `r`, `s`. } default { break } mstore(0x00, hash) let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. break } if iszero(isValid) { let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), signature.length) // Copy the `signature` over. calldatacopy(add(m, 0x64), signature.offset, signature.length) isValid := staticcall(gas(), signer, m, add(signature.length, 0x64), d, 0x20) isValid := and(eq(mload(d), f), isValid) } } } /// @dev Returns whether the signature (`r`, `vs`) is valid for `signer` and `hash`. /// First, it will try to validate with `ecrecover`, and if the validation fails, /// it will try to validate with ERC1271 on `signer`. function isValidSignatureNow(address signer, bytes32 hash, bytes32 r, bytes32 vs) internal view returns (bool isValid) { if (signer == address(0)) return isValid; /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) if iszero(isValid) { let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), 65) // Length of the signature. mstore(add(m, 0x64), r) // `r`. mstore(add(m, 0x84), mload(0x60)) // `s`. mstore8(add(m, 0xa4), mload(0x20)) // `v`. isValid := staticcall(gas(), signer, m, 0xa5, d, 0x20) isValid := and(eq(mload(d), f), isValid) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Returns whether the signature (`v`, `r`, `s`) is valid for `signer` and `hash`. /// First, it will try to validate with `ecrecover`, and if the validation fails, /// it will try to validate with ERC1271 on `signer`. function isValidSignatureNow(address signer, bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (bool isValid) { if (signer == address(0)) return isValid; /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(0x00, hash) mstore(0x20, and(v, 0xff)) // `v`. mstore(0x40, r) // `r`. mstore(0x60, s) // `s`. let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) if iszero(isValid) { let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), 65) // Length of the signature. mstore(add(m, 0x64), r) // `r`. mstore(add(m, 0x84), s) // `s`. mstore8(add(m, 0xa4), v) // `v`. isValid := staticcall(gas(), signer, m, 0xa5, d, 0x20) isValid := and(eq(mload(d), f), isValid) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC1271 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Note: These ERC1271 operations do NOT have an ECDSA fallback. /// @dev Returns whether `signature` is valid for `hash` for an ERC1271 `signer` contract. function isValidERC1271SignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool isValid) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. // Copy the `signature` over. let n := add(0x20, mload(signature)) pop(staticcall(gas(), 4, signature, n, add(m, 0x44), n)) isValid := staticcall(gas(), signer, m, add(returndatasize(), 0x44), d, 0x20) isValid := and(eq(mload(d), f), isValid) } } /// @dev Returns whether `signature` is valid for `hash` for an ERC1271 `signer` contract. function isValidERC1271SignatureNowCalldata( address signer, bytes32 hash, bytes calldata signature ) internal view returns (bool isValid) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), signature.length) // Copy the `signature` over. calldatacopy(add(m, 0x64), signature.offset, signature.length) isValid := staticcall(gas(), signer, m, add(signature.length, 0x64), d, 0x20) isValid := and(eq(mload(d), f), isValid) } } /// @dev Returns whether the signature (`r`, `vs`) is valid for `hash` /// for an ERC1271 `signer` contract. function isValidERC1271SignatureNow(address signer, bytes32 hash, bytes32 r, bytes32 vs) internal view returns (bool isValid) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), 65) // Length of the signature. mstore(add(m, 0x64), r) // `r`. mstore(add(m, 0x84), shr(1, shl(1, vs))) // `s`. mstore8(add(m, 0xa4), add(shr(255, vs), 27)) // `v`. isValid := staticcall(gas(), signer, m, 0xa5, d, 0x20) isValid := and(eq(mload(d), f), isValid) } } /// @dev Returns whether the signature (`v`, `r`, `s`) is valid for `hash` /// for an ERC1271 `signer` contract. function isValidERC1271SignatureNow(address signer, bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (bool isValid) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) let f := shl(224, 0x1626ba7e) mstore(m, f) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m, 0x04), hash) let d := add(m, 0x24) mstore(d, 0x40) // The offset of the `signature` in the calldata. mstore(add(m, 0x44), 65) // Length of the signature. mstore(add(m, 0x64), r) // `r`. mstore(add(m, 0x84), s) // `s`. mstore8(add(m, 0xa4), v) // `v`. isValid := staticcall(gas(), signer, m, 0xa5, d, 0x20) isValid := and(eq(mload(d), f), isValid) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC6492 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Note: These ERC6492 operations now include an ECDSA fallback at the very end. // The calldata variants are excluded for brevity. /// @dev Returns whether `signature` is valid for `hash`. /// If the signature is postfixed with the ERC6492 magic number, it will attempt to /// deploy / prepare the `signer` smart account before doing a regular ERC1271 check. /// Note: This function is NOT reentrancy safe. function isValidERC6492SignatureNowAllowSideEffects( address signer, bytes32 hash, bytes memory signature ) internal returns (bool isValid) { /// @solidity memory-safe-assembly assembly { function callIsValidSignature(signer_, hash_, signature_) -> _isValid { let m_ := mload(0x40) let f_ := shl(224, 0x1626ba7e) mstore(m_, f_) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m_, 0x04), hash_) let d_ := add(m_, 0x24) mstore(d_, 0x40) // The offset of the `signature` in the calldata. let n_ := add(0x20, mload(signature_)) pop(staticcall(gas(), 4, signature_, n_, add(m_, 0x44), n_)) _isValid := staticcall(gas(), signer_, m_, add(returndatasize(), 0x44), d_, 0x20) _isValid := and(eq(mload(d_), f_), _isValid) } let noCode := iszero(extcodesize(signer)) let n := mload(signature) for {} 1 {} { if iszero(eq(mload(add(signature, n)), mul(0x6492, div(not(isValid), 0xffff)))) { if iszero(noCode) { isValid := callIsValidSignature(signer, hash, signature) } break } let o := add(signature, 0x20) // Signature bytes. let d := add(o, mload(add(o, 0x20))) // Factory calldata. if noCode { if iszero(call(gas(), mload(o), 0, add(d, 0x20), mload(d), codesize(), 0x00)) { break } } let s := add(o, mload(add(o, 0x40))) // Inner signature. isValid := callIsValidSignature(signer, hash, s) if iszero(isValid) { if call(gas(), mload(o), 0, add(d, 0x20), mload(d), codesize(), 0x00) { noCode := iszero(extcodesize(signer)) if iszero(noCode) { isValid := callIsValidSignature(signer, hash, s) } } } break } // Do `ecrecover` fallback if `noCode && !isValid`. for {} gt(noCode, isValid) {} { switch n case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { break } let m := mload(0x40) mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. break } } } /// @dev Returns whether `signature` is valid for `hash`. /// If the signature is postfixed with the ERC6492 magic number, it will attempt /// to use a reverting verifier to deploy / prepare the `signer` smart account /// and do a `isValidSignature` check via the reverting verifier. /// Note: This function is reentrancy safe. /// The reverting verifier must be deployed. /// Otherwise, the function will return false if `signer` is not yet deployed / prepared. /// See: https://gist.github.com/Vectorized/846a474c855eee9e441506676800a9ad function isValidERC6492SignatureNow(address signer, bytes32 hash, bytes memory signature) internal returns (bool isValid) { /// @solidity memory-safe-assembly assembly { function callIsValidSignature(signer_, hash_, signature_) -> _isValid { let m_ := mload(0x40) let f_ := shl(224, 0x1626ba7e) mstore(m_, f_) // `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`. mstore(add(m_, 0x04), hash_) let d_ := add(m_, 0x24) mstore(d_, 0x40) // The offset of the `signature` in the calldata. let n_ := add(0x20, mload(signature_)) pop(staticcall(gas(), 4, signature_, n_, add(m_, 0x44), n_)) _isValid := staticcall(gas(), signer_, m_, add(returndatasize(), 0x44), d_, 0x20) _isValid := and(eq(mload(d_), f_), _isValid) } let noCode := iszero(extcodesize(signer)) let n := mload(signature) for {} 1 {} { if iszero(eq(mload(add(signature, n)), mul(0x6492, div(not(isValid), 0xffff)))) { if iszero(noCode) { isValid := callIsValidSignature(signer, hash, signature) } break } if iszero(noCode) { let o := add(signature, 0x20) // Signature bytes. isValid := callIsValidSignature(signer, hash, add(o, mload(add(o, 0x40)))) if isValid { break } } let m := mload(0x40) mstore(m, signer) mstore(add(m, 0x20), hash) let willBeZeroIfRevertingVerifierExists := call( gas(), // Remaining gas. 0x00007bd799e4A591FeA53f8A8a3E9f931626Ba7e, // Reverting verifier. 0, // Send zero ETH. m, // Start of memory. add(returndatasize(), 0x40), // Length of calldata in memory. staticcall(gas(), 4, add(signature, 0x20), n, add(m, 0x40), n), // 1. 0x00 // Length of returndata to write. ) isValid := gt(returndatasize(), willBeZeroIfRevertingVerifierExists) break } // Do `ecrecover` fallback if `noCode && !isValid`. for {} gt(noCode, isValid) {} { switch n case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { break } let m := mload(0x40) mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. let recovered := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) isValid := gt(returndatasize(), shl(96, xor(signer, recovered))) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. break } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HASHING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an Ethereum Signed Message, created from a `hash`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign) /// JSON-RPC method as part of EIP-191. function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { mstore(0x20, hash) // Store into scratch space for keccak256. mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes. result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`. } } /// @dev Returns an Ethereum Signed Message, created from `s`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign) /// JSON-RPC method as part of EIP-191. /// Note: Supports lengths of `s` up to 999999 bytes. function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let sLength := mload(s) let o := 0x20 mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded. mstore(0x00, 0x00) // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`. for { let temp := sLength } 1 {} { o := sub(o, 1) mstore8(o, add(48, mod(temp, 10))) temp := div(temp, 10) if iszero(temp) { break } } let n := sub(0x3a, o) // Header length: `26 + 32 - o`. // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes. returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20)) mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header. result := keccak256(add(s, sub(0x20, n)), add(n, sLength)) mstore(s, sLength) // Restore the length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EMPTY CALLDATA HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an empty calldata bytes. function emptySignature() internal pure returns (bytes calldata signature) { /// @solidity memory-safe-assembly assembly { signature.length := 0 } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Gas optimized ECDSA wrapper. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol) /// /// @dev Note: /// - The recovery functions use the ecrecover precompile (0x1). /// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure. /// This is for more safety by default. /// Use the `tryRecover` variants if you need to get the zero address back /// upon recovery failure instead. /// - As of Solady version 0.0.134, all `bytes signature` variants accept both /// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures. /// See: https://eips.ethereum.org/EIPS/eip-2098 /// This is for calldata efficiency on smart accounts prevalent on L2s. /// /// WARNING! Do NOT directly use signatures as unique identifiers: /// - The recovery operations do NOT check if a signature is non-malleable. /// - Use a nonce in the digest to prevent replay attacks on the same contract. /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts. /// EIP-712 also enables readable signing of typed data for better user safety. /// - If you need a unique hash from a signature, please use the `canonicalHash` functions. library ECDSA { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The order of the secp256k1 elliptic curve. uint256 internal constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141; /// @dev `N/2 + 1`. Used for checking the malleability of the signature. uint256 private constant _HALF_N_PLUS_1 = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The signature is invalid. error InvalidSignature(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RECOVERY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } { switch mload(signature) case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { continue } mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if returndatasize() { break } } } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } { switch signature.length case 64 { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. } default { continue } mstore(0x00, hash) result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if returndatasize() { break } } } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* TRY-RECOVER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // WARNING! // These functions will NOT revert upon recovery failure. // Instead, they will return the zero address upon recovery failure. // It is critical that the returned address is NEVER compared against // a zero address (e.g. an uninitialized address variable). /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 {} { switch mload(signature) case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { break } mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. break } } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 {} { switch signature.length case 64 { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. } default { break } mstore(0x00, hash) pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. break } } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HASHING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an Ethereum Signed Message, created from a `hash`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign) /// JSON-RPC method as part of EIP-191. function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { mstore(0x20, hash) // Store into scratch space for keccak256. mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes. result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`. } } /// @dev Returns an Ethereum Signed Message, created from `s`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign) /// JSON-RPC method as part of EIP-191. /// Note: Supports lengths of `s` up to 999999 bytes. function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let sLength := mload(s) let o := 0x20 mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded. mstore(0x00, 0x00) // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`. for { let temp := sLength } 1 {} { o := sub(o, 1) mstore8(o, add(48, mod(temp, 10))) temp := div(temp, 10) if iszero(temp) { break } } let n := sub(0x3a, o) // Header length: `26 + 32 - o`. // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes. returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20)) mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header. result := keccak256(add(s, sub(0x20, n)), add(n, sLength)) mstore(s, sLength) // Restore the length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CANONICAL HASH FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // The following functions returns the hash of the signature in it's canonicalized format, // which is the 65-byte `abi.encodePacked(r, s, uint8(v))`, where `v` is either 27 or 28. // If `s` is greater than `N / 2` then it will be converted to `N - s` // and the `v` value will be flipped. // If the signature has an invalid length, or if `v` is invalid, // a uniquely corrupt hash will be returned. // These functions are useful for "poor-mans-VRF". /// @dev Returns the canonical hash of `signature`. function canonicalHash(bytes memory signature) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { let l := mload(signature) for {} 1 {} { mstore(0x00, mload(add(signature, 0x20))) // `r`. let s := mload(add(signature, 0x40)) let v := mload(add(signature, 0x41)) if eq(l, 64) { v := add(shr(255, s), 27) s := shr(1, shl(1, s)) } if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. break } // If the length is neither 64 nor 65, return a uniquely corrupted hash. if iszero(lt(sub(l, 64), 2)) { // `bytes4(keccak256("InvalidSignatureLength"))`. result := xor(keccak256(add(signature, 0x20), l), 0xd62f1ab2) } } } /// @dev Returns the canonical hash of `signature`. function canonicalHashCalldata(bytes calldata signature) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { for {} 1 {} { mstore(0x00, calldataload(signature.offset)) // `r`. let s := calldataload(add(signature.offset, 0x20)) let v := calldataload(add(signature.offset, 0x21)) if eq(signature.length, 64) { v := add(shr(255, s), 27) s := shr(1, shl(1, s)) } if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. break } // If the length is neither 64 nor 65, return a uniquely corrupted hash. if iszero(lt(sub(signature.length, 64), 2)) { calldatacopy(mload(0x40), signature.offset, signature.length) // `bytes4(keccak256("InvalidSignatureLength"))`. result := xor(keccak256(mload(0x40), signature.length), 0xd62f1ab2) } } } /// @dev Returns the canonical hash of `signature`. function canonicalHash(bytes32 r, bytes32 vs) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { mstore(0x00, r) // `r`. let v := add(shr(255, vs), 27) let s := shr(1, shl(1, vs)) mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the canonical hash of `signature`. function canonicalHash(uint8 v, bytes32 r, bytes32 s) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { mstore(0x00, r) // `r`. if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EMPTY CALLDATA HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an empty calldata bytes. function emptySignature() internal pure returns (bytes calldata signature) { /// @solidity memory-safe-assembly assembly { signature.length := 0 } } }
// SPDX-License-Identifier: LGPL-3.0-only pragma solidity ^0.8.27; contract BiconomySponsorshipPaymasterErrors { /** * @notice Throws when the paymaster address provided is address(0) */ error PaymasterIdCanNotBeZero(); /** * @notice Throws when the 0 has been provided as deposit */ error DepositCanNotBeZero(); /** * @notice Throws when the verifiying signer address provided is address(0) */ error VerifyingSignerCanNotBeZero(); /** * @notice Throws when the fee collector address provided is address(0) */ error FeeCollectorCanNotBeZero(); /** * @notice Throws when the fee collector address provided is a deployed contract */ error FeeCollectorCanNotBeContract(); /** * @notice Throws when the fee collector address provided is a deployed contract */ error VerifyingSignerCanNotBeContract(); /** * @notice Throws when ETH withdrawal fails */ error WithdrawalFailed(); /** * @notice Throws when insufficient funds to withdraw */ error InsufficientFunds(); /** * @notice Throws when invalid signature length in paymasterAndData */ error InvalidSignatureLength(); /** * @notice Throws when invalid signature length in paymasterAndData */ error InvalidPriceMarkup(); /** * @notice Throws when insufficient funds for paymasterid */ error InsufficientFundsForPaymasterId(); /** * @notice Throws when calling deposit() */ error UseDepositForInstead(); /** * @notice Throws when trying to withdraw to address(0) */ error CanNotWithdrawToZeroAddress(); /** * @notice Throws when trying to withdraw zero amount */ error CanNotWithdrawZeroAmount(); /** * @notice Throws when no request has been submitted */ error NoRequestSubmitted(); /** * @notice Throws when trying unaccountedGas is too high */ error UnaccountedGasTooHigh(); /** * @notice Throws when postOp gas limit is too low */ error PostOpGasLimitTooLow(); /** * @notice Thrown when deposit is too low to reach minDeposit */ error LowDeposit(); /** * @notice Thrown when trying to withdraw more than the balance */ error InsufficientFundsInGasTank(); /** * @notice Thrown when trying to execute withdrawal request before delay has passed */ error RequestNotClearedYet(uint256 clearanceTime); /** * @notice Thrown when trying to directly withdraw instead of submitting a request */ error SubmitRequestInstead(); /** * @notice Thrown when the array lengths are not equal */ error InvalidArrayLengths(); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuardTransient.sol) pragma solidity ^0.8.24; import {TransientSlot} from "./TransientSlot.sol"; /** * @dev Variant of {ReentrancyGuard} that uses transient storage. * * NOTE: This variant only works on networks where EIP-1153 is available. * * _Available since v5.1._ */ abstract contract ReentrancyGuardTransient { using TransientSlot for *; // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant REENTRANCY_GUARD_STORAGE = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00; /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be NOT_ENTERED if (_reentrancyGuardEntered()) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true); } function _nonReentrantAfter() private { REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false); } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return REENTRANCY_GUARD_STORAGE.asBoolean().tload(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol) /// /// @dev Note: /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection. library SafeTransferLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev The ERC20 `transferFrom` has failed. error TransferFromFailed(); /// @dev The ERC20 `transfer` has failed. error TransferFailed(); /// @dev The ERC20 `approve` has failed. error ApproveFailed(); /// @dev The Permit2 operation has failed. error Permit2Failed(); /// @dev The Permit2 amount must be less than `2**160 - 1`. error Permit2AmountOverflow(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes. uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300; /// @dev Suggested gas stipend for contract receiving ETH to perform a few /// storage reads and writes, but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /// @dev The unique EIP-712 domain domain separator for the DAI token contract. bytes32 internal constant DAI_DOMAIN_SEPARATOR = 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7; /// @dev The address for the WETH9 contract on Ethereum mainnet. address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; /// @dev The canonical Permit2 address. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ETH OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants. // // The regular variants: // - Forwards all remaining gas to the target. // - Reverts if the target reverts. // - Reverts if the current contract has insufficient balance. // // The force variants: // - Forwards with an optional gas stipend // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases). // - If the target reverts, or if the gas stipend is exhausted, // creates a temporary contract to force send the ETH via `SELFDESTRUCT`. // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758. // - Reverts if the current contract has insufficient balance. // // The try variants: // - Forwards with a mandatory gas stipend. // - Instead of reverting, returns whether the transfer succeeded. /// @dev Sends `amount` (in wei) ETH to `to`. function safeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Sends all the ETH in the current contract to `to`. function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`. function forceSafeTransferAllETH(address to, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // forgefmt: disable-next-item if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00) } } /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`. function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for /// the current contract to manage. function safeTransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function trySafeTransferFrom(address token, address from, address to, uint256 amount) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { success := lt(or(iszero(extcodesize(token)), returndatasize()), success) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends all of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have their entire balance approved for the current contract to manage. function safeTransferAllFrom(address token, address from, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`. amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransfer(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sends all of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransferAll(address token, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`. mstore(0x20, address()) // Store the address of the current contract. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x14, to) // Store the `to` argument. amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// Reverts upon failure. function safeApprove(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// If the initial attempt to approve fails, attempts to reset the approved amount to zero, /// then retries the approval again (some tokens, e.g. USDT, requires this). /// Reverts upon failure. function safeApproveWithRetry(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, retrying upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x34, 0) // Store 0 for the `amount`. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval. mstore(0x34, amount) // Store back the original `amount`. // Retry the approval, reverting upon failure. success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { // Check the `extcodesize` again just in case the token selfdestructs lol. if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Returns the amount of ERC20 `token` owned by `account`. /// Returns zero if the `token` does not exist. function balanceOf(address token, address account) internal view returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x14, account) // Store the `account` argument. mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. amount := mul( // The arguments of `mul` are evaluated from right to left. mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20) ) ) } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// If the initial attempt fails, try to use Permit2 to transfer the token. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function safeTransferFrom2(address token, address from, address to, uint256 amount) internal { if (!trySafeTransferFrom(token, from, to, amount)) { permit2TransferFrom(token, from, to, amount); } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2. /// Reverts upon failure. function permit2TransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(add(m, 0x74), shr(96, shl(96, token))) mstore(add(m, 0x54), amount) mstore(add(m, 0x34), to) mstore(add(m, 0x20), shl(96, from)) // `transferFrom(address,address,uint160,address)`. mstore(m, 0x36c78516000000000000000000000000) let p := PERMIT2 let exists := eq(chainid(), 1) if iszero(exists) { exists := iszero(iszero(extcodesize(p))) } if iszero( and( call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists. ) ) { mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04) } } } /// @dev Permit a user to spend a given amount of /// another user's tokens via native EIP-2612 permit if possible, falling /// back to Permit2 if native permit fails or is not implemented on the token. function permit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { bool success; /// @solidity memory-safe-assembly assembly { for {} shl(96, xor(token, WETH9)) {} { mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`. if iszero( and( // The arguments of `and` are evaluated from right to left. lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word. // Gas stipend to limit gas burn for tokens that don't refund gas when // an non-existing function is called. 5K should be enough for a SLOAD. staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20) ) ) { break } // After here, we can be sure that token is a contract. let m := mload(0x40) mstore(add(m, 0x34), spender) mstore(add(m, 0x20), shl(96, owner)) mstore(add(m, 0x74), deadline) if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) { mstore(0x14, owner) mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`. mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20)) mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`. // `nonces` is already at `add(m, 0x54)`. // `1` is already stored at `add(m, 0x94)`. mstore(add(m, 0xb4), and(0xff, v)) mstore(add(m, 0xd4), r) mstore(add(m, 0xf4), s) success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00) break } mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`. mstore(add(m, 0x54), amount) mstore(add(m, 0x94), and(0xff, v)) mstore(add(m, 0xb4), r) mstore(add(m, 0xd4), s) success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00) break } } if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s); } /// @dev Simple permit on the Permit2 contract. function simplePermit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(m, 0x927da105) // `allowance(address,address,address)`. { let addressMask := shr(96, not(0)) mstore(add(m, 0x20), and(addressMask, owner)) mstore(add(m, 0x40), and(addressMask, token)) mstore(add(m, 0x60), and(addressMask, spender)) mstore(add(m, 0xc0), and(addressMask, spender)) } let p := mul(PERMIT2, iszero(shr(160, amount))) if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`. staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60) ) ) { mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(p))), 0x04) } mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant). // `owner` is already `add(m, 0x20)`. // `token` is already at `add(m, 0x40)`. mstore(add(m, 0x60), amount) mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`. // `nonce` is already at `add(m, 0xa0)`. // `spender` is already at `add(m, 0xc0)`. mstore(add(m, 0xe0), deadline) mstore(add(m, 0x100), 0x100) // `signature` offset. mstore(add(m, 0x120), 0x41) // `signature` length. mstore(add(m, 0x140), r) mstore(add(m, 0x160), s) mstore(add(m, 0x180), shl(248, v)) if iszero( // Revert if token does not have code, or if the call fails. mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) { mstore(0x00, 0x6b836e6b) // `Permit2Failed()`. revert(0x1c, 0x04) } } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.27; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { PackedUserOperation } from "account-abstraction/core/UserOperationLib.sol"; interface IBiconomySponsorshipPaymaster { struct WithdrawalRequest { uint256 amount; address to; uint256 requestSubmittedTimestamp; } event UnaccountedGasChanged(uint256 indexed oldValue, uint256 indexed newValue); event FixedPriceMarkupChanged(uint256 indexed oldValue, uint256 indexed newValue); event VerifyingSignerChanged(address indexed oldSigner, address indexed newSigner, address indexed actor); event FeeCollectorChanged(address indexed oldFeeCollector, address indexed newFeeCollector, address indexed actor); event GasDeposited(address indexed _paymasterId, uint256 indexed _value); event GasWithdrawn(address indexed _paymasterId, address indexed _to, uint256 indexed _value); event GasBalanceDeducted(address indexed _paymasterId, uint256 indexed _charge, uint256 indexed _premium); event Received(address indexed sender, uint256 value); event TokensWithdrawn(address indexed token, address indexed to, uint256 indexed amount, address actor); event WithdrawalRequestSubmitted(address withdrawAddress, uint256 amount); event WithdrawalRequestCancelledFor(address paymasterId); event TrustedPaymasterIdSet(address indexed paymasterId, bool isTrusted); event EthWithdrawn(address indexed recipient, uint256 indexed amount); event MinDepositChanged(uint256 indexed oldValue, uint256 indexed newValue); function depositFor(address paymasterId) external payable; function setSigner(address newVerifyingSigner) external payable; function setFeeCollector(address newFeeCollector) external payable; function setUnaccountedGas(uint256 value) external payable; function withdrawERC20(IERC20 token, address target, uint256 amount) external; function withdrawEth(address payable recipient, uint256 amount) external payable; function getBalance(address paymasterId) external view returns (uint256 balance); function getHash( PackedUserOperation calldata userOp, address paymasterId, uint48 validUntil, uint48 validAfter, uint32 priceMarkup ) external view returns (bytes32); function parsePaymasterAndData( bytes calldata paymasterAndData ) external pure returns ( address paymasterId, uint48 validUntil, uint48 validAfter, uint32 priceMarkup, uint128 paymasterValidationGasLimit, uint128 paymasterPostOpGasLimit, bytes calldata signature ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.27; import { Ownable } from "solady/auth/Ownable.sol"; contract SoladyOwnable is Ownable { constructor(address _owner) Ownable() { assembly { if iszero(shl(96, _owner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _initializeOwner(_owner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.5; import "./PackedUserOperation.sol"; /** * The interface exposed by a paymaster contract, who agrees to pay the gas for user's operations. * A paymaster must hold a stake to cover the required entrypoint stake and also the gas for the transaction. */ interface IPaymaster { enum PostOpMode { // User op succeeded. opSucceeded, // User op reverted. Still has to pay for gas. opReverted, // Only used internally in the EntryPoint (cleanup after postOp reverts). Never calling paymaster with this value postOpReverted } /** * Payment validation: check if paymaster agrees to pay. * Must verify sender is the entryPoint. * Revert to reject this request. * Note that bundlers will reject this method if it changes the state, unless the paymaster is trusted (whitelisted). * The paymaster pre-pays using its deposit, and receive back a refund after the postOp method returns. * @param userOp - The user operation. * @param userOpHash - Hash of the user's request data. * @param maxCost - The maximum cost of this transaction (based on maximum gas and gas price from userOp). * @return context - Value to send to a postOp. Zero length to signify postOp is not required. * @return validationData - Signature and time-range of this operation, encoded the same as the return * value of validateUserOperation. * <20-byte> sigAuthorizer - 0 for valid signature, 1 to mark signature failure, * other values are invalid for paymaster. * <6-byte> validUntil - last timestamp this operation is valid. 0 for "indefinite" * <6-byte> validAfter - first timestamp this operation is valid * Note that the validation code cannot use block.timestamp (or block.number) directly. */ function validatePaymasterUserOp( PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost ) external returns (bytes memory context, uint256 validationData); /** * Post-operation handler. * Must verify sender is the entryPoint. * @param mode - Enum with the following options: * opSucceeded - User operation succeeded. * opReverted - User op reverted. The paymaster still has to pay for gas. * postOpReverted - never passed in a call to postOp(). * @param context - The context value returned by validatePaymasterUserOp * @param actualGasCost - Actual gas used so far (without this postOp call). * @param actualUserOpFeePerGas - the gas price this UserOp pays. This value is based on the UserOp's maxFeePerGas * and maxPriorityFee (and basefee) * It is not the same as tx.gasprice, which is what the bundler pays. */ function postOp( PostOpMode mode, bytes calldata context, uint256 actualGasCost, uint256 actualUserOpFeePerGas ) external; }
/** ** Account-Abstraction (EIP-4337) singleton EntryPoint implementation. ** Only one instance required on each chain. **/ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.5; /* solhint-disable avoid-low-level-calls */ /* solhint-disable no-inline-assembly */ /* solhint-disable reason-string */ import "./PackedUserOperation.sol"; import "./IStakeManager.sol"; import "./IAggregator.sol"; import "./INonceManager.sol"; interface IEntryPoint is IStakeManager, INonceManager { /*** * An event emitted after each successful request. * @param userOpHash - Unique identifier for the request (hash its entire content, except signature). * @param sender - The account that generates this request. * @param paymaster - If non-null, the paymaster that pays for this request. * @param nonce - The nonce value from the request. * @param success - True if the sender transaction succeeded, false if reverted. * @param actualGasCost - Actual amount paid (by account or paymaster) for this UserOperation. * @param actualGasUsed - Total gas used by this UserOperation (including preVerification, creation, * validation and execution). */ event UserOperationEvent( bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed ); /** * Account "sender" was deployed. * @param userOpHash - The userOp that deployed this account. UserOperationEvent will follow. * @param sender - The account that is deployed * @param factory - The factory used to deploy this account (in the initCode) * @param paymaster - The paymaster used by this UserOp */ event AccountDeployed( bytes32 indexed userOpHash, address indexed sender, address factory, address paymaster ); /** * An event emitted if the UserOperation "callData" reverted with non-zero length. * @param userOpHash - The request unique identifier. * @param sender - The sender of this request. * @param nonce - The nonce used in the request. * @param revertReason - The return bytes from the (reverted) call to "callData". */ event UserOperationRevertReason( bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason ); /** * An event emitted if the UserOperation Paymaster's "postOp" call reverted with non-zero length. * @param userOpHash - The request unique identifier. * @param sender - The sender of this request. * @param nonce - The nonce used in the request. * @param revertReason - The return bytes from the (reverted) call to "callData". */ event PostOpRevertReason( bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason ); /** * UserOp consumed more than prefund. The UserOperation is reverted, and no refund is made. * @param userOpHash - The request unique identifier. * @param sender - The sender of this request. * @param nonce - The nonce used in the request. */ event UserOperationPrefundTooLow( bytes32 indexed userOpHash, address indexed sender, uint256 nonce ); /** * An event emitted by handleOps(), before starting the execution loop. * Any event emitted before this event, is part of the validation. */ event BeforeExecution(); /** * Signature aggregator used by the following UserOperationEvents within this bundle. * @param aggregator - The aggregator used for the following UserOperationEvents. */ event SignatureAggregatorChanged(address indexed aggregator); /** * A custom revert error of handleOps, to identify the offending op. * Should be caught in off-chain handleOps simulation and not happen on-chain. * Useful for mitigating DoS attempts against batchers or for troubleshooting of factory/account/paymaster reverts. * NOTE: If simulateValidation passes successfully, there should be no reason for handleOps to fail on it. * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). * @param reason - Revert reason. The string starts with a unique code "AAmn", * where "m" is "1" for factory, "2" for account and "3" for paymaster issues, * so a failure can be attributed to the correct entity. */ error FailedOp(uint256 opIndex, string reason); /** * A custom revert error of handleOps, to report a revert by account or paymaster. * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). * @param reason - Revert reason. see FailedOp(uint256,string), above * @param inner - data from inner cought revert reason * @dev note that inner is truncated to 2048 bytes */ error FailedOpWithRevert(uint256 opIndex, string reason, bytes inner); error PostOpReverted(bytes returnData); /** * Error case when a signature aggregator fails to verify the aggregated signature it had created. * @param aggregator The aggregator that failed to verify the signature */ error SignatureValidationFailed(address aggregator); // Return value of getSenderAddress. error SenderAddressResult(address sender); // UserOps handled, per aggregator. struct UserOpsPerAggregator { PackedUserOperation[] userOps; // Aggregator address IAggregator aggregator; // Aggregated signature bytes signature; } /** * Execute a batch of UserOperations. * No signature aggregator is used. * If any account requires an aggregator (that is, it returned an aggregator when * performing simulateValidation), then handleAggregatedOps() must be used instead. * @param ops - The operations to execute. * @param beneficiary - The address to receive the fees. */ function handleOps( PackedUserOperation[] calldata ops, address payable beneficiary ) external; /** * Execute a batch of UserOperation with Aggregators * @param opsPerAggregator - The operations to execute, grouped by aggregator (or address(0) for no-aggregator accounts). * @param beneficiary - The address to receive the fees. */ function handleAggregatedOps( UserOpsPerAggregator[] calldata opsPerAggregator, address payable beneficiary ) external; /** * Generate a request Id - unique identifier for this request. * The request ID is a hash over the content of the userOp (except the signature), the entrypoint and the chainid. * @param userOp - The user operation to generate the request ID for. * @return hash the hash of this UserOperation */ function getUserOpHash( PackedUserOperation calldata userOp ) external view returns (bytes32); /** * Gas and return values during simulation. * @param preOpGas - The gas used for validation (including preValidationGas) * @param prefund - The required prefund for this operation * @param accountValidationData - returned validationData from account. * @param paymasterValidationData - return validationData from paymaster. * @param paymasterContext - Returned by validatePaymasterUserOp (to be passed into postOp) */ struct ReturnInfo { uint256 preOpGas; uint256 prefund; uint256 accountValidationData; uint256 paymasterValidationData; bytes paymasterContext; } /** * Returned aggregated signature info: * The aggregator returned by the account, and its current stake. */ struct AggregatorStakeInfo { address aggregator; StakeInfo stakeInfo; } /** * Get counterfactual sender address. * Calculate the sender contract address that will be generated by the initCode and salt in the UserOperation. * This method always revert, and returns the address in SenderAddressResult error * @param initCode - The constructor code to be passed into the UserOperation. */ function getSenderAddress(bytes memory initCode) external; error DelegateAndRevert(bool success, bytes ret); /** * Helper method for dry-run testing. * @dev calling this method, the EntryPoint will make a delegatecall to the given data, and report (via revert) the result. * The method always revert, so is only useful off-chain for dry run calls, in cases where state-override to replace * actual EntryPoint code is less convenient. * @param target a target contract to make a delegatecall from entrypoint * @param data data to pass to target in a delegatecall */ function delegateAndRevert(address target, bytes calldata data) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.5; /** * User Operation struct * @param sender - The sender account of this request. * @param nonce - Unique value the sender uses to verify it is not a replay. * @param initCode - If set, the account contract will be created by this constructor/ * @param callData - The method call to execute on this account. * @param accountGasLimits - Packed gas limits for validateUserOp and gas limit passed to the callData method call. * @param preVerificationGas - Gas not calculated by the handleOps method, but added to the gas paid. * Covers batch overhead. * @param gasFees - packed gas fields maxPriorityFeePerGas and maxFeePerGas - Same as EIP-1559 gas parameters. * @param paymasterAndData - If set, this field holds the paymaster address, verification gas limit, postOp gas limit and paymaster-specific extra data * The paymaster will pay for the transaction instead of the sender. * @param signature - Sender-verified signature over the entire request, the EntryPoint address and the chain ID. */ struct PackedUserOperation { address sender; uint256 nonce; bytes initCode; bytes callData; bytes32 accountGasLimits; uint256 preVerificationGas; bytes32 gasFees; bytes paymasterAndData; bytes signature; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/TransientSlot.sol) // This file was procedurally generated from scripts/generate/templates/TransientSlot.js. pragma solidity ^0.8.24; /** * @dev Library for reading and writing value-types to specific transient storage slots. * * Transient slots are often used to store temporary values that are removed after the current transaction. * This library helps with reading and writing to such slots without the need for inline assembly. * * * Example reading and writing values using transient storage: * ```solidity * contract Lock { * using TransientSlot for *; * * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot. * bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542; * * modifier locked() { * require(!_LOCK_SLOT.asBoolean().tload()); * * _LOCK_SLOT.asBoolean().tstore(true); * _; * _LOCK_SLOT.asBoolean().tstore(false); * } * } * ``` * * TIP: Consider using this library along with {SlotDerivation}. */ library TransientSlot { /** * @dev UDVT that represent a slot holding a address. */ type AddressSlot is bytes32; /** * @dev Cast an arbitrary slot to a AddressSlot. */ function asAddress(bytes32 slot) internal pure returns (AddressSlot) { return AddressSlot.wrap(slot); } /** * @dev UDVT that represent a slot holding a bool. */ type BooleanSlot is bytes32; /** * @dev Cast an arbitrary slot to a BooleanSlot. */ function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) { return BooleanSlot.wrap(slot); } /** * @dev UDVT that represent a slot holding a bytes32. */ type Bytes32Slot is bytes32; /** * @dev Cast an arbitrary slot to a Bytes32Slot. */ function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) { return Bytes32Slot.wrap(slot); } /** * @dev UDVT that represent a slot holding a uint256. */ type Uint256Slot is bytes32; /** * @dev Cast an arbitrary slot to a Uint256Slot. */ function asUint256(bytes32 slot) internal pure returns (Uint256Slot) { return Uint256Slot.wrap(slot); } /** * @dev UDVT that represent a slot holding a int256. */ type Int256Slot is bytes32; /** * @dev Cast an arbitrary slot to a Int256Slot. */ function asInt256(bytes32 slot) internal pure returns (Int256Slot) { return Int256Slot.wrap(slot); } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(AddressSlot slot) internal view returns (address value) { assembly ("memory-safe") { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(AddressSlot slot, address value) internal { assembly ("memory-safe") { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(BooleanSlot slot) internal view returns (bool value) { assembly ("memory-safe") { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(BooleanSlot slot, bool value) internal { assembly ("memory-safe") { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Bytes32Slot slot) internal view returns (bytes32 value) { assembly ("memory-safe") { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Bytes32Slot slot, bytes32 value) internal { assembly ("memory-safe") { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Uint256Slot slot) internal view returns (uint256 value) { assembly ("memory-safe") { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Uint256Slot slot, uint256 value) internal { assembly ("memory-safe") { tstore(slot, value) } } /** * @dev Load the value held at location `slot` in transient storage. */ function tload(Int256Slot slot) internal view returns (int256 value) { assembly ("memory-safe") { value := tload(slot) } } /** * @dev Store `value` at location `slot` in transient storage. */ function tstore(Int256Slot slot, int256 value) internal { assembly ("memory-safe") { tstore(slot, value) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple single owner authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The caller is not authorized to call the function. error Unauthorized(); /// @dev The `newOwner` cannot be the zero address. error NewOwnerIsZeroAddress(); /// @dev The `pendingOwner` does not have a valid handover request. error NoHandoverRequest(); /// @dev Cannot double-initialize. error AlreadyInitialized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This event is intentionally kept the same as OpenZeppelin's Ownable to be /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173), /// despite it not being as lightweight as a single argument event. event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); /// @dev An ownership handover to `pendingOwner` has been requested. event OwnershipHandoverRequested(address indexed pendingOwner); /// @dev The ownership handover to `pendingOwner` has been canceled. event OwnershipHandoverCanceled(address indexed pendingOwner); /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`. uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE = 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0; /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE = 0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d; /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE = 0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The owner slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`. /// It is intentionally chosen to be a high value /// to avoid collision with lower slots. /// The choice of manual storage layout is to enable compatibility /// with both regular and upgradeable contracts. bytes32 internal constant _OWNER_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927; /// The ownership handover slot of `newOwner` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED)) /// let handoverSlot := keccak256(0x00, 0x20) /// ``` /// It stores the expiry timestamp of the two-step ownership handover. uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return true to make `_initializeOwner` prevent double-initialization. function _guardInitializeOwner() internal pure virtual returns (bool guard) {} /// @dev Initializes the owner directly without authorization guard. /// This function must be called upon initialization, /// regardless of whether the contract is upgradeable or not. /// This is to enable generalization to both regular and upgradeable contracts, /// and to save gas in case the initial owner is not the caller. /// For performance reasons, this function will not check if there /// is an existing owner. function _initializeOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT if sload(ownerSlot) { mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`. revert(0x1c, 0x04) } // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } else { /// @solidity memory-safe-assembly assembly { // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(_OWNER_SLOT, newOwner) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } } /// @dev Sets the owner directly without authorization guard. function _setOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) } } else { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, newOwner) } } } /// @dev Throws if the sender is not the owner. function _checkOwner() internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner, revert. if iszero(eq(caller(), sload(_OWNER_SLOT))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Returns how long a two-step ownership handover is valid for in seconds. /// Override to return a different value if needed. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ownershipHandoverValidFor() internal view virtual returns (uint64) { return 48 * 3600; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to transfer the ownership to `newOwner`. function transferOwnership(address newOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { if iszero(shl(96, newOwner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _setOwner(newOwner); } /// @dev Allows the owner to renounce their ownership. function renounceOwnership() public payable virtual onlyOwner { _setOwner(address(0)); } /// @dev Request a two-step ownership handover to the caller. /// The request will automatically expire in 48 hours (172800 seconds) by default. function requestOwnershipHandover() public payable virtual { unchecked { uint256 expires = block.timestamp + _ownershipHandoverValidFor(); /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to `expires`. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), expires) // Emit the {OwnershipHandoverRequested} event. log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller()) } } } /// @dev Cancels the two-step ownership handover to the caller, if any. function cancelOwnershipHandover() public payable virtual { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), 0) // Emit the {OwnershipHandoverCanceled} event. log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller()) } } /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. /// Reverts if there is no existing ownership handover requested by `pendingOwner`. function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) let handoverSlot := keccak256(0x0c, 0x20) // If the handover does not exist, or has expired. if gt(timestamp(), sload(handoverSlot)) { mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`. revert(0x1c, 0x04) } // Set the handover slot to 0. sstore(handoverSlot, 0) } _setOwner(pendingOwner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the owner of the contract. function owner() public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { result := sload(_OWNER_SLOT) } } /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. function ownershipHandoverExpiresAt(address pendingOwner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the handover slot. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) // Load the handover slot. result := sload(keccak256(0x0c, 0x20)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by the owner. modifier onlyOwner() virtual { _checkOwner(); _; } }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.7.5; /** * Manage deposits and stakes. * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account). * Stake is value locked for at least "unstakeDelay" by the staked entity. */ interface IStakeManager { event Deposited(address indexed account, uint256 totalDeposit); event Withdrawn( address indexed account, address withdrawAddress, uint256 amount ); // Emitted when stake or unstake delay are modified. event StakeLocked( address indexed account, uint256 totalStaked, uint256 unstakeDelaySec ); // Emitted once a stake is scheduled for withdrawal. event StakeUnlocked(address indexed account, uint256 withdrawTime); event StakeWithdrawn( address indexed account, address withdrawAddress, uint256 amount ); /** * @param deposit - The entity's deposit. * @param staked - True if this entity is staked. * @param stake - Actual amount of ether staked for this entity. * @param unstakeDelaySec - Minimum delay to withdraw the stake. * @param withdrawTime - First block timestamp where 'withdrawStake' will be callable, or zero if already locked. * @dev Sizes were chosen so that deposit fits into one cell (used during handleOp) * and the rest fit into a 2nd cell (used during stake/unstake) * - 112 bit allows for 10^15 eth * - 48 bit for full timestamp * - 32 bit allows 150 years for unstake delay */ struct DepositInfo { uint256 deposit; bool staked; uint112 stake; uint32 unstakeDelaySec; uint48 withdrawTime; } // API struct used by getStakeInfo and simulateValidation. struct StakeInfo { uint256 stake; uint256 unstakeDelaySec; } /** * Get deposit info. * @param account - The account to query. * @return info - Full deposit information of given account. */ function getDepositInfo( address account ) external view returns (DepositInfo memory info); /** * Get account balance. * @param account - The account to query. * @return - The deposit (for gas payment) of the account. */ function balanceOf(address account) external view returns (uint256); /** * Add to the deposit of the given account. * @param account - The account to add to. */ function depositTo(address account) external payable; /** * Add to the account's stake - amount and delay * any pending unstake is first cancelled. * @param _unstakeDelaySec - The new lock duration before the deposit can be withdrawn. */ function addStake(uint32 _unstakeDelaySec) external payable; /** * Attempt to unlock the stake. * The value can be withdrawn (using withdrawStake) after the unstake delay. */ function unlockStake() external; /** * Withdraw from the (unlocked) stake. * Must first call unlockStake and wait for the unstakeDelay to pass. * @param withdrawAddress - The address to send withdrawn value. */ function withdrawStake(address payable withdrawAddress) external; /** * Withdraw from the deposit. * @param withdrawAddress - The address to send withdrawn value. * @param withdrawAmount - The amount to withdraw. */ function withdrawTo( address payable withdrawAddress, uint256 withdrawAmount ) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.5; import "./PackedUserOperation.sol"; /** * Aggregated Signatures validator. */ interface IAggregator { /** * Validate aggregated signature. * Revert if the aggregated signature does not match the given list of operations. * @param userOps - Array of UserOperations to validate the signature for. * @param signature - The aggregated signature. */ function validateSignatures( PackedUserOperation[] calldata userOps, bytes calldata signature ) external view; /** * Validate signature of a single userOp. * This method should be called by bundler after EntryPointSimulation.simulateValidation() returns * the aggregator this account uses. * First it validates the signature over the userOp. Then it returns data to be used when creating the handleOps. * @param userOp - The userOperation received from the user. * @return sigForUserOp - The value to put into the signature field of the userOp when calling handleOps. * (usually empty, unless account and aggregator support some kind of "multisig". */ function validateUserOpSignature( PackedUserOperation calldata userOp ) external view returns (bytes memory sigForUserOp); /** * Aggregate multiple signatures into a single value. * This method is called off-chain to calculate the signature to pass with handleOps() * bundler MAY use optimized custom code perform this aggregation. * @param userOps - Array of UserOperations to collect the signatures from. * @return aggregatedSignature - The aggregated signature. */ function aggregateSignatures( PackedUserOperation[] calldata userOps ) external view returns (bytes memory aggregatedSignature); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.5; interface INonceManager { /** * Return the next nonce for this sender. * Within a given key, the nonce values are sequenced (starting with zero, and incremented by one on each userop) * But UserOp with different keys can come with arbitrary order. * * @param sender the account address * @param key the high 192 bit of the nonce * @return nonce a full nonce to pass for next UserOp with this sender. */ function getNonce(address sender, uint192 key) external view returns (uint256 nonce); /** * Manually increment the nonce of the sender. * This method is exposed just for completeness.. * Account does NOT need to call it, neither during validation, nor elsewhere, * as the EntryPoint will update the nonce regardless. * Possible use-case is call it with various keys to "initialize" their nonces to one, so that future * UserOperations will not pay extra for the first transaction with a given key. */ function incrementNonce(uint192 key) external; }
{ "remappings": [ "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/", "@prb/test/=node_modules/@prb/test/", "@nexus/=node_modules/nexus/", "forge-std/=lib/forge-std/src/", "account-abstraction/=node_modules/account-abstraction/contracts/", "@ERC4337/account-abstraction/=node_modules/account-abstraction/", "@modulekit/=node_modules/modulekit/src/", "sentinellist/=node_modules/sentinellist/src/", "solady/=node_modules/solady/src/", "@uniswap/v3-periphery/contracts/=node_modules/@uniswap/v3-periphery/contracts/", "@uniswap/v3-core/contracts/=node_modules/@uniswap/v3-core/contracts/", "@uniswap/swap-router-contracts/contracts/=node_modules/@uniswap/swap-router-contracts/contracts/", "solady/src/=node_modules/solady/src/", "excessively-safe-call/=node_modules/excessively-safe-call/src/", "modulekit/=node_modules/@rhinestone/modulekit/src/", "module-bases/=node_modules/module-bases/src/", "erc7579/=node_modules/erc7579/src/", "kernel/=node_modules/@zerodev/kernel/src/", "@safe-global/=node_modules/@safe-global/", "solarray/=node_modules/solarray/src/", "erc7739Validator/=node_modules/erc7739-validator-base/src/", "@biconomy-devx/=node_modules/@biconomy-devx/", "@erc7579/=node_modules/@erc7579/", "@gnosis.pm/=node_modules/@gnosis.pm/", "@prb/math/=node_modules/erc7739-validator-base/node_modules/@prb/math/src/", "@rhinestone/=node_modules/@rhinestone/", "@zerodev/=node_modules/@zerodev/", "ExcessivelySafeCall/=node_modules/erc7739-validator-base/node_modules/excessively-safe-call/src/", "account-abstraction-v0.6/=node_modules/account-abstraction-v0.6/", "accountabstraction/=node_modules/accountabstraction/", "base64-sol/=node_modules/base64-sol/", "ds-test/=node_modules/ds-test/", "enumerableset4337/=node_modules/erc7739-validator-base/node_modules/@erc7579/enumerablemap4337/src/", "erc4337-validation/=node_modules/erc7739-validator-base/node_modules/@rhinestone/erc4337-validation/src/", "erc7739-validator-base/=node_modules/erc7739-validator-base/", "hardhat-deploy/=node_modules/hardhat-deploy/", "hardhat/=node_modules/hardhat/", "nexus/=node_modules/nexus/", "registry/=node_modules/modulekit/node_modules/@rhinestone/registry/src/", "safe7579/=node_modules/erc7739-validator-base/node_modules/@rhinestone/safe7579/src/" ], "optimizer": { "enabled": true, "runs": 800 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "none", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"contract IEntryPoint","name":"entryPointArg","type":"address"},{"internalType":"address","name":"verifyingSignerArg","type":"address"},{"internalType":"address","name":"feeCollectorArg","type":"address"},{"internalType":"uint256","name":"unaccountedGasArg","type":"uint256"},{"internalType":"uint256","name":"paymasterIdWithdrawalDelayArg","type":"uint256"},{"internalType":"uint256","name":"minDepositArg","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"CanNotWithdrawToZeroAddress","type":"error"},{"inputs":[],"name":"CanNotWithdrawZeroAmount","type":"error"},{"inputs":[],"name":"DepositCanNotBeZero","type":"error"},{"inputs":[],"name":"FeeCollectorCanNotBeContract","type":"error"},{"inputs":[],"name":"FeeCollectorCanNotBeZero","type":"error"},{"inputs":[],"name":"InsufficientFunds","type":"error"},{"inputs":[],"name":"InsufficientFundsForPaymasterId","type":"error"},{"inputs":[],"name":"InsufficientFundsInGasTank","type":"error"},{"inputs":[],"name":"InvalidArrayLengths","type":"error"},{"inputs":[],"name":"InvalidPriceMarkup","type":"error"},{"inputs":[],"name":"InvalidSignatureLength","type":"error"},{"inputs":[],"name":"LowDeposit","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NoRequestSubmitted","type":"error"},{"inputs":[],"name":"PaymasterIdCanNotBeZero","type":"error"},{"inputs":[],"name":"PostOpGasLimitTooLow","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"clearanceTime","type":"uint256"}],"name":"RequestNotClearedYet","type":"error"},{"inputs":[],"name":"SubmitRequestInstead","type":"error"},{"inputs":[],"name":"UnaccountedGasTooHigh","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"UseDepositForInstead","type":"error"},{"inputs":[],"name":"VerifyingSignerCanNotBeContract","type":"error"},{"inputs":[],"name":"VerifyingSignerCanNotBeZero","type":"error"},{"inputs":[],"name":"WithdrawalFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"EthWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldFeeCollector","type":"address"},{"indexed":true,"internalType":"address","name":"newFeeCollector","type":"address"},{"indexed":true,"internalType":"address","name":"actor","type":"address"}],"name":"FeeCollectorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldValue","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"FixedPriceMarkupChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_paymasterId","type":"address"},{"indexed":true,"internalType":"uint256","name":"_charge","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_premium","type":"uint256"}],"name":"GasBalanceDeducted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_paymasterId","type":"address"},{"indexed":true,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"GasDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_paymasterId","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"GasWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldValue","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"MinDepositChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"actor","type":"address"}],"name":"TokensWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"paymasterId","type":"address"},{"indexed":false,"internalType":"bool","name":"isTrusted","type":"bool"}],"name":"TrustedPaymasterIdSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldValue","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"UnaccountedGasChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldSigner","type":"address"},{"indexed":true,"internalType":"address","name":"newSigner","type":"address"},{"indexed":true,"internalType":"address","name":"actor","type":"address"}],"name":"VerifyingSignerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"paymasterId","type":"address"}],"name":"WithdrawalRequestCancelledFor","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"withdrawAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawalRequestSubmitted","type":"event"},{"inputs":[{"internalType":"uint32","name":"unstakeDelaySec","type":"uint32"}],"name":"addStake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelWithdrawalRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"paymasterId","type":"address"}],"name":"depositFor","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"entryPoint","outputs":[{"internalType":"contract IEntryPoint","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymasterId","type":"address"}],"name":"executeWithdrawalRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymasterId","type":"address"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"initCode","type":"bytes"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"bytes32","name":"accountGasLimits","type":"bytes32"},{"internalType":"uint256","name":"preVerificationGas","type":"uint256"},{"internalType":"bytes32","name":"gasFees","type":"bytes32"},{"internalType":"bytes","name":"paymasterAndData","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct PackedUserOperation","name":"userOp","type":"tuple"},{"internalType":"address","name":"paymasterId","type":"address"},{"internalType":"uint48","name":"validUntil","type":"uint48"},{"internalType":"uint48","name":"validAfter","type":"uint48"},{"internalType":"uint32","name":"priceMarkup","type":"uint32"}],"name":"getHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"paymasterAndData","type":"bytes"}],"name":"parsePaymasterAndData","outputs":[{"internalType":"address","name":"paymasterId","type":"address"},{"internalType":"uint48","name":"validUntil","type":"uint48"},{"internalType":"uint48","name":"validAfter","type":"uint48"},{"internalType":"uint32","name":"priceMarkup","type":"uint32"},{"internalType":"uint128","name":"paymasterValidationGasLimit","type":"uint128"},{"internalType":"uint128","name":"paymasterPostOpGasLimit","type":"uint128"},{"internalType":"bytes","name":"signature","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"paymasterIdBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymasterIdWithdrawalDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum IPaymaster.PostOpMode","name":"mode","type":"uint8"},{"internalType":"bytes","name":"context","type":"bytes"},{"internalType":"uint256","name":"actualGasCost","type":"uint256"},{"internalType":"uint256","name":"actualUserOpFeePerGas","type":"uint256"}],"name":"postOp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"paymasterIds","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"refundBalances","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeCollector","type":"address"}],"name":"setFeeCollector","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMinDeposit","type":"uint256"}],"name":"setMinDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newVerifyingSigner","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"paymasterId","type":"address"},{"internalType":"bool","name":"isTrusted","type":"bool"}],"name":"setTrustedPaymasterId","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"setUnaccountedGas","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"withdrawAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"submitWithdrawalRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unaccountedGas","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unlockStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"initCode","type":"bytes"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"bytes32","name":"accountGasLimits","type":"bytes32"},{"internalType":"uint256","name":"preVerificationGas","type":"uint256"},{"internalType":"bytes32","name":"gasFees","type":"bytes32"},{"internalType":"bytes","name":"paymasterAndData","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct PackedUserOperation","name":"userOp","type":"tuple"},{"internalType":"bytes32","name":"userOpHash","type":"bytes32"},{"internalType":"uint256","name":"maxCost","type":"uint256"}],"name":"validatePaymasterUserOp","outputs":[{"internalType":"bytes","name":"context","type":"bytes"},{"internalType":"uint256","name":"validationData","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"verifyingSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawEth","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address payable","name":"withdrawAddress","type":"address"}],"name":"withdrawStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"withdrawAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60a0604052346100b55760e0611f96803803809161001c826100b9565b60a039126100b55761006c60a05161003381610116565b60c05161003f81610116565b60e05161004b81610116565b6101005161005881610116565b610120519161014051936101605195610127565b604051611c6690816103308239608051818181610528015281816105d90152818161066e015281816106dd0152818161079301528181611161015281816113f7015261187a0152f35b5f80fd5b60a0601f91909101601f19168101906001600160401b038211908210176100df57604052565b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b038211908210176100df57604052565b6001600160a01b038116036100b557565b95949291959390938060601b15610240576001600160a01b0316638b78c6d8198190555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a36040516301ffc9a760e01b815263122a0e9b60e31b6004820152916020836024816001600160a01b0389165afa90811561023557610204976101ff966101c36101f5946101fa975f91610206575b506102e3565b6080526101d184838361024d565b5f55600180546001600160a01b0319166001600160a01b0392909216919091179055565b600255565b600355565b600455565b565b610228915060203d60201161022e575b61022081836100f3565b8101906102cb565b5f6101bd565b503d610216565b6040513d5f823e3d90fd5b637448fbae5f526004601cfd5b6001600160a01b03811661026a576381618de160e01b5f5260045ffd5b3b1561027f5763edc30c2760e01b5f5260045ffd5b6001600160a01b03811661029c57633fd0943d60e11b5f5260045ffd5b3b156102b157631f47525f60e21b5f5260045ffd5b620186a0106102bc57565b63313db2a560e11b5f5260045ffd5b908160209103126100b5575180151581036100b55790565b156102ea57565b60405162461bcd60e51b815260206004820152601e60248201527f49456e747279506f696e7420696e74657266616365206d69736d6174636800006044820152606490fdfe60806040526004361015610046575b3615610018575f80fd5b6040513481527f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f8852587460203392a2005b5f5f3560e01c80630396cb60146113c75780631b9a91a414611302578063205c2878146112d857806323d9ac9b146112b257806325692962146112675780633261fd581461107557806341b3d1851461105757806344004cc114610f5057806352b7512c14610ecb57806354d1f13d14610e8557806359ffb13014610d845780636c19e78314610cfc578063715018a614610cb157806373acf54214610c525780637c627b2114610b005780638c253a3914610a4c5780638da5cb5b14610a215780638fcc9cfb146109db57806394d4ad6014610917578063a40a7ddc146102ef578063a42dce8014610874578063aa67c9191461071f578063ab94cad714610701578063b0d691fe146106bd578063bb9fe6bf1461064a578063c23a5cea146105ac578063c399ec88146104fc578063c415b95c146104d5578063d0e30db0146104ba578063def042571461042a578063e714a028146103d2578063f04e283e14610384578063f0c12a3214610366578063f2fde38b14610327578063f8b2cb4f146102ef578063f8cf826d1461021d5763fee81cf4146101e8575061000e565b3461021a57602036600319011261021a57610201611467565b9063389a75e1600c5252602080600c2054604051908152f35b80fd5b50604036600319011261021a5760043567ffffffffffffffff81116102eb5761024a9036906004016114c1565b9060243567ffffffffffffffff81116102e75761026b9036906004016114c1565b906102746117d3565b8184036102d857845b848110610288578580f35b6102938184846117af565b35906102a08187876117af565b35916001600160a01b0383168093036102d457600192885260056020526102cc60408920918254611560565b90550161027d565b8780fd5b63a9854bc960e01b8552600485fd5b8380fd5b5080fd5b503461021a57602036600319011261021a5760406020916001600160a01b03610316611467565b168152600583522054604051908152f35b50602036600319011261021a5761033c611467565b6103446117d3565b8060601b156103595761035690611c1b565b80f35b637448fbae82526004601cfd5b503461021a578060031936011261021a576020600354604051908152f35b50602036600319011261021a57610399611467565b6103a16117d3565b63389a75e1600c528082526020600c20805442116103c55790826103569255611c1b565b636f5e881883526004601cfd5b503461021a578060031936011261021a5733815260076020525f60026040832082815582600182015501557fe227a0e51918df92c3a9837808b4825847fa7c14cbacd937b650c337e91712416020604051338152a180f35b503461021a5760a036600319011261021a5760043567ffffffffffffffff81116102eb5761012060031982360301126102eb5761046561147d565b6044359065ffffffffffff821682036102e7576064359265ffffffffffff841684036104b6576084359463ffffffff8616860361021a5760206104ae87878787876004016116b3565b604051908152f35b8480fd5b508060031936011261021a5763302076c960e01b8152600490fd5b503461021a578060031936011261021a5760206001600160a01b0360015416604051908152f35b503461021a578060031936011261021a576040516370a0823160e01b81523060048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156105a157829161056b575b602082604051908152f35b90506020813d602011610599575b8161058660209383611522565b810103126102eb5760209150515f610560565b3d9150610579565b6040513d84823e3d90fd5b503461021a57602036600319011261021a57806105c7611467565b6105cf6117d3565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690813b15610646576001600160a01b036024849283604051958694859363611d2e7560e11b85521660048401525af180156105a1576106355750f35b8161063f91611522565b61021a5780f35b5050fd5b503461021a578060031936011261021a576106636117d3565b806001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b156106ba5781809160046040518094819363bb9fe6bf60e01b83525af180156105a1576106355750f35b50fd5b503461021a578060031936011261021a5760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b503461021a578060031936011261021a576020600254604051908152f35b50602036600319011261021a576001600160a01b0361073c611467565b6107446117ef565b168015610865573415610856578082526005602052610767346040842054611560565b6004541161084757808252600560205260408220610786348254611560565b9055816001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b156102eb57816024916040519283809263b760faf960e01b825230600483015234905af180156105a157610832575b505034907f1dbbf474736d6415d6a265fabee708fe6e988f6fd0c9d870ded36cab380898dd8380a3807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b8161083c91611522565b6102eb57815f6107e4565b6305d163b560e11b8252600482fd5b6333a6177160e11b8252600482fd5b63016e7bd760e61b8252600482fd5b50602036600319011261021a57610889611467565b6108916117d3565b803b610908576001600160a01b031680156108f957600154908073ffffffffffffffffffffffffffffffffffffffff198316176001556001600160a01b033392167fc6bc29e495f43077b898bfa29b8be68f4c836ccf780f9f7782f916dfd3874f158480a480f35b633fd0943d60e11b8252600482fd5b631f47525f60e21b8252600482fd5b503461021a57602036600319011261021a5760043567ffffffffffffffff81116102eb57610949903690600401611493565b610952916115c4565b959794938694604094929451996001600160a01b038b9a168a5265ffffffffffff1660208a015265ffffffffffff16604089015263ffffffff1660608801526001600160801b031660808701526001600160801b031660a086015260c0850160e090528160e08601526101008501378183016101000152601f1990601f01168101036101000190f35b50602036600319011261021a576004356109f36117d3565b806004547fcacd94bd1e7bb1185c816a740d9439bc8eff8159f6f4ffad8d306b5aca2ebd928480a360045580f35b503461021a578060031936011261021a576020638b78c6d819546001600160a01b0360405191168152f35b50604036600319011261021a57610a61611467565b60243590811515809203610afc576001600160a01b0390610a806117d3565b16908115610aed5781835260066020528060ff604085205416151503610aa4578280f35b60207fd20b41feac4c77c85eaf676a2d91056dc1b6ba4cc02253745a3152ca4f23d87991838552600682526040852060ff1981541660ff8316179055604051908152a25f808280f35b63016e7bd760e61b8352600483fd5b8280fd5b503461021a57608036600319011261021a576003600435101561021a5760243567ffffffffffffffff81116102eb57610b3f6060913690600401611493565b90809291610b4b611870565b810103126102eb578035906001600160a01b038216809203610afc5760208101359063ffffffff82168092036102e7576040013591610bb2620f4240610baa610ba3610b9b6064356002546118e7565b604435611560565b94856118e7565b049283611581565b926001600160a01b03600154168552600560205260408520610bd5858254611560565b90558280821115610c2a57610be991611581565b8185526005602052610c0060408620918254611560565b90555b7f683b3fc4c8726e960b5b0aa3838c1071e2a9b7045fcd4dfc953fc1092923f5378480a480f35b90610c3491611581565b8185526005602052610c4b60408620918254611581565b9055610c03565b50602036600319011261021a57600435610c6a6117d3565b620186a08111610ca257600254816002557f33ddf610723ec48e858790576fb3294cc312fcbd937c1475d53e3673145488eb8380a380f35b63313db2a560e11b8252600482fd5b508060031936011261021a57610cc56117d3565b80638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380638b78c6d8195580f35b50602036600319011261021a57610d11611467565b610d196117d3565b803b610d75576001600160a01b0381168015610d66576001600160a01b0383541691835533917fe1f62c0e6d7bb6d470828565415bf2e87dbfea50e52d2d753788b529bd0c6d628480a480f35b6381618de160e01b8352600483fd5b63edc30c2760e01b8252600482fd5b503461021a57604036600319011261021a57610d9e611467565b6001600160a01b03166024358115610e76578015610e6757338352600560205260408320548111610e58577fe1a007fa1edbdbd989490b46b37c8a7342e8f2f1162a20078a80a9528ab0a149916040918251610df9816114f2565b818152600260208201848152858301904282523389526007602052868920935184556001600160a01b036001850191511673ffffffffffffffffffffffffffffffffffffffff198254161790555191015582519182526020820152a180f35b6345f34ee560e01b8352600483fd5b6339d3420560e11b8352600483fd5b6392bc9df360e01b8352600483fd5b508060031936011261021a5763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b503461021a57606036600319011261021a5760043567ffffffffffffffff81116102eb5761012060031982360301126102eb576020610f1a606092610f0e611870565b604435906004016118fa565b604092919251948593604085528051938491826040880152018686015e8383018501526020830152601f01601f19168101030190f35b503461021a57606036600319011261021a576004356001600160a01b0381168091036102eb57610f7e61147d565b60443591610f8a6117d3565b610f926117ef565b6001600160a01b03821691821561104857601452826034526fa9059cbb00000000000000000000000084526020846044601082855af1806001865114161561102a575b50836034527f4e5ba90310f16273bb12f3c33f23905e573b86df58a2895a525285d083bf043f6020604051338152a4807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b3d823b1517101561103b575f610fd5565b6390b8ec1884526004601cfd5b6392bc9df360e01b8552600485fd5b503461021a578060031936011261021a576020600454604051908152f35b503461021a57602036600319011261021a5761108f611467565b6110976117ef565b6001600160a01b03811690818352600760205260408320604051916110bb836114f2565b8154835260026001600160a01b036001840154169260208501938452015460408401908082521561125857516110fa916110f49061184a565b90611560565b8042106112465750828452600560205260408420548251818111156112415750805b8084521561123257825161112f91611581565b8385526005602052604085205582845260076020525f6002604086208281558260018201550155836001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166001600160a01b038351168451823b156102e7576044849283604051958694859363040b850f60e31b8552600485015260248401525af180156105a15761121d575b50506001600160a01b039051169051917f926a144b6fffc1d73f115b81af7ec66a7c12aed0ff73197c39a683753fc1d9258480a4807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b8161122791611522565b6102e757835f6111c3565b6339d3420560e11b8552600485fd5b61111c565b63fb817d3d60e01b8552600452602484fd5b6336fbdb4f60e01b8652600486fd5b508060031936011261021a5763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b503461021a578060031936011261021a576001600160a01b036020915416604051908152f35b503461021a57604036600319011261021a576004906112f5611467565b5063ad42eb9960e01b8152fd5b50604036600319011261021a57611317611467565b6001600160a01b036024359161132b6117d3565b6113336117ef565b168280808085855af13d156113c2573d61134c81611544565b9061135a6040519283611522565b81528460203d92013e5b156113b3577f8455ae6be5d92f1df1c3c1484388e247a36c7e60d72055ae216dbc258f257d4b8380a3807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b6327fcd9d160e01b8352600483fd5b611364565b5060203660031901126114635760043563ffffffff8116809103611463576113ed6117d3565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690813b15611463575f90602460405180948193621cb65b60e51b8352600483015234905af180156114585761144a575080f35b61145691505f90611522565b005b6040513d5f823e3d90fd5b5f80fd5b600435906001600160a01b038216820361146357565b602435906001600160a01b038216820361146357565b9181601f840112156114635782359167ffffffffffffffff8311611463576020838186019501011161146357565b9181601f840112156114635782359167ffffffffffffffff8311611463576020808501948460051b01011161146357565b6060810190811067ffffffffffffffff82111761150e57604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff82111761150e57604052565b67ffffffffffffffff811161150e57601f01601f191660200190565b9190820180921161156d57565b634e487b7160e01b5f52601160045260245ffd5b9190820391821161156d57565b919091356001600160d01b0319811692600681106115aa575050565b6001600160d01b0319929350829060060360031b1b161690565b9190918260481161146357603481013560601c9280604e11611463576115ee60066048840161158e565b60d01c9281605411611463576116086006604e850161158e565b60d01c928260581161146357605481013560e01c926024811061146357601482013560801c926034821061146357602483013560801c92605801916057190190565b903590601e1981360301821215611463570180359067ffffffffffffffff82116114635760200191813603831361146357565b92919261168982611544565b916116976040519384611522565b829481845281830111611463578281602093845f960137010152565b929093916116ce6116c7604086018661164a565b369161167d565b60208151910120946116e66116c7606087018761164a565b60208151910120946116fb60e082018261164a565b6034116114635760405196602088019883356001600160a01b03168a52602084013560408a015260608901526080880152608082013560a08801526014013560c087015260a081013560e087015260c0013561010086015246610120860152306101408601526001600160a01b031661016085015265ffffffffffff1661018084015265ffffffffffff166101a083015263ffffffff166101c08201526101c081526117a96101e082611522565b51902090565b91908110156117bf5760051b0190565b634e487b7160e01b5f52603260045260245ffd5b638b78c6d8195433036117e257565b6382b429005f526004601cfd5b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c61183b5760017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d565b633ee5aeb560e01b5f5260045ffd5b6001600160a01b03165f52600660205260ff60405f20541661186c5760035490565b5f90565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633036118a257565b60405162461bcd60e51b815260206004820152601560248201527f53656e646572206e6f7420456e747279506f696e7400000000000000000000006044820152606490fd5b8181029291811591840414171561156d57565b919060609260e0810190611917611911838361164a565b906115c4565b60409198969a95979c9350809250141580611c10575b611c01576002549661193f898761164a565b603411611463576024013560801c8811611bf2576119949061196585898f8e908b6116b3565b6020527b19457468657265756d205369676e6564204d6573736167653a0a33325f52603c60042092369161167d565b915f92604051926020820191805180604014611bb457604114611b7e5750505050505b6001600160a01b03805f54169116145f14611b785760015b15611b385763ffffffff1694621e848086118015611b2c575b611b1d576119f6908361164a565b6034116114635760246001600160801b0391013560801c166001600160801b03608084013516016001600160801b03811161156d576001600160801b03600a911602916001600160801b03831692830361156d57611a7b611a80926110f4620f4240956064611a746001600160801b0360c08d9801351680936118e7565b04986118e7565b6118e7565b046001600160a01b03611a938483611560565b971696875f52600560205260405f205410611b0e5765ffffffffffff60a01b93611ac66001600160d01b03199483611560565b885f526005602052611add60405f20918254611581565b90556040519760208901526040880152606087015260608652611b01608087611522565b60d01b169160a01b161790565b632771c53960e01b5f5260045ffd5b630a02dbf760e21b5f5260045ffd5b50620f424086106119e8565b505050600194955065ffffffffffff60a01b92506001600160d01b0319915060d01b169160a01b16171790604051611b71602082611522565b5f81529190565b5f6119cf565b808401515f1a60205260400151835292935090915b5f52516040526020604060805f60015afa505f81523d1851906040526119b7565b507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91929394955060400151601b8160ff1c01602052168352611b93565b630359a00f60e01b5f5260045ffd5b634be6321b60e01b5f5260045ffd5b50604181141561192d565b6001600160a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d8195556fea164736f6c634300081b000a000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc70000000000000000000000000000000071727de22e5e9d8baf0edac6f37da032000000000000000000000000c6dab8652e5e9749523ba948f42d5944584e4e73000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc7000000000000000000000000000000000000000000000000000000000000c3500000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000de0b6b3a7640000
Deployed Bytecode
0x60806040526004361015610046575b3615610018575f80fd5b6040513481527f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f8852587460203392a2005b5f5f3560e01c80630396cb60146113c75780631b9a91a414611302578063205c2878146112d857806323d9ac9b146112b257806325692962146112675780633261fd581461107557806341b3d1851461105757806344004cc114610f5057806352b7512c14610ecb57806354d1f13d14610e8557806359ffb13014610d845780636c19e78314610cfc578063715018a614610cb157806373acf54214610c525780637c627b2114610b005780638c253a3914610a4c5780638da5cb5b14610a215780638fcc9cfb146109db57806394d4ad6014610917578063a40a7ddc146102ef578063a42dce8014610874578063aa67c9191461071f578063ab94cad714610701578063b0d691fe146106bd578063bb9fe6bf1461064a578063c23a5cea146105ac578063c399ec88146104fc578063c415b95c146104d5578063d0e30db0146104ba578063def042571461042a578063e714a028146103d2578063f04e283e14610384578063f0c12a3214610366578063f2fde38b14610327578063f8b2cb4f146102ef578063f8cf826d1461021d5763fee81cf4146101e8575061000e565b3461021a57602036600319011261021a57610201611467565b9063389a75e1600c5252602080600c2054604051908152f35b80fd5b50604036600319011261021a5760043567ffffffffffffffff81116102eb5761024a9036906004016114c1565b9060243567ffffffffffffffff81116102e75761026b9036906004016114c1565b906102746117d3565b8184036102d857845b848110610288578580f35b6102938184846117af565b35906102a08187876117af565b35916001600160a01b0383168093036102d457600192885260056020526102cc60408920918254611560565b90550161027d565b8780fd5b63a9854bc960e01b8552600485fd5b8380fd5b5080fd5b503461021a57602036600319011261021a5760406020916001600160a01b03610316611467565b168152600583522054604051908152f35b50602036600319011261021a5761033c611467565b6103446117d3565b8060601b156103595761035690611c1b565b80f35b637448fbae82526004601cfd5b503461021a578060031936011261021a576020600354604051908152f35b50602036600319011261021a57610399611467565b6103a16117d3565b63389a75e1600c528082526020600c20805442116103c55790826103569255611c1b565b636f5e881883526004601cfd5b503461021a578060031936011261021a5733815260076020525f60026040832082815582600182015501557fe227a0e51918df92c3a9837808b4825847fa7c14cbacd937b650c337e91712416020604051338152a180f35b503461021a5760a036600319011261021a5760043567ffffffffffffffff81116102eb5761012060031982360301126102eb5761046561147d565b6044359065ffffffffffff821682036102e7576064359265ffffffffffff841684036104b6576084359463ffffffff8616860361021a5760206104ae87878787876004016116b3565b604051908152f35b8480fd5b508060031936011261021a5763302076c960e01b8152600490fd5b503461021a578060031936011261021a5760206001600160a01b0360015416604051908152f35b503461021a578060031936011261021a576040516370a0823160e01b81523060048201526020816024817f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0326001600160a01b03165afa9081156105a157829161056b575b602082604051908152f35b90506020813d602011610599575b8161058660209383611522565b810103126102eb5760209150515f610560565b3d9150610579565b6040513d84823e3d90fd5b503461021a57602036600319011261021a57806105c7611467565b6105cf6117d3565b6001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0321690813b15610646576001600160a01b036024849283604051958694859363611d2e7560e11b85521660048401525af180156105a1576106355750f35b8161063f91611522565b61021a5780f35b5050fd5b503461021a578060031936011261021a576106636117d3565b806001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da03216803b156106ba5781809160046040518094819363bb9fe6bf60e01b83525af180156105a1576106355750f35b50fd5b503461021a578060031936011261021a5760206040516001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da032168152f35b503461021a578060031936011261021a576020600254604051908152f35b50602036600319011261021a576001600160a01b0361073c611467565b6107446117ef565b168015610865573415610856578082526005602052610767346040842054611560565b6004541161084757808252600560205260408220610786348254611560565b9055816001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da03216803b156102eb57816024916040519283809263b760faf960e01b825230600483015234905af180156105a157610832575b505034907f1dbbf474736d6415d6a265fabee708fe6e988f6fd0c9d870ded36cab380898dd8380a3807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b8161083c91611522565b6102eb57815f6107e4565b6305d163b560e11b8252600482fd5b6333a6177160e11b8252600482fd5b63016e7bd760e61b8252600482fd5b50602036600319011261021a57610889611467565b6108916117d3565b803b610908576001600160a01b031680156108f957600154908073ffffffffffffffffffffffffffffffffffffffff198316176001556001600160a01b033392167fc6bc29e495f43077b898bfa29b8be68f4c836ccf780f9f7782f916dfd3874f158480a480f35b633fd0943d60e11b8252600482fd5b631f47525f60e21b8252600482fd5b503461021a57602036600319011261021a5760043567ffffffffffffffff81116102eb57610949903690600401611493565b610952916115c4565b959794938694604094929451996001600160a01b038b9a168a5265ffffffffffff1660208a015265ffffffffffff16604089015263ffffffff1660608801526001600160801b031660808701526001600160801b031660a086015260c0850160e090528160e08601526101008501378183016101000152601f1990601f01168101036101000190f35b50602036600319011261021a576004356109f36117d3565b806004547fcacd94bd1e7bb1185c816a740d9439bc8eff8159f6f4ffad8d306b5aca2ebd928480a360045580f35b503461021a578060031936011261021a576020638b78c6d819546001600160a01b0360405191168152f35b50604036600319011261021a57610a61611467565b60243590811515809203610afc576001600160a01b0390610a806117d3565b16908115610aed5781835260066020528060ff604085205416151503610aa4578280f35b60207fd20b41feac4c77c85eaf676a2d91056dc1b6ba4cc02253745a3152ca4f23d87991838552600682526040852060ff1981541660ff8316179055604051908152a25f808280f35b63016e7bd760e61b8352600483fd5b8280fd5b503461021a57608036600319011261021a576003600435101561021a5760243567ffffffffffffffff81116102eb57610b3f6060913690600401611493565b90809291610b4b611870565b810103126102eb578035906001600160a01b038216809203610afc5760208101359063ffffffff82168092036102e7576040013591610bb2620f4240610baa610ba3610b9b6064356002546118e7565b604435611560565b94856118e7565b049283611581565b926001600160a01b03600154168552600560205260408520610bd5858254611560565b90558280821115610c2a57610be991611581565b8185526005602052610c0060408620918254611560565b90555b7f683b3fc4c8726e960b5b0aa3838c1071e2a9b7045fcd4dfc953fc1092923f5378480a480f35b90610c3491611581565b8185526005602052610c4b60408620918254611581565b9055610c03565b50602036600319011261021a57600435610c6a6117d3565b620186a08111610ca257600254816002557f33ddf610723ec48e858790576fb3294cc312fcbd937c1475d53e3673145488eb8380a380f35b63313db2a560e11b8252600482fd5b508060031936011261021a57610cc56117d3565b80638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380638b78c6d8195580f35b50602036600319011261021a57610d11611467565b610d196117d3565b803b610d75576001600160a01b0381168015610d66576001600160a01b0383541691835533917fe1f62c0e6d7bb6d470828565415bf2e87dbfea50e52d2d753788b529bd0c6d628480a480f35b6381618de160e01b8352600483fd5b63edc30c2760e01b8252600482fd5b503461021a57604036600319011261021a57610d9e611467565b6001600160a01b03166024358115610e76578015610e6757338352600560205260408320548111610e58577fe1a007fa1edbdbd989490b46b37c8a7342e8f2f1162a20078a80a9528ab0a149916040918251610df9816114f2565b818152600260208201848152858301904282523389526007602052868920935184556001600160a01b036001850191511673ffffffffffffffffffffffffffffffffffffffff198254161790555191015582519182526020820152a180f35b6345f34ee560e01b8352600483fd5b6339d3420560e11b8352600483fd5b6392bc9df360e01b8352600483fd5b508060031936011261021a5763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b503461021a57606036600319011261021a5760043567ffffffffffffffff81116102eb5761012060031982360301126102eb576020610f1a606092610f0e611870565b604435906004016118fa565b604092919251948593604085528051938491826040880152018686015e8383018501526020830152601f01601f19168101030190f35b503461021a57606036600319011261021a576004356001600160a01b0381168091036102eb57610f7e61147d565b60443591610f8a6117d3565b610f926117ef565b6001600160a01b03821691821561104857601452826034526fa9059cbb00000000000000000000000084526020846044601082855af1806001865114161561102a575b50836034527f4e5ba90310f16273bb12f3c33f23905e573b86df58a2895a525285d083bf043f6020604051338152a4807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b3d823b1517101561103b575f610fd5565b6390b8ec1884526004601cfd5b6392bc9df360e01b8552600485fd5b503461021a578060031936011261021a576020600454604051908152f35b503461021a57602036600319011261021a5761108f611467565b6110976117ef565b6001600160a01b03811690818352600760205260408320604051916110bb836114f2565b8154835260026001600160a01b036001840154169260208501938452015460408401908082521561125857516110fa916110f49061184a565b90611560565b8042106112465750828452600560205260408420548251818111156112415750805b8084521561123257825161112f91611581565b8385526005602052604085205582845260076020525f6002604086208281558260018201550155836001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da032166001600160a01b038351168451823b156102e7576044849283604051958694859363040b850f60e31b8552600485015260248401525af180156105a15761121d575b50506001600160a01b039051169051917f926a144b6fffc1d73f115b81af7ec66a7c12aed0ff73197c39a683753fc1d9258480a4807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b8161122791611522565b6102e757835f6111c3565b6339d3420560e11b8552600485fd5b61111c565b63fb817d3d60e01b8552600452602484fd5b6336fbdb4f60e01b8652600486fd5b508060031936011261021a5763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b503461021a578060031936011261021a576001600160a01b036020915416604051908152f35b503461021a57604036600319011261021a576004906112f5611467565b5063ad42eb9960e01b8152fd5b50604036600319011261021a57611317611467565b6001600160a01b036024359161132b6117d3565b6113336117ef565b168280808085855af13d156113c2573d61134c81611544565b9061135a6040519283611522565b81528460203d92013e5b156113b3577f8455ae6be5d92f1df1c3c1484388e247a36c7e60d72055ae216dbc258f257d4b8380a3807f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d80f35b6327fcd9d160e01b8352600483fd5b611364565b5060203660031901126114635760043563ffffffff8116809103611463576113ed6117d3565b6001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0321690813b15611463575f90602460405180948193621cb65b60e51b8352600483015234905af180156114585761144a575080f35b61145691505f90611522565b005b6040513d5f823e3d90fd5b5f80fd5b600435906001600160a01b038216820361146357565b602435906001600160a01b038216820361146357565b9181601f840112156114635782359167ffffffffffffffff8311611463576020838186019501011161146357565b9181601f840112156114635782359167ffffffffffffffff8311611463576020808501948460051b01011161146357565b6060810190811067ffffffffffffffff82111761150e57604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff82111761150e57604052565b67ffffffffffffffff811161150e57601f01601f191660200190565b9190820180921161156d57565b634e487b7160e01b5f52601160045260245ffd5b9190820391821161156d57565b919091356001600160d01b0319811692600681106115aa575050565b6001600160d01b0319929350829060060360031b1b161690565b9190918260481161146357603481013560601c9280604e11611463576115ee60066048840161158e565b60d01c9281605411611463576116086006604e850161158e565b60d01c928260581161146357605481013560e01c926024811061146357601482013560801c926034821061146357602483013560801c92605801916057190190565b903590601e1981360301821215611463570180359067ffffffffffffffff82116114635760200191813603831361146357565b92919261168982611544565b916116976040519384611522565b829481845281830111611463578281602093845f960137010152565b929093916116ce6116c7604086018661164a565b369161167d565b60208151910120946116e66116c7606087018761164a565b60208151910120946116fb60e082018261164a565b6034116114635760405196602088019883356001600160a01b03168a52602084013560408a015260608901526080880152608082013560a08801526014013560c087015260a081013560e087015260c0013561010086015246610120860152306101408601526001600160a01b031661016085015265ffffffffffff1661018084015265ffffffffffff166101a083015263ffffffff166101c08201526101c081526117a96101e082611522565b51902090565b91908110156117bf5760051b0190565b634e487b7160e01b5f52603260045260245ffd5b638b78c6d8195433036117e257565b6382b429005f526004601cfd5b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c61183b5760017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d565b633ee5aeb560e01b5f5260045ffd5b6001600160a01b03165f52600660205260ff60405f20541661186c5760035490565b5f90565b6001600160a01b037f0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da0321633036118a257565b60405162461bcd60e51b815260206004820152601560248201527f53656e646572206e6f7420456e747279506f696e7400000000000000000000006044820152606490fd5b8181029291811591840414171561156d57565b919060609260e0810190611917611911838361164a565b906115c4565b60409198969a95979c9350809250141580611c10575b611c01576002549661193f898761164a565b603411611463576024013560801c8811611bf2576119949061196585898f8e908b6116b3565b6020527b19457468657265756d205369676e6564204d6573736167653a0a33325f52603c60042092369161167d565b915f92604051926020820191805180604014611bb457604114611b7e5750505050505b6001600160a01b03805f54169116145f14611b785760015b15611b385763ffffffff1694621e848086118015611b2c575b611b1d576119f6908361164a565b6034116114635760246001600160801b0391013560801c166001600160801b03608084013516016001600160801b03811161156d576001600160801b03600a911602916001600160801b03831692830361156d57611a7b611a80926110f4620f4240956064611a746001600160801b0360c08d9801351680936118e7565b04986118e7565b6118e7565b046001600160a01b03611a938483611560565b971696875f52600560205260405f205410611b0e5765ffffffffffff60a01b93611ac66001600160d01b03199483611560565b885f526005602052611add60405f20918254611581565b90556040519760208901526040880152606087015260608652611b01608087611522565b60d01b169160a01b161790565b632771c53960e01b5f5260045ffd5b630a02dbf760e21b5f5260045ffd5b50620f424086106119e8565b505050600194955065ffffffffffff60a01b92506001600160d01b0319915060d01b169160a01b16171790604051611b71602082611522565b5f81529190565b5f6119cf565b808401515f1a60205260400151835292935090915b5f52516040526020604060805f60015afa505f81523d1851906040526119b7565b507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91929394955060400151601b8160ff1c01602052168352611b93565b630359a00f60e01b5f5260045ffd5b634be6321b60e01b5f5260045ffd5b50604181141561192d565b6001600160a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d8195556fea164736f6c634300081b000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc70000000000000000000000000000000071727de22e5e9d8baf0edac6f37da032000000000000000000000000c6dab8652e5e9749523ba948f42d5944584e4e73000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc7000000000000000000000000000000000000000000000000000000000000c3500000000000000000000000000000000000000000000000000000000000000e100000000000000000000000000000000000000000000000000de0b6b3a7640000
-----Decoded View---------------
Arg [0] : owner (address): 0x129443cA2a9Dec2020808a2868b38dDA457eaCC7
Arg [1] : entryPointArg (address): 0x0000000071727De22E5E9d8BAf0edAc6f37da032
Arg [2] : verifyingSignerArg (address): 0xC6dAB8652E5E9749523bA948F42d5944584E4e73
Arg [3] : feeCollectorArg (address): 0x129443cA2a9Dec2020808a2868b38dDA457eaCC7
Arg [4] : unaccountedGasArg (uint256): 50000
Arg [5] : paymasterIdWithdrawalDelayArg (uint256): 3600
Arg [6] : minDepositArg (uint256): 1000000000000000000
-----Encoded View---------------
7 Constructor Arguments found :
Arg [0] : 000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc7
Arg [1] : 0000000000000000000000000000000071727de22e5e9d8baf0edac6f37da032
Arg [2] : 000000000000000000000000c6dab8652e5e9749523ba948f42d5944584e4e73
Arg [3] : 000000000000000000000000129443ca2a9dec2020808a2868b38dda457eacc7
Arg [4] : 000000000000000000000000000000000000000000000000000000000000c350
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000e10
Arg [6] : 0000000000000000000000000000000000000000000000000de0b6b3a7640000
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.