22pragma solidity ^ 0.8.0 ;
33
44// Import the entropy SDK in order to interact with the entropy contracts
5- import "entropy-sdk-solidity/IEntropy .sol " ;
5+ import "entropy-sdk-solidity/IEntropyV2 .sol " ;
66import "entropy-sdk-solidity/IEntropyConsumer.sol " ;
77
88library CoinFlipErrors {
@@ -26,43 +26,38 @@ contract CoinFlip is IEntropyConsumer {
2626 // Event emitted when the result of the coin flip is known.
2727 event FlipResult (uint64 sequenceNumber , bool isHeads );
2828
29- // Contracts using Pyth Entropy should import the solidity SDK and then store both the Entropy contract
30- // and a specific entropy provider to use for requests. Each provider commits to a sequence of random numbers.
31- // Providers are then responsible for fulfilling a request on chain by revealing their random number.
32- // Users should choose a reliable provider who they trust to uphold these commitments.
33- // (For the moment, the only available provider is 0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344)
34- IEntropy private entropy;
35- address private entropyProvider;
29+ // Contracts using Pyth Entropy should import the solidity SDK and then store the Entropy contract
30+ // address in the constructor.
31+ IEntropyV2 private entropy;
3632
37- constructor (address _entropy , address _entropyProvider ) {
33+ constructor (address _entropy ) {
3834 entropy = IEntropy (_entropy);
39- entropyProvider = _entropyProvider;
4035 }
4136
42- // Request to flip a coin. The caller should generate and pass in a random number when calling this method.
43- function requestFlip (bytes32 userRandomNumber ) external payable {
37+ // Request to flip a coin.
38+ function requestFlip () external payable {
4439 // The entropy protocol requires the caller to pay a fee (in native gas tokens) per requested random number.
4540 // This fee can either be paid by the contract itself or passed on to the end user.
4641 // This implementation of the requestFlip method passes on the fee to the end user.
47- uint256 fee = entropy.getFee (entropyProvider );
42+ uint256 fee = entropy.getFeeV2 ( );
4843 if (msg .value < fee) {
4944 revert CoinFlipErrors.InsufficientFee ();
5045 }
5146
5247 // Request the random number from the Entropy protocol. The call returns a sequence number that uniquely
5348 // identifies the generated random number. Callers can use this sequence number to match which request
5449 // is being revealed in the next stage of the protocol.
55- uint64 sequenceNumber = entropy. requestWithCallback {value: fee}(
56- entropyProvider,
57- userRandomNumber
58- );
50+ //
51+ // Note that callers can also request a specific gas limit for the callback by passing a gasLimit parameter
52+ // to this function. See the IEntropyV2 interface for details.
53+ uint64 sequenceNumber = entropy. requestV2 {value: fee}( );
5954
6055 emit FlipRequest (sequenceNumber);
6156 }
6257
6358 // Get the fee to flip a coin. See the comment above about fees.
6459 function getFlipFee () public view returns (uint256 fee ) {
65- fee = entropy.getFee (entropyProvider );
60+ fee = entropy.getFeeV2 ( );
6661 }
6762
6863 // This method is required by the IEntropyConsumer interface.
0 commit comments