Source Code
Overview
POL Balance
More Info
ContractCreator
Multichain Info
N/A
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
8102293 | 243 days ago | Contract Creation | 0 POL |
Loading...
Loading
Contract Name:
FreeBet
Compiler Version
v0.8.16+commit.07a7930e
Optimization Enabled:
Yes with 2 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.9; import "../interface/IAccess.sol"; import "../interface/ILP.sol"; import "../interface/IOwnable.sol"; import "../interface/ICoreBase.sol"; import "../libraries/FixedMath.sol"; import "../utils/OwnableUpgradeable.sol"; import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@uniswap/lib/contracts/libraries/TransferHelper.sol"; interface IFreeBet is IOwnable { struct FreeBet_ { address owner; address core; uint256 azuroBetId; uint128 amount; uint128 payout; uint256 conditionId; uint64 outcomeId; uint64 odds; } struct FreeBetData { uint256 chainId; uint256 freeBetId; address owner; uint128 amount; uint64 minOdds; uint64 expiresAt; } event AffiliateChanged(address newAffiliate); event BettorWin( address indexed core, address indexed bettor, uint256 indexed freeBetId, uint256 amount ); event NewBet( uint256 indexed freeBetId, address core, address indexed bettor, uint256 indexed azuroBetId, uint128 amount, uint64 minOdds, uint64 expiresAt ); event LpChanged(address indexed newLp); event ManagerChanged(address newManager); event PayoutsResolved(uint256[] azuroBetId); error AlreadyResolved(); error BetAlreadyClaimed(); error BetDoesNotExist(); error BetExpired(); error InsufficientContractBalance(); error IncorrectChainId(); error InvalidSignature(); error OnlyFreeBetOwner(); error OnlyManager(); error SmallMinOdds(); function initialize( address lpAddress, address affiliate, address manager ) external; } /// @title This tool enables the granting of free bets to any user through an airdrop distribution using a Merkle tree. contract FreeBet is OwnableUpgradeable, IFreeBet { using ECDSA for bytes32; using FixedMath for *; mapping(uint256 => FreeBet_) public freeBets; uint256 public lockedReserve; address public affiliate; address public manager; address public token; ILP public lp; /** * @notice Throw if caller is not a Manager. */ modifier onlyManager() { if (msg.sender != manager) revert OnlyManager(); _; } receive() external payable { require(msg.sender == token); } function initialize( address lpAddress, address affiliate_, address manager_ ) external initializer { __Ownable_init(); ILP lp_ = ILP(lpAddress); token = lp_.token(); lp = lp_; affiliate = affiliate_; manager = manager_; } /** * @notice Owner: Set affiliate address for each bet made through free bet redeem. */ function setAffiliate(address affiliate_) external onlyOwner { affiliate = affiliate_; emit AffiliateChanged(affiliate_); } /** * @notice Owner: Bound the contract with Liquidity Pool 'lp'. */ function setLp(address lp_) external onlyOwner { lp = ILP(lp_); emit LpChanged(lp_); } /** * @notice Owner: Set a manager. The manager is responsible for issuing new free bets and withdrawing funds locked * in the smart contract */ function setManager(address manager_) external onlyOwner { manager = manager_; emit ManagerChanged(manager_); } /** * @notice Withdraw unlocked token reserves. * @param amount amount to withdraw */ function withdrawReserve(uint256 amount) external onlyManager { _checkInsufficient(amount); TransferHelper.safeTransfer(token, msg.sender, amount); } /** * @notice Make free bet. * @notice See {ILP-bet}. * @param freeBetData the Manager's response that contains the free bet data as well as additional * data necessary to ensure that the manager's signature will not be reused for another bet. * @param signature the Manager's signature on `freeBetData`. * @return azuroBetId Minted AzuroBet token ID */ function bet( FreeBetData calldata freeBetData, bytes memory signature, address core, uint256 conditionId, uint64 outcomeId, uint64 deadline, uint64 minOdds ) external returns (uint256 azuroBetId) { _verifySignature(freeBetData, signature); _checkInsufficient(freeBetData.amount); FreeBet_ storage freeBet = freeBets[freeBetData.freeBetId]; if (freeBetData.chainId != _getChainId()) revert IncorrectChainId(); if (freeBetData.owner != msg.sender) revert OnlyFreeBetOwner(); if (freeBetData.expiresAt <= block.timestamp) revert BetExpired(); if (freeBet.owner != address(0)) revert BetAlreadyClaimed(); if (minOdds < freeBetData.minOdds) revert SmallMinOdds(); freeBet.owner = msg.sender; freeBet.core = core; freeBet.amount = freeBetData.amount; freeBet.conditionId = conditionId; freeBet.outcomeId = outcomeId; freeBet.odds = ICoreBase(core).calcOdds( conditionId, freeBetData.amount, outcomeId ); TransferHelper.safeApprove(token, address(lp), freeBetData.amount); azuroBetId = lp.bet( core, freeBetData.amount, deadline, IBet.BetData(affiliate, minOdds, abi.encode(conditionId, outcomeId)) ); freeBet.azuroBetId = azuroBetId; emit NewBet( freeBetData.freeBetId, core, msg.sender, azuroBetId, freeBetData.amount, freeBetData.minOdds, freeBetData.expiresAt ); } /** * @notice Resolve the payout for already redeemed free bets with IDs `freeBetIds`. */ function resolvePayout(uint256[] calldata freeBetIds) external { uint256 length = freeBetIds.length; for (uint256 i = 0; i < length; ++i) { uint256 freeBetId = freeBetIds[i]; uint256 payout = _resolvePayout(freeBetId); freeBets[freeBetId].payout = uint128(payout); lockedReserve += payout; } emit PayoutsResolved(freeBetIds); } /** * @notice Withdraw the payout for already redeemed free bet with ID `freeBetId`. */ function withdrawPayout(uint256 freeBetId) external { FreeBet_ storage freeBet = freeBets[freeBetId]; address bettor = freeBet.owner; if (bettor == address(0)) revert BetDoesNotExist(); uint256 payout; if (freeBet.amount == 0) { // was resolved payout = freeBet.payout; if (payout > 0) { freeBet.payout = 0; lockedReserve -= payout; } } else { // was not resolved payout = _resolvePayout(freeBetId); } if (payout > 0) TransferHelper.safeTransfer(token, bettor, payout); emit BettorWin(freeBet.core, bettor, freeBetId, payout); } /** * @notice Resolve the payout for already redeemed free bet with ID `freeBetId`. */ function _resolvePayout( uint256 freeBetId ) internal returns (uint256 payout) { FreeBet_ storage freeBet = freeBets[freeBetId]; uint256 betAmount = freeBet.amount; if (betAmount == 0) revert AlreadyResolved(); freeBet.amount = 0; try lp.withdrawPayout(freeBet.core, freeBet.azuroBetId) returns ( uint128 fullPayout ) { return (fullPayout > betAmount) ? (fullPayout - betAmount) : 0; } catch (bytes memory reason) { if (bytes4(reason) == ICoreBase.AlreadyPaid.selector) return ICoreBase(freeBet.core).isOutcomeWinning( freeBet.conditionId, freeBet.outcomeId ) ? freeBet.odds.mul(betAmount) - betAmount : 0; assembly { revert(add(32, reason), mload(reason)) } } } /** * @notice Gets the current chain ID. * @return The chain ID. */ function _getChainId() internal view returns (uint256) { uint256 chainId; assembly { chainId := chainid() } return chainId; } /** * @notice Verifies the signature of the oracle response. * @param freeBetData The manager response to be verified. * @param signature The signature to be validated. */ function _verifySignature( FreeBetData memory freeBetData, bytes memory signature ) internal view { bytes32 message = keccak256(abi.encode(freeBetData)); bytes32 hash = message.toEthSignedMessageHash(); address signer = hash.recover(signature); if (manager != signer) revert InvalidSignature(); } /** * @notice Throw if the contract free reserves of tokens `tokens` are less than `amount`. */ function _checkInsufficient(uint256 amount) internal view { if (IERC20(token).balanceOf(address(this)) < lockedReserve + amount) revert InsufficientContractBalance(); } } /// @title Azuro FreeBet contract factory. contract FreeBetFactory is OwnableUpgradeable { address public freeBetBeacon; IAccess public access; event NewFreeBet( address indexed freeBetAddress, address indexed lpAddress, address affiliate, address manager ); /** * @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 accessAddress) external initializer { __Ownable_init(); access = IAccess(accessAddress); UpgradeableBeacon freeBetBeacon_ = new UpgradeableBeacon( address(new FreeBet()) ); freeBetBeacon_.transferOwnership(msg.sender); freeBetBeacon = address(freeBetBeacon_); } /** * @notice Deploy a new FreeBet contract. * @param lpAddress Liquidity Pool's address for which FreeBets will be issued. * @param affiliate Address to be used as the affiliate address in minted FreeBets. * @param manager Address that manages the FreeBets. */ function createFreeBet( address lpAddress, address affiliate, address manager ) external restricted(this.createFreeBet.selector) { address freeBetAddress = address(new BeaconProxy(freeBetBeacon, "")); IFreeBet freeBet = IFreeBet(freeBetAddress); freeBet.initialize(lpAddress, affiliate, manager); freeBet.transferOwnership(msg.sender); emit NewFreeBet(freeBetAddress, lpAddress, affiliate, manager); } }
// 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: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * 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 Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { 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); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/beacon/BeaconProxy.sol) pragma solidity ^0.8.0; import "./IBeacon.sol"; import "../Proxy.sol"; import "../ERC1967/ERC1967Upgrade.sol"; /** * @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}. * * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't * conflict with the storage layout of the implementation behind the proxy. * * _Available since v3.4._ */ contract BeaconProxy is Proxy, ERC1967Upgrade { /** * @dev Initializes the proxy with `beacon`. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This * will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity * constructor. * * Requirements: * * - `beacon` must be a contract with the interface {IBeacon}. */ constructor(address beacon, bytes memory data) payable { _upgradeBeaconToAndCall(beacon, data, false); } /** * @dev Returns the current beacon address. */ function _beacon() internal view virtual returns (address) { return _getBeacon(); } /** * @dev Returns the current implementation address of the associated beacon. */ function _implementation() internal view virtual override returns (address) { return IBeacon(_getBeacon()).implementation(); } /** * @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. * * Requirements: * * - `beacon` must be a contract. * - The implementation returned by `beacon` must be a contract. */ function _setBeacon(address beacon, bytes memory data) internal virtual { _upgradeBeaconToAndCall(beacon, data, false); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/UpgradeableBeacon.sol) pragma solidity ^0.8.0; import "./IBeacon.sol"; import "../../access/Ownable.sol"; import "../../utils/Address.sol"; /** * @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their * implementation contract, which is where they will delegate all function calls. * * An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon. */ contract UpgradeableBeacon is IBeacon, Ownable { address private _implementation; /** * @dev Emitted when the implementation returned by the beacon is changed. */ event Upgraded(address indexed implementation); /** * @dev Sets the address of the initial implementation, and the deployer account as the owner who can upgrade the * beacon. */ constructor(address implementation_) { _setImplementation(implementation_); } /** * @dev Returns the current implementation address. */ function implementation() public view virtual override returns (address) { return _implementation; } /** * @dev Upgrades the beacon to a new implementation. * * Emits an {Upgraded} event. * * Requirements: * * - msg.sender must be the owner of the contract. * - `newImplementation` must be a contract. */ function upgradeTo(address newImplementation) public virtual onlyOwner { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Sets the implementation contract address for this beacon * * Requirements: * * - `newImplementation` must be a contract. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract"); _implementation = newImplementation; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeacon.sol"; import "../../interfaces/draft-IERC1822.sol"; import "../../utils/Address.sol"; import "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967Upgrade { // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS( address newImplementation, bytes memory data, bool forceCall ) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overridden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overridden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @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 functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // 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; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } if (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.6.0; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false library TransferHelper { function safeApprove( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::safeApprove: approve failed' ); } function safeTransfer( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::safeTransfer: transfer failed' ); } function safeTransferFrom( address token, address from, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require( success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper::transferFrom: transferFrom failed' ); } function safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'TransferHelper::safeTransferETH: ETH transfer failed'); } }
// 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 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 */ function createCondition( uint256 gameId, uint256 conditionId, uint256[] calldata odds, uint64[] calldata outcomes, uint128 reinforcement, uint64 margin, uint8 winningOutcomesCount, bool isExpressForbidden ) 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; /// @title Fixed-point math tools library FixedMath { uint256 constant ONE = 1e12; /** * @notice Get the ratio of `self` and `other` that is larger than 'ONE'. */ function ratio( uint256 self, uint256 other ) internal pure returns (uint256) { return self > other ? div(self, other) : div(other, self); } function mul(uint256 self, uint256 other) internal pure returns (uint256) { return (self * other) / ONE; } function div(uint256 self, uint256 other) internal pure returns (uint256) { return (self * ONE) / other; } /** * @notice Implementation of the sigmoid function. * @notice The sigmoid function is commonly used in machine learning to limit output values within a range of 0 to 1. */ function sigmoid(uint256 self) internal pure returns (uint256) { return (self * ONE) / (self + ONE); } }
// 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; }
{ "optimizer": { "enabled": true, "runs": 2 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"inputs":[],"name":"AlreadyResolved","type":"error"},{"inputs":[],"name":"BetAlreadyClaimed","type":"error"},{"inputs":[],"name":"BetDoesNotExist","type":"error"},{"inputs":[],"name":"BetExpired","type":"error"},{"inputs":[],"name":"IncorrectChainId","type":"error"},{"inputs":[],"name":"InsufficientContractBalance","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"OnlyFreeBetOwner","type":"error"},{"inputs":[],"name":"OnlyManager","type":"error"},{"inputs":[],"name":"SmallMinOdds","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newAffiliate","type":"address"}],"name":"AffiliateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"core","type":"address"},{"indexed":true,"internalType":"address","name":"bettor","type":"address"},{"indexed":true,"internalType":"uint256","name":"freeBetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BettorWin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newLp","type":"address"}],"name":"LpChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newManager","type":"address"}],"name":"ManagerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"freeBetId","type":"uint256"},{"indexed":false,"internalType":"address","name":"core","type":"address"},{"indexed":true,"internalType":"address","name":"bettor","type":"address"},{"indexed":true,"internalType":"uint256","name":"azuroBetId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"amount","type":"uint128"},{"indexed":false,"internalType":"uint64","name":"minOdds","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"expiresAt","type":"uint64"}],"name":"NewBet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256[]","name":"azuroBetId","type":"uint256[]"}],"name":"PayoutsResolved","type":"event"},{"inputs":[],"name":"affiliate","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"freeBetId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint64","name":"minOdds","type":"uint64"},{"internalType":"uint64","name":"expiresAt","type":"uint64"}],"internalType":"struct IFreeBet.FreeBetData","name":"freeBetData","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"address","name":"core","type":"address"},{"internalType":"uint256","name":"conditionId","type":"uint256"},{"internalType":"uint64","name":"outcomeId","type":"uint64"},{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"minOdds","type":"uint64"}],"name":"bet","outputs":[{"internalType":"uint256","name":"azuroBetId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"checkOwner","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"freeBets","outputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"core","type":"address"},{"internalType":"uint256","name":"azuroBetId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"payout","type":"uint128"},{"internalType":"uint256","name":"conditionId","type":"uint256"},{"internalType":"uint64","name":"outcomeId","type":"uint64"},{"internalType":"uint64","name":"odds","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"lpAddress","type":"address"},{"internalType":"address","name":"affiliate_","type":"address"},{"internalType":"address","name":"manager_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lockedReserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lp","outputs":[{"internalType":"contract ILP","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"freeBetIds","type":"uint256[]"}],"name":"resolvePayout","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"affiliate_","type":"address"}],"name":"setAffiliate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"lp_","type":"address"}],"name":"setLp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"manager_","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"freeBetId","type":"uint256"}],"name":"withdrawPayout","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawReserve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561001057600080fd5b50611f03806100206000396000f3fe6080604052600436106100d25760003560e01c80632bbb56d9146100f5578063313c06a0146101155780633e696f381461014b5780633f1d64d81461016b5780634177ad0a1461018f57806345e05f43146101af578063481c6a75146101cf5780636346d5d5146101ef5780638da5cb5b146102d0578063b21c7935146102e5578063c0c53b8b14610305578063d0ebdbe714610325578063d5a1c67614610345578063e0e3671c14610365578063f2fde38b14610385578063f4c2baa9146103a5578063fc0c546a146103c557600080fd5b366100f0576069546001600160a01b031633146100ee57600080fd5b005b600080fd5b34801561010157600080fd5b506100ee61011036600461186d565b6103e5565b34801561012157600080fd5b50606a54610135906001600160a01b031681565b604051610142919061188a565b60405180910390f35b34801561015757600080fd5b506100ee61016636600461189e565b610444565b34801561017757600080fd5b5061018160665481565b604051908152602001610142565b34801561019b57600080fd5b506101816101aa36600461191d565b610492565b3480156101bb57600080fd5b50606754610135906001600160a01b031681565b3480156101db57600080fd5b50606854610135906001600160a01b031681565b3480156101fb57600080fd5b5061027461020a36600461189e565b6065602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b0394851695939094169391926001600160801b0380831693600160801b90930416916001600160401b0380821691600160401b90041688565b604080516001600160a01b03998a168152989097166020890152958701949094526001600160801b0392831660608701529116608085015260a08401526001600160401b0390811660c08401521660e082015261010001610142565b3480156102dc57600080fd5b506101356108f4565b3480156102f157600080fd5b506100ee61030036600461189e565b610903565b34801561031157600080fd5b506100ee610320366004611a1c565b610a16565b34801561033157600080fd5b506100ee61034036600461186d565b610bde565b34801561035157600080fd5b506100ee610360366004611a67565b610c32565b34801561037157600080fd5b506100ee61038036600461186d565b610cff565b34801561039157600080fd5b506100ee6103a036600461186d565b610d71565b3480156103b157600080fd5b506100ee6103c036600461186d565b610de8565b3480156103d157600080fd5b50606954610135906001600160a01b031681565b6103ee33610cff565b606780546001600160a01b0319166001600160a01b0383161790556040517fe19055046dfef573b2fa49ecf8a090264a874d696fa77fabec601b1c602e342a9061043990839061188a565b60405180910390a150565b6068546001600160a01b0316331461046f5760405163605919ad60e11b815260040160405180910390fd5b61047881610e3b565b60695461048f906001600160a01b03163383610ed9565b50565b60006104ac6104a6368a90038a018a611af0565b8861100c565b6104cd6104bf60808a0160608b01611b8a565b6001600160801b0316610e3b565b6020888101356000908152606590915260409020468935146105025760405163a971329360e01b815260040160405180910390fd5b3361051360608b0160408c0161186d565b6001600160a01b03161461053a57604051637004584560e01b815260040160405180910390fd5b4261054b60c08b0160a08c01611ba7565b6001600160401b03161161057257604051637a0ef04360e11b815260040160405180910390fd5b80546001600160a01b03161561059b57604051633e81d50f60e01b815260040160405180910390fd5b6105ab60a08a0160808b01611ba7565b6001600160401b0316836001600160401b031610156105dd57604051631004a1eb60e21b815260040160405180910390fd5b8054336001600160a01b03199182161782556001820180549091166001600160a01b03891617905561061560808a0160608b01611b8a565b6003820180546001600160801b0319166001600160801b0392909216919091179055600481018690556005810180546001600160401b0319166001600160401b0387161790556001600160a01b03871663b78b89e98761067b60808d0160608e01611b8a565b6040516001600160e01b031960e085901b16815260048101929092526001600160801b031660248201526001600160401b0388166044820152606401602060405180830381865afa1580156106d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f89190611bc4565b6005820180546001600160401b0392909216600160401b02600160401b600160801b0319909216919091179055606954606a5461075a916001600160a01b03908116911661074c60808d0160608e01611b8a565b6001600160801b031661110c565b606a546001600160a01b031663ec24ffbf8861077c60808d0160608e01611b8a565b604080516060810182526067546001600160a01b031681526001600160401b03891660208083019190915282518b938301916107bc918f918f9101611be1565b6040516020818303038152906040528152506040518563ffffffff1660e01b81526004016107ed9493929190611c1c565b6020604051808303816000875af115801561080c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108309190611ca6565b915081816002018190555081336001600160a01b03168a602001357f7882ff8aae17c4e7d08db056041b488d5550a7468d561c0f7d0b1a1d772e12158a8d60600160208101906108809190611b8a565b8e60800160208101906108939190611ba7565b8f60a00160208101906108a69190611ba7565b604080516001600160a01b039590951685526001600160801b039390931660208501526001600160401b0391821684840152166060830152519081900360800190a450979650505050505050565b6033546001600160a01b031690565b600081815260656020526040902080546001600160a01b03168061093a57604051633f9b7dd560e11b815260040160405180910390fd5b60038201546000906001600160801b0316810361099e57506003820154600160801b90046001600160801b03168015610999576003830180546001600160801b0316905560668054829190600090610993908490611cd5565b90915550505b6109aa565b6109a784611236565b90505b80156109c7576069546109c7906001600160a01b03168383610ed9565b600183015460405182815285916001600160a01b03858116929116907f53df85a6d27721f38c9c99d095a4c565f68a5e74f22f17c711578461253cbef29060200160405180910390a450505050565b600054610100900460ff1615808015610a365750600054600160ff909116105b80610a505750303b158015610a50575060005460ff166001145b610ab85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015610adb576000805461ff0019166101001790555b610ae3611444565b6000849050806001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4a9190611ce8565b606980546001600160a01b03199081166001600160a01b0393841617909155606a8054821693831693909317909255606780548316868316179055606880549092169084161790558015610bd8576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b610be733610cff565b606880546001600160a01b0319166001600160a01b0383161790556040517f198db6e425fb8aafd1823c6ca50be2d51e5764571a5ae0f0f21c6812e45def0b9061043990839061188a565b8060005b81811015610cc0576000848483818110610c5257610c52611d05565b9050602002013590506000610c6682611236565b600083815260656020526040812060030180546001600160801b03808516600160801b029116179055606680549293508392909190610ca6908490611d1b565b92505081905550505080610cb990611d2e565b9050610c36565b507fc6d0d5351deeb034178080b2dd43535abe01ba1281d34a70e9914f5451dd31638383604051610cf2929190611d47565b60405180910390a1505050565b806001600160a01b0316610d116108f4565b6001600160a01b03161461048f5760405162461bcd60e51b815260206004820152602160248201527f4f776e61626c653a206163636f756e74206973206e6f7420746865206f776e656044820152603960f91b6064820152608401610aaf565b610d7a33610cff565b6001600160a01b038116610ddf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610aaf565b61048f8161147d565b610df133610cff565b606a80546001600160a01b0319166001600160a01b0383169081179091556040517f5f7748c284ee1ce72903c01c317ef43dd5a82d24aa3376bf246e98f8b3b74da190600090a250565b80606654610e499190611d1b565b6069546040516370a0823160e01b81526001600160a01b03909116906370a0823190610e7990309060040161188a565b602060405180830381865afa158015610e96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eba9190611ca6565b101561048f5760405163786e0a9960e01b815260040160405180910390fd5b600080846001600160a01b031663a9059cbb8585604051602401610efe929190611d80565b6040516020818303038152906040529060e01b6020820180516001600160e01b038381831617835250505050604051610f379190611d99565b6000604051808303816000865af19150503d8060008114610f74576040519150601f19603f3d011682016040523d82523d6000602084013e610f79565b606091505b5091509150818015610fa3575080511580610fa3575080806020019051810190610fa39190611db5565b6110055760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608401610aaf565b5050505050565b6040805183516020808301919091528085015182840152848301516001600160a01b03166060808401919091528501516001600160801b03166080808401919091528501516001600160401b0390811660a0808501919091528601511660c0808401919091528351808403909101815260e0830184528051908201207b0ca2ba3432b932bab69029b4b3b732b21026b2b9b9b0b3b29d05199960211b61010084015261011c8084018290528451808503909101815261013c909301909352815191012060006110db82856114cf565b6068549091506001600160a01b0380831691161461100557604051638baa579f60e01b815260040160405180910390fd5b600080846001600160a01b031663095ea7b38585604051602401611131929190611d80565b6040516020818303038152906040529060e01b6020820180516001600160e01b03838183161783525050505060405161116a9190611d99565b6000604051808303816000865af19150503d80600081146111a7576040519150601f19603f3d011682016040523d82523d6000602084013e6111ac565b606091505b50915091508180156111d65750805115806111d65750808060200190518101906111d69190611db5565b6110055760405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b6064820152608401610aaf565b600081815260656020526040812060038101546001600160801b0316808303611272576040516336ab81e160e11b815260040160405180910390fd5b6003820180546001600160801b0319169055606a5460018301546002840154604051630161d07760e41b81526001600160a01b039384169363161d0770936112bf93911691600401611d80565b6020604051808303816000875af19250505080156112fa575060408051601f3d908101601f191682019092526112f791810190611dd7565b60015b61141a573d808015611328576040519150601f19603f3d011682016040523d82523d6000602084013e61132d565b606091505b50630d70a0e360e41b61133f82611df4565b6001600160e01b031916036114125760018301546004808501546005860154604051631ec956b360e01b81526001600160a01b0390941693631ec956b39361139293926001600160401b03169101611be1565b602060405180830381865afa1580156113af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113d39190611db5565b6113de576000611409565b600583015482906113ff90600160401b90046001600160401b0316826114f5565b6114099190611cd5565b95945050505050565b805181602001fd5b81816001600160801b031611611431576000611409565b611409826001600160801b038316611cd5565b600054610100900460ff1661146b5760405162461bcd60e51b8152600401610aaf90611e2b565b611473611518565b61147b61153f565b565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008060006114de858561156f565b915091506114eb816115b4565b5090505b92915050565b600064e8d4a510006115078385611e76565b6115119190611e95565b9392505050565b600054610100900460ff1661147b5760405162461bcd60e51b8152600401610aaf90611e2b565b600054610100900460ff166115665760405162461bcd60e51b8152600401610aaf90611e2b565b61147b3361147d565b60008082516041036115a55760208301516040840151606085015160001a61159987828585611765565b945094505050506115ad565b506000905060025b9250929050565b60008160048111156115c8576115c8611eb7565b036115d05750565b60018160048111156115e4576115e4611eb7565b0361162c5760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b6044820152606401610aaf565b600281600481111561164057611640611eb7565b0361168d5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610aaf565b60038160048111156116a1576116a1611eb7565b036116f95760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610aaf565b600481600481111561170d5761170d611eb7565b0361048f5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610aaf565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03831115611792575060009050600361183f565b8460ff16601b141580156117aa57508460ff16601c14155b156117bb575060009050600461183f565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561180f573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166118385760006001925092505061183f565b9150600090505b94509492505050565b6001600160a01b038116811461048f57600080fd5b803561186881611848565b919050565b60006020828403121561187f57600080fd5b813561151181611848565b6001600160a01b0391909116815260200190565b6000602082840312156118b057600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156118f5576118f56118b7565b604052919050565b6001600160401b038116811461048f57600080fd5b8035611868816118fd565b600080600080600080600087890361018081121561193a57600080fd5b60c081121561194857600080fd5b5087965060c08701356001600160401b038082111561196657600080fd5b818a0191508a601f83011261197a57600080fd5b81358181111561198c5761198c6118b7565b61199f601f8201601f19166020016118cd565b91508082528b60208285010111156119b657600080fd5b8060208401602084013760009082016020015296506119d9905060e0890161185d565b945061010088013593506119f06101208901611912565b92506119ff6101408901611912565b9150611a0e6101608901611912565b905092959891949750929550565b600080600060608486031215611a3157600080fd5b8335611a3c81611848565b92506020840135611a4c81611848565b91506040840135611a5c81611848565b809150509250925092565b60008060208385031215611a7a57600080fd5b82356001600160401b0380821115611a9157600080fd5b818501915085601f830112611aa557600080fd5b813581811115611ab457600080fd5b8660208260051b8501011115611ac957600080fd5b60209290920196919550909350505050565b6001600160801b038116811461048f57600080fd5b600060c08284031215611b0257600080fd5b60405160c081016001600160401b0381118282101715611b2457611b246118b7565b806040525082358152602083013560208201526040830135611b4581611848565b60408201526060830135611b5881611adb565b60608201526080830135611b6b816118fd565b608082015260a0830135611b7e816118fd565b60a08201529392505050565b600060208284031215611b9c57600080fd5b813561151181611adb565b600060208284031215611bb957600080fd5b8135611511816118fd565b600060208284031215611bd657600080fd5b8151611511816118fd565b9182526001600160401b0316602082015260400190565b60005b83811015611c13578181015183820152602001611bfb565b50506000910152565b600060018060a01b03808716835260018060801b038616602084015260018060401b038086166040850152608060608501528185511660808501528060208601511660a085015250506040830151606060c084015280518060e0850152610100611c8c8282870160208601611bf8565b80601f19601f840116860101935050505095945050505050565b600060208284031215611cb857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b818103818111156114ef576114ef611cbf565b600060208284031215611cfa57600080fd5b815161151181611848565b634e487b7160e01b600052603260045260246000fd5b808201808211156114ef576114ef611cbf565b600060018201611d4057611d40611cbf565b5060010190565b6020808252810182905260006001600160fb1b03831115611d6757600080fd5b8260051b80856040850137919091016040019392505050565b6001600160a01b03929092168252602082015260400190565b60008251611dab818460208701611bf8565b9190910192915050565b600060208284031215611dc757600080fd5b8151801515811461151157600080fd5b600060208284031215611de957600080fd5b815161151181611adb565b805160208201516001600160e01b03198082169291906004831015611e235780818460040360031b1b83161693505b505050919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000816000190483118215151615611e9057611e90611cbf565b500290565b600082611eb257634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220e65696860e7dfdfec5eb1fe374e27b92c171b7196b605b52493e8c99f5bdaab564736f6c63430008100033
Deployed Bytecode
0x6080604052600436106100d25760003560e01c80632bbb56d9146100f5578063313c06a0146101155780633e696f381461014b5780633f1d64d81461016b5780634177ad0a1461018f57806345e05f43146101af578063481c6a75146101cf5780636346d5d5146101ef5780638da5cb5b146102d0578063b21c7935146102e5578063c0c53b8b14610305578063d0ebdbe714610325578063d5a1c67614610345578063e0e3671c14610365578063f2fde38b14610385578063f4c2baa9146103a5578063fc0c546a146103c557600080fd5b366100f0576069546001600160a01b031633146100ee57600080fd5b005b600080fd5b34801561010157600080fd5b506100ee61011036600461186d565b6103e5565b34801561012157600080fd5b50606a54610135906001600160a01b031681565b604051610142919061188a565b60405180910390f35b34801561015757600080fd5b506100ee61016636600461189e565b610444565b34801561017757600080fd5b5061018160665481565b604051908152602001610142565b34801561019b57600080fd5b506101816101aa36600461191d565b610492565b3480156101bb57600080fd5b50606754610135906001600160a01b031681565b3480156101db57600080fd5b50606854610135906001600160a01b031681565b3480156101fb57600080fd5b5061027461020a36600461189e565b6065602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b0394851695939094169391926001600160801b0380831693600160801b90930416916001600160401b0380821691600160401b90041688565b604080516001600160a01b03998a168152989097166020890152958701949094526001600160801b0392831660608701529116608085015260a08401526001600160401b0390811660c08401521660e082015261010001610142565b3480156102dc57600080fd5b506101356108f4565b3480156102f157600080fd5b506100ee61030036600461189e565b610903565b34801561031157600080fd5b506100ee610320366004611a1c565b610a16565b34801561033157600080fd5b506100ee61034036600461186d565b610bde565b34801561035157600080fd5b506100ee610360366004611a67565b610c32565b34801561037157600080fd5b506100ee61038036600461186d565b610cff565b34801561039157600080fd5b506100ee6103a036600461186d565b610d71565b3480156103b157600080fd5b506100ee6103c036600461186d565b610de8565b3480156103d157600080fd5b50606954610135906001600160a01b031681565b6103ee33610cff565b606780546001600160a01b0319166001600160a01b0383161790556040517fe19055046dfef573b2fa49ecf8a090264a874d696fa77fabec601b1c602e342a9061043990839061188a565b60405180910390a150565b6068546001600160a01b0316331461046f5760405163605919ad60e11b815260040160405180910390fd5b61047881610e3b565b60695461048f906001600160a01b03163383610ed9565b50565b60006104ac6104a6368a90038a018a611af0565b8861100c565b6104cd6104bf60808a0160608b01611b8a565b6001600160801b0316610e3b565b6020888101356000908152606590915260409020468935146105025760405163a971329360e01b815260040160405180910390fd5b3361051360608b0160408c0161186d565b6001600160a01b03161461053a57604051637004584560e01b815260040160405180910390fd5b4261054b60c08b0160a08c01611ba7565b6001600160401b03161161057257604051637a0ef04360e11b815260040160405180910390fd5b80546001600160a01b03161561059b57604051633e81d50f60e01b815260040160405180910390fd5b6105ab60a08a0160808b01611ba7565b6001600160401b0316836001600160401b031610156105dd57604051631004a1eb60e21b815260040160405180910390fd5b8054336001600160a01b03199182161782556001820180549091166001600160a01b03891617905561061560808a0160608b01611b8a565b6003820180546001600160801b0319166001600160801b0392909216919091179055600481018690556005810180546001600160401b0319166001600160401b0387161790556001600160a01b03871663b78b89e98761067b60808d0160608e01611b8a565b6040516001600160e01b031960e085901b16815260048101929092526001600160801b031660248201526001600160401b0388166044820152606401602060405180830381865afa1580156106d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106f89190611bc4565b6005820180546001600160401b0392909216600160401b02600160401b600160801b0319909216919091179055606954606a5461075a916001600160a01b03908116911661074c60808d0160608e01611b8a565b6001600160801b031661110c565b606a546001600160a01b031663ec24ffbf8861077c60808d0160608e01611b8a565b604080516060810182526067546001600160a01b031681526001600160401b03891660208083019190915282518b938301916107bc918f918f9101611be1565b6040516020818303038152906040528152506040518563ffffffff1660e01b81526004016107ed9493929190611c1c565b6020604051808303816000875af115801561080c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108309190611ca6565b915081816002018190555081336001600160a01b03168a602001357f7882ff8aae17c4e7d08db056041b488d5550a7468d561c0f7d0b1a1d772e12158a8d60600160208101906108809190611b8a565b8e60800160208101906108939190611ba7565b8f60a00160208101906108a69190611ba7565b604080516001600160a01b039590951685526001600160801b039390931660208501526001600160401b0391821684840152166060830152519081900360800190a450979650505050505050565b6033546001600160a01b031690565b600081815260656020526040902080546001600160a01b03168061093a57604051633f9b7dd560e11b815260040160405180910390fd5b60038201546000906001600160801b0316810361099e57506003820154600160801b90046001600160801b03168015610999576003830180546001600160801b0316905560668054829190600090610993908490611cd5565b90915550505b6109aa565b6109a784611236565b90505b80156109c7576069546109c7906001600160a01b03168383610ed9565b600183015460405182815285916001600160a01b03858116929116907f53df85a6d27721f38c9c99d095a4c565f68a5e74f22f17c711578461253cbef29060200160405180910390a450505050565b600054610100900460ff1615808015610a365750600054600160ff909116105b80610a505750303b158015610a50575060005460ff166001145b610ab85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015610adb576000805461ff0019166101001790555b610ae3611444565b6000849050806001600160a01b031663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b4a9190611ce8565b606980546001600160a01b03199081166001600160a01b0393841617909155606a8054821693831693909317909255606780548316868316179055606880549092169084161790558015610bd8576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50505050565b610be733610cff565b606880546001600160a01b0319166001600160a01b0383161790556040517f198db6e425fb8aafd1823c6ca50be2d51e5764571a5ae0f0f21c6812e45def0b9061043990839061188a565b8060005b81811015610cc0576000848483818110610c5257610c52611d05565b9050602002013590506000610c6682611236565b600083815260656020526040812060030180546001600160801b03808516600160801b029116179055606680549293508392909190610ca6908490611d1b565b92505081905550505080610cb990611d2e565b9050610c36565b507fc6d0d5351deeb034178080b2dd43535abe01ba1281d34a70e9914f5451dd31638383604051610cf2929190611d47565b60405180910390a1505050565b806001600160a01b0316610d116108f4565b6001600160a01b03161461048f5760405162461bcd60e51b815260206004820152602160248201527f4f776e61626c653a206163636f756e74206973206e6f7420746865206f776e656044820152603960f91b6064820152608401610aaf565b610d7a33610cff565b6001600160a01b038116610ddf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610aaf565b61048f8161147d565b610df133610cff565b606a80546001600160a01b0319166001600160a01b0383169081179091556040517f5f7748c284ee1ce72903c01c317ef43dd5a82d24aa3376bf246e98f8b3b74da190600090a250565b80606654610e499190611d1b565b6069546040516370a0823160e01b81526001600160a01b03909116906370a0823190610e7990309060040161188a565b602060405180830381865afa158015610e96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eba9190611ca6565b101561048f5760405163786e0a9960e01b815260040160405180910390fd5b600080846001600160a01b031663a9059cbb8585604051602401610efe929190611d80565b6040516020818303038152906040529060e01b6020820180516001600160e01b038381831617835250505050604051610f379190611d99565b6000604051808303816000865af19150503d8060008114610f74576040519150601f19603f3d011682016040523d82523d6000602084013e610f79565b606091505b5091509150818015610fa3575080511580610fa3575080806020019051810190610fa39190611db5565b6110055760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b6064820152608401610aaf565b5050505050565b6040805183516020808301919091528085015182840152848301516001600160a01b03166060808401919091528501516001600160801b03166080808401919091528501516001600160401b0390811660a0808501919091528601511660c0808401919091528351808403909101815260e0830184528051908201207b0ca2ba3432b932bab69029b4b3b732b21026b2b9b9b0b3b29d05199960211b61010084015261011c8084018290528451808503909101815261013c909301909352815191012060006110db82856114cf565b6068549091506001600160a01b0380831691161461100557604051638baa579f60e01b815260040160405180910390fd5b600080846001600160a01b031663095ea7b38585604051602401611131929190611d80565b6040516020818303038152906040529060e01b6020820180516001600160e01b03838183161783525050505060405161116a9190611d99565b6000604051808303816000865af19150503d80600081146111a7576040519150601f19603f3d011682016040523d82523d6000602084013e6111ac565b606091505b50915091508180156111d65750805115806111d65750808060200190518101906111d69190611db5565b6110055760405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b6064820152608401610aaf565b600081815260656020526040812060038101546001600160801b0316808303611272576040516336ab81e160e11b815260040160405180910390fd5b6003820180546001600160801b0319169055606a5460018301546002840154604051630161d07760e41b81526001600160a01b039384169363161d0770936112bf93911691600401611d80565b6020604051808303816000875af19250505080156112fa575060408051601f3d908101601f191682019092526112f791810190611dd7565b60015b61141a573d808015611328576040519150601f19603f3d011682016040523d82523d6000602084013e61132d565b606091505b50630d70a0e360e41b61133f82611df4565b6001600160e01b031916036114125760018301546004808501546005860154604051631ec956b360e01b81526001600160a01b0390941693631ec956b39361139293926001600160401b03169101611be1565b602060405180830381865afa1580156113af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113d39190611db5565b6113de576000611409565b600583015482906113ff90600160401b90046001600160401b0316826114f5565b6114099190611cd5565b95945050505050565b805181602001fd5b81816001600160801b031611611431576000611409565b611409826001600160801b038316611cd5565b600054610100900460ff1661146b5760405162461bcd60e51b8152600401610aaf90611e2b565b611473611518565b61147b61153f565b565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008060006114de858561156f565b915091506114eb816115b4565b5090505b92915050565b600064e8d4a510006115078385611e76565b6115119190611e95565b9392505050565b600054610100900460ff1661147b5760405162461bcd60e51b8152600401610aaf90611e2b565b600054610100900460ff166115665760405162461bcd60e51b8152600401610aaf90611e2b565b61147b3361147d565b60008082516041036115a55760208301516040840151606085015160001a61159987828585611765565b945094505050506115ad565b506000905060025b9250929050565b60008160048111156115c8576115c8611eb7565b036115d05750565b60018160048111156115e4576115e4611eb7565b0361162c5760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b6044820152606401610aaf565b600281600481111561164057611640611eb7565b0361168d5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610aaf565b60038160048111156116a1576116a1611eb7565b036116f95760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610aaf565b600481600481111561170d5761170d611eb7565b0361048f5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610aaf565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03831115611792575060009050600361183f565b8460ff16601b141580156117aa57508460ff16601c14155b156117bb575060009050600461183f565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561180f573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166118385760006001925092505061183f565b9150600090505b94509492505050565b6001600160a01b038116811461048f57600080fd5b803561186881611848565b919050565b60006020828403121561187f57600080fd5b813561151181611848565b6001600160a01b0391909116815260200190565b6000602082840312156118b057600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156118f5576118f56118b7565b604052919050565b6001600160401b038116811461048f57600080fd5b8035611868816118fd565b600080600080600080600087890361018081121561193a57600080fd5b60c081121561194857600080fd5b5087965060c08701356001600160401b038082111561196657600080fd5b818a0191508a601f83011261197a57600080fd5b81358181111561198c5761198c6118b7565b61199f601f8201601f19166020016118cd565b91508082528b60208285010111156119b657600080fd5b8060208401602084013760009082016020015296506119d9905060e0890161185d565b945061010088013593506119f06101208901611912565b92506119ff6101408901611912565b9150611a0e6101608901611912565b905092959891949750929550565b600080600060608486031215611a3157600080fd5b8335611a3c81611848565b92506020840135611a4c81611848565b91506040840135611a5c81611848565b809150509250925092565b60008060208385031215611a7a57600080fd5b82356001600160401b0380821115611a9157600080fd5b818501915085601f830112611aa557600080fd5b813581811115611ab457600080fd5b8660208260051b8501011115611ac957600080fd5b60209290920196919550909350505050565b6001600160801b038116811461048f57600080fd5b600060c08284031215611b0257600080fd5b60405160c081016001600160401b0381118282101715611b2457611b246118b7565b806040525082358152602083013560208201526040830135611b4581611848565b60408201526060830135611b5881611adb565b60608201526080830135611b6b816118fd565b608082015260a0830135611b7e816118fd565b60a08201529392505050565b600060208284031215611b9c57600080fd5b813561151181611adb565b600060208284031215611bb957600080fd5b8135611511816118fd565b600060208284031215611bd657600080fd5b8151611511816118fd565b9182526001600160401b0316602082015260400190565b60005b83811015611c13578181015183820152602001611bfb565b50506000910152565b600060018060a01b03808716835260018060801b038616602084015260018060401b038086166040850152608060608501528185511660808501528060208601511660a085015250506040830151606060c084015280518060e0850152610100611c8c8282870160208601611bf8565b80601f19601f840116860101935050505095945050505050565b600060208284031215611cb857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b818103818111156114ef576114ef611cbf565b600060208284031215611cfa57600080fd5b815161151181611848565b634e487b7160e01b600052603260045260246000fd5b808201808211156114ef576114ef611cbf565b600060018201611d4057611d40611cbf565b5060010190565b6020808252810182905260006001600160fb1b03831115611d6757600080fd5b8260051b80856040850137919091016040019392505050565b6001600160a01b03929092168252602082015260400190565b60008251611dab818460208701611bf8565b9190910192915050565b600060208284031215611dc757600080fd5b8151801515811461151157600080fd5b600060208284031215611de957600080fd5b815161151181611adb565b805160208201516001600160e01b03198082169291906004831015611e235780818460040360031b1b83161693505b505050919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000816000190483118215151615611e9057611e90611cbf565b500290565b600082611eb257634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220e65696860e7dfdfec5eb1fe374e27b92c171b7196b605b52493e8c99f5bdaab564736f6c63430008100033
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.