- Contract name:
- SpecialHorseFarmV2
- Optimization enabled
- true
- Compiler version
- v0.8.2+commit.661d1103
- Optimization runs
- 999999
- Verified at
- 2024-08-21 02:49:26.701914Z
contracts/farm-v2/SpecialHorseFarmV2.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "../libraries/BytesLibrary.sol"; import "../libraries/StringLibrary.sol"; import "../interfaces/ITransporter.sol"; import "../abtracts/OwnerOperator.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; contract SpecialHorseFarmV2 is ERC721HolderUpgradeable, OwnerOperator, PausableUpgradeable, ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; using SafeMath for uint256; using StringLibrary for string; using BytesLibrary for bytes32; struct LeaseData { address owner; address horseAddress; uint256 horseId; uint256 blockExpired; string nonce; uint8 v; bytes32 r; bytes32 s; } struct SavedLease { address owner; address horseAddress; uint256 horseId; uint256 blockExpired; } struct WithdrawData { address owner; address horseAddress; uint256 horseId; uint256 blockExpired; string nonce; uint8 v; bytes32 r; bytes32 s; } struct SavedWithdraw { address owner; address horseAddress; uint256 horseId; uint256 blockExpired; } // Mapping from nft token id to owner of token mapping(address => mapping(uint256 => address)) public ownerOf; // Mapping from sign message to checking value mapping(bytes32 => bool) public leaseCompleted; // Mapping from nonce to leaseData mapping(string => SavedLease) public leaseData; // Mapping from user address to lease count mapping(address => uint256) public leaseCountOf; // Mapping from user address and lease index to lease nonce mapping(address => mapping(uint256 => string)) public leaseNoneOf; // Mapping from sign message to checking value mapping(bytes32 => bool) public withdrawCompleted; // Mapping from nonce to withdrawData mapping(string => SavedWithdraw) public withdrawData; // Mapping from user address to withdraw count mapping(address => uint256) public withdrawCountOf; // Mapping from user address and withdraw index to withdraw nonce mapping(address => mapping(uint256 => string)) public withdrawNoneOf; //Mapping verify horsenft mapping(address => bool) public isHorseNFT; event Lease(address indexed owner, address indexed signer, uint256 indexed horseId, string nonce); event Withdraw(address indexed owner, address indexed signer, uint256 indexed horseId, string nonce); event Signer(address signers); ITransporter public transporter; function init() external initializer { super.initialize(); super.__Pausable_init(); } function pause() external virtual onlyOwner { _pause(); } function unpause() external virtual onlyOwner { _unpause(); } function setTransporter(address _transporter) external virtual onlyOwner { transporter = ITransporter(_transporter); } function setHorseNFT(address _horseNFT) external virtual operatorOrOwner { isHorseNFT[_horseNFT] = true; } /** * @dev withdraw token that user mistakenly transferred. */ function withdrawToken(address token) external virtual onlyOwner { uint256 amount = IERC20(token).balanceOf(address(this)); require(amount > 0, "SpecialHorseFarmV2: zero out amount"); IERC20(token).safeTransfer(msg.sender, amount); } /** * @dev withdraw nft that user mistakenly transferred. */ function withdrawNFT(address token, uint256 tokenId) external virtual onlyOwner { require( !isHorseNFT[token] || ownerOf[token][tokenId] == address(0), "SpecialHorseFarmV2: horse belong to contract" ); IERC721(token).safeTransferFrom(address(this), msg.sender, tokenId); } /** * @dev user lease horse. */ function lease(LeaseData memory data) external virtual nonReentrant whenNotPaused { require(isHorseNFT[data.horseAddress], "SpecialHorseFarmV2: invalid horse address"); require(msg.sender == data.owner, "SpecialHorseFarmV2: sender is not owner"); (bytes32 message, address signer) = _verifyLease(data); leaseCompleted[message] = true; leaseData[data.nonce] = SavedLease({ owner: data.owner, horseAddress: data.horseAddress, horseId: data.horseId, blockExpired: data.blockExpired }); leaseNoneOf[data.owner][leaseCountOf[data.owner]] = data.nonce; leaseCountOf[data.owner] = leaseCountOf[data.owner].add(1); ownerOf[data.horseAddress][data.horseId] = data.owner; transporter.safeTransferNFT721From(data.horseAddress, data.owner, address(this), data.horseId); emit Lease(data.owner, signer, data.horseId, data.nonce); } function _verifyLease(LeaseData memory data) internal view returns (bytes32, address) { bytes32 message = keccak256( abi.encode( address(this), "Lease", data.owner, data.horseAddress, data.horseId, data.blockExpired, data.nonce ) ); address signer = message.toString().recover(data.v, data.r, data.s); require(operators[signer], "SpecialHorseFarmV2: lease not verify"); require(block.number < data.blockExpired, "SpecialHorseFarmV2: lease expired"); require(!leaseCompleted[message], "SpecialHorseFarmV2: lease completed"); require(leaseData[data.nonce].owner == address(0), "SpecialHorseFarmV2: nonce existed"); return (message, signer); } /** * @dev user withdraw horse. */ function withdraw(WithdrawData memory data) external virtual nonReentrant whenNotPaused { require(isHorseNFT[data.horseAddress], "SpecialHorseFarmV2: invalid horse address"); require(ownerOf[data.horseAddress][data.horseId] != address(0), "SpecialHorseFarmV2: horse withdrawed"); require(msg.sender == data.owner, "SpecialHorseFarmV2: sender is not owner"); require( msg.sender == ownerOf[data.horseAddress][data.horseId], "SpecialHorseFarmV2: sender is not horse owner" ); (bytes32 message, address signer) = _verifyWithdraw(data); withdrawCompleted[message] = true; withdrawData[data.nonce] = SavedWithdraw({ owner: data.owner, horseAddress: data.horseAddress, horseId: data.horseId, blockExpired: data.blockExpired }); withdrawNoneOf[msg.sender][withdrawCountOf[msg.sender]] = data.nonce; withdrawCountOf[msg.sender] = withdrawCountOf[msg.sender].add(1); ownerOf[data.horseAddress][data.horseId] = address(0); IERC721(data.horseAddress).safeTransferFrom(address(this), msg.sender, data.horseId); emit Withdraw(msg.sender, signer, data.horseId, data.nonce); } function _verifyWithdraw(WithdrawData memory data) internal view returns (bytes32, address) { bytes32 message = keccak256( abi.encode( address(this), "Withdraw", data.owner, data.horseAddress, data.horseId, data.blockExpired, data.nonce ) ); address signer = message.toString().recover(data.v, data.r, data.s); require(operators[signer], "SpecialHorseFarmV2: withdraw not verify"); require(block.number < data.blockExpired, "SpecialHorseFarmV2: withdraw expired"); require(!withdrawCompleted[message], "SpecialHorseFarmV2: withdraw completed"); require(withdrawData[data.nonce].blockExpired == 0, "SpecialHorseFarmV2: nonce existed"); return (message, signer); } }
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.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 Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __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(); _; } /** * @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. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (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] * ```solidity * 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 Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } /** * @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; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } /** * @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; }
@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721ReceiverUpgradeable { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/utils/ERC721Holder.sol) pragma solidity ^0.8.0; import "../IERC721ReceiverUpgradeable.sol"; import {Initializable} from "../../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC721Receiver} interface. * * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable { function __ERC721Holder_init() internal onlyInitializing { } function __ERC721Holder_init_unchained() internal onlyInitializing { } /** * @dev See {IERC721Receiver-onERC721Received}. * * Always returns `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) { return this.onERC721Received.selector; } /** * @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; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [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://consensys.net/diligence/blog/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.8.0/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 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) { (bool success, bytes memory returndata) = target.delegatecall(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); } } }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol) pragma solidity ^0.8.0; import {Initializable} from "../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; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } /** * @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; }
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); }
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * 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 Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @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 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); /** * @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; }
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 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); } function _verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) private 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 assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT 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 IERC165 { /** * @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); }
@openzeppelin/contracts/utils/math/SafeMath.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
contracts/abtracts/OwnerOperator.sol
//SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; abstract contract OwnerOperator is OwnableUpgradeable { mapping(address => bool) public operators; function initialize() public initializer { __Context_init_unchained(); __Ownable_init_unchained(); } modifier operatorOrOwner() { require(operators[msg.sender] || owner() == msg.sender, "OwnerOperator: !operator, !owner"); _; } modifier onlyOperator() { require(operators[msg.sender], "OwnerOperator: !operator"); _; } function addOperator(address operator) external virtual onlyOwner { require(operator != address(0), "OwnerOperator: operator is the zero address"); operators[operator] = true; } function removeOperator(address operator) external virtual onlyOwner { require(operator != address(0), "OwnerOperator: operator is the zero address"); operators[operator] = false; } }
contracts/interfaces/ITransporter.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITransporter { function safeTransferTokenFrom( address token_, address from_, address to_, uint256 amount_ ) external; function safeTransferNFT721From( address token_, address from_, address to_, uint256 tokenId_ ) external; function safeBurnNFT721From(address token_, uint256 tokenId_) external; function safeTransferNFT1155From( address token_, address from_, address to_, uint256 tokenId_, uint256 amount_ ) external; function safeBurnNFT1155From( address token_, address from_, uint256 tokenId_, uint256 amount_ ) external; function safeBurnBatchNFT1155From( address token_, address from_, uint256[] memory tokenId_, uint256[] memory amount_ ) external; }
contracts/libraries/BytesLibrary.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev BytesLibrary operations. */ library BytesLibrary { function toString(bytes32 value) internal pure returns (string memory) { bytes memory alphabet = "0123456789abcdef"; bytes memory str = new bytes(64); for (uint256 i = 0; i < 32; i++) { str[i * 2] = alphabet[uint8(value[i] >> 4)]; str[1 + i * 2] = alphabet[uint8(value[i] & 0x0f)]; } return string(str); } }
contracts/libraries/StringLibrary.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./UintLibrary.sol"; library StringLibrary { using UintLibrary for uint256; function append(string memory a, string memory b) internal pure returns (string memory) { bytes memory ba = bytes(a); bytes memory bb = bytes(b); bytes memory bab = new bytes(ba.length + bb.length); uint256 k = 0; for (uint256 i = 0; i < ba.length; i++) bab[k++] = ba[i]; for (uint256 i = 0; i < bb.length; i++) bab[k++] = bb[i]; return string(bab); } function append( string memory a, string memory b, string memory c ) internal pure returns (string memory) { bytes memory ba = bytes(a); bytes memory bb = bytes(b); bytes memory bc = bytes(c); bytes memory bbb = new bytes(ba.length + bb.length + bc.length); uint256 k = 0; for (uint256 i = 0; i < ba.length; i++) bbb[k++] = ba[i]; for (uint256 i = 0; i < bb.length; i++) bbb[k++] = bb[i]; for (uint256 i = 0; i < bc.length; i++) bbb[k++] = bc[i]; return string(bbb); } function recover( string memory message, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { bytes memory msgBytes = bytes(message); bytes memory fullMessage = concat( bytes("\x19Ethereum Signed Message:\n"), bytes(msgBytes.length.toString()), msgBytes, new bytes(0), new bytes(0), new bytes(0), new bytes(0) ); return ecrecover(keccak256(fullMessage), v, r, s); } function concat( bytes memory ba, bytes memory bb, bytes memory bc, bytes memory bd, bytes memory be, bytes memory bf, bytes memory bg ) internal pure returns (bytes memory) { bytes memory resultBytes = new bytes(ba.length + bb.length + bc.length + bd.length + be.length + bf.length + bg.length); uint256 k = 0; for (uint256 i = 0; i < ba.length; i++) resultBytes[k++] = ba[i]; for (uint256 i = 0; i < bb.length; i++) resultBytes[k++] = bb[i]; for (uint256 i = 0; i < bc.length; i++) resultBytes[k++] = bc[i]; for (uint256 i = 0; i < bd.length; i++) resultBytes[k++] = bd[i]; for (uint256 i = 0; i < be.length; i++) resultBytes[k++] = be[i]; for (uint256 i = 0; i < bf.length; i++) resultBytes[k++] = bf[i]; for (uint256 i = 0; i < bg.length; i++) resultBytes[k++] = bg[i]; return resultBytes; } }
contracts/libraries/UintLibrary.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; library UintLibrary { using SafeMath for uint256; function toString(uint256 i) internal pure returns (string memory) { if (i == 0) { return "0"; } uint256 j = i; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); for (uint256 k = len; k > 0; k--) { bstr[k - 1] = bytes1(uint8(48 + (i % 10))); i /= 10; } return string(bstr); } function bp(uint256 value, uint256 bpValue) internal pure returns (uint256) { return value.mul(bpValue).div(10000); } }
Contract ABI
[{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"Lease","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"signer","internalType":"address","indexed":true},{"type":"uint256","name":"horseId","internalType":"uint256","indexed":true},{"type":"string","name":"nonce","internalType":"string","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Signer","inputs":[{"type":"address","name":"signers","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Withdraw","inputs":[{"type":"address","name":"owner","internalType":"address","indexed":true},{"type":"address","name":"signer","internalType":"address","indexed":true},{"type":"uint256","name":"horseId","internalType":"uint256","indexed":true},{"type":"string","name":"nonce","internalType":"string","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"init","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isHorseNFT","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"lease","inputs":[{"type":"tuple","name":"data","internalType":"struct SpecialHorseFarmV2.LeaseData","components":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"horseAddress","internalType":"address"},{"type":"uint256","name":"horseId","internalType":"uint256"},{"type":"uint256","name":"blockExpired","internalType":"uint256"},{"type":"string","name":"nonce","internalType":"string"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"leaseCompleted","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"leaseCountOf","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"horseAddress","internalType":"address"},{"type":"uint256","name":"horseId","internalType":"uint256"},{"type":"uint256","name":"blockExpired","internalType":"uint256"}],"name":"leaseData","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"leaseNoneOf","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"operators","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"ownerOf","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHorseNFT","inputs":[{"type":"address","name":"_horseNFT","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTransporter","inputs":[{"type":"address","name":"_transporter","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ITransporter"}],"name":"transporter","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"tuple","name":"data","internalType":"struct SpecialHorseFarmV2.WithdrawData","components":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"horseAddress","internalType":"address"},{"type":"uint256","name":"horseId","internalType":"uint256"},{"type":"uint256","name":"blockExpired","internalType":"uint256"},{"type":"string","name":"nonce","internalType":"string"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"withdrawCompleted","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"withdrawCountOf","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"horseAddress","internalType":"address"},{"type":"uint256","name":"horseId","internalType":"uint256"},{"type":"uint256","name":"blockExpired","internalType":"uint256"}],"name":"withdrawData","inputs":[{"type":"string","name":"","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawNFT","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"withdrawNoneOf","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawToken","inputs":[{"type":"address","name":"token","internalType":"address"}]}]
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c8063715018a61161010457806399725af1116100a2578063e1c7392a11610071578063e1c7392a1461058a578063e42b021214610592578063e817d0e5146105b3578063f2fde38b146105c6576101cf565b806399725af1146105205780639c8dadae14610540578063a8ed22a314610553578063ac8a584a14610577576101cf565b80638456cb59116100de5780638456cb59146104d457806389476069146104dc5780638da5cb5b146104ef5780639870d7fe1461050d576101cf565b8063715018a6146104695780637a2ef48b146104715780638129fc1c146104cc576101cf565b80631f29d2dc116101715780633f4ba83a1161014b5780633f4ba83a146103af5780635c975abb146103b7578063604ff5a4146103c25780636088e93a14610456576101cf565b80631f29d2dc1461031257806332a46144146103785780633453af211461039c576101cf565b806313e7c9d8116101ad57806313e7c9d81461025f578063150b7a021461028257806317c6395d146102ea5780631ed924f1146102fd576101cf565b8063037a4a4a146101d457806304d45b49146101fd57806307d0ef9714610230575b600080fd5b6101e76101e2366004613a28565b6105d9565b6040516101f49190613c7f565b60405180910390f35b61022061020b366004613a71565b60fd6020526000908152604090205460ff1681565b60405190151581526020016101f4565b61025161023e366004613995565b6101036020526000908152604090205481565b6040519081526020016101f4565b61022061026d366004613995565b60976020526000908152604090205460ff1681565b6102b96102903660046139af565b7f150b7a0200000000000000000000000000000000000000000000000000000000949350505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020016101f4565b6101e76102f8366004613a28565b61067f565b61031061030b366004613995565b6106a4565b005b610353610320366004613a28565b60fc60209081526000928352604080842090915290825290205473ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016101f4565b610220610386366004613995565b6101056020526000908152604090205460ff1681565b6103106103aa366004613abc565b6107b0565b610310610c38565b60985460ff16610220565b61041e6103d0366004613a89565b80518082016020908101805161010282529282019190930120915280546001820154600283015460039093015473ffffffffffffffffffffffffffffffffffffffff92831693919092169184565b6040805173ffffffffffffffffffffffffffffffffffffffff95861681529490931660208501529183015260608201526080016101f4565b610310610464366004613a28565b610c4a565b610310610dd4565b61041e61047f366004613a89565b80518082016020908101805160fe82529282019190930120915280546001820154600283015460039093015473ffffffffffffffffffffffffffffffffffffffff92831693919092169184565b610310610de6565b610310610f86565b6103106104ea366004613995565b610f96565b60655473ffffffffffffffffffffffffffffffffffffffff16610353565b61031061051b366004613995565b6110f5565b61025161052e366004613995565b60ff6020526000908152604090205481565b61031061054e366004613995565b6111ef565b610220610561366004613a71565b6101016020526000908152604090205460ff1681565b610310610585366004613995565b61123f565b610310611336565b610106546103539073ffffffffffffffffffffffffffffffffffffffff1681565b6103106105c1366004613abc565b611471565b6103106105d4366004613995565b611a3f565b610104602090815260009283526040808420909152908252902080546105fe90613dc6565b80601f016020809104026020016040519081016040528092919081815260200182805461062a90613dc6565b80156106775780601f1061064c57610100808354040283529160200191610677565b820191906000526020600020905b81548152906001019060200180831161065a57829003601f168201915b505050505081565b610100602090815260009283526040808420909152908252902080546105fe90613dc6565b3360009081526097602052604090205460ff16806106f55750336106dd60655473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff16145b610760576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e65724f70657261746f723a20216f70657261746f722c20216f776e657260448201526064015b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff1660009081526101056020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b6107b8611af3565b6107c0611b67565b60208082015173ffffffffffffffffffffffffffffffffffffffff166000908152610105909152604090205460ff1661087b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f5370656369616c486f7273654661726d56323a20696e76616c696420686f727360448201527f65206164647265737300000000000000000000000000000000000000000000006064820152608401610757565b805173ffffffffffffffffffffffffffffffffffffffff163314610921576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f5370656369616c486f7273654661726d56323a2073656e646572206973206e6f60448201527f74206f776e6572000000000000000000000000000000000000000000000000006064820152608401610757565b60008061092d83611bd4565b600082815260fd602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055815160808082018452885173ffffffffffffffffffffffffffffffffffffffff9081168352898401511692820192909252878301518184015260608089015190820152908701519151939550919350909160fe916109c591613b51565b9081526040805160209281900383019020835181547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff92831617835585850151600184018054909216908316179055848301516002830155606090940151600390910155608086015186518416600090815261010084528281208851909516815260ff845282812054815293835292208251610a7f939192919091019061378c565b50825173ffffffffffffffffffffffffffffffffffffffff16600090815260ff6020526040902054610ab2906001611f17565b835173ffffffffffffffffffffffffffffffffffffffff908116600090815260ff6020908152604080832094909455865181880180518516845260fc8352858420868a018051865293529285902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169185169190911790556101065491518751915194517fa5bc64ca000000000000000000000000000000000000000000000000000000008152908416600482015290831660248201523060448201526064810193909352169063a5bc64ca90608401600060405180830381600087803b158015610b9f57600080fd5b505af1158015610bb3573d6000803e3d6000fd5b5050505082604001518173ffffffffffffffffffffffffffffffffffffffff16846000015173ffffffffffffffffffffffffffffffffffffffff167f6c0f40da73c577567dd97a5f1acfd9d4a433a9832757bf34c6bdee20791c113d8660800151604051610c219190613c7f565b60405180910390a45050610c35600160ca55565b50565b610c40611f2a565b610c48611fab565b565b610c52611f2a565b73ffffffffffffffffffffffffffffffffffffffff82166000908152610105602052604090205460ff161580610cb8575073ffffffffffffffffffffffffffffffffffffffff828116600090815260fc6020908152604080832085845290915290205416155b610d44576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602c60248201527f5370656369616c486f7273654661726d56323a20686f7273652062656c6f6e6760448201527f20746f20636f6e747261637400000000000000000000000000000000000000006064820152608401610757565b6040517f42842e0e0000000000000000000000000000000000000000000000000000000081523060048201523360248201526044810182905273ffffffffffffffffffffffffffffffffffffffff8316906342842e0e90606401600060405180830381600087803b158015610db857600080fd5b505af1158015610dcc573d6000803e3d6000fd5b505050505050565b610ddc611f2a565b610c486000612028565b600054610100900460ff1615808015610e065750600054600160ff909116105b80610e275750610e153061209f565b158015610e27575060005460ff166001145b610eb3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610757565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015610f1157600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b610f196120bf565b610f21612156565b8015610c3557600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b610f8e611f2a565b610c486121f6565b610f9e611f2a565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a082319060240160206040518083038186803b15801561100657600080fd5b505afa15801561101a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061103e9190613aef565b9050600081116110d0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f5370656369616c486f7273654661726d56323a207a65726f206f757420616d6f60448201527f756e7400000000000000000000000000000000000000000000000000000000006064820152608401610757565b6110f173ffffffffffffffffffffffffffffffffffffffff83163383612251565b5050565b6110fd611f2a565b73ffffffffffffffffffffffffffffffffffffffff81166111a0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f4f776e65724f70657261746f723a206f70657261746f7220697320746865207a60448201527f65726f20616464726573730000000000000000000000000000000000000000006064820152608401610757565b73ffffffffffffffffffffffffffffffffffffffff16600090815260976020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b6111f7611f2a565b61010680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b611247611f2a565b73ffffffffffffffffffffffffffffffffffffffff81166112ea576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f4f776e65724f70657261746f723a206f70657261746f7220697320746865207a60448201527f65726f20616464726573730000000000000000000000000000000000000000006064820152608401610757565b73ffffffffffffffffffffffffffffffffffffffff16600090815260976020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b600054610100900460ff16158080156113565750600054600160ff909116105b8061137757506113653061209f565b158015611377575060005460ff166001145b611403576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610757565b600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055801561146157600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b611469610de6565b610f216122e3565b611479611af3565b611481611b67565b60208082015173ffffffffffffffffffffffffffffffffffffffff166000908152610105909152604090205460ff1661153c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f5370656369616c486f7273654661726d56323a20696e76616c696420686f727360448201527f65206164647265737300000000000000000000000000000000000000000000006064820152608401610757565b60208082015173ffffffffffffffffffffffffffffffffffffffff908116600090815260fc83526040808220818601518352909352919091205416611602576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f5370656369616c486f7273654661726d56323a20686f7273652077697468647260448201527f61776564000000000000000000000000000000000000000000000000000000006064820152608401610757565b805173ffffffffffffffffffffffffffffffffffffffff1633146116a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f5370656369616c486f7273654661726d56323a2073656e646572206973206e6f60448201527f74206f776e6572000000000000000000000000000000000000000000000000006064820152608401610757565b60208181015173ffffffffffffffffffffffffffffffffffffffff908116600090815260fc835260408082208186015183529093529190912054163314611771576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602d60248201527f5370656369616c486f7273654661726d56323a2073656e646572206973206e6f60448201527f7420686f727365206f776e6572000000000000000000000000000000000000006064820152608401610757565b60008061177d83612382565b6000828152610101602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055815160808082018452885173ffffffffffffffffffffffffffffffffffffffff908116835289840151169282019290925287830151818401526060808901519082015290870151915193955091935090916101029161181791613b51565b908152604080519182900360209081019092208351815473ffffffffffffffffffffffffffffffffffffffff9182167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161783558585015160018401805491909316911617905583820151600282015560609093015160039093019290925560808501513360009081526101048352838120610103845284822054825283529290922082516118ce939192919091019061378c565b5033600090815261010360205260409020546118eb906001611f17565b3360008181526101036020908152604080832094909455868101805173ffffffffffffffffffffffffffffffffffffffff908116845260fc83528584208987018051865293529285902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016905551905193517f42842e0e0000000000000000000000000000000000000000000000000000000081523060048201526024810193909352604483019390935291909116906342842e0e90606401600060405180830381600087803b1580156119c157600080fd5b505af11580156119d5573d6000803e3d6000fd5b5050505082604001518173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c73b702b261c879bc4ebea83f44bd0c9a90cffb4aa0f324e52750d831b9cb4f8660800151604051610c219190613c7f565b611a47611f2a565b73ffffffffffffffffffffffffffffffffffffffff8116611aea576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610757565b610c3581612028565b600260ca541415611b60576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610757565b600260ca55565b60985460ff1615610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610757565b60008060003084600001518560200151866040015187606001518860800151604051602001611c0896959493929190613b6d565b6040516020818303038152906040528051906020012090506000611c458560a001518660c001518760e00151611c3d8661268b565b92919061295a565b73ffffffffffffffffffffffffffffffffffffffff811660009081526097602052604090205490915060ff16611cfc576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f5370656369616c486f7273654661726d56323a206c65617365206e6f7420766560448201527f72696679000000000000000000000000000000000000000000000000000000006064820152608401610757565b84606001514310611d8f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f5370656369616c486f7273654661726d56323a206c656173652065787069726560448201527f64000000000000000000000000000000000000000000000000000000000000006064820152608401610757565b600082815260fd602052604090205460ff1615611e2e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f5370656369616c486f7273654661726d56323a206c6561736520636f6d706c6560448201527f74656400000000000000000000000000000000000000000000000000000000006064820152608401610757565b600073ffffffffffffffffffffffffffffffffffffffff1660fe8660800151604051611e5a9190613b51565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff1614611f0d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f5370656369616c486f7273654661726d56323a206e6f6e63652065786973746560448201527f64000000000000000000000000000000000000000000000000000000000000006064820152608401610757565b9092509050915091565b6000611f238284613ce1565b9392505050565b60655473ffffffffffffffffffffffffffffffffffffffff163314610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610757565b611fb3612a6d565b609880547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b6065805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b73ffffffffffffffffffffffffffffffffffffffff81163b15155b919050565b600054610100900460ff16610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610757565b600054610100900460ff166121ed576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610757565b610c4833612028565b6121fe611b67565b609880547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611ffe3390565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526122de908490612ad9565b505050565b600054610100900460ff1661237a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610757565b610c48612be5565b600080600030846000015185602001518660400151876060015188608001516040516020016123b696959493929190613bfd565b60405160208183030381529060405280519060200120905060006123eb8560a001518660c001518760e00151611c3d8661268b565b73ffffffffffffffffffffffffffffffffffffffff811660009081526097602052604090205490915060ff166124a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602760248201527f5370656369616c486f7273654661726d56323a207769746864726177206e6f7460448201527f20766572696679000000000000000000000000000000000000000000000000006064820152608401610757565b84606001514310612535576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f5370656369616c486f7273654661726d56323a2077697468647261772065787060448201527f69726564000000000000000000000000000000000000000000000000000000006064820152608401610757565b6000828152610101602052604090205460ff16156125d5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f5370656369616c486f7273654661726d56323a20776974686472617720636f6d60448201527f706c6574656400000000000000000000000000000000000000000000000000006064820152608401610757565b61010285608001516040516125ea9190613b51565b908152602001604051809103902060030154600014611f0d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f5370656369616c486f7273654661726d56323a206e6f6e63652065786973746560448201527f64000000000000000000000000000000000000000000000000000000000000006064820152608401610757565b604080518082018252601081527f30313233343536373839616263646566000000000000000000000000000000006020820152815182815260608181018452926000919060208201818036833701905050905060005b602081101561295257826004868360208110612726577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b1a60f81b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916901c60f81c60ff168151811061278b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016826127be836002613d0d565b815181106127f5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508285826020811061285e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b825191901a600f1690811061289c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016826128cf836002613d0d565b6128da906001613ce1565b81518110612911577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508061294a81613e1a565b9150506126e1565b509392505050565b60008085905060006129d26040518060400160405280601a81526020017f19457468657265756d205369676e6564204d6573736167653a0a0000000000008152506129a58451612ca6565b60408051600080825260208201818152828401828152606084019283526080840190945288939091612e3b565b90506001818051906020012087878760405160008152602001604052604051612a17949392919093845260ff9290921660208401526040830152606082015260800190565b6020604051602081039080840390855afa158015612a39573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015198975050505050505050565b60985460ff16610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610757565b6000612b3b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166135a29092919063ffffffff16565b8051909150156122de5780806020019051810190612b599190613a51565b6122de576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610757565b600054610100900460ff16612c7c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401610757565b609880547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055565b606081612ce7575060408051808201909152600181527f300000000000000000000000000000000000000000000000000000000000000060208201526120ba565b8160005b8115612d115780612cfb81613e1a565b9150612d0a9050600a83613cf9565b9150612ceb565b60008167ffffffffffffffff811115612d53577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612d7d576020820181803683370190505b509050815b8015612e3257612d93600a87613e53565b612d9e906030613ce1565b60f81b82612dad600184613d4a565b81518110612de4577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350612e1e600a87613cf9565b955080612e2a81613d91565b915050612d82565b50949350505050565b6060600082518451865188518a518c518e51612e579190613ce1565b612e619190613ce1565b612e6b9190613ce1565b612e759190613ce1565b612e7f9190613ce1565b612e899190613ce1565b67ffffffffffffffff811115612ec8577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612ef2576020820181803683370190505b5090506000805b8a51811015612fe7578a8181518110612f3b577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff00000000000000000000000000000000000000000000000000000000000000168383612f6d81613e1a565b945081518110612fa6577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080612fdf81613e1a565b915050612ef9565b5060005b89518110156130d95789818151811061302d577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361305f81613e1a565b945081518110613098577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806130d181613e1a565b915050612feb565b5060005b88518110156131cb5788818151811061311f577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361315181613e1a565b94508151811061318a577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806131c381613e1a565b9150506130dd565b5060005b87518110156132bd57878181518110613211577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361324381613e1a565b94508151811061327c577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806132b581613e1a565b9150506131cf565b5060005b86518110156133af57868181518110613303577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361333581613e1a565b94508151811061336e577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350806133a781613e1a565b9150506132c1565b5060005b85518110156134a1578581815181106133f5577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361342781613e1a565b945081518110613460577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508061349981613e1a565b9150506133b3565b5060005b8451811015613593578481815181106134e7577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b01602001517fff0000000000000000000000000000000000000000000000000000000000000016838361351981613e1a565b945081518110613552577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508061358b81613e1a565b9150506134a5565b50909998505050505050505050565b60606135b184846000856135b9565b949350505050565b60608247101561364b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610757565b843b6136b3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610757565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516136dc9190613b51565b60006040518083038185875af1925050503d8060008114613719576040519150601f19603f3d011682016040523d82523d6000602084013e61371e565b606091505b509150915061372e828286613739565b979650505050505050565b60608315613748575081611f23565b8251156137585782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107579190613c7f565b82805461379890613dc6565b90600052602060002090601f0160209004810192826137ba5760008555613800565b82601f106137d357805160ff1916838001178555613800565b82800160010185558215613800579182015b828111156138005782518255916020019190600101906137e5565b5061380c929150613810565b5090565b5b8082111561380c5760008155600101613811565b600067ffffffffffffffff83111561383f5761383f613ec5565b61387060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f86011601613c92565b905082815283838301111561388457600080fd5b828260208301376000602084830101529392505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146120ba57600080fd5b600082601f8301126138cf578081fd5b611f2383833560208501613825565b60006101008083850312156138f1578182fd5b6138fa81613c92565b9150506139068261389b565b81526139146020830161389b565b60208201526040820135604082015260608201356060820152608082013567ffffffffffffffff81111561394757600080fd5b613953848285016138bf565b60808301525061396560a08301613984565b60a082015260c082013560c082015260e082013560e082015292915050565b803560ff811681146120ba57600080fd5b6000602082840312156139a6578081fd5b611f238261389b565b600080600080608085870312156139c4578283fd5b6139cd8561389b565b93506139db6020860161389b565b925060408501359150606085013567ffffffffffffffff8111156139fd578182fd5b8501601f81018713613a0d578182fd5b613a1c87823560208401613825565b91505092959194509250565b60008060408385031215613a3a578182fd5b613a438361389b565b946020939093013593505050565b600060208284031215613a62578081fd5b81518015158114611f23578182fd5b600060208284031215613a82578081fd5b5035919050565b600060208284031215613a9a578081fd5b813567ffffffffffffffff811115613ab0578182fd5b6135b1848285016138bf565b600060208284031215613acd578081fd5b813567ffffffffffffffff811115613ae3578182fd5b6135b1848285016138de565b600060208284031215613b00578081fd5b5051919050565b60008151808452613b1f816020860160208601613d61565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60008251613b63818460208701613d61565b9190910192915050565b600073ffffffffffffffffffffffffffffffffffffffff808916835260e06020840152600560e08401527f4c65617365000000000000000000000000000000000000000000000000000000610100840152610120818916604085015281881660608501528660808501528560a08501528060c0850152613bef81850186613b07565b9a9950505050505050505050565b600073ffffffffffffffffffffffffffffffffffffffff808916835260e06020840152600860e08401527f5769746864726177000000000000000000000000000000000000000000000000610100840152610120818916604085015281881660608501528660808501528560a08501528060c0850152613bef81850186613b07565b600060208252611f236020830184613b07565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715613cd957613cd9613ec5565b604052919050565b60008219821115613cf457613cf4613e67565b500190565b600082613d0857613d08613e96565b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613d4557613d45613e67565b500290565b600082821015613d5c57613d5c613e67565b500390565b60005b83811015613d7c578181015183820152602001613d64565b83811115613d8b576000848401525b50505050565b600081613da057613da0613e67565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b600281046001821680613dda57607f821691505b60208210811415613e14577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415613e4c57613e4c613e67565b5060010190565b600082613e6257613e62613e96565b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fdfea26469706673582212207c335704a07af71367eb51ec2eb303f9e1af9e1c786865d51461ea98ec4f3d5d64736f6c63430008020033