| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- // SPDX-License-Identifier: Apache 2
- pragma solidity ^0.8.0;
- import "./EntropyEvents.sol";
- import "./EntropyEventsV2.sol";
- import "./EntropyStructsV2.sol";
- interface IEntropy is EntropyEvents, EntropyEventsV2 {
- // Register msg.sender as a randomness provider. The arguments are the provider's configuration parameters
- // and initial commitment. Re-registering the same provider rotates the provider's commitment (and updates
- // the feeInWei).
- //
- // chainLength is the number of values in the hash chain *including* the commitment, that is, chainLength >= 1.
- function register(
- uint128 feeInWei,
- bytes32 commitment,
- bytes calldata commitmentMetadata,
- uint64 chainLength,
- bytes calldata uri
- ) external;
- // Withdraw a portion of the accumulated fees for the provider msg.sender.
- // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
- // balance of fees in the contract).
- function withdraw(uint128 amount) external;
- // Withdraw a portion of the accumulated fees for provider. The msg.sender must be the fee manager for this provider.
- // Calling this function will transfer `amount` wei to the caller (provided that they have accrued a sufficient
- // balance of fees in the contract).
- function withdrawAsFeeManager(address provider, uint128 amount) external;
- /// @notice Request a random number using the default provider with default gas limit
- /// @return assignedSequenceNumber A unique identifier for this request
- /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
- /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
- /// the generated random number.
- ///
- /// `entropyCallback` will be run with the `gasLimit` provided to this function.
- /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
- /// by the provider's configured default limit.
- ///
- /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2()`) as msg.value.
- /// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2()`
- /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
- ///
- /// Note that this method uses an in-contract PRNG to generate the user's portion of the random number.
- /// Users must trust this PRNG in order to prove the result is random. If you wish to avoid this trust assumption,
- /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
- function requestV2()
- external
- payable
- returns (uint64 assignedSequenceNumber);
- /// @notice Request a random number using the default provider with specified gas limit
- /// @param gasLimit The gas limit for the callback function.
- /// @return assignedSequenceNumber A unique identifier for this request
- /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
- /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
- /// the generated random number.
- ///
- /// `entropyCallback` will be run with the `gasLimit` provided to this function.
- /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
- /// by the provider's configured default limit.
- ///
- /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(gasLimit)`) as msg.value.
- /// Note that the fee can change over time. Callers of this method should explicitly compute `getFeeV2(gasLimit)`
- /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
- ///
- /// Note that this method uses an in-contract PRNG to generate the user's portion of the random number.
- /// Users must trust this PRNG in order to prove the result is random. If you wish to avoid this trust assumption,
- /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
- function requestV2(
- uint32 gasLimit
- ) external payable returns (uint64 assignedSequenceNumber);
- /// @notice Request a random number from a specific provider with specified gas limit
- /// @param provider The address of the provider to request from
- /// @param gasLimit The gas limit for the callback function
- /// @return assignedSequenceNumber A unique identifier for this request
- /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
- /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
- /// the generated random number.
- ///
- /// `entropyCallback` will be run with the `gasLimit` provided to this function.
- /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
- /// by the provider's configured default limit.
- ///
- /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
- /// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
- /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
- ///
- /// Note that this method uses an in-contract PRNG to generate the user's portion of the random number.
- /// Users must trust this PRNG in order to prove the result is random. If you wish to avoid this trust assumption,
- /// call a variant of `requestV2` that accepts a `userRandomNumber` parameter.
- function requestV2(
- address provider,
- uint32 gasLimit
- ) external payable returns (uint64 assignedSequenceNumber);
- /// @notice Request a random number from a specific provider with a user-provided random number and gas limit
- /// @param provider The address of the provider to request from
- /// @param userRandomNumber A random number provided by the user for additional entropy
- /// @param gasLimit The gas limit for the callback function
- /// @return assignedSequenceNumber A unique identifier for this request
- /// @dev The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
- /// The `entropyCallback` method on that interface will receive a callback with the returned sequence number and
- /// the generated random number.
- ///
- /// `entropyCallback` will be run with the `gasLimit` provided to this function.
- /// The `gasLimit` will be rounded up to a multiple of 10k (e.g., 19000 -> 20000), and furthermore is lower bounded
- /// by the provider's configured default limit.
- ///
- /// This method will revert unless the caller provides a sufficient fee (at least `getFeeV2(provider, gasLimit)`) as msg.value.
- /// Note that provider fees can change over time. Callers of this method should explicitly compute `getFeeV2(provider, gasLimit)`
- /// prior to each invocation (as opposed to hardcoding a value). Further note that excess value is *not* refunded to the caller.
- function requestV2(
- address provider,
- bytes32 userRandomNumber,
- uint32 gasLimit
- ) external payable returns (uint64 assignedSequenceNumber);
- // As a user, request a random number from `provider`. Prior to calling this method, the user should
- // generate a random number x and keep it secret. The user should then compute hash(x) and pass that
- // as the userCommitment argument. (You may call the constructUserCommitment method to compute the hash.)
- //
- // This method returns a sequence number. The user should pass this sequence number to
- // their chosen provider (the exact method for doing so will depend on the provider) to retrieve the provider's
- // number. The user should then call fulfillRequest to construct the final random number.
- //
- // This method will revert unless the caller provides a sufficient fee (at least getFee(provider)) as msg.value.
- // Note that excess value is *not* refunded to the caller.
- function request(
- address provider,
- bytes32 userCommitment,
- bool useBlockHash
- ) external payable returns (uint64 assignedSequenceNumber);
- // Request a random number. The method expects the provider address and a secret random number
- // in the arguments. It returns a sequence number.
- //
- // The address calling this function should be a contract that inherits from the IEntropyConsumer interface.
- // The `entropyCallback` method on that interface will receive a callback with the generated random number.
- // `entropyCallback` will be run with the provider's default gas limit (see `getProviderInfo(provider).defaultGasLimit`).
- // If your callback needs additional gas, please use `requestWithCallbackAndGasLimit`.
- //
- // This method will revert unless the caller provides a sufficient fee (at least `getFee(provider)`) as msg.value.
- // Note that excess value is *not* refunded to the caller.
- function requestWithCallback(
- address provider,
- bytes32 userRandomNumber
- ) external payable returns (uint64 assignedSequenceNumber);
- // Fulfill a request for a random number. This method validates the provided userRandomness and provider's proof
- // against the corresponding commitments in the in-flight request. If both values are validated, this function returns
- // the corresponding random number.
- //
- // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
- // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
- // If you need to use the returned random number more than once, you are responsible for storing it.
- function reveal(
- address provider,
- uint64 sequenceNumber,
- bytes32 userRevelation,
- bytes32 providerRevelation
- ) external returns (bytes32 randomNumber);
- // Fulfill a request for a random number. This method validates the provided userRandomness
- // and provider's revelation against the corresponding commitment in the in-flight request. If both values are validated
- // and the requestor address is a contract address, this function calls the requester's entropyCallback method with the
- // sequence number, provider address and the random number as arguments. Else if the requestor is an EOA, it won't call it.
- //
- // Note that this function can only be called once per in-flight request. Calling this function deletes the stored
- // request information (so that the contract doesn't use a linear amount of storage in the number of requests).
- // If you need to use the returned random number more than once, you are responsible for storing it.
- //
- // Anyone can call this method to fulfill a request, but the callback will only be made to the original requester.
- function revealWithCallback(
- address provider,
- uint64 sequenceNumber,
- bytes32 userRandomNumber,
- bytes32 providerRevelation
- ) external;
- function getProviderInfo(
- address provider
- ) external view returns (EntropyStructs.ProviderInfo memory info);
- function getProviderInfoV2(
- address provider
- ) external view returns (EntropyStructsV2.ProviderInfo memory info);
- function getDefaultProvider() external view returns (address provider);
- function getRequest(
- address provider,
- uint64 sequenceNumber
- ) external view returns (EntropyStructs.Request memory req);
- function getRequestV2(
- address provider,
- uint64 sequenceNumber
- ) external view returns (EntropyStructsV2.Request memory req);
- // Get the fee charged by provider for a request with the default gasLimit (`request` or `requestWithCallback`).
- // If you are calling any of the `requestV2` methods, please use `getFeeV2`.
- function getFee(address provider) external view returns (uint128 feeAmount);
- // Get the fee charged by the default provider for the default gas limit.
- // Use this function to determine the fee to pass to `requestV2`.
- function getFeeV2() external view returns (uint128 feeAmount);
- // Get the fee charged by the default provider for the specified gas limit.
- // Use this function to determine the fee to pass to `requestV2`.
- function getFeeV2(
- uint32 gasLimit
- ) external view returns (uint128 feeAmount);
- // Get the fee charged by `provider` for a request with a specific `gasLimit`.
- // Use this function to determine the fee to pass to `requestV2`.
- function getFeeV2(
- address provider,
- uint32 gasLimit
- ) external view returns (uint128 feeAmount);
- function getAccruedPythFees()
- external
- view
- returns (uint128 accruedPythFeesInWei);
- function setProviderFee(uint128 newFeeInWei) external;
- function setProviderFeeAsFeeManager(
- address provider,
- uint128 newFeeInWei
- ) external;
- function setProviderUri(bytes calldata newUri) external;
- // Set manager as the fee manager for the provider msg.sender.
- // After calling this function, manager will be able to set the provider's fees and withdraw them.
- // Only one address can be the fee manager for a provider at a time -- calling this function again with a new value
- // will override the previous value. Call this function with the all-zero address to disable the fee manager role.
- function setFeeManager(address manager) external;
- // Set the maximum number of hashes to record in a request. This should be set according to the maximum gas limit
- // the provider supports for callbacks.
- function setMaxNumHashes(uint32 maxNumHashes) external;
- // Set the default gas limit for a request. If 0, no
- function setDefaultGasLimit(uint32 gasLimit) external;
- // Advance the provider commitment and increase the sequence number.
- // This is used to reduce the `numHashes` required for future requests which leads to reduced gas usage.
- function advanceProviderCommitment(
- address provider,
- uint64 advancedSequenceNumber,
- bytes32 providerRevelation
- ) external;
- function constructUserCommitment(
- bytes32 userRandomness
- ) external pure returns (bytes32 userCommitment);
- function combineRandomValues(
- bytes32 userRandomness,
- bytes32 providerRandomness,
- bytes32 blockHash
- ) external pure returns (bytes32 combinedRandomness);
- }
|