IRelayRecipient.sol 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity >=0.6.0 <0.8.0;
  3. /**
  4. * @dev Base interface for a contract that will be called via the GSN from {IRelayHub}.
  5. *
  6. * TIP: You don't need to write an implementation yourself! Inherit from {GSNRecipient} instead.
  7. */
  8. interface IRelayRecipient {
  9. /**
  10. * @dev Returns the address of the {IRelayHub} instance this recipient interacts with.
  11. */
  12. function getHubAddr() external view returns (address);
  13. /**
  14. * @dev Called by {IRelayHub} to validate if this recipient accepts being charged for a relayed call. Note that the
  15. * recipient will be charged regardless of the execution result of the relayed call (i.e. if it reverts or not).
  16. *
  17. * The relay request was originated by `from` and will be served by `relay`. `encodedFunction` is the relayed call
  18. * calldata, so its first four bytes are the function selector. The relayed call will be forwarded `gasLimit` gas,
  19. * and the transaction executed with a gas price of at least `gasPrice`. ``relay``'s fee is `transactionFee`, and the
  20. * recipient will be charged at most `maxPossibleCharge` (in wei). `nonce` is the sender's (`from`) nonce for
  21. * replay attack protection in {IRelayHub}, and `approvalData` is a optional parameter that can be used to hold a signature
  22. * over all or some of the previous values.
  23. *
  24. * Returns a tuple, where the first value is used to indicate approval (0) or rejection (custom non-zero error code,
  25. * values 1 to 10 are reserved) and the second one is data to be passed to the other {IRelayRecipient} functions.
  26. *
  27. * {acceptRelayedCall} is called with 50k gas: if it runs out during execution, the request will be considered
  28. * rejected. A regular revert will also trigger a rejection.
  29. */
  30. function acceptRelayedCall(
  31. address relay,
  32. address from,
  33. bytes calldata encodedFunction,
  34. uint256 transactionFee,
  35. uint256 gasPrice,
  36. uint256 gasLimit,
  37. uint256 nonce,
  38. bytes calldata approvalData,
  39. uint256 maxPossibleCharge
  40. )
  41. external
  42. view
  43. returns (uint256, bytes memory);
  44. /**
  45. * @dev Called by {IRelayHub} on approved relay call requests, before the relayed call is executed. This allows to e.g.
  46. * pre-charge the sender of the transaction.
  47. *
  48. * `context` is the second value returned in the tuple by {acceptRelayedCall}.
  49. *
  50. * Returns a value to be passed to {postRelayedCall}.
  51. *
  52. * {preRelayedCall} is called with 100k gas: if it runs out during execution or otherwise reverts, the relayed call
  53. * will not be executed, but the recipient will still be charged for the transaction's cost.
  54. */
  55. function preRelayedCall(bytes calldata context) external returns (bytes32);
  56. /**
  57. * @dev Called by {IRelayHub} on approved relay call requests, after the relayed call is executed. This allows to e.g.
  58. * charge the user for the relayed call costs, return any overcharges from {preRelayedCall}, or perform
  59. * contract-specific bookkeeping.
  60. *
  61. * `context` is the second value returned in the tuple by {acceptRelayedCall}. `success` is the execution status of
  62. * the relayed call. `actualCharge` is an estimate of how much the recipient will be charged for the transaction,
  63. * not including any gas used by {postRelayedCall} itself. `preRetVal` is {preRelayedCall}'s return value.
  64. *
  65. *
  66. * {postRelayedCall} is called with 100k gas: if it runs out during execution or otherwise reverts, the relayed call
  67. * and the call to {preRelayedCall} will be reverted retroactively, but the recipient will still be charged for the
  68. * transaction's cost.
  69. */
  70. function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external;
  71. }