IEntropyV2.sol 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. import "./EntropyEvents.sol";
  4. import "./EntropyEventsV2.sol";
  5. import "./EntropyStructsV2.sol";
  6. interface IEntropyV2 is EntropyEventsV2 {
  7. /// @notice Request a random number using the default provider with default gas limit
  8. /// @return assignedSequenceNumber A unique identifier for this request
  9. /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
  10. /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
  11. /// the generated random number.
  12. ///
  13. /// `entropyCallback` will be run with the provider's configured default gas limit.
  14. ///
  15. /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2()`) as msg.value.
  16. /// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2()`
  17. /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
  18. ///
  19. /// Note that this method uses an in-contract PRNG to generate the user's contribution to the random number.
  20. /// This approach modifies the security guarantees such that a dishonest validator and provider can
  21. /// collude to manipulate the result (as opposed to a malicious user and provider). That is, the user
  22. /// now trusts the validator honestly draw a random number. If you wish to avoid this trust assumption,
  23. /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
  24. function requestV2()
  25. external
  26. payable
  27. returns (uint64 assignedSequenceNumber);
  28. /// @notice Request a random number using the default provider with specified gas limit
  29. /// @param gasLimit The gas limit for the callback function.
  30. /// @return assignedSequenceNumber A unique identifier for this request
  31. /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
  32. /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
  33. /// the generated random number.
  34. ///
  35. /// `entropyCallback` will be run with the `gasLimit` provided to this function.
  36. /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
  37. /// by the provider's configured default limit.
  38. ///
  39. /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(gasLimit)`) as msg.value.
  40. /// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2(gasLimit)`
  41. /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
  42. ///
  43. /// Note that this method uses an in-contract PRNG to generate the user's contribution to the random number.
  44. /// This approach modifies the security guarantees such that a dishonest validator and provider can
  45. /// collude to manipulate the result (as opposed to a malicious user and provider). That is, the user
  46. /// now trusts the validator honestly draw a random number. If you wish to avoid this trust assumption,
  47. /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
  48. function requestV2(
  49. uint32 gasLimit
  50. ) external payable returns (uint64 assignedSequenceNumber);
  51. /// @notice Request a random number from a specific provider with specified gas limit
  52. /// @param provider The address of the provider to request from
  53. /// @param gasLimit The gas limit for the callback function
  54. /// @return assignedSequenceNumber A unique identifier for this request
  55. /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
  56. /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
  57. /// the generated random number.
  58. ///
  59. /// `entropyCallback` will be run with the `gasLimit` provided to this function.
  60. /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
  61. /// by the provider's configured default limit.
  62. ///
  63. /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
  64. /// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
  65. /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
  66. ///
  67. /// Note that this method uses an in-contract PRNG to generate the user's contribution to the random number.
  68. /// This approach modifies the security guarantees such that a dishonest validator and provider can
  69. /// collude to manipulate the result (as opposed to a malicious user and provider). That is, the user
  70. /// now trusts the validator honestly draw a random number. If you wish to avoid this trust assumption,
  71. /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
  72. function requestV2(
  73. address provider,
  74. uint32 gasLimit
  75. ) external payable returns (uint64 assignedSequenceNumber);
  76. /// @notice Request a random number from a specific provider with a user-provided random number and gas limit
  77. /// @param provider The address of the provider to request from
  78. /// @param userRandomNumber A random number provided by the user for additional entropy
  79. /// @param gasLimit The gas limit for the callback function. Pass 0 to get a sane default value -- see note below.
  80. /// @return assignedSequenceNumber A unique identifier for this request
  81. /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
  82. /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
  83. /// the generated random number.
  84. ///
  85. /// `entropyCallback` will be run with the `gasLimit` provided to this function.
  86. /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
  87. /// by the provider's configured default limit.
  88. ///
  89. /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
  90. /// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
  91. /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
  92. function requestV2(
  93. address provider,
  94. bytes32 userRandomNumber,
  95. uint32 gasLimit
  96. ) external payable returns (uint64 assignedSequenceNumber);
  97. /// @notice Get information about a specific entropy provider
  98. /// @param provider The address of the provider to query
  99. /// @return info The provider information including configuration, fees, and operational status
  100. /// @dev This method returns detailed information about a provider's configuration and capabilities.
  101. /// The returned ProviderInfo struct contains information such as the provider's fee structure and gas limits.
  102. function getProviderInfoV2(
  103. address provider
  104. ) external view returns (EntropyStructsV2.ProviderInfo memory info);
  105. /// @notice Get the address of the default entropy provider
  106. /// @return provider The address of the default provider
  107. /// @dev This method returns the address of the provider that will be used when no specific provider is specified
  108. /// in the requestV2 calls. The default provider can be used to get the base fee and gas limit information.
  109. function getDefaultProvider() external view returns (address provider);
  110. /// @notice Get information about a specific request
  111. /// @param provider The address of the provider that handled the request
  112. /// @param sequenceNumber The unique identifier of the request
  113. /// @return req The request information including status, random number, and other metadata
  114. /// @dev This method allows querying the state of a previously made request. The returned Request struct
  115. /// contains information about whether the request was fulfilled, the generated random number (if available),
  116. /// and other metadata about the request.
  117. function getRequestV2(
  118. address provider,
  119. uint64 sequenceNumber
  120. ) external view returns (EntropyStructsV2.Request memory req);
  121. /// @notice Get the fee charged by the default provider for the default gas limit
  122. /// @return feeAmount The fee amount in wei
  123. /// @dev This method returns the base fee required to make a request using the default provider with
  124. /// the default gas limit. This fee should be passed as msg.value when calling requestV2().
  125. /// The fee can change over time, so this method should be called before each request.
  126. function getFeeV2() external view returns (uint128 feeAmount);
  127. /// @notice Get the fee charged by the default provider for a specific gas limit
  128. /// @param gasLimit The gas limit for the callback function
  129. /// @return feeAmount The fee amount in wei
  130. /// @dev This method returns the fee required to make a request using the default provider with
  131. /// the specified gas limit. This fee should be passed as msg.value when calling requestV2(gasLimit).
  132. /// The fee can change over time, so this method should be called before each request.
  133. function getFeeV2(
  134. uint32 gasLimit
  135. ) external view returns (uint128 feeAmount);
  136. /// @notice Get the fee charged by a specific provider for a request with a given gas limit
  137. /// @param provider The address of the provider to query
  138. /// @param gasLimit The gas limit for the callback function
  139. /// @return feeAmount The fee amount in wei
  140. /// @dev This method returns the fee required to make a request using the specified provider with
  141. /// the given gas limit. This fee should be passed as msg.value when calling requestV2(provider, gasLimit)
  142. /// or requestV2(provider, userRandomNumber, gasLimit). The fee can change over time, so this method
  143. /// should be called before each request.
  144. function getFeeV2(
  145. address provider,
  146. uint32 gasLimit
  147. ) external view returns (uint128 feeAmount);
  148. }