Contract Name:
ProxyOracle
Contract Source Code:
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.1) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.1) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0-rc.1) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "../interface/IAccess.sol";
import "../interface/ILP.sol";
import "../interface/IPrematchCore.sol";
import "../interface/IProxyOracle.sol";
import "../utils/OwnableUpgradeable.sol";
/**
* @notice Operation of oracles management tool.
*/
contract ProxyOracle is OwnableUpgradeable, IProxyOracle {
IAccess public access;
ILP public lp;
uint128 reinforcementLimit;
/**
* @notice Throw if caller have no access to function with selector `selector`.
*/
modifier restricted(bytes4 selector) {
access.checkAccess(msg.sender, address(this), selector);
_;
}
function initialize(
address access_,
address lp_
) external virtual initializer {
__Ownable_init();
access = IAccess(access_);
lp = ILP(lp_);
reinforcementLimit = type(uint128).max;
}
/**
* @notice Owner: Change maximum condition reinforcement limit to `reinforcementLimit_`.
*/
function changeReinforcementLimit(
uint128 reinforcementLimit_
) external onlyOwner {
reinforcementLimit = reinforcementLimit_;
emit ReinforcementLimitChanged(reinforcementLimit_);
}
/**
* @notice The batch version of {ILP-createGame}.
* @param data an array of input data structures for creating games using {ILP-createGame}
*/
function createGames(
CreateGameData[] calldata data
) external restricted(this.createGames.selector) {
for (uint256 i = 0; i < data.length; ++i) {
lp.createGame(data[i].gameId, data[i].startsAt, data[i].data);
}
}
/**
* @notice The batch version of {ILP-cancelGame}.
* @param gameIds IDs of the games to be canceled
*/
function cancelGames(
uint256[] calldata gameIds
) external restricted(this.cancelGames.selector) {
for (uint256 i = 0; i < gameIds.length; ++i) {
lp.cancelGame(gameIds[i]);
}
}
/**
* @notice The batch version of {ILP-shiftGame}.
* @param data an array of input data structures for changing games start using {ILP-shiftGame}
*/
function shiftGames(
ShiftGameData[] calldata data
) external restricted(this.shiftGames.selector) {
for (uint256 i = 0; i < data.length; ++i) {
lp.shiftGame(data[i].gameId, data[i].startsAt);
}
}
/**
* @notice The batch version of {IPrematchCore-changeMargin}.
* @param core the address of the Core using for creating conditions
* @param data an array of input data structures for changing conditions margin using {IPrematchCore-changeMargin}
*/
function changeMargins(
address core,
changeMarginData[] calldata data
) external restricted(this.changeMargins.selector) {
IPrematchCore core_ = IPrematchCore(core);
for (uint256 i = 0; i < data.length; ++i)
core_.changeMargin(data[i].conditionId, data[i].margin);
}
/**
* @notice The batch version of {IPrematchCore-changeReinforcement}.
* @param core the address of the Core using for creating conditions
* @param data an array of input data structures for changing conditions reinforcement using {IPrematchCore-changeReinforcement}
*/
function changeReinforcements(
address core,
changeReinforcementData[] calldata data
) external restricted(this.changeReinforcements.selector) {
IPrematchCore core_ = IPrematchCore(core);
uint256 reinforcementLimit_ = reinforcementLimit;
uint128 reinforcement;
for (uint256 i = 0; i < data.length; ++i) {
reinforcement = data[i].reinforcement;
if (reinforcement > reinforcementLimit_)
revert TooLargeReinforcement();
core_.changeReinforcement(data[i].conditionId, reinforcement);
}
}
/**
* @notice Call `changeMargins` and `changeReinforcements` in the same time.
* @param core the address of the Core using for creating conditions
* @param data an array of input data structures for changing conditions settings
*/
function changeConditionSettings(
address core,
ChangeConditionSettingsData[] calldata data
) external restricted(this.changeReinforcements.selector) {
IPrematchCore core_ = IPrematchCore(core);
uint256 reinforcementLimit_ = reinforcementLimit;
for (uint256 i = 0; i < data.length; ++i) {
uint64 newMargin = data[i].margin;
uint128 newReinforcement = data[i].reinforcement;
uint256 conditionId = data[i].conditionId;
(uint128 reinforcement, uint64 margin) = core_.getConditionSettings(
conditionId
);
if (newReinforcement == reinforcement && newMargin == margin)
revert NothingChanged();
if (newReinforcement != reinforcement) {
if (reinforcement > reinforcementLimit_)
revert TooLargeReinforcement();
core_.changeReinforcement(conditionId, newReinforcement);
}
if (newMargin != margin) core_.changeMargin(conditionId, newMargin);
}
}
/**
* @notice The batch version of {IPrematchCore-createCondition}.
* @param core the address of the Core using for creating conditions
* @param data an array of input data structures for creating conditions using {IPrematchCore-createCondition}
*/
function createConditions(
address core,
CreateConditionData[] calldata data
) external restricted(this.createConditions.selector) {
IPrematchCore core_ = IPrematchCore(core);
uint256 reinforcementLimit_ = reinforcementLimit;
for (uint256 i = 0; i < data.length; ++i) {
CreateConditionData memory data_ = data[i];
uint128 reinforcement = data_.reinforcement;
if (reinforcement > reinforcementLimit_)
revert TooLargeReinforcement();
core_.createCondition(
data_.gameId,
data_.conditionId,
data_.odds,
data_.outcomes,
reinforcement,
data_.margin,
data_.winningOutcomesCount,
data_.isExpressForbidden,
data_.data
);
}
}
/**
* @notice The batch version of {IPrematchCore-cancelCondition}.
* @param core the address of the Core using for canceling conditions
* @param conditionIds IDs of the conditions to be canceled
*/
function cancelConditions(
address core,
uint256[] calldata conditionIds
) external restricted(this.cancelConditions.selector) {
IPrematchCore core_ = IPrematchCore(core);
for (uint256 i = 0; i < conditionIds.length; ++i) {
core_.cancelCondition(conditionIds[i]);
}
}
/**
* @notice The batch version of {IPrematchCore-changeOdds}.
* @param core the address of the Core using for changing odds
* @param data an array of input data structures for changing odds using {IPrematchCore-changeOdds}.
*/
function changeOdds(
address core,
ChangeOddsData[] calldata data
) external restricted(this.changeOdds.selector) {
IPrematchCore core_ = IPrematchCore(core);
for (uint256 i = 0; i < data.length; ++i) {
core_.changeOdds(data[i].conditionId, data[i].odds);
}
}
/**
* @notice The batch version of {IPrematchCore-resolveConditions}.
* @param core the address of the Core using for resolving conditions
* @param data an array of input data structures for resolving conditions using {IPrematchCore-resolveConditions}.
*/
function resolveConditions(
address core,
ResolveConditionData[] calldata data
) external restricted(this.resolveConditions.selector) {
IPrematchCore core_ = IPrematchCore(core);
for (uint256 i = 0; i < data.length; ++i) {
core_.resolveCondition(
data[i].conditionId,
data[i].winningOutcomes
);
}
}
/**
* @notice The batch version of {IPrematchCore-stopConditions}.
* @param core the address of the Core using for stopping conditions
* @param data an array of input data structures for stopping conditions using {IPrematchCore-stopConditions}.
*/
function stopConditions(
address core,
StopConditionData[] calldata data
) external restricted(this.stopConditions.selector) {
IPrematchCore core_ = IPrematchCore(core);
for (uint256 i = 0; i < data.length; ++i) {
core_.stopCondition(data[i].conditionId, data[i].flag);
}
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./IOwnable.sol";
interface IAccess is IOwnable {
struct RoleData {
address target; // target contract address
bytes4 selector; // target function selector
uint8 roleId; // ID of the role associated with contract-function combination
}
event RoleAdded(bytes32 indexed role, uint256 indexed roleId);
event RoleRenamed(bytes32 indexed role, uint8 indexed roleId);
event RoleBound(bytes32 indexed funcId, uint8 indexed roleId);
event RoleUnbound(bytes32 indexed funcId, uint8 indexed roleId);
event RoleGranted(address indexed user, uint8 indexed roleId);
event RoleRevoked(address indexed user, uint8 indexed roleId);
error NotTokenOwner();
error MaxRolesReached();
error AccessNotGranted();
error RoleAlreadyGranted();
function initialize() external;
function checkAccess(
address sender,
address _contract,
bytes4 selector
) external;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./IOwnable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol";
interface IAzuroBet is IOwnable, IERC721EnumerableUpgradeable {
function initialize(address core) external;
function burn(uint256 id) external;
function mint(address account) external returns (uint256);
error OnlyCore();
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
interface IBet {
struct BetData {
address affiliate; // address indicated as an affiliate when placing bet
uint64 minOdds;
bytes data; // core-specific customized bet data
}
error BetNotExists();
error SmallOdds();
/**
* @notice Register new bet.
* @param bettor wallet for emitting bet token
* @param amount amount of tokens to bet
* @param betData customized bet data
*/
function putBet(
address bettor,
uint128 amount,
BetData calldata betData
) external returns (uint256 tokenId);
function resolvePayout(
uint256 tokenId
) external returns (address account, uint128 payout);
function viewPayout(uint256 tokenId) external view returns (uint128 payout);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
interface ICondition {
enum ConditionState {
CREATED,
RESOLVED,
CANCELED,
PAUSED
}
struct Condition {
uint256 gameId;
uint128[] payouts;
uint128[] virtualFunds;
uint128 totalNetBets;
uint128 reinforcement;
uint128 fund;
uint64 margin;
uint64 endsAt;
uint48 lastDepositId;
uint8 winningOutcomesCount;
ConditionState state;
address oracle;
bool isExpressForbidden;
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./IBet.sol";
import "./ICondition.sol";
import "./ILP.sol";
import "./IOwnable.sol";
import "./IAzuroBet.sol";
interface ICoreBase is ICondition, IOwnable, IBet {
struct Bet {
uint256 conditionId;
uint128 amount;
uint128 payout;
uint64 outcome;
uint64 timestamp;
bool isPaid;
}
struct CoreBetData {
uint256 conditionId; // The match or game ID
uint64 outcomeId; // ID of predicted outcome
}
event ConditionCreated(
uint256 indexed gameId,
uint256 indexed conditionId,
uint64[] outcomes
);
event ConditionResolved(
uint256 indexed conditionId,
uint8 state,
uint64[] winningOutcomes,
int128 lpProfit
);
event ConditionStopped(uint256 indexed conditionId, bool flag);
event CreatedConditionMetadata(uint256 indexed conditionId, bytes data);
event ReinforcementChanged(
uint256 indexed conditionId,
uint128 newReinforcement
);
event MarginChanged(uint256 indexed conditionId, uint64 newMargin);
event OddsChanged(uint256 indexed conditionId, uint256[] newOdds);
error OnlyLp();
error AlreadyPaid();
error DuplicateOutcomes(uint64 outcome);
error IncorrectConditionId();
error IncorrectMargin();
error IncorrectReinforcement();
error NothingChanged();
error IncorrectTimestamp();
error IncorrectWinningOutcomesCount();
error IncorrectOutcomesCount();
error NoPendingReward();
error OnlyOracle(address);
error OutcomesAndOddsCountDiffer();
error StartOutOfRange(uint256 pendingRewardsCount);
error WrongOutcome();
error ZeroOdds();
error CantChangeFlag();
error ConditionAlreadyCreated();
error ConditionAlreadyResolved();
error ConditionNotFinished();
error ConditionNotExists();
error ConditionNotRunning();
error GameAlreadyStarted();
error InsufficientFund();
error ResolveTooEarly(uint64 waitTime);
function lp() external view returns (ILP);
function azuroBet() external view returns (IAzuroBet);
function initialize(address azuroBet, address lp) external;
function calcOdds(
uint256 conditionId,
uint128 amount,
uint64 outcome
) external view returns (uint64 odds);
/**
* @notice Change the current condition `conditionId` margin.
*/
function changeMargin(uint256 conditionId, uint64 newMargin) external;
/**
* @notice Change the current condition `conditionId` odds.
*/
function changeOdds(
uint256 conditionId,
uint256[] calldata newOdds
) external;
/**
* @notice Change the current condition `conditionId` reinforcement.
*/
function changeReinforcement(
uint256 conditionId,
uint128 newReinforcement
) external;
function getCondition(
uint256 conditionId
) external view returns (Condition memory);
/**
* @notice Get condition's reinforcement and margin by it's ID.
* @param conditionId the match or condition ID
* @return the condition struct
*/
function getConditionSettings(
uint256 conditionId
) external view returns (uint128, uint64);
/**
* @notice Indicate the condition `conditionId` as canceled.
* @notice The condition creator can always cancel it regardless of granted access tokens.
*/
function cancelCondition(uint256 conditionId) external;
/**
* @notice Indicate the status of condition `conditionId` bet lock.
* @param conditionId the match or condition ID
* @param flag if stop receiving bets for the condition or not
*/
function stopCondition(uint256 conditionId, bool flag) external;
/**
* @notice Register new condition.
* @param gameId the game ID the condition belongs
* @param conditionId the match or condition ID according to oracle's internal numbering
* @param odds start odds for [team 1, ..., team N]
* @param outcomes unique outcomes for the condition [outcome 1, ..., outcome N]
* @param reinforcement maximum amount of liquidity intended to condition reinforcement
* @param margin bookmaker commission
* @param winningOutcomesCount the number of winning outcomes of the Condition
* @param isExpressForbidden true - not allowed to use in express bets
* @param data the additional data to emit in the `CreatedConditionMetadata` event
*/
function createCondition(
uint256 gameId,
uint256 conditionId,
uint256[] calldata odds,
uint64[] calldata outcomes,
uint128 reinforcement,
uint64 margin,
uint8 winningOutcomesCount,
bool isExpressForbidden,
bytes calldata data
) external;
function getOutcomeIndex(
uint256 conditionId,
uint64 outcome
) external view returns (uint256);
function isOutcomeWinning(
uint256 conditionId,
uint64 outcome
) external view returns (bool);
function isConditionCanceled(
uint256 conditionId
) external view returns (bool);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./IBet.sol";
import "./IOwnable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol";
interface ILP is IOwnable, IERC721EnumerableUpgradeable {
enum FeeType {
DAO,
DATA_PROVIDER,
AFFILIATES
}
enum CoreState {
UNKNOWN,
ACTIVE,
INACTIVE
}
struct Condition {
address core;
uint256 conditionId;
}
struct CoreData {
CoreState state;
uint64 reinforcementAbility;
uint128 minBet;
uint128 lockedLiquidity;
}
struct Game {
bytes32 unusedVariable;
uint128 lockedLiquidity;
uint64 startsAt;
bool canceled;
}
struct Reward {
int128 amount;
uint64 claimedAt;
}
event CoreSettingsUpdated(
address indexed core,
CoreState state,
uint64 reinforcementAbility,
uint128 minBet
);
event AffiliateChanged(address newAffilaite);
event BettorWin(
address indexed core,
address indexed bettor,
uint256 tokenId,
uint256 amount
);
event ClaimTimeoutChanged(uint64 newClaimTimeout);
event DataProviderChanged(address newDataProvider);
event FeeChanged(FeeType feeType, uint64 fee);
event GameCanceled(uint256 indexed gameId);
event GameShifted(uint256 indexed gameId, uint64 newStart);
event LiquidityAdded(
address indexed account,
uint48 indexed depositId,
uint256 amount
);
event LiquidityDonated(
address indexed account,
uint48 indexed depositId,
uint256 amount
);
event LiquidityManagerChanged(address newLiquidityManager);
event LiquidityRemoved(
address indexed account,
uint48 indexed depositId,
uint256 amount
);
event MinBetChanged(address core, uint128 newMinBet);
event MinDepoChanged(uint128 newMinDepo);
event NewGame(uint256 indexed gameId, uint64 startsAt, bytes data);
event ReinforcementAbilityChanged(uint128 newReinforcementAbility);
event WithdrawTimeoutChanged(uint64 newWithdrawTimeout);
error OnlyFactory();
error SmallDepo();
error SmallDonation();
error BetExpired();
error CoreNotActive();
error ClaimTimeout(uint64 waitTime);
error DepositDoesNotExist();
error GameAlreadyCanceled();
error GameAlreadyCreated();
error GameCanceled_();
error GameNotExists();
error IncorrectCoreState();
error IncorrectFee();
error IncorrectGameId();
error IncorrectMinBet();
error IncorrectMinDepo();
error IncorrectReinforcementAbility();
error IncorrectTimestamp();
error LiquidityNotOwned();
error LiquidityIsLocked();
error NoLiquidity();
error NotEnoughLiquidity();
error SmallBet();
error UnknownCore();
error WithdrawalTimeout(uint64 waitTime);
function initialize(
address access,
address dataProvider,
address affiliate,
address token,
uint128 minDepo,
uint64 daoFee,
uint64 dataProviderFee,
uint64 affiliateFee
) external;
function addCore(address core) external;
function addLiquidity(
uint128 amount,
bytes calldata data
) external returns (uint48);
function withdrawLiquidity(
uint48 depositId,
uint40 percent
) external returns (uint128);
function viewPayout(
address core,
uint256 tokenId
) external view returns (uint128 payout);
function betFor(
address bettor,
address core,
uint128 amount,
uint64 expiresAt,
IBet.BetData calldata betData
) external returns (uint256 tokenId);
/**
* @notice Make new bet.
* @notice Emits bet token to `msg.sender`.
* @param core address of the Core the bet is intended
* @param amount amount of tokens to bet
* @param expiresAt the time before which bet should be made
* @param betData customized bet data
*/
function bet(
address core,
uint128 amount,
uint64 expiresAt,
IBet.BetData calldata betData
) external returns (uint256 tokenId);
function changeDataProvider(address newDataProvider) external;
function claimReward() external returns (uint128);
function getReserve() external view returns (uint128);
function addReserve(
uint256 gameId,
uint128 lockedReserve,
uint128 profitReserve,
uint48 depositId
) external;
function addCondition(uint256 gameId) external view returns (uint64);
function withdrawPayout(
address core,
uint256 tokenId
) external returns (uint128);
function changeLockedLiquidity(
uint256 gameId,
int128 deltaReserve
) external;
/**
* @notice Indicate the game `gameId` as canceled.
* @param gameId the game ID
*/
function cancelGame(uint256 gameId) external;
/**
* @notice Create new game.
* @param gameId the match or condition ID according to oracle's internal numbering
* @param startsAt timestamp when the game starts
* @param data the additional data to emit in the `NewGame` event
*/
function createGame(
uint256 gameId,
uint64 startsAt,
bytes calldata data
) external;
/**
* @notice Set `startsAt` as new game `gameId` start time.
* @param gameId the game ID
* @param startsAt new timestamp when the game starts
*/
function shiftGame(uint256 gameId, uint64 startsAt) external;
function getGameInfo(
uint256 gameId
) external view returns (uint64 startsAt, bool canceled);
function getLockedLiquidityLimit(
address core
) external view returns (uint128);
function isGameCanceled(
uint256 gameId
) external view returns (bool canceled);
function checkAccess(
address account,
address target,
bytes4 selector
) external;
function checkCore(address core) external view;
function getLastDepositId() external view returns (uint48 depositId);
function isDepositExists(uint256 depositId) external view returns (bool);
function token() external view returns (address);
function fees(uint256) external view returns (uint64);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
interface IOwnable {
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
function owner() external view returns (address);
function checkOwner(address account) external view;
function transferOwnership(address newOwner) external;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./ICoreBase.sol";
interface IPrematchCore is ICoreBase {
event NewBet(
address indexed bettor,
address indexed affiliate,
uint256 indexed conditionId,
uint256 tokenId,
uint64 outcomeId,
uint128 amount,
uint256 odds,
uint128[] funds
);
event NewBetMargin(uint256 indexed betId, uint256 margin);
/**
* @notice Indicate outcomes `winningOutcomes` as happened in condition `conditionId`.
* @notice See {CoreBase-_resolveCondition}.
*/
function resolveCondition(
uint256 conditionId,
uint64[] calldata winningOutcomes
) external;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
interface IProxyOracle {
struct ChangeOddsData {
uint256 conditionId;
uint256[] odds;
}
struct CreateConditionData {
uint256 gameId;
uint256 conditionId;
uint256[] odds;
uint64[] outcomes;
uint128 reinforcement;
uint64 margin;
uint8 winningOutcomesCount;
bool isExpressForbidden;
bytes data;
}
struct CreateGameData {
uint256 gameId;
uint64 startsAt;
bytes data;
}
struct ResolveConditionData {
uint256 conditionId;
uint64[] winningOutcomes;
}
struct ShiftGameData {
uint256 gameId;
uint64 startsAt;
}
struct StopConditionData {
uint256 conditionId;
bool flag;
}
struct ChangeConditionSettingsData {
uint256 conditionId;
uint64 margin;
uint128 reinforcement;
}
struct changeMarginData {
uint256 conditionId;
uint64 margin;
}
struct changeReinforcementData {
uint256 conditionId;
uint128 reinforcement;
}
event ReinforcementLimitChanged(uint256);
error NothingChanged();
error TooLargeReinforcement();
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "../interface/IOwnable.sol";
/**
* @dev Forked from OpenZeppelin contract:
* https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/ae03ee04ae226526abad6731cf4024134f46ae28/contracts/access/OwnableUpgradeable.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.
*
* By default, the owner account will be the one that deploys the contract. 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 OwnableUpgradeable is
IOwnable,
Initializable,
ContextUpgradeable
{
address private _owner;
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
checkOwner(_msgSender());
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual override returns (address) {
return _owner;
}
/**
* @dev Throws if the account is not the owner.
*/
function checkOwner(address account) public view virtual override {
require(owner() == account, "Ownable: account is not the owner");
}
/**
* @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 override onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}