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