// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// c=<
// |
// | ////\ 1@2
// @@ | /___\** @@@2 @@@@@@@@@@@@@@@@@@@@@@
// @@@ | |~L~ |* @@@@@@ @@@ @@@@@ @@@@ @@@ @@@@ @@@ @@@@@@@@ @@@@ @@@@ @@@ @@@@@@@@@ @@@@ @@@@
// @@@@@ | \=_/8 @@@@1@@ @@@ @@@@@ @@@@ @@@@ @@@ @@@@@ @@@ @@@@@@@@@ @@@@ @@@@@ @@@@ @@@@@@@@@ @@@@ @@@@
// @@@@@@| _ /| |\__ @@@@@@@@2 @@@ @@@@@ @@@@ @@@@ @@@ @@@@@@@ @@@ @@@@ @@@@ @@@@@@ @@@@ @@@ @@@@@@@
// 1@@@@@@|\ \___/) @@1@@@@@2 ~~~ ~~~~~ @@@@ ~~@@ ~~~ ~~~~~~~~~~~ ~~~~ ~~~~ ~~~~~~~~~~~ ~@@ @@@@@
// 2@@@@@ | \ \ / | @@@@@@2 @@@ @@@@@ @@@@ @@@@ @@@ @@@@@@@@@@@ @@@@@@@@@ @@@@ @@@@@@@@@@@ @@@@@@@@@ @@@@@
// 2@@@@ |_ > <|__ @@1@12 @@@ @@@@@ @@@@ @@@@ @@@ @@@@ @@@@@@ @@@@ @@@@ @@@@ @@@@@@ @@@ @@@@@@@
// @@@@ / _| / \/ \ @@1@ @@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@@ @@@@ @@@@ @@@@ @@@@@ @@@@@@@@@ @@@@ @@@@
// @@ / |^\/ | | @@1 @@@ @@@@ @@@@ @@@ @@@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@@@@@@ @@@@ @@@@
// / / ---- \ \\\= @@ @@@@@@@@@@@@@@@@@@@@@@
// \___/ -------- ~~ @@@
// @@ | | | | -- @@
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import { IEntropy } from "@pythnetwork/entropy-sdk-solidity/IEntropy.sol";
import { IEntropyConsumer } from "@pythnetwork/entropy-sdk-solidity/IEntropyConsumer.sol";
import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { ERC2771Context } from "src/forwarder/ERC2771Context.sol";
import { ICrateOpener } from "src/interfaces/craterun/ICrateOpener.sol";
import { IPoints } from "src/interfaces/virtual/IPoints.sol";
import { Error } from "src/libraries/Error.sol";
/**
* @title CrateOpener contract
* @notice constructor function
*/
contract CrateOpener is Ownable2Step, ICrateOpener, IEntropyConsumer, ReentrancyGuard {
IEntropy public immutable entropy;
IPoints public immutable cratePoints;
address public immutable entropyProvider;
mapping(uint64 => RequestInfo) public openingRequests;
mapping(address => bool) public authorizedKeepers;
uint256 public remainingCrates;
/*///////////////////////////////////////////////////////////////
CONSTRUCTOR
///////////////////////////////////////////////////////////////*/
/**
* @param _owner The owner of the contract
* @param _entropy The address of the Entropy contract
* @param _entropyProvider The address of the Entropy provider
* @param _cratePoints The address of the Points contract
* @param _totalCrates The total number of crates
*/
constructor(
address _owner,
address _trustedForwarder,
address _entropy,
address _entropyProvider,
address _cratePoints,
uint256 _totalCrates
) Ownable(_owner) {
if (_trustedForwarder == address(0)) revert Error.NullAddress();
if (_entropy == address(0)) revert Error.NullAddress();
if (_entropyProvider == address(0)) revert Error.NullAddress();
if (_cratePoints == address(0)) revert Error.NullAddress();
if (_totalCrates == 0) revert Error.ZeroValue();
entropy = IEntropy(_entropy);
entropyProvider = _entropyProvider;
cratePoints = IPoints(_cratePoints);
remainingCrates = _totalCrates;
ERC2771Context.initialize(_trustedForwarder);
}
/*///////////////////////////////////////////////////////////////
VIEW FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Returns the fee from the specified entropy provider.
* @return The fee amount as a uint128 value.
*/
function getEntropyFee() external view returns (uint128) {
return entropy.getFee(entropyProvider);
}
/*///////////////////////////////////////////////////////////////
MUTATIVE FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Requests the opening of a crate by calling the Entropy contract.
* @param _crateHolder The address of the crate holder.
* @param _crateAmount The amount of crates to be opened.
* @param _userRandomBytes The random bytes provided by the user.
* @return sequenceNumber The sequence number of the crate opening request given by Entropy
*/
function requestCrateOpening(address _crateHolder, uint256 _crateAmount, bytes32 _userRandomBytes)
external
nonReentrant
returns (uint64 sequenceNumber)
{
if (!authorizedKeepers[ERC2771Context._msgSender()]) revert Error.Unauthorized();
if (remainingCrates == 0 || _crateAmount > remainingCrates) revert NotEnoughCrates();
if (cratePoints.balanceOf(_crateHolder) < _crateAmount * 1e18) revert Error.InsufficientBalance();
uint128 requestFee = entropy.getFee(entropyProvider);
if (address(this).balance < requestFee) revert EthBalanceTooLow();
// slither-disable-next-line reentrancy-benign
sequenceNumber = entropy.requestWithCallback{ value: requestFee }(entropyProvider, _userRandomBytes);
emit CrateOpeningRequested(sequenceNumber, _userRandomBytes, _crateHolder, _crateAmount);
openingRequests[sequenceNumber] = RequestInfo(_userRandomBytes, _crateHolder, _crateAmount, bytes32(0), false);
}
/*///////////////////////////////////////////////////////////////
ADMIN FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Sets an authorized keeper
* @param _keeper The address of the keeper
* @param _authorized A boolean indicating if the keeper is authorized
*/
function setAuthorizedKeeper(address _keeper, bool _authorized) external onlyOwner {
if (_keeper == address(0)) revert Error.NullAddress();
emit KeeperAuthorizationSet(_keeper, _authorized);
authorizedKeepers[_keeper] = _authorized;
}
/**
* @notice Withdraws the ETH balance from the contract.
* @param _to The address to which the ETH balance will be transferred.
*/
function withdrawEth(address _to) external onlyOwner {
if (_to == address(0)) revert Error.NullAddress();
uint256 balance = address(this).balance;
if (balance == 0) revert Error.ZeroValue();
(bool success,) = _to.call{ value: balance }("");
if (!success) revert WithdrawalFailed();
}
/*///////////////////////////////////////////////////////////////
ENTROPY OVERRIDE FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Callback function that is called by Entropy when the random number is generated.
* @param _sequenceNumber The sequence number of the request.
* @param _randomNumber The generated random number.
*/
function entropyCallback(uint64 _sequenceNumber, address, bytes32 _randomNumber) internal override {
_processRandomNumber(_sequenceNumber, _randomNumber);
}
/**
* @notice Returns the address of the Entropy contract.
* @return The address of the Entropy contract.
*/
function getEntropy() internal view override returns (address) {
return address(entropy);
}
/*///////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Processes the random number generated by Entropy.
* @param _sequenceNumber The sequence number of the request.
* @param _randomNumber The generated random number.
*/
function _processRandomNumber(uint64 _sequenceNumber, bytes32 _randomNumber) internal {
RequestInfo memory request = openingRequests[_sequenceNumber];
if (request.processed) revert RequestAlreadyProcessed();
if (remainingCrates == 0 || request.crateAmount > remainingCrates) revert NotEnoughCrates();
emit RandomNumberProcessed(
request.userRandomBytes, _sequenceNumber, request.crateHolder, _randomNumber, request.crateAmount, remainingCrates
);
openingRequests[_sequenceNumber].randomNumber = _randomNumber;
openingRequests[_sequenceNumber].processed = true;
remainingCrates -= request.crateAmount;
cratePoints.burn(request.crateHolder, request.crateAmount * 1e18);
}
/*///////////////////////////////////////////////////////////////
FALLBACK FUNCTION
///////////////////////////////////////////////////////////////*/
receive() external payable { }
}
// SPDX-License-Identifier: MIT
// Originally sourced from OpenZeppelin Contracts (last updated v4.9.3) (metatx/ERC2771Context.sol)
pragma solidity ^0.8.21;
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { Initializable } from "src/Initializable.sol";
import { Error } from "src/libraries/Error.sol";
/**
* @dev Context variant with ERC2771 support.
*/
library ERC2771Context {
event TrustedForwarderAdded(address forwarder);
event TrustedForwarderRemoved(address forwarder);
struct Data {
EnumerableSet.AddressSet trustedForwarders;
}
function getStorage() internal pure returns (Data storage data) {
bytes32 slot = keccak256(abi.encode("io.infinex.ERC2771Context"));
assembly {
data.slot := slot
}
}
function initialize(address initialTrustedForwarder) internal {
Initializable.initialize();
EnumerableSet.add(getStorage().trustedForwarders, initialTrustedForwarder);
}
function isTrustedForwarder(address forwarder) internal view returns (bool) {
return EnumerableSet.contains(getStorage().trustedForwarders, forwarder);
}
function trustedForwarder() internal view returns (address[] memory) {
return EnumerableSet.values(getStorage().trustedForwarders);
}
function _addTrustedForwarder(address forwarder) internal returns (bool) {
if (EnumerableSet.add(getStorage().trustedForwarders, forwarder)) {
emit TrustedForwarderAdded(forwarder);
return true;
} else {
revert Error.AlreadyExists();
}
}
function _removeTrustedForwarder(address forwarder) internal returns (bool) {
if (EnumerableSet.remove(getStorage().trustedForwarders, forwarder)) {
emit TrustedForwarderRemoved(forwarder);
return true;
} else {
revert Error.DoesNotExist();
}
}
function _msgSender() internal view returns (address) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
return address(bytes20(msg.data[calldataLength - contextSuffixLength:]));
} else {
return msg.sender;
}
}
// slither-disable-start dead-code
function _msgData() internal view returns (bytes calldata) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
return msg.data[:calldataLength - contextSuffixLength];
} else {
return msg.data;
}
}
/**
* @dev ERC-2771 specifies the context as being a single address (20 bytes).
*/
function _contextSuffixLength() internal pure returns (uint256) {
return 20;
}
// slither-disable-end dead-code
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import "./EntropyStructs.sol";
interface EntropyEvents {
event Registered(EntropyStructs.ProviderInfo provider);
event Requested(EntropyStructs.Request request);
event RequestedWithCallback(
address indexed provider,
address indexed requestor,
uint64 indexed sequenceNumber,
bytes32 userRandomNumber,
EntropyStructs.Request request
);
event Revealed(
EntropyStructs.Request request,
bytes32 userRevelation,
bytes32 providerRevelation,
bytes32 blockHash,
bytes32 randomNumber
);
event RevealedWithCallback(
EntropyStructs.Request request,
bytes32 userRandomNumber,
bytes32 providerRevelation,
bytes32 randomNumber
);
event ProviderFeeUpdated(address provider, uint128 oldFee, uint128 newFee);
event ProviderUriUpdated(address provider, bytes oldUri, bytes newUri);
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
contract EntropyStructs {
struct ProviderInfo {
uint128 feeInWei;
uint128 accruedFeesInWei;
// The commitment that the provider posted to the blockchain, and the sequence number
// where they committed to this. This value is not advanced after the provider commits,
// and instead is stored to help providers track where they are in the hash chain.
bytes32 originalCommitment;
uint64 originalCommitmentSequenceNumber;
// Metadata for the current commitment. Providers may optionally use this field to to help
// manage rotations (i.e., to pick the sequence number from the correct hash chain).
bytes commitmentMetadata;
// Optional URI where clients can retrieve revelations for the provider.
// Client SDKs can use this field to automatically determine how to retrieve random values for each provider.
// TODO: specify the API that must be implemented at this URI
bytes uri;
// The first sequence number that is *not* included in the current commitment (i.e., an exclusive end index).
// The contract maintains the invariant that sequenceNumber <= endSequenceNumber.
// If sequenceNumber == endSequenceNumber, the provider must rotate their commitment to add additional random values.
uint64 endSequenceNumber;
// The sequence number that will be assigned to the next inbound user request.
uint64 sequenceNumber;
// The current commitment represents an index/value in the provider's hash chain.
// These values are used to verify requests for future sequence numbers. Note that
// currentCommitmentSequenceNumber < sequenceNumber.
//
// The currentCommitment advances forward through the provider's hash chain as values
// are revealed on-chain.
bytes32 currentCommitment;
uint64 currentCommitmentSequenceNumber;
}
struct Request {
// Storage slot 1 //
address provider;
uint64 sequenceNumber;
// The number of hashes required to verify the provider revelation.
uint32 numHashes;
// Storage slot 2 //
// The commitment is keccak256(userCommitment, providerCommitment). Storing the hash instead of both saves 20k gas by
// eliminating 1 store.
bytes32 commitment;
// Storage slot 3 //
// The number of the block where this request was created.
// Note that we're using a uint64 such that we have an additional space for an address and other fields in
// this storage slot. Although block.number returns a uint256, 64 bits should be plenty to index all of the
// blocks ever generated.
uint64 blockNumber;
// The address that requested this random number.
address requester;
// If true, incorporate the blockhash of blockNumber into the generated random value.
bool useBlockhash;
// If true, the requester will be called back with the generated random value.
bool isRequestWithCallback;
// There are 2 remaining bytes of free space in this slot.
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
// c=<
// |
// | ////\ 1@2
// @@ | /___\** @@@2 @@@@@@@@@@@@@@@@@@@@@@
// @@@ | |~L~ |* @@@@@@ @@@ @@@@@ @@@@ @@@ @@@@ @@@ @@@@@@@@ @@@@ @@@@ @@@ @@@@@@@@@ @@@@ @@@@
// @@@@@ | \=_/8 @@@@1@@ @@@ @@@@@ @@@@ @@@@ @@@ @@@@@ @@@ @@@@@@@@@ @@@@ @@@@@ @@@@ @@@@@@@@@ @@@@ @@@@
// @@@@@@| _ /| |\__ @@@@@@@@2 @@@ @@@@@ @@@@ @@@@ @@@ @@@@@@@ @@@ @@@@ @@@@ @@@@@@ @@@@ @@@ @@@@@@@
// 1@@@@@@|\ \___/) @@1@@@@@2 ~~~ ~~~~~ @@@@ ~~@@ ~~~ ~~~~~~~~~~~ ~~~~ ~~~~ ~~~~~~~~~~~ ~@@ @@@@@
// 2@@@@@ | \ \ / | @@@@@@2 @@@ @@@@@ @@@@ @@@@ @@@ @@@@@@@@@@@ @@@@@@@@@ @@@@ @@@@@@@@@@@ @@@@@@@@@ @@@@@
// 2@@@@ |_ > <|__ @@1@12 @@@ @@@@@ @@@@ @@@@ @@@ @@@@ @@@@@@ @@@@ @@@@ @@@@ @@@@@@ @@@ @@@@@@@
// @@@@ / _| / \/ \ @@1@ @@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@@ @@@@ @@@@ @@@@ @@@@@ @@@@@@@@@ @@@@ @@@@
// @@ / |^\/ | | @@1 @@@ @@@@ @@@@ @@@ @@@@ @@@ @@@@ @@@@ @@@ @@@@ @@@@@@@@@ @@@@ @@@@
// / / ---- \ \\\= @@ @@@@@@@@@@@@@@@@@@@@@@
// \___/ -------- ~~ @@@
// @@ | | | | -- @@
// ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
library Error {
/*///////////////////////////////////////////////////////////////
GENERIC
///////////////////////////////////////////////////////////////*/
error AlreadyExists();
error DoesNotExist();
error Unauthorized();
error InvalidLength();
error NotOwner();
error InvalidWormholeChainId();
error InvalidCallerContext();
/*///////////////////////////////////////////////////////////////
ADDRESS
///////////////////////////////////////////////////////////////*/
error ImplementationMismatch(address implementation, address latestImplementation);
error InvalidWithdrawalAddress(address to);
error NullAddress();
error SameAddress();
error InvalidSolanaAddress();
error AddressAlreadySet();
error InsufficientAllowlistDelay();
/*///////////////////////////////////////////////////////////////
AMOUNT / BALANCE
///////////////////////////////////////////////////////////////*/
error InsufficientBalance();
error InsufficientWithdrawalAmount(uint256 amount);
error InsufficientBalanceForFee(uint256 balance, uint256 fee);
error InvalidNonce(bytes32 nonce);
error ZeroValue();
error AmountDeltaZeroValue();
error DecimalsMoreThan18(uint256 decimals);
error InsufficientBridgeAmount();
error BridgeMaxAmountExceeded();
error ETHTransferFailed();
error OutOfBounds();
/*///////////////////////////////////////////////////////////////
ACCOUNT
///////////////////////////////////////////////////////////////*/
error CreateAccountDisabled();
error InvalidKeysForSalt();
error PredictAddressDisabled();
error FundsRecoveryActivationDeadlinePending();
error InvalidAppAccount();
error InvalidAppBeacon();
/*///////////////////////////////////////////////////////////////
KEY MANAGEMENT
///////////////////////////////////////////////////////////////*/
error InvalidRequest();
error InvalidKeySignature(address from);
error KeyAlreadyInvalid();
error KeyAlreadyValid();
error KeyNotFound();
error CannotRemoveLastKey();
/*///////////////////////////////////////////////////////////////
GAS FEE REBATE
///////////////////////////////////////////////////////////////*/
error InvalidDeductGasFunction(bytes4 sig);
/*///////////////////////////////////////////////////////////////
FEATURE FLAGS
///////////////////////////////////////////////////////////////*/
error FundsRecoveryNotActive();
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
interface ICrateOpener {
/*///////////////////////////////////////////////////////////////
STRUCTS
///////////////////////////////////////////////////////////////*/
struct RequestInfo {
bytes32 userRandomBytes;
address crateHolder;
uint256 crateAmount;
bytes32 randomNumber;
bool processed;
}
/*///////////////////////////////////////////////////////////////
EVENTS
///////////////////////////////////////////////////////////////*/
event CrateOpeningRequested(
uint64 indexed sequenceNumber, bytes32 indexed userRandomBytes, address indexed crateHolder, uint256 crateAmount
);
event RandomNumberProcessed(
bytes32 indexed userRandomBytes,
uint64 indexed sequenceNumber,
address indexed crateHolder,
bytes32 randomNumber,
uint256 crateAmount,
uint256 remainingCrates
);
event KeeperAuthorizationSet(address indexed keeper, bool authorized);
/*///////////////////////////////////////////////////////////////
ERRORS
///////////////////////////////////////////////////////////////*/
error EthBalanceTooLow();
error RequestAlreadyProcessed();
error NotEnoughCrates();
error WithdrawalFailed();
/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Returns the entropy fee
* @return The Entropy fee
*/
function getEntropyFee() external view returns (uint128);
/**
* @notice Requests the opening of a crate by calling the Entropy contract.
* @param _crateHolder The address of the crate holder.
* @param _crateAmount The amount of crates to be opened.
* @param _userRandomNumber The random number provided by the caller.
* @return sequenceNumber The sequence number of the crate opening request given by Entropy
*/
function requestCrateOpening(address _crateHolder, uint256 _crateAmount, bytes32 _userRandomNumber)
external
returns (uint64 sequenceNumber);
/**
* @notice Sets an authorized keeper
* @param _keeper The address of the keeper
* @param _authorized A boolean indicating if the keeper is authorized
*/
function setAuthorizedKeeper(address _keeper, bool _authorized) external;
/**
* @notice Withdraws the ETH balance from the contract.
* @param _to The address to which the ETH balance will be transferred.
*/
function withdrawEth(address _to) external;
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
import "./EntropyEvents.sol";
interface IEntropy is EntropyEvents {
// 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;
// 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.
//
// 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 getDefaultProvider() external view returns (address provider);
function getRequest(
address provider,
uint64 sequenceNumber
) external view returns (EntropyStructs.Request memory req);
function getFee(address provider) external view returns (uint128 feeAmount);
function getAccruedPythFees()
external
view
returns (uint128 accruedPythFeesInWei);
function setProviderFee(uint128 newFeeInWei) external;
function setProviderUri(bytes calldata newUri) external;
function constructUserCommitment(
bytes32 userRandomness
) external pure returns (bytes32 userCommitment);
function combineRandomValues(
bytes32 userRandomness,
bytes32 providerRandomness,
bytes32 blockHash
) external pure returns (bytes32 combinedRandomness);
}
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
abstract contract IEntropyConsumer {
// This method is called by Entropy to provide the random number to the consumer.
// It asserts that the msg.sender is the Entropy contract. It is not meant to be
// override by the consumer.
function _entropyCallback(
uint64 sequence,
address provider,
bytes32 randomNumber
) external {
address entropy = getEntropy();
require(entropy != address(0), "Entropy address not set");
require(msg.sender == entropy, "Only Entropy can call this function");
entropyCallback(sequence, provider, randomNumber);
}
// getEntropy returns Entropy contract address. The method is being used to check that the
// callback is indeed from Entropy contract. The consumer is expected to implement this method.
// Entropy address can be found here - https://docs.pyth.network/entropy/contract-addresses
function getEntropy() internal view virtual returns (address);
// This method is expected to be implemented by the consumer to handle the random number.
// It will be called by _entropyCallback after _entropyCallback ensures that the call is
// indeed from Entropy contract.
function entropyCallback(
uint64 sequence,
address provider,
bytes32 randomNumber
) internal virtual;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
interface IPoints {
/*///////////////////////////////////////////////////////////////
EVENTS
///////////////////////////////////////////////////////////////*/
event MinterAuthorizationSet(address indexed keeper, bool authorized);
event Minted(address indexed account, uint256 amount);
event Burned(address indexed account, uint256 amount);
/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
///////////////////////////////////////////////////////////////*/
/**
* @notice Returns the name of the Points.
*/
function name() external view returns (string memory);
/**
* @notice Returns the balance of an account
* @param _account The address of the account
*/
function balanceOf(address _account) external view returns (uint256);
/**
* @notice Returns the total supply of governance points
*/
function totalSupply() external view returns (uint256);
/**
* @notice Returns whether an account is an authorized minter
* @param _account The address of the account
*/
function isAuthorizedMinter(address _account) external view returns (bool);
/**
* @notice Initializes the contract
* @param _owner The address of the owner
* @param _name The name of the Points
*/
function initialize(address _owner, string calldata _name) external;
/**
* @notice Increases the balance of an account by the specified amount
* @param _account The address of the account
* @param _amount The amount to increase the balance by
*/
function mint(address _account, uint256 _amount) external;
/**
* @notice Decreases the balance of an account by the specified amount
* @param _account The address of the account
* @param _amount The amount to decrease the balance by
*/
function burn(address _account, uint256 _amount) external;
/**
* @notice Sets an authorized minter
* @param _keeper The address of the minter
* @param _isAuthorized A boolean indicating if the minter is authorized
*/
function setAuthorizedMinter(address _keeper, bool _isAuthorized) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
/**
* @title Initializable module
*/
library Initializable {
// ------- Storage -------
struct InitializableStorageData {
bool initialized;
}
error AlreadyInitialized();
error NotInitialized();
/**
* @dev Returns the account stored at the specified account id.
*/
function getStorage() internal pure returns (InitializableStorageData storage data) {
bytes32 slot = keccak256(abi.encode("io.infinex.InitializableStorage"));
// solhint-disable-next-line no-inline-assembly
assembly {
data.slot := slot
}
}
// ------- Implementation -------
function initialize() internal {
InitializableStorageData storage data = getStorage();
// Note: We don't use onlyUninitialized here to save gas by preventing a double call to load().
if (data.initialized) revert AlreadyInitialized();
data.initialized = true;
}
modifier onlyInitialized() {
if (!getStorage().initialized) revert NotInitialized();
_;
}
modifier onlyUninitialized() {
if (getStorage().initialized) revert AlreadyInitialized();
_;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
{
"compilationTarget": {
"src/craterun/CrateOpener.sol": "CrateOpener"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity/",
":@synthetixio/core-contracts/=node_modules/@synthetixio/core-contracts/",
":@synthetixio/core-modules/=node_modules/@synthetixio/core-modules/",
":@synthetixio/main/=node_modules/@synthetixio/main/",
":@synthetixio/oracle-manager/=node_modules/@synthetixio/oracle-manager/",
":@synthetixio/perps-market/=node_modules/@synthetixio/perps-market/",
":@synthetixio/spot-market/=node_modules/@synthetixio/spot-market/",
":cannon-std/=lib/cannon-std/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":src/=src/",
":test/=test/",
":wormhole-circle-integration/=lib/wormhole-circle-integration/evm/src/",
":wormhole/=lib/wormhole-circle-integration/evm/src/"
]
}
[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_trustedForwarder","type":"address"},{"internalType":"address","name":"_entropy","type":"address"},{"internalType":"address","name":"_entropyProvider","type":"address"},{"internalType":"address","name":"_cratePoints","type":"address"},{"internalType":"uint256","name":"_totalCrates","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"EthBalanceTooLow","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"NotEnoughCrates","type":"error"},{"inputs":[],"name":"NullAddress","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"RequestAlreadyProcessed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"WithdrawalFailed","type":"error"},{"inputs":[],"name":"ZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"sequenceNumber","type":"uint64"},{"indexed":true,"internalType":"bytes32","name":"userRandomBytes","type":"bytes32"},{"indexed":true,"internalType":"address","name":"crateHolder","type":"address"},{"indexed":false,"internalType":"uint256","name":"crateAmount","type":"uint256"}],"name":"CrateOpeningRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"keeper","type":"address"},{"indexed":false,"internalType":"bool","name":"authorized","type":"bool"}],"name":"KeeperAuthorizationSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"userRandomBytes","type":"bytes32"},{"indexed":true,"internalType":"uint64","name":"sequenceNumber","type":"uint64"},{"indexed":true,"internalType":"address","name":"crateHolder","type":"address"},{"indexed":false,"internalType":"bytes32","name":"randomNumber","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"crateAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"remainingCrates","type":"uint256"}],"name":"RandomNumberProcessed","type":"event"},{"inputs":[{"internalType":"uint64","name":"sequence","type":"uint64"},{"internalType":"address","name":"provider","type":"address"},{"internalType":"bytes32","name":"randomNumber","type":"bytes32"}],"name":"_entropyCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"authorizedKeepers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cratePoints","outputs":[{"internalType":"contract IPoints","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entropy","outputs":[{"internalType":"contract IEntropy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"entropyProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEntropyFee","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"","type":"uint64"}],"name":"openingRequests","outputs":[{"internalType":"bytes32","name":"userRandomBytes","type":"bytes32"},{"internalType":"address","name":"crateHolder","type":"address"},{"internalType":"uint256","name":"crateAmount","type":"uint256"},{"internalType":"bytes32","name":"randomNumber","type":"bytes32"},{"internalType":"bool","name":"processed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"remainingCrates","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_crateHolder","type":"address"},{"internalType":"uint256","name":"_crateAmount","type":"uint256"},{"internalType":"bytes32","name":"_userRandomBytes","type":"bytes32"}],"name":"requestCrateOpening","outputs":[{"internalType":"uint64","name":"sequenceNumber","type":"uint64"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keeper","type":"address"},{"internalType":"bool","name":"_authorized","type":"bool"}],"name":"setAuthorizedKeeper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"withdrawEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]