Skip to content

Commit 578741c

Browse files
authored
feat(entropy): Split out V2 interface into separate file. (#2645)
* comment * version num * missed doc
1 parent f5923cd commit 578741c

File tree

5 files changed

+1080
-121
lines changed

5 files changed

+1080
-121
lines changed

target_chains/ethereum/entropy_sdk/solidity/IEntropy.sol

+2-119
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ pragma solidity ^0.8.0;
44
import "./EntropyEvents.sol";
55
import "./EntropyEventsV2.sol";
66
import "./EntropyStructsV2.sol";
7+
import "./IEntropyV2.sol";
78

8-
interface IEntropy is EntropyEvents, EntropyEventsV2 {
9+
interface IEntropy is EntropyEvents, EntropyEventsV2, IEntropyV2 {
910
// Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
1011
// and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates
1112
// the feeInWei).
@@ -29,96 +30,6 @@ interface IEntropy is EntropyEvents, EntropyEventsV2 {
2930
// balance of fees in the contract).
3031
function withdrawAsFeeManager(address provider, uint128 amount) external;
3132

32-
/// @notice Request a random number using the default provider with default gas limit
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()`) as msg.value.
43-
/// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2()`
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-
external
51-
payable
52-
returns (uint64 assignedSequenceNumber);
53-
54-
/// @notice Request a random number using the default provider with specified gas limit
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(gasLimit)`) as msg.value.
66-
/// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2(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-
uint32 gasLimit
74-
) external payable returns (uint64 assignedSequenceNumber);
75-
76-
/// @notice Request a random number from a specific provider with specified gas limit
77-
/// @param provider The address of the provider to request from
78-
/// @param gasLimit The gas limit for the callback function
79-
/// @return assignedSequenceNumber A unique identifier for this request
80-
/// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
81-
/// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
82-
/// the generated random number.
83-
///
84-
/// `entropyCallback` will be run with the `gasLimit` provided to this function.
85-
/// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
86-
/// by the provider's configured default limit.
87-
///
88-
/// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
89-
/// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
90-
/// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
91-
///
92-
/// Note that this method uses an in-contract PRNG to generate the user's portion of the random number.
93-
/// Users must trust this PRNG in order to prove the result is random. If you wish to avoid this trust assumption,
94-
/// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
95-
function requestV2(
96-
address provider,
97-
uint32 gasLimit
98-
) external payable returns (uint64 assignedSequenceNumber);
99-
100-
/// @notice Request a random number from a specific provider with a user-provided random number and gas limit
101-
/// @param provider The address of the provider to request from
102-
/// @param userRandomNumber A random number provided by the user for additional entropy
103-
/// @param gasLimit The gas limit for the callback function
104-
/// @return assignedSequenceNumber A unique identifier for this request
105-
/// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
106-
/// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
107-
/// the generated random number.
108-
///
109-
/// `entropyCallback` will be run with the `gasLimit` provided to this function.
110-
/// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
111-
/// by the provider's configured default limit.
112-
///
113-
/// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
114-
/// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
115-
/// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
116-
function requestV2(
117-
address provider,
118-
bytes32 userRandomNumber,
119-
uint32 gasLimit
120-
) external payable returns (uint64 assignedSequenceNumber);
121-
12233
// As a user, request a random number from `provider`. Prior to calling this method, the user should
12334
// generate a random number x and keep it secret. The user should then compute hash(x) and pass that
12435
// as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
@@ -185,43 +96,15 @@ interface IEntropy is EntropyEvents, EntropyEventsV2 {
18596
address provider
18697
) external view returns (EntropyStructs.ProviderInfo memory info);
18798

188-
function getProviderInfoV2(
189-
address provider
190-
) external view returns (EntropyStructsV2.ProviderInfo memory info);
191-
192-
function getDefaultProvider() external view returns (address provider);
193-
19499
function getRequest(
195100
address provider,
196101
uint64 sequenceNumber
197102
) external view returns (EntropyStructs.Request memory req);
198103

199-
function getRequestV2(
200-
address provider,
201-
uint64 sequenceNumber
202-
) external view returns (EntropyStructsV2.Request memory req);
203-
204104
// Get the fee charged by provider for a request with the default gasLimit (`request` or `requestWithCallback`).
205105
// If you are calling any of the `requestV2` methods, please use `getFeeV2`.
206106
function getFee(address provider) external view returns (uint128 feeAmount);
207107

208-
// Get the fee charged by the default provider for the default gas limit.
209-
// Use this function to determine the fee to pass to `requestV2`.
210-
function getFeeV2() external view returns (uint128 feeAmount);
211-
212-
// Get the fee charged by the default provider for the specified gas limit.
213-
// Use this function to determine the fee to pass to `requestV2`.
214-
function getFeeV2(
215-
uint32 gasLimit
216-
) external view returns (uint128 feeAmount);
217-
218-
// Get the fee charged by `provider` for a request with a specific `gasLimit`.
219-
// Use this function to determine the fee to pass to `requestV2`.
220-
function getFeeV2(
221-
address provider,
222-
uint32 gasLimit
223-
) external view returns (uint128 feeAmount);
224-
225108
function getAccruedPythFees()
226109
external
227110
view
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

Comments
 (0)