IEntropyV2.sol 11 KB

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