|
| 1 | +// SPDX-License-Identifier:MIT |
| 2 | +pragma solidity 0.4.24; |
| 3 | +pragma experimental ABIEncoderV2; |
| 4 | + |
| 5 | +import "./GsnTypes.sol"; |
| 6 | + |
| 7 | +contract IPaymaster { |
| 8 | + /** |
| 9 | + * @param acceptanceBudget - |
| 10 | + * Paymaster expected gas budget to accept (or reject) a request |
| 11 | + * This a gas required by any calculations that might need to reject the |
| 12 | + * transaction, by preRelayedCall, forwarder and recipient. |
| 13 | + * See value in BasePaymaster.PAYMASTER_ACCEPTANCE_BUDGET |
| 14 | + * Transaction that gets rejected above that gas usage is on the paymaster's expense. |
| 15 | + * As long this value is above preRelayedCallGasLimit (see defaults in BasePaymaster), the |
| 16 | + * Paymaster is guaranteed it will never pay for rejected transactions. |
| 17 | + * If this value is below preRelayedCallGasLimt, it might might make Paymaster open to a "griefing" attack. |
| 18 | + * |
| 19 | + * Specifying value too high might make the call rejected by some relayers. |
| 20 | + * |
| 21 | + * From a Relay's point of view, this is the highest gas value a paymaster might "grief" the relay, |
| 22 | + * since the paymaster will pay anything above that (regardless if the tx reverts) |
| 23 | + * |
| 24 | + * @param preRelayedCallGasLimit - the max gas usage of preRelayedCall. any revert (including OOG) |
| 25 | + * of preRelayedCall is a reject by the paymaster. |
| 26 | + * as long as acceptanceBudget is above preRelayedCallGasLimit, any such revert (including OOG) |
| 27 | + * is not payed by the paymaster. |
| 28 | + * @param postRelayedCallGasLimit - the max gas usage of postRelayedCall. |
| 29 | + * note that an OOG will revert the transaction, but the paymaster already committed to pay, |
| 30 | + * so the relay will get compensated, at the expense of the paymaster |
| 31 | + */ |
| 32 | + struct GasLimits { |
| 33 | + uint256 acceptanceBudget; |
| 34 | + uint256 preRelayedCallGasLimit; |
| 35 | + uint256 postRelayedCallGasLimit; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Return the GasLimits constants used by the Paymaster. |
| 40 | + */ |
| 41 | + function getGasLimits() external view returns (GasLimits memory limits); |
| 42 | + |
| 43 | + /** |
| 44 | + * return the relayHub of this contract. |
| 45 | + */ |
| 46 | + function getHubAddr() public view returns (address); |
| 47 | + |
| 48 | + /** |
| 49 | + * Can be used to determine if the contract can pay for incoming calls before making any. |
| 50 | + * @return the paymaster's deposit in the RelayHub. |
| 51 | + */ |
| 52 | + function getRelayHubDeposit() public view returns (uint256); |
| 53 | + |
| 54 | + /** |
| 55 | + * Called by Relay (and RelayHub), to validate if the paymaster agrees to pay for this call. |
| 56 | + * |
| 57 | + * MUST be protected with relayHubOnly() in case it modifies state. |
| 58 | + * |
| 59 | + * The Paymaster rejects by the following "revert" operations |
| 60 | + * - preRelayedCall() method reverts |
| 61 | + * - the forwarder reverts because of nonce or signature error |
| 62 | + * - the paymaster returned "rejectOnRecipientRevert", and the recipient contract reverted. |
| 63 | + * In any of the above cases, all paymaster calls (and recipient call) are reverted. |
| 64 | + * In any other case, the paymaster agrees to pay for the gas cost of the transaction (note |
| 65 | + * that this includes also postRelayedCall revert) |
| 66 | + * |
| 67 | + * The rejectOnRecipientRevert flag means the Paymaster "delegate" the rejection to the recipient |
| 68 | + * code. It also means the Paymaster trust the recipient to reject fast: both preRelayedCall, |
| 69 | + * forwarder check and receipient checks must fit into the GasLimits.acceptanceBudget, |
| 70 | + * otherwise the TX is paid by the Paymaster. |
| 71 | + * |
| 72 | + * @param relayRequest - the full relay request structure |
| 73 | + * @param signature - user's EIP712-compatible signature of the {@link relayRequest}. |
| 74 | + * Note that in most cases the paymaster shouldn't try use it at all. It is always checked |
| 75 | + * by the forwarder immediately after preRelayedCall returns. |
| 76 | + * @param approvalData - extra dapp-specific data (e.g. signature from trusted party) |
| 77 | + * @param maxPossibleGas - based on values returned from {@link getGasLimits}, |
| 78 | + * the RelayHub will calculate the maximum possible amount of gas the user may be charged for. |
| 79 | + * In order to convert this value to wei, the Paymaster has to call "relayHub.calculateCharge()" |
| 80 | + * return: |
| 81 | + * a context to be passed to postRelayedCall |
| 82 | + * rejectOnRecipientRevert - TRUE if paymaster want to reject the TX if the recipient reverts. |
| 83 | + * FALSE means that rejects by the recipient will be completed on chain, and paid by the paymaster. |
| 84 | + * (note that in the latter case, the preRelayedCall and postRelayedCall are not reverted). |
| 85 | + */ |
| 86 | + function preRelayedCall( |
| 87 | + GsnTypes.RelayRequest relayRequest, |
| 88 | + bytes signature, |
| 89 | + bytes approvalData, |
| 90 | + uint256 maxPossibleGas |
| 91 | + ) public returns (bytes memory context, bool rejectOnRecipientRevert); |
| 92 | + |
| 93 | + /** |
| 94 | + * This method is called after the actual relayed function call. |
| 95 | + * It may be used to record the transaction (e.g. charge the caller by some contract logic) for this call. |
| 96 | + * |
| 97 | + * MUST be protected with relayHubOnly() in case it modifies state. |
| 98 | + * |
| 99 | + * @param context - the call context, as returned by the preRelayedCall |
| 100 | + * @param success - true if the relayed call succeeded, false if it reverted |
| 101 | + * @param gasUseWithoutPost - the actual amount of gas used by the entire transaction, EXCEPT |
| 102 | + * the gas used by the postRelayedCall itself. |
| 103 | + * @param relayData - the relay params of the request. can be used by relayHub.calculateCharge() |
| 104 | + * |
| 105 | + * Revert in this functions causes a revert of the client's relayed call (and preRelayedCall(), but the Paymaster |
| 106 | + * is still committed to pay the relay for the entire transaction. |
| 107 | + */ |
| 108 | + function postRelayedCall(bytes context, bool success, uint256 gasUseWithoutPost, GsnTypes.RelayData relayData) |
| 109 | + public; |
| 110 | + |
| 111 | + function versionPaymaster() external view returns (string memory); |
| 112 | +} |
0 commit comments