|
{
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface AggregatorV3Interface {\n function decimals() external view returns (uint8);\n\n function description() external view returns (string memory);\n\n function version() external view returns (uint256);\n\n function getRoundData(uint80 _roundId)\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n\n function latestRoundData()\n external\n view\n returns (\n uint80 roundId,\n int256 answer,\n uint256 startedAt,\n uint256 updatedAt,\n uint80 answeredInRound\n );\n}\n"
|
|
},
|
|
"@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface VRFCoordinatorV2Interface {\n /**\n * @notice Get configuration relevant for making requests\n * @return minimumRequestConfirmations global min for request confirmations\n * @return maxGasLimit global max for request gas limit\n * @return s_provingKeyHashes list of registered key hashes\n */\n function getRequestConfig()\n external\n view\n returns (\n uint16,\n uint32,\n bytes32[] memory\n );\n\n /**\n * @notice Request a set of random words.\n * @param keyHash - Corresponds to a particular oracle job which uses\n * that key for generating the VRF proof. Different keyHash's have different gas price\n * ceilings, so you can select a specific one to bound your maximum per request cost.\n * @param subId - The ID of the VRF subscription. Must be funded\n * with the minimum subscription balance required for the selected keyHash.\n * @param minimumRequestConfirmations - How many blocks you'd like the\n * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS\n * for why you may want to request more. The acceptable range is\n * [minimumRequestBlockConfirmations, 200].\n * @param callbackGasLimit - How much gas you'd like to receive in your\n * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords\n * may be slightly less than this amount because of gas used calling the function\n * (argument decoding etc.), so you may need to request slightly more than you expect\n * to have inside fulfillRandomWords. The acceptable range is\n * [0, maxGasLimit]\n * @param numWords - The number of uint256 random values you'd like to receive\n * in your fulfillRandomWords callback. Note these numbers are expanded in a\n * secure way by the VRFCoordinator from a single random value supplied by the oracle.\n * @return requestId - A unique identifier of the request. Can be used to match\n * a request to a response in fulfillRandomWords.\n */\n function requestRandomWords(\n bytes32 keyHash,\n uint64 subId,\n uint16 minimumRequestConfirmations,\n uint32 callbackGasLimit,\n uint32 numWords\n ) external returns (uint256 requestId);\n\n /**\n * @notice Create a VRF subscription.\n * @return subId - A unique subscription id.\n * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.\n * @dev Note to fund the subscription, use transferAndCall. For example\n * @dev LINKTOKEN.transferAndCall(\n * @dev address(COORDINATOR),\n * @dev amount,\n * @dev abi.encode(subId));\n */\n function createSubscription() external returns (uint64 subId);\n\n /**\n * @notice Get a VRF subscription.\n * @param subId - ID of the subscription\n * @return balance - LINK balance of the subscription in juels.\n * @return reqCount - number of requests for this subscription, determines fee tier.\n * @return owner - owner of the subscription.\n * @return consumers - list of consumer address which are able to use this subscription.\n */\n function getSubscription(uint64 subId)\n external\n view\n returns (\n uint96 balance,\n uint64 reqCount,\n address owner,\n address[] memory consumers\n );\n\n /**\n * @notice Request subscription owner transfer.\n * @param subId - ID of the subscription\n * @param newOwner - proposed new owner of the subscription\n */\n function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;\n\n /**\n * @notice Request subscription owner transfer.\n * @param subId - ID of the subscription\n * @dev will revert if original owner of subId has\n * not requested that msg.sender become the new owner.\n */\n function acceptSubscriptionOwnerTransfer(uint64 subId) external;\n\n /**\n * @notice Add a consumer to a VRF subscription.\n * @param subId - ID of the subscription\n * @param consumer - New consumer which can use the subscription\n */\n function addConsumer(uint64 subId, address consumer) external;\n\n /**\n * @notice Remove a consumer from a VRF subscription.\n * @param subId - ID of the subscription\n * @param consumer - Consumer to remove from the subscription\n */\n function removeConsumer(uint64 subId, address consumer) external;\n\n /**\n * @notice Cancel a subscription\n * @param subId - ID of the subscription\n * @param to - Where to send the remaining LINK to\n */\n function cancelSubscription(uint64 subId, address to) external;\n\n /*\n * @notice Check to see if there exists a request commitment consumers\n * for all consumers and keyhashes for a given sub.\n * @param subId - ID of the subscription\n * @return true if there exists at least one unfulfilled request for the subscription, false\n * otherwise.\n */\n function pendingRequestExists(uint64 subId) external view returns (bool);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified\n * proxy whose upgrades are fully controlled by the current implementation.\n */\ninterface IERC1822ProxiableUpgradeable {\n /**\n * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation\n * address.\n *\n * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n * function revert if invoked through a proxy.\n */\n function proxiableUUID() external view returns (bytes32);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev This is the interface that {BeaconProxy} expects of its beacon.\n */\ninterface IBeaconUpgradeable {\n /**\n * @dev Must return an address that can be used as a delegate call target.\n *\n * {BeaconProxy} will check that this address is a contract.\n */\n function implementation() external view returns (address);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../beacon/IBeaconUpgradeable.sol\";\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\nimport \"../../utils/StorageSlotUpgradeable.sol\";\nimport \"../utils/Initializable.sol\";\n\n/**\n * @dev This abstract contract provides getters and event emitting update functions for\n * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.\n *\n * _Available since v4.1._\n *\n * @custom:oz-upgrades-unsafe-allow delegatecall\n */\nabstract contract ERC1967UpgradeUpgradeable is Initializable {\n function __ERC1967Upgrade_init() internal onlyInitializing {\n }\n\n function __ERC1967Upgrade_init_unchained() internal onlyInitializing {\n }\n // This is the keccak-256 hash of \"eip1967.proxy.rollback\" subtracted by 1\n bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;\n\n /**\n * @dev Storage slot with the address of the current implementation.\n * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n * validated in the constructor.\n */\n bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n /**\n * @dev Emitted when the implementation is upgraded.\n */\n event Upgraded(address indexed implementation);\n\n /**\n * @dev Returns the current implementation address.\n */\n function _getImplementation() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n }\n\n /**\n * @dev Stores a new address in the EIP1967 implementation slot.\n */\n function _setImplementation(address newImplementation) private {\n require(AddressUpgradeable.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n }\n\n /**\n * @dev Perform implementation upgrade\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeTo(address newImplementation) internal {\n _setImplementation(newImplementation);\n emit Upgraded(newImplementation);\n }\n\n /**\n * @dev Perform implementation upgrade with additional setup call.\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeToAndCall(\n address newImplementation,\n bytes memory data,\n bool forceCall\n ) internal {\n _upgradeTo(newImplementation);\n if (data.length > 0 || forceCall) {\n _functionDelegateCall(newImplementation, data);\n }\n }\n\n /**\n * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeToAndCallUUPS(\n address newImplementation,\n bytes memory data,\n bool forceCall\n ) internal {\n // Upgrades from old implementations will perform a rollback test. This test requires the new\n // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing\n // this special case will break upgrade paths from old UUPS implementation to new ones.\n if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {\n _setImplementation(newImplementation);\n } else {\n try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {\n require(slot == _IMPLEMENTATION_SLOT, \"ERC1967Upgrade: unsupported proxiableUUID\");\n } catch {\n revert(\"ERC1967Upgrade: new implementation is not UUPS\");\n }\n _upgradeToAndCall(newImplementation, data, forceCall);\n }\n }\n\n /**\n * @dev Storage slot with the admin of the contract.\n * This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n * validated in the constructor.\n */\n bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n /**\n * @dev Emitted when the admin account has changed.\n */\n event AdminChanged(address previousAdmin, address newAdmin);\n\n /**\n * @dev Returns the current admin.\n */\n function _getAdmin() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;\n }\n\n /**\n * @dev Stores a new address in the EIP1967 admin slot.\n */\n function _setAdmin(address newAdmin) private {\n require(newAdmin != address(0), \"ERC1967: new admin is the zero address\");\n StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;\n }\n\n /**\n * @dev Changes the admin of the proxy.\n *\n * Emits an {AdminChanged} event.\n */\n function _changeAdmin(address newAdmin) internal {\n emit AdminChanged(_getAdmin(), newAdmin);\n _setAdmin(newAdmin);\n }\n\n /**\n * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.\n * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.\n */\n bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;\n\n /**\n * @dev Emitted when the beacon is upgraded.\n */\n event BeaconUpgraded(address indexed beacon);\n\n /**\n * @dev Returns the current beacon.\n */\n function _getBeacon() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;\n }\n\n /**\n * @dev Stores a new beacon in the EIP1967 beacon slot.\n */\n function _setBeacon(address newBeacon) private {\n require(AddressUpgradeable.isContract(newBeacon), \"ERC1967: new beacon is not a contract\");\n require(\n AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),\n \"ERC1967: beacon implementation is not a contract\"\n );\n StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;\n }\n\n /**\n * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does\n * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).\n *\n * Emits a {BeaconUpgraded} event.\n */\n function _upgradeBeaconToAndCall(\n address newBeacon,\n bytes memory data,\n bool forceCall\n ) internal {\n _setBeacon(newBeacon);\n emit BeaconUpgraded(newBeacon);\n if (data.length > 0 || forceCall) {\n _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);\n }\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function _functionDelegateCall(address target, bytes memory data) private returns (bytes memory) {\n require(AddressUpgradeable.isContract(target), \"Address: delegate call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return AddressUpgradeable.verifyCallResult(success, returndata, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts.\n *\n * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n * constructor.\n *\n * Emits an {Initialized} event.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n * are added through upgrades and that require initialization.\n *\n * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n * cannot be nested. If one is invoked in the context of another, execution will revert.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n *\n * WARNING: setting the version to 255 will prevent any future reinitialization.\n *\n * Emits an {Initialized} event.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n *\n * Emits an {Initialized} event the first time it is successfully executed.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n\n /**\n * @dev Internal function that returns the initialized version. Returns `_initialized`\n */\n function _getInitializedVersion() internal view returns (uint8) {\n return _initialized;\n }\n\n /**\n * @dev Internal function that returns the initialized version. Returns `_initializing`\n */\n function _isInitializing() internal view returns (bool) {\n return _initializing;\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/UUPSUpgradeable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../ERC1967/ERC1967UpgradeUpgradeable.sol\";\nimport \"./Initializable.sol\";\n\n/**\n * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an\n * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.\n *\n * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is\n * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing\n * `UUPSUpgradeable` with a custom implementation of upgrades.\n *\n * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.\n *\n * _Available since v4.1._\n */\nabstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {\n function __UUPSUpgradeable_init() internal onlyInitializing {\n }\n\n function __UUPSUpgradeable_init_unchained() internal onlyInitializing {\n }\n /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment\n address private immutable __self = address(this);\n\n /**\n * @dev Check that the execution is being performed through a delegatecall call and that the execution context is\n * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case\n * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a\n * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to\n * fail.\n */\n modifier onlyProxy() {\n require(address(this) != __self, \"Function must be called through delegatecall\");\n require(_getImplementation() == __self, \"Function must be called through active proxy\");\n _;\n }\n\n /**\n * @dev Check that the execution is not being performed through a delegate call. This allows a function to be\n * callable on the implementing contract but not through proxies.\n */\n modifier notDelegated() {\n require(address(this) == __self, \"UUPSUpgradeable: must not be called through delegatecall\");\n _;\n }\n\n /**\n * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the\n * implementation. It is used to validate the implementation's compatibility when performing an upgrade.\n *\n * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.\n */\n function proxiableUUID() external view virtual override notDelegated returns (bytes32) {\n return _IMPLEMENTATION_SLOT;\n }\n\n /**\n * @dev Upgrade the implementation of the proxy to `newImplementation`.\n *\n * Calls {_authorizeUpgrade}.\n *\n * Emits an {Upgraded} event.\n */\n function upgradeTo(address newImplementation) external virtual onlyProxy {\n _authorizeUpgrade(newImplementation);\n _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);\n }\n\n /**\n * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call\n * encoded in `data`.\n *\n * Calls {_authorizeUpgrade}.\n *\n * Emits an {Upgraded} event.\n */\n function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {\n _authorizeUpgrade(newImplementation);\n _upgradeToAndCallUUPS(newImplementation, data, true);\n }\n\n /**\n * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by\n * {upgradeTo} and {upgradeToAndCall}.\n *\n * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.\n *\n * ```solidity\n * function _authorizeUpgrade(address) internal override onlyOwner {}\n * ```\n */\n function _authorizeUpgrade(address newImplementation) internal virtual;\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/PullPaymentUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (security/PullPayment.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/escrow/EscrowUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Simple implementation of a\n * https://consensys.github.io/smart-contract-best-practices/development-recommendations/general/external-calls/#favor-pull-over-push-for-external-calls[pull-payment]\n * strategy, where the paying contract doesn't interact directly with the\n * receiver account, which must withdraw its payments itself.\n *\n * Pull-payments are often considered the best practice when it comes to sending\n * Ether, security-wise. It prevents recipients from blocking execution, and\n * eliminates reentrancy concerns.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n *\n * To use, derive from the `PullPayment` contract, and use {_asyncTransfer}\n * instead of Solidity's `transfer` function. Payees can query their due\n * payments with {payments}, and retrieve them with {withdrawPayments}.\n *\n * @custom:storage-size 51\n */\nabstract contract PullPaymentUpgradeable is Initializable {\n EscrowUpgradeable private _escrow;\n\n function __PullPayment_init() internal onlyInitializing {\n __PullPayment_init_unchained();\n }\n\n function __PullPayment_init_unchained() internal onlyInitializing {\n _escrow = new EscrowUpgradeable();\n _escrow.initialize();\n }\n\n /**\n * @dev Withdraw accumulated payments, forwarding all gas to the recipient.\n *\n * Note that _any_ account can call this function, not just the `payee`.\n * This means that contracts unaware of the `PullPayment` protocol can still\n * receive funds this way, by having a separate account call\n * {withdrawPayments}.\n *\n * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.\n * Make sure you trust the recipient, or are either following the\n * checks-effects-interactions pattern or using {ReentrancyGuard}.\n *\n * @param payee Whose payments will be withdrawn.\n *\n * Causes the `escrow` to emit a {Withdrawn} event.\n */\n function withdrawPayments(address payable payee) public virtual {\n _escrow.withdraw(payee);\n }\n\n /**\n * @dev Returns the payments owed to an address.\n * @param dest The creditor's address.\n */\n function payments(address dest) public view returns (uint256) {\n return _escrow.depositsOf(dest);\n }\n\n /**\n * @dev Called by the payer to store the sent amount as credit to be pulled.\n * Funds sent in this way are stored in an intermediate {Escrow} contract, so\n * there is no danger of them being spent before withdrawal.\n *\n * @param dest The destination address of the funds.\n * @param amount The amount to transfer.\n *\n * Causes the `escrow` to emit a {Deposited} event.\n */\n function _asyncTransfer(address dest, uint256 amount) internal virtual {\n _escrow.deposit{value: amount}(dest);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be _NOT_ENTERED\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/escrow/EscrowUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/escrow/Escrow.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../access/OwnableUpgradeable.sol\";\nimport \"../AddressUpgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @title Escrow\n * @dev Base escrow contract, holds funds designated for a payee until they\n * withdraw them.\n *\n * Intended usage: This contract (and derived escrow contracts) should be a\n * standalone contract, that only interacts with the contract that instantiated\n * it. That way, it is guaranteed that all Ether will be handled according to\n * the `Escrow` rules, and there is no need to check for payable functions or\n * transfers in the inheritance tree. The contract that uses the escrow as its\n * payment method should be its owner, and provide public methods redirecting\n * to the escrow's deposit and withdraw.\n */\ncontract EscrowUpgradeable is Initializable, OwnableUpgradeable {\n function __Escrow_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Escrow_init_unchained() internal onlyInitializing {\n }\n function initialize() public virtual initializer {\n __Escrow_init();\n }\n using AddressUpgradeable for address payable;\n\n event Deposited(address indexed payee, uint256 weiAmount);\n event Withdrawn(address indexed payee, uint256 weiAmount);\n\n mapping(address => uint256) private _deposits;\n\n function depositsOf(address payee) public view returns (uint256) {\n return _deposits[payee];\n }\n\n /**\n * @dev Stores the sent amount as credit to be withdrawn.\n * @param payee The destination address of the funds.\n *\n * Emits a {Deposited} event.\n */\n function deposit(address payee) public payable virtual onlyOwner {\n uint256 amount = msg.value;\n _deposits[payee] += amount;\n emit Deposited(payee, amount);\n }\n\n /**\n * @dev Withdraw accumulated balance for a payee, forwarding all gas to the\n * recipient.\n *\n * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.\n * Make sure you trust the recipient, or are either following the\n * checks-effects-interactions pattern or using {ReentrancyGuard}.\n *\n * @param payee The address whose funds will be withdrawn and transferred to.\n *\n * Emits a {Withdrawn} event.\n */\n function withdraw(address payable payee) public virtual onlyOwner {\n uint256 payment = _deposits[payee];\n\n _deposits[payee] = 0;\n\n payee.sendValue(payment);\n\n emit Withdrawn(payee, payment);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlotUpgradeable {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n}\n"
|
|
},
|
|
"contracts/Drawing.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n\n// DO NOT CHANGE: this is the timestamp of the first Saturday evening in seconds since the Unix\n// Epoch. It's used to align the allowed drawing windows with Saturday evenings.\nuint constant FIRST_SATURDAY_EVENING = 244800;\n\n\nstruct DrawData {\n uint256 blockNumber;\n uint8[6] numbers;\n uint64[][5] winners;\n}\n\nstruct PrizeData {\n uint64 ticket;\n uint256 prize;\n}\n\n\nlibrary Drawing {\n function choose(uint n, uint k) public pure returns (uint) {\n if (k > n) {\n return 0;\n } else if (k == 0) {\n return 1;\n } else if (k * 2 > n) {\n return choose(n, n - k);\n } else {\n return n * choose(n - 1, k - 1) / k;\n }\n }\n\n function getCurrentDrawingWindow() public view returns (uint) {\n return FIRST_SATURDAY_EVENING + (block.timestamp - FIRST_SATURDAY_EVENING) / 7 days * 7 days;\n }\n\n function _ceil(uint time, uint window) private pure returns (uint) {\n return (time + window - 1) / window * window;\n }\n\n function nextDrawTime() public view returns (uint) {\n return FIRST_SATURDAY_EVENING + _ceil(block.timestamp - FIRST_SATURDAY_EVENING, 7 days);\n }\n\n function getRandomNumbersWithoutRepetitions(uint256 randomness)\n public pure returns (uint8[6] memory numbers)\n {\n uint8[90] memory source;\n for (uint8 i = 1; i <= 90; i++) {\n source[i - 1] = i;\n }\n for (uint i = 0; i < 6; i++) {\n uint j = i + randomness % (90 - i);\n randomness /= 90;\n numbers[i] = source[j];\n source[j] = source[i];\n }\n }\n\n function sortNumbersByTicketCount(uint64[][90] storage ticketsByNumber, uint8[6] memory numbers)\n public view returns (uint8[6] memory)\n {\n for (uint i = 0; i < numbers.length - 1; i++) {\n uint j = i;\n for (uint k = j + 1; k < numbers.length; k++) {\n if (ticketsByNumber[numbers[k] - 1].length < ticketsByNumber[numbers[j] - 1].length) {\n j = k;\n }\n }\n if (j != i) {\n uint8 t = numbers[i];\n numbers[i] = numbers[j];\n numbers[j] = t;\n }\n }\n return numbers;\n }\n}\n"
|
|
},
|
|
"contracts/Lottery.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';\nimport '@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol';\nimport '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/security/PullPaymentUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';\nimport '@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol';\n\nimport './Drawing.sol';\nimport './TicketIndex.sol';\nimport './TicketSet.sol';\nimport './UserTickets.sol';\n\n\n// This is in USD cents, so it's $1.50\nuint constant BASE_TICKET_PRICE_USD = 150;\n\n// ChainLink USD price feed (8 decimals)\naddress constant USD_PRICE_FEED = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;\n\n// Width of the weekly drawing window.\nuint constant DRAWING_WINDOW_WIDTH = 4 hours;\n\n// ChainLink VRF callback gas limit.\nuint32 constant VRF_CALLBACK_GAS_LIMIT = 300000;\n\n\ncontract Lottery is UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable,\n PullPaymentUpgradeable, ReentrancyGuardUpgradeable\n{\n using AddressUpgradeable for address payable;\n using UserTickets for TicketData[];\n using TicketSet for uint64[];\n using TicketIndex for uint64[][90];\n\n enum State {OPEN, DRAWING, DRAWN, CLOSING}\n\n VRFCoordinatorV2Interface private _vrfCoordinator;\n\n uint256 public baseTicketPrice;\n\n uint64 public nextTicketId;\n uint64 public currentRound;\n\n State public state;\n uint public nextDrawTime;\n\n mapping (address => TicketData[]) public ticketsByPlayer;\n\n address payable[] public playersByTicket;\n uint64[][90][] public ticketsByNumber;\n DrawData[] public draws;\n\n event NewTicketPrice(uint indexed round, uint256 price);\n event Ticket(uint indexed round, address indexed player, uint8[] numbers);\n event VRFRequest(uint indexed round, uint256 requestId);\n event Draw(uint indexed round, uint8[6] numbers, uint256 currentBalance);\n event CloseRound(uint indexed round, uint256 currentBalance);\n\n // Accept funds from ICO and possibly other sources in the future.\n receive() external payable {}\n\n /// @custom:oz-upgrades-unsafe-allow constructor\n constructor() {\n _disableInitializers();\n }\n\n function initialize(address vrfCoordinator) public initializer {\n __UUPSUpgradeable_init();\n __Ownable_init();\n __Pausable_init();\n __PullPayment_init();\n __ReentrancyGuard_init();\n _vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinator);\n _updateTicketPrice();\n nextTicketId = 0;\n currentRound = 0;\n ticketsByNumber.push();\n draws.push();\n state = State.OPEN;\n nextDrawTime = Drawing.nextDrawTime();\n }\n\n // Backfill missing block numbers in the DrawDatas.\n // See https://github.com/ethernalotto/lottery/issues/1.\n function fix_issue_1() public initializer {\n // https://etherscan.io/tx/0x9cbb48bda3fbd4d37b8c136208ef71f71608e4818727d2d99642fab9fa39b808\n draws[0].blockNumber = 16106543;\n // https://etherscan.io/tx/0xc4fdcd19755607fb4c50ca44927f87549ca261d468993aff13c5edb1b3c315b9\n draws[1].blockNumber = 16156614;\n // https://etherscan.io/tx/0xc4d265352446349bd1e9042fa6a066df37a678d5dc2ced7661812b6772d22b2f\n draws[2].blockNumber = 16206689;\n // https://etherscan.io/tx/0x3fd098318f8b07cf2956ae65c84998795dd4d2518a00e370c74e913c13c73b25\n draws[3].blockNumber = 16256857;\n // https://etherscan.io/tx/0x599d379c4ac688c2fb9669b426ec0f54f8331c838d48d761e32f005c42a55a46\n draws[4].blockNumber = 16307044;\n }\n\n function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}\n\n function _updateTicketPrice() private {\n AggregatorV3Interface priceFeed = AggregatorV3Interface(USD_PRICE_FEED);\n (, int256 price, , , ) = priceFeed.latestRoundData();\n baseTicketPrice = BASE_TICKET_PRICE_USD *\n uint256(10 ** (16 + priceFeed.decimals())) / uint256(price);\n emit NewTicketPrice(currentRound, baseTicketPrice);\n }\n\n function pause() public onlyOwner {\n _pause();\n }\n\n function unpause() public onlyOwner {\n _unpause();\n }\n\n function getTicketPrice(uint8[] calldata playerNumbers) public view returns (uint256) {\n require(state == State.OPEN, 'please wait for the next round');\n require(playerNumbers.length >= 6, 'too few numbers');\n require(playerNumbers.length <= 90, 'too many numbers');\n for (uint i = 0; i < playerNumbers.length; i++) {\n require(playerNumbers[i] > 0 && playerNumbers[i] <= 90, 'invalid numbers');\n for (uint j = i + 1; j < playerNumbers.length; j++) {\n require(playerNumbers[i] != playerNumbers[j], 'duplicate numbers');\n }\n }\n return baseTicketPrice * Drawing.choose(playerNumbers.length, 6);\n }\n\n function buyTicket(uint8[] calldata playerNumbers) public payable whenNotPaused nonReentrant {\n uint256 ticketPrice = getTicketPrice(playerNumbers);\n require(msg.value == ticketPrice, 'incorrect value, please check the price of your ticket');\n uint64 ticketId = nextTicketId++;\n ticketsByPlayer[msg.sender].push(TicketData({\n id: ticketId,\n round: currentRound,\n timestamp: uint64(block.timestamp),\n cardinality: uint64(playerNumbers.length)\n }));\n playersByTicket.push(payable(msg.sender));\n for (uint i = 0; i < playerNumbers.length; i++) {\n ticketsByNumber[currentRound][playerNumbers[i] - 1].push(ticketId);\n }\n emit Ticket(currentRound, msg.sender, playerNumbers);\n payable(owner()).sendValue(msg.value / 10);\n }\n\n function getTicketIds(address player) public view returns (uint64[] memory ids) {\n return ticketsByPlayer[player].getTicketIds();\n }\n\n function getTicketIdsForRound(address player, uint64 round)\n public view returns (uint64[] memory ids)\n {\n return ticketsByPlayer[player].getTicketIdsForRound(round);\n }\n\n function getTicket(uint64 ticketId) public view returns (\n address player, uint64 round, uint256 timestamp, uint8[] memory numbers)\n {\n player = playersByTicket[ticketId];\n require(player != address(0), 'invalid ticket');\n TicketData storage ticket = ticketsByPlayer[player].getTicket(ticketId);\n round = ticket.round;\n timestamp = ticket.timestamp;\n uint8[90] memory temp;\n uint count = 0;\n for (uint8 number = 0; number < 90; number++) {\n if (ticketsByNumber[ticket.round][number].contains(ticketId)) {\n temp[count++] = number + 1;\n }\n }\n numbers = new uint8[](count);\n for (uint i = 0; i < count; i++) {\n numbers[i] = temp[i];\n }\n }\n\n function canDraw() public view returns (bool) {\n if (block.timestamp < nextDrawTime) {\n return false;\n } else {\n return block.timestamp < Drawing.getCurrentDrawingWindow() + DRAWING_WINDOW_WIDTH;\n }\n }\n\n function draw(uint64 vrfSubscriptionId, bytes32 vrfKeyHash) public onlyOwner {\n require(state == State.OPEN, 'invalid state');\n require(canDraw(), 'the next drawing window has not started yet');\n state = State.DRAWING;\n nextDrawTime += 7 days;\n uint256 vrfRequestId = _vrfCoordinator.requestRandomWords(\n vrfKeyHash,\n vrfSubscriptionId,\n /*requestConfirmations=*/10,\n VRF_CALLBACK_GAS_LIMIT,\n /*numWords=*/1);\n emit VRFRequest(currentRound, vrfRequestId);\n }\n\n function cancelFailedDrawing() public onlyOwner {\n require(state == State.DRAWING, 'invalid state');\n require(\n block.timestamp > Drawing.getCurrentDrawingWindow() + DRAWING_WINDOW_WIDTH,\n 'cancellation not allowed inside a drawing window');\n state = State.OPEN;\n }\n\n function rawFulfillRandomWords(uint256, uint256[] memory randomWords) external whenNotPaused {\n require(msg.sender == address(_vrfCoordinator), 'permission denied');\n require(state == State.DRAWING, 'invalid state');\n draws[currentRound].blockNumber = block.number;\n draws[currentRound].numbers = Drawing.sortNumbersByTicketCount(\n ticketsByNumber[currentRound],\n Drawing.getRandomNumbersWithoutRepetitions(randomWords[0]));\n state = State.DRAWN;\n emit Draw(currentRound, draws[currentRound].numbers, address(this).balance);\n }\n\n function getDrawData(uint64 round)\n public view returns (uint256 blockNumber, uint8[6] memory numbers, uint64[][5] memory winners)\n {\n require(round < draws.length, 'invalid round number');\n require(round < draws.length - 1 || state > State.DRAWING, 'invalid state');\n DrawData storage data = draws[round];\n return (data.blockNumber, data.numbers, data.winners);\n }\n\n function findWinners() public onlyOwner {\n require(state == State.DRAWN, 'please call draw() first');\n draws[currentRound].winners = ticketsByNumber[currentRound].findWinningTickets(\n draws[currentRound].numbers);\n state = State.CLOSING;\n }\n\n function _getTicket(uint64 id) private view returns (TicketData storage) {\n return ticketsByPlayer[playersByTicket[id]].getTicket(id);\n }\n\n function _calculatePrizes(uint64[][5] storage winners) private view returns (PrizeData[] memory) {\n PrizeData[][5] memory prizes;\n uint count = 0;\n for (int i = 4; i >= 0; i--) {\n count += winners[uint(i)].length;\n prizes[uint(i)] = new PrizeData[](count);\n }\n uint offset = 0;\n for (int i = 4; i >= 0; i--) {\n uint ui = uint(i);\n uint maxMatches = ui + 2;\n for (uint j = 0; j < winners[ui].length; j++) {\n TicketData storage ticket = _getTicket(winners[ui][j]);\n for (int k = i; k >= 0; k--) {\n uint matches = uint(k) + 2;\n prizes[ui][offset + j] = PrizeData({\n ticket: winners[ui][j],\n prize: Drawing.choose(maxMatches, matches) *\n Drawing.choose(ticket.cardinality - maxMatches, 6 - matches)\n });\n }\n }\n offset += winners[ui].length;\n }\n uint256 jackpot = address(this).balance;\n for (uint i = 0; i < prizes.length; i++) {\n uint totalWeight = 0;\n for (uint j = 0; j < prizes[i].length; j++) {\n totalWeight += prizes[i][j].prize;\n }\n if (totalWeight > 0) {\n for (uint j = 0; j < prizes[i].length; j++) {\n uint weight = prizes[i][j].prize;\n prizes[i][j].prize = jackpot * weight * 18 / (totalWeight * 100);\n }\n } else {\n for (uint j = 0; j < prizes[i].length; j++) {\n prizes[i][j].prize = 0;\n }\n }\n }\n for (uint i = prizes.length - 1; i > 0; i--) {\n for (uint j = 0; j < prizes[i].length; j++) {\n prizes[0][j].prize += prizes[i][j].prize;\n }\n }\n return prizes[0];\n }\n\n function _reset() private {\n currentRound++;\n ticketsByNumber.push();\n draws.push();\n state = State.OPEN;\n _updateTicketPrice();\n }\n\n function closeRound() public onlyOwner {\n require(state == State.CLOSING, 'please call findWinners() first');\n uint256 jackpot = address(this).balance;\n PrizeData[] memory prizes = _calculatePrizes(draws[currentRound].winners);\n for (uint i = 0; i < prizes.length; i++) {\n _asyncTransfer(playersByTicket[prizes[i].ticket], prizes[i].prize);\n }\n emit CloseRound(currentRound, jackpot);\n delete prizes;\n _reset();\n }\n}\n"
|
|
},
|
|
"contracts/TicketIndex.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport './TicketSet.sol';\n\n\nlibrary TicketIndex {\n using TicketSet for uint64[];\n\n function findWinningTickets(uint64[][90] storage ticketsByNumber, uint8[6] storage numbers)\n public view returns (uint64[][5] memory winners)\n {\n winners = [\n new uint64[](0), // tickets matching exactly 2 numbers\n new uint64[](0), // tickets matching exactly 3 numbers\n new uint64[](0), // tickets matching exactly 4 numbers\n new uint64[](0), // tickets matching exactly 5 numbers\n new uint64[](0) // tickets matching exactly 6 numbers\n ];\n uint8[6] memory i = [0, 0, 0, 0, 0, 0];\n for (i[0] = 0; i[0] < numbers.length; i[0]++) {\n uint64[] memory tickets0 = ticketsByNumber[numbers[i[0]] - 1];\n if (tickets0.length > 0) {\n for (i[1] = i[0] + 1; i[1] < numbers.length; i[1]++) {\n uint64[] memory tickets1 = tickets0.intersect(\n ticketsByNumber[numbers[i[1]] - 1]);\n if (tickets1.length > 0) {\n tickets0 = tickets0.subtract(tickets1);\n for (i[2] = i[1] + 1; i[2] < numbers.length; i[2]++) {\n uint64[] memory tickets2 = tickets1.intersect(\n ticketsByNumber[numbers[i[2]] - 1]);\n if (tickets2.length > 0) {\n tickets1 = tickets1.subtract(tickets2);\n for (i[3] = i[2] + 1; i[3] < numbers.length; i[3]++) {\n uint64[] memory tickets3 = tickets2.intersect(\n ticketsByNumber[numbers[i[3]] - 1]);\n if (tickets3.length > 0) {\n tickets2 = tickets2.subtract(tickets3);\n for (i[4] = i[3] + 1; i[4] < numbers.length; i[4]++) {\n uint64[] memory tickets4 = tickets3.intersect(\n ticketsByNumber[numbers[i[4]] - 1]);\n if (tickets4.length > 0) {\n tickets3 = tickets3.subtract(tickets4);\n for (i[5] = i[4] + 1; i[5] < numbers.length; i[5]++) {\n uint64[] memory tickets5 = tickets4.intersect(\n ticketsByNumber[numbers[i[5]] - 1]);\n if (tickets5.length > 0) {\n tickets4 = tickets4.subtract(tickets5);\n winners[4] = winners[4].union(tickets5);\n }\n delete tickets5;\n }\n winners[3] = winners[3].union(tickets4);\n }\n delete tickets4;\n }\n winners[2] = winners[2].union(tickets3);\n }\n delete tickets3;\n }\n winners[1] = winners[1].union(tickets2);\n }\n delete tickets2;\n }\n winners[0] = winners[0].union(tickets1);\n }\n delete tickets1;\n }\n }\n delete tickets0;\n }\n delete i;\n for (uint j = 0; j < winners.length - 1; j++) {\n for (uint k = j + 1; k < winners.length; k++) {\n winners[j] = winners[j].subtract(winners[k]);\n }\n }\n }\n}\n"
|
|
},
|
|
"contracts/TicketSet.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n\nlibrary TicketSet {\n function contains(uint64[] storage array, uint64 ticketId) public view returns (bool) {\n uint i = 0;\n uint j = array.length;\n while (j > i) {\n uint k = i + ((j - i) >> 1);\n if (ticketId < array[k]) {\n j = k;\n } else if (ticketId > array[k]) {\n i = k + 1;\n } else {\n return true;\n }\n }\n return false;\n }\n\n function _advanceTo(uint64[] memory array, uint offset, uint64 minValue)\n private pure returns (uint)\n {\n uint i = 1;\n uint j = 2;\n while (offset + j < array.length && array[offset + j] < minValue) {\n i = j + 1;\n j <<= 1;\n }\n while (i < j) {\n uint k = i + ((j - i) >> 1);\n if (offset + k >= array.length || array[offset + k] > minValue) {\n j = k;\n } else if (array[offset + k] < minValue) {\n i = k + 1;\n } else {\n return offset + k;\n }\n }\n return offset + i;\n }\n\n function _advanceToStorage(uint64[] storage array, uint offset, uint64 minValue)\n private view returns (uint)\n {\n uint i = 1;\n uint j = 2;\n while (offset + j < array.length && array[offset + j] < minValue) {\n i = j + 1;\n j <<= 1;\n }\n while (i < j) {\n uint k = i + ((j - i) >> 1);\n if (offset + k >= array.length || array[offset + k] > minValue) {\n j = k;\n } else if (array[offset + k] < minValue) {\n i = k + 1;\n } else {\n return offset + k;\n }\n }\n return offset + i;\n }\n\n function _shrink(uint64[] memory array, uint count)\n private pure returns (uint64[] memory result)\n {\n if (count < array.length) {\n result = new uint64[](count);\n for (uint i = 0; i < result.length; i++) {\n result[i] = array[i];\n }\n delete array;\n } else {\n result = array;\n }\n }\n\n function intersect(uint64[] memory first, uint64[] storage second)\n public view returns (uint64[] memory result)\n {\n uint capacity = second.length < first.length ? second.length : first.length;\n result = new uint64[](capacity);\n uint i = 0;\n uint j = 0;\n uint k = 0;\n while (i < first.length && j < second.length) {\n if (first[i] < second[j]) {\n i = _advanceTo(first, i, second[j]);\n } else if (second[j] < first[i]) {\n j = _advanceToStorage(second, j, first[i]);\n } else {\n result[k++] = first[i];\n i++;\n j++;\n }\n }\n return _shrink(result, k);\n }\n\n function subtract(uint64[] memory left, uint64[] memory right)\n public pure returns (uint64[] memory)\n {\n if (right.length == 0) {\n return left;\n }\n uint i = 0;\n uint j = 0;\n uint k = 0;\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n left[k++] = left[i++];\n } else if (left[i] > right[j]) {\n j = _advanceTo(right, j, left[i]);\n } else {\n i++;\n j++;\n }\n }\n while (i < left.length) {\n left[k++] = left[i++];\n }\n return _shrink(left, k);\n }\n\n function union(uint64[] memory left, uint64[] memory right)\n public pure returns (uint64[] memory result)\n {\n if (right.length == 0) {\n return left;\n }\n result = new uint64[](left.length + right.length);\n uint i = 0;\n uint j = 0;\n uint k = 0;\n while (i < left.length && j < right.length) {\n if (left[i] < right[j]) {\n result[k++] = left[i++];\n } else if (left[i] > right[j]) {\n result[k++] = right[j++];\n } else {\n result[k++] = left[i];\n i++;\n j++;\n }\n }\n while (i < left.length) {\n result[k++] = left[i++];\n }\n delete left;\n while (j < right.length) {\n result[k++] = right[j++];\n }\n return _shrink(result, k);\n }\n}\n"
|
|
},
|
|
"contracts/UserTickets.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n\nstruct TicketData {\n uint64 id;\n uint64 round;\n uint64 timestamp;\n uint64 cardinality;\n}\n\n\nlibrary UserTickets {\n function _lowerBound(TicketData[] storage tickets, uint64 round) private view returns (uint64) {\n uint64 i = 0;\n uint64 j = uint64(tickets.length);\n while (j > i) {\n uint64 k = i + ((j - i) >> 1);\n if (round > tickets[k].round) {\n i = k + 1;\n } else {\n j = k;\n }\n }\n return i;\n }\n\n function _upperBound(TicketData[] storage tickets, uint64 round) private view returns (uint64) {\n uint64 i = 0;\n uint64 j = uint64(tickets.length);\n while (j > i) {\n uint64 k = i + ((j - i) >> 1);\n if (round < tickets[k].round) {\n j = k;\n } else {\n i = k + 1;\n }\n }\n return j;\n }\n\n function getTicketIds(TicketData[] storage tickets) public view returns (uint64[] memory ids) {\n ids = new uint64[](tickets.length);\n for (uint64 i = 0; i < tickets.length; i++) {\n ids[i] = tickets[i].id;\n }\n }\n\n function getTicketIdsForRound(TicketData[] storage tickets, uint64 round)\n public view returns (uint64[] memory ids)\n {\n uint64 min = _lowerBound(tickets, round);\n uint64 max = _upperBound(tickets, round);\n ids = new uint64[](max - min);\n for (uint64 i = min; i < max; i++) {\n ids[i - min] = tickets[i].id;\n }\n }\n\n function getTicket(TicketData[] storage tickets, uint64 ticketId)\n public view returns (TicketData storage)\n {\n uint64 i = 0;\n uint64 j = uint64(tickets.length);\n while (j > i) {\n uint64 k = i + ((j - i) >> 1);\n if (ticketId < tickets[k].id) {\n j = k;\n } else if (ticketId > tickets[k].id) {\n i = k + 1;\n } else {\n return tickets[k];\n }\n }\n revert('invalid ticket ID');\n }\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"debug": {
|
|
"revertStrings": "strip"
|
|
},
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 1000000
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"libraries": {
|
|
"contracts/Drawing.sol": {
|
|
"Drawing": "0x11495f6ccc540a23c263974d58db38ef336508d6"
|
|
},
|
|
"contracts/TicketIndex.sol": {
|
|
"TicketIndex": "0x93b7efb02d70085bbf2c91a9e3814817b39ae152"
|
|
},
|
|
"contracts/TicketSet.sol": {
|
|
"TicketSet": "0x0d2c2c745950d122ae9ab24838d5b8734c9bcbc4"
|
|
},
|
|
"contracts/UserTickets.sol": {
|
|
"UserTickets": "0x5b4634c423687e2320be4641cd3747a60dcf08a7"
|
|
}
|
|
}
|
|
}
|
|
} |