Transaction Hash:
Block:
15560882 at Sep-18-2022 01:59:11 PM +UTC
Transaction Fee:
0.00156149001944586 ETH
$3.99
Gas Used:
207,171 Gas / 7.53720366 Gwei
Emitted Events:
232 |
OrcsOfOrakion.Approval( owner=0x946a8de833db03dfc2aaea8ead0ee7f4b21696b6, approved=0x00000000...000000000, tokenId=5704 )
|
233 |
OrcsOfOrakion.Transfer( from=0x946a8de833db03dfc2aaea8ead0ee7f4b21696b6, to=[Sender] 0xa39fc89ecb9132930e3aec8eccbefbe312b125ff, tokenId=5704 )
|
234 |
TransparentUpgradeableProxy.0xe2c49856b032c255ae7e325d18109bc4e22a2804e2e49a017ec0f59f19cd447b( 0xe2c49856b032c255ae7e325d18109bc4e22a2804e2e49a017ec0f59f19cd447b, 85e4b3d4a61070b4662c2c4856dc63b17a8e5bd2b1342f9ecc0af720c253d74c, 0000000000000000000000000000000000000000000000000000000000000000, 000000000000000000000000946a8de833db03dfc2aaea8ead0ee7f4b21696b6, 0000000000000000000000000000000000000000000000000052b7c3e04e3000 )
|
235 |
TransparentUpgradeableProxy.0x3cbb63f144840e5b1b0a38a7c19211d2e89de4d7c5faf8b2d3c1776c302d1d33( 0x3cbb63f144840e5b1b0a38a7c19211d2e89de4d7c5faf8b2d3c1776c302d1d33, 0x85e4b3d4a61070b4662c2c4856dc63b17a8e5bd2b1342f9ecc0af720c253d74c, 000000000000000000000000946a8de833db03dfc2aaea8ead0ee7f4b21696b6, 000000000000000000000000a39fc89ecb9132930e3aec8eccbefbe312b125ff, 00000000000000000000000000000000a2df8d5fcdbb7a69c8b130d3625e8171, 000000000000000000000000000000000000000000000000000292cd6b5cb52e, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000001, 00000000000000000000000000000000000000000000000000000000634eafed, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000160, 0000000000000000000000000000000000000000000000000000000000000180, 0000000000000000000000000000000000000000000000000000000000000260, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000053222d0fbe8000, 0000000000000000000000000000000000000000000000000000000000000040, 0000000000000000000000000000000000000000000000000000000000000080, 0000000000000000000000000000000000000000000000000000000000000020, 0000000000000000000000000000000000000000000000000000000000000001, 000000000000000000000000b39f5f5199042086d6f162ededb761d0f33a2849, 0000000000000000000000000000000000000000000000000000000000001648, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000053222d0fbe8000, 85e4b3d4a61070b4662c2c4856dc63b17a8e5bd2b1342f9ecc0af720c253d74c, 000000000000000000000000f849de01b080adc3a814fabe1e2087475cf2e354, 0000000000000000000000000000000000000000000000000000000000000160, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000180, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000001388, 000000000000000000000000d823c605807cc5e6bd6fc0d7e4eea50d3e2d66cd )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x74312363...65a67EeD3 | (X2Y2: Exchange) | ||||
0x946a8DE8...4b21696b6 | 0.355945453656912507 Eth | 0.379228453656912507 Eth | 0.023283 | ||
0xa39fC89E...312b125ff |
0.489957674566148679 Eth
Nonce: 59
|
0.464996184546702819 Eth
Nonce: 60
| 0.02496149001944586 | ||
0xB39f5F51...0F33a2849 | |||||
0xD823C605...d3e2d66cd | (X2Y2: Fee Management) | 10.333612913910890338 Eth | 10.333729913910890338 Eth | 0.000117 | |
0xEe5F5c53...390D04846
Miner
| (Fee Recipient: 0xee5f...846) | 1.456084435869564628 Eth | 1.456395192369564628 Eth | 0.0003107565 |
Execution Trace
ETH 0.0234
TransparentUpgradeableProxy.357a150b( )
ETH 0.0234
X2Y2_r1.run( input=[{name:orders, type:tuple[], order:1, indexed:false}, {name:details, type:tuple[], order:2, indexed:false}, {name:shared, type:tuple, order:3, indexed:false, value:[{name:salt, type:uint256, order:1, indexed:false, value:724360920610094, valueString:724360920610094}, {name:deadline, type:uint256, order:2, indexed:false, value:1663520330, valueString:1663520330}, {name:amountToEth, type:uint256, order:3, indexed:false, value:0, valueString:0}, {name:amountToWeth, type:uint256, order:4, indexed:false, value:0, valueString:0}, {name:user, type:address, order:5, indexed:false, value:0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff, valueString:0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff}, {name:canFail, type:bool, order:6, indexed:false, value:false, valueString:False}], valueString:[{name:salt, type:uint256, order:1, indexed:false, value:724360920610094, valueString:724360920610094}, {name:deadline, type:uint256, order:2, indexed:false, value:1663520330, valueString:1663520330}, {name:amountToEth, type:uint256, order:3, indexed:false, value:0, valueString:0}, {name:amountToWeth, type:uint256, order:4, indexed:false, value:0, valueString:0}, {name:user, type:address, order:5, indexed:false, value:0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff, valueString:0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff}, {name:canFail, type:bool, order:6, indexed:false, value:false, valueString:False}]}, {name:r, type:bytes32, order:4, indexed:false, value:C237457B868B4CFA7E8B7960F4A307F225D80D1EC32217678FB03D109A102584, valueString:C237457B868B4CFA7E8B7960F4A307F225D80D1EC32217678FB03D109A102584}, {name:s, type:bytes32, order:5, indexed:false, value:414A8BF94A350D52950A98A936082053841344A158D9F304358AF1292118EB2A, valueString:414A8BF94A350D52950A98A936082053841344A158D9F304358AF1292118EB2A}, {name:v, type:uint8, order:6, indexed:false, value:28, valueString:28}] )
-
Null: 0x000...001.7f4e9082( )
-
Null: 0x000...001.dc084a26( )
-
ERC721Delegate.STATICCALL( )
ERC721Delegate.executeSell( seller=0x946a8DE833Db03dfc2aAEA8EaD0EE7F4b21696b6, buyer=0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff, data=0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000B39F5F5199042086D6F162EDEDB761D0F33A28490000000000000000000000000000000000000000000000000000000000001648 ) => ( True )
-
OrcsOfOrakion.safeTransferFrom( from=0x946a8DE833Db03dfc2aAEA8EaD0EE7F4b21696b6, to=0xa39fC89ECB9132930e3aEc8ECcbeFbe312b125ff, tokenId=5704 )
-
- ETH 0.000117
FeeManagement.CALL( )
- ETH 0.023283
0x946a8de833db03dfc2aaea8ead0ee7f4b21696b6.CALL( )
-
File 1 of 5: TransparentUpgradeableProxy
File 2 of 5: OrcsOfOrakion
File 3 of 5: X2Y2_r1
File 4 of 5: ERC721Delegate
File 5 of 5: FeeManagement
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; // Kept for backwards compatibility with older versions of Hardhat and Truffle plugins. contract AdminUpgradeabilityProxy is TransparentUpgradeableProxy { constructor(address logic, address admin, bytes memory data) payable TransparentUpgradeableProxy(logic, admin, data) {} } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../Proxy.sol"; import "./ERC1967Upgrade.sol"; /** * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an * implementation address that can be changed. This address is stored in storage in the location specified by * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the * implementation behind the proxy. */ contract ERC1967Proxy is Proxy, ERC1967Upgrade { /** * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`. * * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded * function call, and allows initializating the storage of the proxy like a Solidity constructor. */ constructor(address _logic, bytes memory _data) payable { assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); _upgradeToAndCall(_logic, _data, false); } /** * @dev Returns the current implementation address. */ function _implementation() internal view virtual override returns (address impl) { return ERC1967Upgrade._getImplementation(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../ERC1967/ERC1967Proxy.sol"; /** * @dev This contract implements a proxy that is upgradeable by an admin. * * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector * clashing], which can potentially be used in an attack, this contract uses the * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two * things that go hand in hand: * * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if * that call matches one of the admin functions exposed by the proxy itself. * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the * implementation. If the admin tries to call a function on the implementation it will fail with an error that says * "admin cannot fallback to proxy target". * * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due * to sudden errors when trying to call a function from the proxy implementation. * * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy. */ contract TransparentUpgradeableProxy is ERC1967Proxy { /** * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. */ constructor(address _logic, address admin_, bytes memory _data) payable ERC1967Proxy(_logic, _data) { assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1)); _changeAdmin(admin_); } /** * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin. */ modifier ifAdmin() { if (msg.sender == _getAdmin()) { _; } else { _fallback(); } } /** * @dev Returns the current admin. * * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` */ function admin() external ifAdmin returns (address admin_) { admin_ = _getAdmin(); } /** * @dev Returns the current implementation. * * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` */ function implementation() external ifAdmin returns (address implementation_) { implementation_ = _implementation(); } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. * * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. */ function changeAdmin(address newAdmin) external virtual ifAdmin { _changeAdmin(newAdmin); } /** * @dev Upgrade the implementation of the proxy. * * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeToAndCall(newImplementation, bytes(""), false); } /** * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the * proxied contract. * * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. */ function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeToAndCall(newImplementation, data, true); } /** * @dev Returns the current admin. */ function _admin() internal view virtual returns (address) { return _getAdmin(); } /** * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. */ function _beforeFallback() internal virtual override { require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); super._beforeFallback(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./TransparentUpgradeableProxy.sol"; import "../../access/Ownable.sol"; /** * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}. */ contract ProxyAdmin is Ownable { /** * @dev Returns the current implementation of `proxy`. * * Requirements: * * - This contract must be the admin of `proxy`. */ function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) { // We need to manually run the static call since the getter cannot be flagged as view // bytes4(keccak256("implementation()")) == 0x5c60da1b (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b"); require(success); return abi.decode(returndata, (address)); } /** * @dev Returns the current admin of `proxy`. * * Requirements: * * - This contract must be the admin of `proxy`. */ function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) { // We need to manually run the static call since the getter cannot be flagged as view // bytes4(keccak256("admin()")) == 0xf851a440 (bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440"); require(success); return abi.decode(returndata, (address)); } /** * @dev Changes the admin of `proxy` to `newAdmin`. * * Requirements: * * - This contract must be the current admin of `proxy`. */ function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner { proxy.changeAdmin(newAdmin); } /** * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}. * * Requirements: * * - This contract must be the admin of `proxy`. */ function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner { proxy.upgradeTo(implementation); } /** * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See * {TransparentUpgradeableProxy-upgradeToAndCall}. * * Requirements: * * - This contract must be the admin of `proxy`. */ function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner { proxy.upgradeToAndCall{value: msg.value}(implementation, data); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { // solhint-disable-next-line no-inline-assembly assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internall call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback () external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive () external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overriden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual { } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "../beacon/IBeacon.sol"; import "../../utils/Address.sol"; import "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ * * @custom:oz-upgrades-unsafe-allow delegatecall */ abstract contract ERC1967Upgrade { // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal { address oldImplementation = _getImplementation(); // Initial upgrade and setup call _setImplementation(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } // Perform rollback test if not already in progress StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT); if (!rollbackTesting.value) { // Trigger rollback using upgradeTo from the new implementation rollbackTesting.value = true; Address.functionDelegateCall( newImplementation, abi.encodeWithSignature( "upgradeTo(address)", oldImplementation ) ); rollbackTesting.value = false; // Check rollback was effective require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); // Finally reset to the new implementation and log the upgrade _setImplementation(newImplementation); emit Upgraded(newImplementation); } } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Emitted when the beacon is upgraded. */ event BeaconUpgraded(address indexed beacon); /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require( Address.isContract(newBeacon), "ERC1967: new beacon is not a contract" ); require( Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); } // SPDX-License-Identifier: MIT 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; // solhint-disable-next-line no-inline-assembly 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"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (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"); // solhint-disable-next-line avoid-low-level-calls (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"); // solhint-disable-next-line avoid-low-level-calls (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"); // solhint-disable-next-line avoid-low-level-calls (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 // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly { r.slot := slot } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../ERC1967/ERC1967Upgrade.sol"; /** * @dev Base contract for building openzeppelin-upgrades compatible implementations for the {ERC1967Proxy}. It includes * publicly available upgrade functions that are called by the plugin and by the secure upgrade mechanism to verify * continuation of the upgradability. * * The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is ERC1967Upgrade { function upgradeTo(address newImplementation) external virtual { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, bytes(""), false); } function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual { _authorizeUpgrade(newImplementation); _upgradeToAndCallSecure(newImplementation, data, true); } function _authorizeUpgrade(address newImplementation) internal virtual; } // SPDX-License-Identifier: MIT pragma solidity ^0.8.2; import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; abstract contract Proxiable is UUPSUpgradeable { function _authorizeUpgrade(address newImplementation) internal override { _beforeUpgrade(newImplementation); } function _beforeUpgrade(address newImplementation) internal virtual; } contract ChildOfProxiable is Proxiable { function _beforeUpgrade(address newImplementation) internal virtual override {} }
File 2 of 5: OrcsOfOrakion
// SPDX-License-Identifier: GPL-3.0 /* * Orcs of Orakion A fantasy exodus by alvar368. Part I: Exodus Origins. 1- Introduction. There is perhaps no story in recent memory as tragic as that of the Orcs of Orakion, a thriving civilization whose growth was cut short by terrible forces well outside their control. Maybe you’ve seen some of them, arriving in small flocks of destitute survivors at human and dwarven cities, or maybe you’ve seen their more tragic side, in the shape of starved bodies by the roadway. Be that how it may, it’s impossible to ignore that something has disturbed the peace in the ancient lands of Orakion. The orcs that have managed to flee speak of metaphysical prophecies, curses and divine punishments - certainly nothing coherent, as testimonies contradict each other and make little conventional sense. 2- The Cradle of Civilizations. The semi-desertic land of Orakion is the subject of much prophetic and religious writing, especially in texts that come to us from ancient times. While the canyons, dunes and arid grasslands have been dominated by the orcish tribes for as long as anyone alive today can remember, it’s important to note that this hasn’t always been the case. Orakion is known as the cradle of civilizations for a reason, which is that many of today’s most powerful societies were born there, and eventually displaced for one reason or another. However, unlike other mythical lands charged with religious and political meaning, there have been no crusades to retake it, no pilgrimages to visit its ancient wonders, or tales of returning. This seeming lack of interest towards their origins is, to say the least, extremely surprising considering the proud nature of many civilizations with their roots in Orakion. The simple fact that the orcs were able to hold it uncontested for hundreds of years should be considered a miracle in and of its own. 3- The Primordial Demise. As with everything, there is an answer for even the most complicated questions. To solve this puzzle, we’ll have to travel back to the times when the very first civilization was born in the mythical land of Orakion. Known nowadays as the primordials, this society is little more than a footnote in the gargantuan tomes of knowledgeable arcanists and historians. They grew to become the most powerful empire in the world over the course of a few centuries, mostly thanks to their incredible arcane prowess which saw them rise above threats that profoundly oppressed other civilizations, such as dragon incursions and natural disasters. They became so powerful in fact, that some say they had a direct connection to the gods themselves, like they could talk to them. Whether this is true or just vestiges of the primordials’ hubris that lived on to this very day will probably remain unknown, but it certainly isn’t impossible considering just how proficient they were with magic; this civilization could make rivers flow backwards, enchant whole islands to float in the sky as if they were weightless, and teleport entire towns across great distances when convenient. The reason every kingdom nowadays isn’t a vassal to this supernaturally powerful empire is that they went extinct. Maybe it’s the nature of all sentient species to overreach when they achieve levels of power similar to that of the primordials. A collaboration between the world’s best historians, arcanists, theologists, and archeologists has finally shed some light on how the downfall of this original civilization is related to not only the exodus of the orcs, but also that of several races before them. The primordials created a cursed artifact, a gargantuan arcane cannon capable of syphoning the energy of the gods, a weapon whose very existence triggered a war between divinity and mortals. As it’s natural, the gods prevailed over the comparatively fickle and power-drunk primordials. They cursed the arcane cannon with divine magic of cataclysmic power, suspecting that they would eventually come to use it in an attempt of replacing them by absorbing their essence. As fortune would have it, the gods were right, and the might of the cannon had a very different effect than what the primordials expected. A wave of dark energy washed over Orakion, turning fertile grasslands into desert, vaporizing anyone it came into contact with, and placing omens of misfortune all around; anything that could go wrong, did go wrong. Infrastructure collapsed, armies mutinied, and civil war took care of the few surviving primordials. The arcane cannon was buried beneath the sands, consigned to darkness within forgotten ruins with strange markings that spell catastrophe in ancient language etched on their walls. After centuries, the darkness subsided and allowed for life to thrive again in Orakion, as if the gods were giving mortals a second chance. Ever since, new societies have risen in the desert, and when they become powerful enough, they can’t resist digging up the vestiges left behind by the primordials and experimenting with artifacts whose power they are very far from comprehending. New waves of darkness have washed over Orakion every time, after the new inhabitants of the land accidentally or purposefully activate the arcane cannon’s magic. This has caused the massive diasporas that seem to take place every few centuries, and the one we are seeing now with survivors from the Orcish Tribes of Orakion. Part II: The Journey. 1- Prelude. After a major political event known as the Consortium of the Tribes, Orakion’s many orcish clans established a central council to rule over all of them, paving the way for the orc nation to gain superior influence and cohesion by ending territorial disputes and focusing the races’ efforts on the building of a more prosperous nation. They followed the path of all civilizations born in the land of Orakion, of course. They discovered ancient artifacts buried in the sand that allowed them to perform wondrous magic, and they wondered what else they could find if they just dug deep enough. High King Waikar did what any ruler would do when finding a magical structure larger than anything his civilization ever made - use it. A few members of the central council opposed triggering the arcane cannon for fear of prophetic curses, but the warnings of history and prophecy are fickle in comparison to the freedom of the present moment. What happened after Waikar fiddled with the intricate mechanisms of the primordials was an absolute catastrophe, as expected. The same dark wave washed over Orakion, thrusting the orcs into near-extinction, and immediately killing those who were too close at the time. 2- The Orcish Diaspora. Those that survived the grim shockwave -about a third of the total population before the disaster- soon became acquainted with the devastating aftermath it leaves behind - infertile soil, auras of misfortune, psychic energies capable of blasting sanity away, and a plethora of similar curses. If they wanted to maintain their survivor status, fleeing Orakion was the only option. The remaining question was how would they do that, as most other races despise the orcs and would probably kill them on sight. The other option was to cross the Kyrr mountains to the north and venture into a completely unexplored land. With both prospects being terrifying, the remaining orcs were deeply divided and disorganized. Out of the shadows, a charismatic and valiant figure emerged to lead them, although not everyone agreed with her decision. The daughter of High King Waikar, Thytak, was one of the few central council members to disagree with her father, and decided to leave the capital along her most ardent followers, sheltering themselves and anyone who would listen to their reasons within a hastily build bunker teeming with abjuration runes. Thytak thought that the best option was crossing the mountain range to the north, because life as slaves of other races was not a worthy destiny for the proud orcish children of Orakion. Some agreed, others disagreed, but in the end most were desperate enough to follow her into the frost. And with the exception of a few groups that decided to travel south to the humansor east to the dwarves, they equipped their warmest and sturdiest leather clothes and began the odyssey that would take them to their new home. 3- Crossing the Kyrr Peaks. When Thytak, daughter of Waikar, said that the orcs were to cross the Kyrr Peaks, no one doubted it would be the harshest endeavor they had ever faced - but still much better than staying behind in the cursed land of Orakion. However, they couldn’t have possibly imagined just how terrible it would be. Kyrr is the very definition of the word uninhabitable, not only because of its freezing weather, snowstorms, avalanches and precipices, but also because of something few ever speak of: the monstrosities that have made it their home. Frost spiders, horrible beings the size of a barrel, were one of the worst creatures they encountered. Their poison is cruel like no other, increasing the freezing point of blood, effectively solidifying their victims’ bodies in a painful process known as sanguine crystallization. They were not the only species to claim the lives of many orcs, though; zenith wolves, a winged variant of the common predators, took hundreds of them in their aerial hunting raids. After nineteen gruelling months of travel, they managed to leave behind the icy hellscape of Kyrr, descending into more temperate hills, but still taller than anything the orcs had ever climbed before the cataclysm, of course. Those hills are known as Death’s Stairway by the orcs - such is the trauma Kyrr left on them. Only a small fraction of all those who followed Thytak survived the perilous journey. 4- Arrival at Seamstone. From the last hills of Death’s Stairway, the twice-surviving Orcs of Orakion could finally bear witness to their new homeland, a beautiful region they named Seamstone because of its curious rocky formations that intertwine with patches of moss and grass. Slowly descending, their bones still chilled from the journey through Kyrr, the orcs made their first huts. Despite all the loss and suffering, a festive mood washed over Thytak’s host, and hastily collected fruit and roasted boar were laid out in a feast. Relative abundance welcomed them into this new land, with readily available fruit, lumber and wild animals. After most had recovered from the exhaustion of the journey, the orcs began their quest to scout the land around them, to locate good hunting spots and mark down the places where valuable resources could be found. According to folklore, a town only becomes a town when the first inhabitant dies and is buried by their people - that milestone marks the moment where the settlement is established not only in the material plane, but also in the spirit realm. Seamstone’s first death arrived fairly quickly, only three days after they landed down from Death’s Stairway, as a bravewarrior named Kural Taikir died after the wounds left by a frost spider proved too much to bear. And as the spirit realm became acquainted with the Orcs of Orakion’s new home,something eerie encroached their settlement... Even the dullest of orcs has noticed that something isn’t quite in its place within Seamstone, not since Kural died. Children are scared of playing outside, and they speak of moving shadows that observe them from the edges of the region’s many caves. No one knows what strange powers rule this land, but Thytak and her followers know that they must uncover it quickly, before they are exiled by the supernatural once again. * / // File: @openzeppelin/contracts/utils/introspection/IERC165.sol pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface 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); } // File: @openzeppelin/contracts/token/ERC721/IERC721.sol pragma solidity ^0.8.0; /** * @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; } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File: @openzeppelin/contracts/utils/introspection/ERC165.sol pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File: @openzeppelin/contracts/utils/Strings.sol pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // File: @openzeppelin/contracts/utils/Address.sol 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); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol pragma solidity ^0.8.0; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File: @openzeppelin/contracts/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 IERC721Receiver { /** * @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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // File: @openzeppelin/contracts/utils/Context.sol pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: @openzeppelin/contracts/token/ERC721/ERC721.sol pragma solidity ^0.8.0; /** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata extension, but not including the Enumerable extension, which is available separately as * {ERC721Enumerable}. */ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata { using Address for address; using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _balances[owner]; } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "ERC721: owner query for nonexistent token"); return owner; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require( _msgSender() == owner || isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ""); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @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. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer( address from, address to, uint256 tokenId, bytes memory _data ) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: * * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint( address to, uint256 tokenId, bytes memory _data ) internal virtual { _mint(to, tokenId); require( _checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer" ); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver.onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert("ERC721: transfer to non ERC721Receiver implementer"); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual {} } // File: @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol pragma solidity ^0.8.0; /** * @dev This implements an optional extension of {ERC721} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); return _ownedTokens[owner][index]; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = ERC721.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // File: @openzeppelin/contracts/access/Ownable.sol pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(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"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // Created by HashLips /** These contracts have been used to create tutorials, please review them on your own before using any of the following code for production. */ pragma solidity >=0.7.0 <0.9.0; contract OrcsOfOrakion is ERC721Enumerable, Ownable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; string public notRevealedUri; uint256 public cost = .036 ether; uint256 public maxSupply = 10101; uint256 public maxMintAmount = 20; uint256 public nftPerAddressLimit = 12; bool public paused = true; bool public revealed = false; bool public onlyWhitelisted = true; mapping(address => bool) public whitelistedAddresses; mapping(address => uint256) public addressPresaleMinted; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); whitelistedAddresses[0x4758ebEd66Bba81058efD08d1ea5a471fE31e1B7] = true; whitelistedAddresses[0xbE264cC36eb3cfAd71fa269f6b4960586393135F] = true; whitelistedAddresses[0x2fDB18E9FFDFCa350B0Aeb7CC799E1321664EDf7] = true; whitelistedAddresses[0xb50e6eD73323262E1750Ede06213C44CC09063D4] = true; whitelistedAddresses[0xDFe459eEF79721E5551c7778B54f459E2A113d31] = true; whitelistedAddresses[0x4A79D7D3E5C0C554323D4134425ebFEA473536EB] = true; whitelistedAddresses[0x974b20E3c2682a3dd37A01645aC5165bbcA623F2] = true; whitelistedAddresses[0x775A3B8AF62A53c5241c2375480521d444aE1309] = true; whitelistedAddresses[0x29e01eC68521FA1c3bd685aA4aDa59FAe1e7C048] = true; whitelistedAddresses[0x0Be12a0fE70F24f054a5565956D71047eb976dB0] = true; whitelistedAddresses[0x602b6f59F56a1008D76cB556a974ffe84266B5C6] = true; whitelistedAddresses[0xF29438cB61ac85564329F0e470e90a7247945a0D] = true; whitelistedAddresses[0x42175856652185ddDBD5477fBb1f7f4FC446847D] = true; whitelistedAddresses[0xC76B852AFaD99eEf4338561246f8a2C327AFab0d] = true; whitelistedAddresses[0x4b41AA10bf309aa7b5eB30e18263fd9963434F2d] = true; whitelistedAddresses[0x1Edaa6011c0187B0Af5516ec35BC0a22e2994C31] = true; whitelistedAddresses[0xcf5931a325d0FF94ecfF3f946c283F05634aD106] = true; whitelistedAddresses[0x608350082bA3766aFeFE84771fD0bE95210D220A] = true; whitelistedAddresses[0x3BF2fE6BFB2c713fd82ca4b93f1Fbb507A389671] = true; whitelistedAddresses[0xf85Df24BEBBf98758164cd24831704cF1707c656] = true; whitelistedAddresses[0xd6BB082d1167aCFC4bd856f75cACd9aEd634C724] = true; whitelistedAddresses[0x1d008783A469Cf5D017f467fe139695040d9B465] = true; whitelistedAddresses[0x0565c501640ccF3E1cc37AA3E4241bDea98010c4] = true; whitelistedAddresses[0x2Af8fEc81FF8822170E3263E9D07F88D2F5f05c8] = true; whitelistedAddresses[0x8f0f3FFDfa8D418Ccd8F2c7659efb25980Fb736d] = true; whitelistedAddresses[0x200eBF3C9cAa6c762cbD0f1f420830e793C8FA88] = true; whitelistedAddresses[0x7DC78F088d1ddd30d75aD6205893Ea2Ff5B0a8E4] = true; whitelistedAddresses[0x98005bF51B93Ee31309c7Dc68783EfbB47B63D1c] = true; whitelistedAddresses[0x7140ff1BC29d56e2ef0a32C078f4f0acbF7aB0Bd] = true; whitelistedAddresses[0x88b4C088830a6cfed3bE2d5A6aaAcf0482ACf561] = true; whitelistedAddresses[0x0063146925Da753F393bBce6522e87dc524e9Bd2] = true; whitelistedAddresses[0xf95699b2c0bBe33195fe1aBcD97171d64F817c35] = true; whitelistedAddresses[0x3aebF17C58C425a4Cb3789cdaf22eBb0CcC9073E] = true; whitelistedAddresses[0x89bAF7A6516BE419bAc84ae10e7857BC33B25f8a] = true; whitelistedAddresses[0x23D5EEC14AFc9d642c41109b0C7e0eC782990411] = true; whitelistedAddresses[0x672CBFF03eF5A6D0B4AD736EA181CB6c0b467c88] = true; whitelistedAddresses[0x791C67718E70eEeDA196B1C5219f9892551fbC9A] = true; whitelistedAddresses[0x26057502EbBE02dDD5D0F0878b1490B3ee00D9eb] = true; whitelistedAddresses[0xe1E97e9554e3C1269b82c702F69D98da8e49f0a9] = true; whitelistedAddresses[0x945A4cbae4eF06C0114F53457404A49a6765d9a6] = true; whitelistedAddresses[0x7e15893ed2ccFcB8a34C0b6557e7107322C32e59] = true; whitelistedAddresses[0x40d6F4B4d5Ef496682c7C3fCC0dBfa113E5B0336] = true; whitelistedAddresses[0x9fF09099a9126d131aDcc594857405380c6FA3b3] = true; whitelistedAddresses[0x8616cA1705A3a3B70cF53638012d44857A40CD78] = true; whitelistedAddresses[0x1EB4E259EAc3d97ceD2d88923eB3CCa5139019F7] = true; whitelistedAddresses[0xBfB4848894e6C30d9121B6460e13287d96881391] = true; whitelistedAddresses[0x3302545161633a3B55D11496fB38f0aa7b10ab3d] = true; whitelistedAddresses[0x9bE87B0edeac66d8b8d262Ee970F6F241bA5c2C0] = true; whitelistedAddresses[0x09f7365d1ecE51Ae2821D8647Fea73477AA9E705] = true; whitelistedAddresses[0x6fFfb61Eac20041F442A56D10A5CdB24deeabA0e] = true; whitelistedAddresses[0x1b46D512E2D22cD4c5186d34525EE2bfAE70ecbE] = true; whitelistedAddresses[0xB69Ce5c5a14DafbF476F16f2918ac3c860242fbe] = true; whitelistedAddresses[0x5609A3944FE052fecbf0a362E305C8c72531B5d4] = true; whitelistedAddresses[0x1Ff5a5c5eAFBF880b092ED07aDa724169b81148F] = true; whitelistedAddresses[0xA345710c3C720f20d571Bf6F03eCbA434E9FC92B] = true; whitelistedAddresses[0x883405eBD164aBE509CFE0e2E14D3D7C80d3BeF6] = true; whitelistedAddresses[0x895D4CEE80523f8e52777d5fb87B2297495d41e3] = true; whitelistedAddresses[0x69Ae4a613A0aBf6fBb2bF2AafF91AE2c113B49d3] = true; whitelistedAddresses[0x1E87fee9DE0C6453c0a405eb87BaD0d3c5Ecec0f] = true; whitelistedAddresses[0x25A18C68aF97eE250980Db306B68E9D3Bc0A184d] = true; whitelistedAddresses[0x11E17Cdc4C298f3B2b5530b6beCf95c02954aE51] = true; whitelistedAddresses[0x5b7Cb6CE6Dc5ab6b3bA89483De86e8E403f22e7e] = true; whitelistedAddresses[0x5012805693dDd6a5B13F7B103a0F17781cfF6Fe4] = true; whitelistedAddresses[0x7aAF6A9d9d48b52530acad957deA3Fe05abA6313] = true; whitelistedAddresses[0x56b229Ca304507A17abB26A80d7a723d8D8513e0] = true; whitelistedAddresses[0x3fB840c9F362407Eeb62b221f712D78fECCfC80B] = true; whitelistedAddresses[0x570A4aDF9Ce7Ad402b2BA7615909Bbd45532A8De] = true; whitelistedAddresses[0x2B6F5ee4d2275DcC1CF08EC01baa5B4D5b967d0E] = true; whitelistedAddresses[0x9a951FF7D6b1d00216B4242696C57A3232BdA1E6] = true; whitelistedAddresses[0x6405af00280152866500E4ED91ee462E7f7588bC] = true; whitelistedAddresses[0xE85DBB09A699c0543C363c3f6E51ef0049e3edC5] = true; whitelistedAddresses[0x3B16B077aA86baE7eD45c41906Adc4fFAcccFf0E] = true; whitelistedAddresses[0x643B34C9d7C851bf69Bb766615F860A70f4C9C86] = true; whitelistedAddresses[0x77fb9C7D16BE80744E29E8F7De6Fe82ae6c9d11D] = true; whitelistedAddresses[0xb84d84019Af5EeBf81b378E98567068dCB9B622b] = true; whitelistedAddresses[0x4Cd919427f745B40096EaBdF38110b42695c41cb] = true; whitelistedAddresses[0x62a8cA10762DFa01475B7c5C232362DF28861C08] = true; whitelistedAddresses[0xc7322ee2d0E4EBD824adbee58F38FB51352ca8C9] = true; whitelistedAddresses[0x6Db9C794d95e63FB9Bf4D12151A7e5315BDC4871] = true; whitelistedAddresses[0xC72F857434F0a0ca9bf08FC2750A2B874e201550] = true; whitelistedAddresses[0xA959735A1aF98eB7596FaBFe6E135E9f0ABd7E4d] = true; whitelistedAddresses[0xEC1acA289F794473277aeb09a073f7e610aFB1Ff] = true; whitelistedAddresses[0x2B167CA199E6EBDeF5008CbAd7a21A9Ccb15c46d] = true; whitelistedAddresses[0x4769Aab421dE170f1f5781B9b0d3c1415645293E] = true; whitelistedAddresses[0xd4e0269F31c5E0ecc3fF9fd47cfF282f51101767] = true; whitelistedAddresses[0xA2cA851525d76e7D1Ab2154292a614E0f59CA67D] = true; whitelistedAddresses[0x47D0DD1c5A0125F6e52fBAc3e202bfec60eCBDc2] = true; whitelistedAddresses[0x88AaA2027Abb20a9180ae051Fd0662226C148E57] = true; whitelistedAddresses[0x5b26888b2fD5C617e95Df5bB7b22644Bf2Aa5930] = true; whitelistedAddresses[0xb604F3b93882dFaEDc878154cea9892f78e0Ea45] = true; whitelistedAddresses[0x7438319E0784612dE7804e303baA52Cb3c8dB5F5] = true; whitelistedAddresses[0x3A87081794fE7506ae0F7cc30a64ad5FE82dC47e] = true; whitelistedAddresses[0xA95c8435846F82F4D35d57f9973A4e0D96E69a22] = true; whitelistedAddresses[0x0D3Ef24cCd12827CcE51bcA43Cf9EfB78380429c] = true; whitelistedAddresses[0xE51341E05699Ed92C4d0402F4E955862423d3aa8] = true; whitelistedAddresses[0x3d57e3C0fe386F57766995F84BB4eefFAee72bA6] = true; whitelistedAddresses[0xbdfb224D5e089d85366D535eEFEE5810F23e08BE] = true; whitelistedAddresses[0x3f0749EE9a009EDE06A95d1e19986B9bB8D3b0A8] = true; whitelistedAddresses[0xb0086CEd87CeD727E01c3b15E54D7Ef04301aC31] = true; whitelistedAddresses[0x58C48A54a36D346cB71D63ACa5599166bAd21851] = true; whitelistedAddresses[0x0E36299e2b2CA72a777567dDaB019bc0Ebd92965] = true; whitelistedAddresses[0x8F6a7A97f3b6CEE0E374b38292Eb87723679C882] = true; whitelistedAddresses[0x68710ea91627232d3b7D4083c7aeec912cCDc2A6] = true; whitelistedAddresses[0x8A029549B53b04B1003f25e6E3c830E5Ed477509] = true; whitelistedAddresses[0x96F91e3eB4840140eeDC51126A4DF1b51B6bc746] = true; whitelistedAddresses[0xB3D264380FFcf9E764A16Ee9Addd08bdCF46093f] = true; whitelistedAddresses[0x41cf769131D4F75C662c53D592c91d56fFD45a76] = true; whitelistedAddresses[0x12ADc0CFB830f71D52ee600d952976054557E5C2] = true; whitelistedAddresses[0xeD947a0F9170DE48e347F657762199F7E2992110] = true; whitelistedAddresses[0x3f109fca5C317Ec9Ce06a6E5D8e9C7792737bC7b] = true; whitelistedAddresses[0x3B1fc9653f03789BC399fC343d8D5B8fC1520EA0] = true; whitelistedAddresses[0xB98C60Fe6736454999af07D642c21Cc0Dc443f25] = true; whitelistedAddresses[0x6d6Fb3FAf9432AcE1900A3B9F66ba40Ca5cd7C0e] = true; whitelistedAddresses[0x14378456B32f2Dc8f41D44b3613b4D6fF9eA2b83] = true; whitelistedAddresses[0x12AcD4607393F5cf772bfF4138107325d7c4Ca09] = true; whitelistedAddresses[0xF4151e12614478c94Db8Df53F1E1Ad12c778c4cD] = true; whitelistedAddresses[0x662195b64795a74f0e4b32A64f0B220010dd5562] = true; whitelistedAddresses[0x959786a8128F5FAB24b86871266a36bb0DecD495] = true; whitelistedAddresses[0x6BA167a348DA1d17C34DDa4f94CaD7C6155C5702] = true; whitelistedAddresses[0xc5c0E639EE5d59F40f14BC4110bb0BE99C06988e] = true; whitelistedAddresses[0xcF991E3f8414A8949967D51550683852D47F88F2] = true; whitelistedAddresses[0x63294F76dD7E0Dd78fb3c430281B2DAE494EC926] = true; whitelistedAddresses[0x445a368791A20735860d42a88987F29BF9d22E01] = true; whitelistedAddresses[0x4DB6cDd13653736044C2ce25751FC5656ca4763F] = true; whitelistedAddresses[0xe576b9C06Ff11869127e7CD97CcDE7141ee004BF] = true; whitelistedAddresses[0x9d45Aa7D07d9945bD011E59Ad3Fc9aCD380a4258] = true; whitelistedAddresses[0x0715C3329e38790C853F6fFD824f2771a02D37bf] = true; whitelistedAddresses[0x8d160063E641252F4B424A9Af89E88B24e04e444] = true; whitelistedAddresses[0xd6957Ce22991b02e352EE11E94FBc7800d5918e0] = true; whitelistedAddresses[0x4cec1074e2A72E6943a13CE16dA7589388bf94C7] = true; whitelistedAddresses[0x2A4E9CeE0b1c25f026A0E77Ca5931ce7BAb20a23] = true; whitelistedAddresses[0xCd6d1513C6ebB784661Faff7a4b3CD595C555cc6] = true; whitelistedAddresses[0x3eb8F88422dFd2AeCd1969E24443281cdA239aCD] = true; whitelistedAddresses[0xa43589Fc8f89f02AB33f3a96De1601624f7Ee06c] = true; whitelistedAddresses[0x84096Bd010Fee8F97C307bBDAa57bDd98EFA93B5] = true; whitelistedAddresses[0x3f8ADbe12456188433d0CF09E0472084c4F29671] = true; whitelistedAddresses[0x4fDA56C38fE5f6752106D4bAD20D50D1331744c5] = true; whitelistedAddresses[0x5c9E61218b86c3a698F5F2B9802eEAADe1a09fe2] = true; whitelistedAddresses[0x46d3318E8E669a311A8535798213Cb6E3f321cDc] = true; whitelistedAddresses[0xca04b727f8b776c1F62616448aa2A0bE25C82ab9] = true; whitelistedAddresses[0xb94872bc787343e194c069FFeB7621cBea41FF73] = true; whitelistedAddresses[0xF35341818A13B783664053B1B0f834e658Dcba87] = true; whitelistedAddresses[0x1cD09116Fc412247f09f4E3CA562D24d1866BBe2] = true; whitelistedAddresses[0x66e31A557cAac68d3c218ffD0ebE6146D57F66DE] = true; whitelistedAddresses[0x9eb5b3414B197F7ee1fA7C036931741f081897D4] = true; whitelistedAddresses[0x02Cd407BD1216C4b227e20dDaB1837f5A74233E4] = true; whitelistedAddresses[0xDd6969dC2ed9256cE3c399315a685cE4D4E5F720] = true; whitelistedAddresses[0x52D3e1E323C1c99E049Ab2639B5D0F4d4fe612B7] = true; whitelistedAddresses[0xcc747443a483a0559F666F5d3D4B6F7b6d2280E9] = true; whitelistedAddresses[0xDb4eaEC2bE282909E46aCEbD57ff89D8dFecC13d] = true; whitelistedAddresses[0x5A884D400df60D92391185D39BF169700A049539] = true; whitelistedAddresses[0xAa74BE7b5Df3891fA88e383Db17A0D39965ABAf9] = true; whitelistedAddresses[0x31e4a3EF430A729A133483AC783963CE41ceDa3E] = true; whitelistedAddresses[0x7b207d27FF26069E48EA631518a2E784a1460cB0] = true; whitelistedAddresses[0xf329D15E72a6AbeD9F9290F1065312819f43727a] = true; whitelistedAddresses[0xC9d60143128cbAc15037cF555dEdd23CCA7e4393] = true; whitelistedAddresses[0x29d6aB0E6316F90766c0A158eb204A2Bf60AC23d] = true; whitelistedAddresses[0xCB0835D01fd2c20f68fA3B918d86343fE4EC1A25] = true; whitelistedAddresses[0xabb893748F86B289E67D01231fda5015BE02Ab83] = true; whitelistedAddresses[0x9c4b443632B7d511379fe3AcA3DDcfA8F197b302] = true; whitelistedAddresses[0x37C86E28548ddA9267Ead1CA363D6441c0bbCd6e] = true; whitelistedAddresses[0x5D3b8520dac5b0CCA62Df147528f04Dc39BA23aa] = true; whitelistedAddresses[0x0a06C890438F84e9848AF76102341C7A7E2133AD] = true; whitelistedAddresses[0xbAC1b29acB014AFab23Dca3B7Be6Fbe90256AB53] = true; whitelistedAddresses[0x637ef5aA5CaeF174a2b45EcDC560a1AfB16668bd] = true; whitelistedAddresses[0x2C434867d28Da51549Dff76fB127cE22B9aA46c6] = true; whitelistedAddresses[0x15af8DF7541d8d1264dd14aC6baddB04b98A89aa] = true; whitelistedAddresses[0x4E0A88B2bEC15a8c1cD87d79DF5D145323c5EcB7] = true; whitelistedAddresses[0x2749Af4bef7c7042D37DEeFA7978Dc325f461eb0] = true; whitelistedAddresses[0x0E1606f50626D92aBBc39E6fbEEbbC3DC76E7b3b] = true; whitelistedAddresses[0xB4C574334615cC5155639038b67208063cc278b8] = true; whitelistedAddresses[0x60b1659C8b848bdBCb85F4E4792F69C90AAa3648] = true; whitelistedAddresses[0x06e669e9E19D4FAE54171326A11105F4FD12BeDe] = true; whitelistedAddresses[0xEDa4c9B9E79011852A1D7c2105122b0c637B5b05] = true; whitelistedAddresses[0x9CEc27472De184D84d9872377241Cbe4009F3709] = true; whitelistedAddresses[0x2398c7Cb91A3E929B222C045e0A5A5Cd80826b93] = true; whitelistedAddresses[0x0E1b6F1b4697C885cCCC9C31d076947522F7CAed] = true; whitelistedAddresses[0xDb5e9f11d0161780cd1C2be5A1C949eaA7557352] = true; whitelistedAddresses[0x505438B4211D596D7B2A1f0ED47579cE474e5605] = true; whitelistedAddresses[0xff4c0AD1A5c616eB96b96DABF5F39C56948BF83F] = true; whitelistedAddresses[0x3aE6690d3b1b27A3D1aa0d399EF78edF13bFd610] = true; whitelistedAddresses[0xd5323d893D721954B2d7bE195279cB2e08f48342] = true; whitelistedAddresses[0x58491C8138e41101bFEC260466EBD3DF053868e0] = true; whitelistedAddresses[0x82Bf6D61b2cB35f9bb08Ec99d02f80D6833271Da] = true; whitelistedAddresses[0xD9587b5851cfD9917D358721Bf56C31DD285CeE1] = true; whitelistedAddresses[0xF3c84E5cc17E59a78F2fdd5500BABD61023aC830] = true; whitelistedAddresses[0x7636A5878FD870421D3e546a4b3076BaD870Ec8E] = true; whitelistedAddresses[0x1Dc1615b4f3a7ad3e5E340e8002bA34Ad0B773Ad] = true; whitelistedAddresses[0xce25Fc8a802eF77AD244429387CD8eb0cA2557A9] = true; whitelistedAddresses[0x48302b76c0Ff2fd1cD1b698Be2a8cA5be4De0daF] = true; whitelistedAddresses[0xbd891dF7b6a7C2eBF4da7f3EE10e6B4642AbA2c9] = true; whitelistedAddresses[0xB20B5e7Dd0525dC442649C7Dee450Feda2E43C9d] = true; whitelistedAddresses[0xD6d57d174BE03101c29C1EB3a335559014896BC7] = true; whitelistedAddresses[0x9352421E3163a85Fe32CE6aaA116F3C64b3e6aD9] = true; whitelistedAddresses[0x380fEEA870DB5EDd638A8fe78A271FA6E707826f] = true; whitelistedAddresses[0xBBf17d93A2307dF43F7cC1098EFcf0985e995C65] = true; whitelistedAddresses[0x0C4938ec23887D1384dA8c0E611042905a366f0E] = true; whitelistedAddresses[0xc8b506B8150Ea6Ee0cbd7dC71034B12d902141d7] = true; whitelistedAddresses[0x19E34146D1719bb7ceC1cA0896ED5fA88DCEc5C7] = true; whitelistedAddresses[0xAe04e4AeFe095D6591c0d5774A226Bc7098D5fA7] = true; whitelistedAddresses[0xeE97cbF18Fc41C068eb8AFE67025353346c5fA02] = true; whitelistedAddresses[0x4986ac8522E8831e71439C529E514022596c301B] = true; whitelistedAddresses[0xc40b73C6356c98de9a32680a6466d0dAbba04C37] = true; whitelistedAddresses[0x94705A9d675daa924F9190Eca4c05ED6B12d5345] = true; whitelistedAddresses[0x92451CCf65d681ECB2294114795873e63a4a6883] = true; whitelistedAddresses[0x74A8bbe4329024ce3D4920474Fb58ca72bfAF42D] = true; whitelistedAddresses[0x95c59B9ac2c6F2eD1BFC218CB38f87Ff9d3Bf047] = true; whitelistedAddresses[0x338bEF2AF24EcC89261c81d3fD23F012f0ABcC4E] = true; whitelistedAddresses[0x1ba7852b19994145bceC6b4F94A0BBc95BcFa94a] = true; whitelistedAddresses[0x80b759F0A9391e64351e6b94E32c384A40D96b7D] = true; whitelistedAddresses[0x664E2D99df6747ef42E8a767c0BF8B8CEfd6F373] = true; whitelistedAddresses[0xb8ff1c4Bf352e5D2986a7c7d1196759602A4abFd] = true; whitelistedAddresses[0xb3244abE943ff149fc98096c8fe024cf7146A4ad] = true; whitelistedAddresses[0xBC82a96210555A04bdaDb29cd442F18687F1Fb9A] = true; whitelistedAddresses[0x3aa003558fA236B3beB9B935B85e04D150ABa9bc] = true; whitelistedAddresses[0x8c1D80bD49374d7d3f6cE123df2d8A13121486eb] = true; whitelistedAddresses[0xD3CE769b8EDda71B86CADb0d4BdBd252897F1753] = true; whitelistedAddresses[0xa4A0eE63Ac185Df4E2CAB3583F21a48C6d80b919] = true; whitelistedAddresses[0x13119eA6B582302Eeb3fe78931CD3aE9b7A7532F] = true; whitelistedAddresses[0x81f927795b64Eb3867Cb55D4eb47a06ffceB5daA] = true; whitelistedAddresses[0xdb8c009F29F8A376e7aE2Fc75D55e8C12F109aB4] = true; whitelistedAddresses[0x98d80eD82a3e68157139E2d9Ea6b137e9a358f7D] = true; whitelistedAddresses[0xE934837666854c8B81FB85F93c2ba110602b77Ea] = true; whitelistedAddresses[0x929B8AEC1084FaC2b6cA1239c82E5Fe78Dc79d2B] = true; whitelistedAddresses[0x1fCca6CcB88AFBc361f0e2a7BFd0AF7d737548c3] = true; whitelistedAddresses[0x2D3178af3Dfbb679716cc14E245Be0A9E5945500] = true; whitelistedAddresses[0xecbd13e77b74F9Fb052C8dc30Cc0E989BF3dD0A6] = true; whitelistedAddresses[0x940E6267bbaC505d6b902472e8D2f367b4Ac0997] = true; whitelistedAddresses[0x7Ac9385A9E821BDF5eEfDf0393F06aa844C5a061] = true; whitelistedAddresses[0x23330e0A0fd8c954DD377bC7435C8BB409031D23] = true; whitelistedAddresses[0x861a085492476E06077B18DD62176fbCDa663425] = true; whitelistedAddresses[0xc26e0041a142D8A77aba79D73b76fbFD8e627dA0] = true; whitelistedAddresses[0xf26C285B4AdAb350e7E46144CdEF01D4Ad2E46Ae] = true; whitelistedAddresses[0x699dD336AC982AF000d2171275f1DD0Ec5668C2B] = true; whitelistedAddresses[0xFb74ad209eB3B114C05e02c45a761aF03334E184] = true; whitelistedAddresses[0x727AaB0c8f805395444D069408492AC7b8065525] = true; whitelistedAddresses[0x2AA2DeA1cD1dEB2a67C055C5daE974EFD347d5cB] = true; whitelistedAddresses[0xABfe6Aa0284c548f891c5942DB2743D2dfE4D9E1] = true; whitelistedAddresses[0xcf800e8080C3B7F508ec90CF16e3529849CeAB8F] = true; whitelistedAddresses[0x80f30d26fe2c61B56ACF51f0C12eF74d09d41F26] = true; whitelistedAddresses[0x639638a0879e5b4151aff8a643A58B2931c2336A] = true; whitelistedAddresses[0x18EB2e1f8eFcFcb092B700aeA3324f00FdBa08Ee] = true; whitelistedAddresses[0xB49E25DfF20B4393379F7D54f0106E0bb7c7b28D] = true; whitelistedAddresses[0x33bF863e0DC4001ac96c80f4aE8B449B8aD48F88] = true; whitelistedAddresses[0x126B9489FB9c9BA88DcBEa78AB476b8F910F6D6e] = true; whitelistedAddresses[0xdbc898A01c6B6b9E5F73aa321BE32FC5F136C69e] = true; whitelistedAddresses[0x70Ddc7ba0c36CB41EAe05EA86221C9b5f5709db3] = true; whitelistedAddresses[0xA78153D70acFdD2cbf32Ffea9D84074D9d6a5DE9] = true; whitelistedAddresses[0x742B5F5FD0c3D32cA23D0bcE4095Ca652723A549] = true; whitelistedAddresses[0x55a05dedcF2344758F6022D9648494DF8F61C9f1] = true; whitelistedAddresses[0xF3bb575269D16DC7a11De9A6A34175bFB90acC3e] = true; whitelistedAddresses[0x70cDC5CED681EA2D965D72C71d668dBe6235B24c] = true; whitelistedAddresses[0xFECc5C778B6634A9A173D8dB932181666dD95ec6] = true; whitelistedAddresses[0x3828330e1a4DD3b97E976e249C7Bc8979eDA6B32] = true; whitelistedAddresses[0x7b01D04faE0aB2479344Be8dAaEdd0Ae1b04486F] = true; whitelistedAddresses[0xF9663df170979Ac64F5806b101C894a1A8F683BD] = true; whitelistedAddresses[0xb57c0b622A5a5FCdeb22E49953210fd4c1DE2194] = true; whitelistedAddresses[0x9De4E4cc181d9d1966ab58E07378EF225425ccF0] = true; whitelistedAddresses[0xc36E7E0f9A102308C52a53004c171B42AC6A7160] = true; whitelistedAddresses[0x75EC2e2976decAe6303b7C6AE6C453C3A98b4D72] = true; whitelistedAddresses[0x07F9046B8f8F3b93ba688F97D1a85bfd4b08d9A7] = true; whitelistedAddresses[0x016D4412299A7B77b61078E73BAC9d6de4821000] = true; whitelistedAddresses[0x53B581f0F916e09ba07B6204e8720a1d9323521A] = true; whitelistedAddresses[0x9D2a6Dc7aff9950CF725241441584540B2ac1ca5] = true; whitelistedAddresses[0xCA7080A463706725E1632145cfcc7dB53eD25f96] = true; whitelistedAddresses[0x5fbfe8dAB81A39A04B9590dFcEac9a93e7aa3302] = true; whitelistedAddresses[0x6dF01b9e66d3267F1f8949A9e35f89043FE9822c] = true; whitelistedAddresses[0xE876B553741a879967f8c502b757E919Db1a8b5e] = true; whitelistedAddresses[0xe05006Dc1369ef6BBcFd696A38a573C8C28A8E7C] = true; whitelistedAddresses[0xd9718542D7832B322e92Fa03F408D02a4d47C2c5] = true; whitelistedAddresses[0xC6b62b1688C2B3B1a12E3d222DdaD43BE379c1B6] = true; whitelistedAddresses[0x0e93545Edad0Ba8884bCEe70618c3D8D4D73d5B4] = true; whitelistedAddresses[0x4Db180f14A91d3e01776DB3cA2993676543C2A06] = true; whitelistedAddresses[0x4f4FCA10d1863FF5fea61b8dD3E7a7F8a6bC77EE] = true; whitelistedAddresses[0x2f8e0f91Df5A26783633910bA9Ed4B3b7b7883E3] = true; whitelistedAddresses[0x9713222695378e27511779Ba00b7cBF178120371] = true; whitelistedAddresses[0x0475fFc635B0F1cd52c7DAEa24e7aF02A575551B] = true; whitelistedAddresses[0xA8f6Af28BFab672859AcF31EcA54C81a9CbBeB66] = true; whitelistedAddresses[0x466C40b45Fd199282EF116406DE3Ba7e548426e5] = true; whitelistedAddresses[0x2657344889F180A85a845fA2b04ECD5637508038] = true; whitelistedAddresses[0x17A985095BD612A9B6278f8dd8A6D91Ec79dD81e] = true; whitelistedAddresses[0x17136144999C10439D90A2aC22386595BfEf0527] = true; whitelistedAddresses[0xE7CCfF5De5D5bbc638394D917EBFA6a60Cf38C08] = true; whitelistedAddresses[0x01DaC505E000d4B87e427271Eac85B4a46B5141D] = true; whitelistedAddresses[0xb63ea4865cDfedF3A7bCa5Df5BD49F04D59ea348] = true; whitelistedAddresses[0xc3A8b0eE40098E32C1d749EBcDc6C144ada911CD] = true; whitelistedAddresses[0xc58374eA34717411FcE751B29498ea234FabE17a] = true; whitelistedAddresses[0x1c7bc5daaF0A913d922839196c08CF1d7b74fb12] = true; whitelistedAddresses[0x04f23CD6624A3a1E205A59DAAe3F7b589bBb56CE] = true; whitelistedAddresses[0xBEA8e78462246F7Ea4B531B4cB2425B329846208] = true; whitelistedAddresses[0x291B104D72Be6a1eff9cAcA557E4745c4b10b064] = true; whitelistedAddresses[0xD89863049aABCd4626590fdebD00aF11D8233173] = true; whitelistedAddresses[0xE83370D402504Ba36F0866068F0c2afA5243A969] = true; whitelistedAddresses[0x5475647b2393328eCd47B0256782365c7F42fb15] = true; whitelistedAddresses[0x59a9bB69dd15f8E932Fbd1982389f62CfefB68f4] = true; whitelistedAddresses[0x4F3c114735101EF8Edd81760A05bf269d2F04889] = true; whitelistedAddresses[0x8B1dD48344de9922AC1f24B7563fC07EBaA00b20] = true; whitelistedAddresses[0x0D492E61C9f4C90f144aa479892d0c25Aa934425] = true; whitelistedAddresses[0x98A282dF175c7720E8439e6129F7A557746A3D03] = true; whitelistedAddresses[0xEBaB7d355f15a21fa37F4a0E0B303f07e1a320De] = true; whitelistedAddresses[0x45C14654CF2eAC6a7904e80Bd3F4B58ad24E0235] = true; whitelistedAddresses[0x42C70946962DEd7fb4489D8dd543d1857eDD3291] = true; whitelistedAddresses[0x60a26961E4cCb7DE430C8357695Dc6022417165b] = true; whitelistedAddresses[0xe9B7092940B4631c87e406EB2d292EF9a039e4Ea] = true; whitelistedAddresses[0x3863B7d72aE4E36B170FfFf900E5A61637011953] = true; whitelistedAddresses[0xa78b19c5683363dE380d56CE0A164360B59E711A] = true; whitelistedAddresses[0x9D2158f50307A971345F9bC38441FA60688BAA1E] = true; whitelistedAddresses[0xE68c542363A74369Cc41d1490C870c41c3Da6E2A] = true; whitelistedAddresses[0x96a603254e66AcffF3b641c461270e2b37DA67Ee] = true; whitelistedAddresses[0x9Edb768e329d4F6F60eADAA16bb8549d52120819] = true; whitelistedAddresses[0x4f186d24C29a02e633092e655d27ced9439f4967] = true; whitelistedAddresses[0x1BDE23313c081512e10dfac770f23f6C99685122] = true; whitelistedAddresses[0xea9FeBaEcDDAE02967f70F5cF79688786c851463] = true; whitelistedAddresses[0x25A411f95aD3b558a783f6730e7C7d8E297b0fEE] = true; whitelistedAddresses[0x404CC659ec36E3e84B6578FBf874Dcba7bc2bF3d] = true; whitelistedAddresses[0x08254C88e28363BB1135f884f5B616dAEc79d7EE] = true; whitelistedAddresses[0x0b13f13c0E99F24b96A835B787D1347B33d87776] = true; whitelistedAddresses[0xAA1E92dDd28C835fe66689771d35f38947950FD4] = true; whitelistedAddresses[0xC3D067D6C8A5803882DFAC2dce6E2CAd0225E6e1] = true; whitelistedAddresses[0x0A7Dd6591271b5dd1E73Ccf5aF6895B6A370D297] = true; whitelistedAddresses[0x07B0b1121aF252B5e2AC3e0899350656b9900eDF] = true; whitelistedAddresses[0x6A660c35A38D7c23d28F8f37e2eA8Db0D9133518] = true; whitelistedAddresses[0xD82f3ea3c688D6ba92A9F22e5DD2E78230940cc3] = true; whitelistedAddresses[0x5B1700e3F1C6433Ce6317A82BB40F22276E6e0d1] = true; whitelistedAddresses[0x860164830c7d3Ce6758FceB7Be95701175cb2e6A] = true; whitelistedAddresses[0x45328d856Fa2E3694De5896157214E6a418fA217] = true; whitelistedAddresses[0xF72781976cb2fA2c81E43D23392Daa313FaB6B21] = true; whitelistedAddresses[0x153AA1106140DB47120065819644E753Ca7F8854] = true; whitelistedAddresses[0x23928DE1688a7B9Fb6fF143f881fB03A70c187FE] = true; whitelistedAddresses[0xDaE6B3Ea322EA51D18A766F269CC86a13592c082] = true; whitelistedAddresses[0x86A09A23688c19258416876B7157fE11F354c3f1] = true; whitelistedAddresses[0x850db8b32D5dD815F1E3eaec65D9898D56C1C185] = true; whitelistedAddresses[0xA476fa671F7e5ce0d7C5bEFd7Cac8042608e15DF] = true; whitelistedAddresses[0xFb7F0808000C30d28aBA61Cdb8b4eE03c11653a7] = true; whitelistedAddresses[0x9Ad2Bce03c45E1463a4f76864436A3048086546e] = true; whitelistedAddresses[0x3f2c0f1c8Df862289c0bE08a8D1003449a968492] = true; whitelistedAddresses[0x8924e4185aD0317f0C9A8d3F92E9076AD220D4e1] = true; whitelistedAddresses[0x97b28492da285dAFF9153fE89F354E7547e4206E] = true; whitelistedAddresses[0xB9E60A72a70B94bC74d4de1a89d5001Be6579cb9] = true; whitelistedAddresses[0xB4600da0048D2C5002f8785A4Bf3fa8C5B41F412] = true; whitelistedAddresses[0xDD36ecb4840432EACAC61301Bc234f917Aba84A0] = true; whitelistedAddresses[0x292B1116753C7aFf68111D35227621e591441A6e] = true; whitelistedAddresses[0x8F867e50b06f0Cc88B7b34C35f85BA9e567A280d] = true; whitelistedAddresses[0xeE78f64E1613DB75A4625C4A18095BC269c9379B] = true; whitelistedAddresses[0x0764dc400C280FF2B6D1F0582969C0c668271340] = true; whitelistedAddresses[0x79b505e246b66B1B800C20B6fb47b835053C971F] = true; whitelistedAddresses[0xDF0DD57Acc0509C70665C6Be25263179E9aeEdfa] = true; whitelistedAddresses[0xa43de1705b141fb211D52cF41B5edB76eE2502c3] = true; whitelistedAddresses[0x9F0F6B0Eefe8Fd3594688d55BACd2a876F25eF36] = true; whitelistedAddresses[0x1A4394ad3d5B6A40D0528d586f2eDb282a847399] = true; whitelistedAddresses[0xbbE094AC19A523176Ea73924Ca18C7906e23d954] = true; whitelistedAddresses[0x56c945311362B2Ad79BF7764c1b7111538BB58F9] = true; whitelistedAddresses[0xcb9C3b903Eec023E39Ef6c719C9C6D0C4F65A154] = true; whitelistedAddresses[0xA33453aF2EAe9EDF9DA96A54fB0401C86E240D69] = true; whitelistedAddresses[0x4985bB31cc6B9309F616Cf0250dA8172aD744363] = true; whitelistedAddresses[0xE79e09ffa6ac702D15c8bb71B136df55997C4A69] = true; whitelistedAddresses[0x282f9E0a7A135B6b2812ec5842A57e6C129bAbf5] = true; whitelistedAddresses[0x5B956De9d2B82f50C8F4ee54DA478a7fE8E21A22] = true; whitelistedAddresses[0x661A49476C0821Dc790972000ea941C3e851e7Af] = true; whitelistedAddresses[0x584CF1A8825990c69b7c02A8e2669a551A1692F7] = true; whitelistedAddresses[0x877adF7A6d29A4678Dc86cBa270A2C5257B6ECc9] = true; whitelistedAddresses[0x1225a95CE4f6E9e27987A36FF5939aD9Fb2C967b] = true; whitelistedAddresses[0x57aF013384d969E4A838FdCeCf6deEe1D56172DF] = true; whitelistedAddresses[0x551Cfb7D44B0b84B9608B3480FE727f6aBA2dE02] = true; whitelistedAddresses[0x31270810b7A0A76CC4664c76D9CBc48d85bd6505] = true; whitelistedAddresses[0x82e129173f19Ae25f8D4AA2e6e710E60bA55ED96] = true; whitelistedAddresses[0xDC61B2b6918ea88a977D2F8701b029b25496ba97] = true; whitelistedAddresses[0x0a35EfF316b5F24b4b85a0252f1Bb09c416953F9] = true; whitelistedAddresses[0xe4D441ffAFEB5A3f9FB804DE42d4c80579010B3a] = true; whitelistedAddresses[0x5EC90Cca6069bc4C5ABf5D5AeD68111B2cDA47fA] = true; whitelistedAddresses[0x6E69BB2c41f78186DD05d1e03c7EA458E88A2211] = true; whitelistedAddresses[0xd26e712EAA4d47b89E740cD1A65322f3331C3EaF] = true; whitelistedAddresses[0x58879266350Cc134D1073B5F4E1ADF42B4420c3E] = true; whitelistedAddresses[0x5F42B1CEE8226A2AA674E937E9E69fEA26060D2F] = true; whitelistedAddresses[0xf822C406f9c8F92C3C17F6c470B69faa82D3c26a] = true; whitelistedAddresses[0x7d4aCBE69448fb96E517eFC9d203aeAAdBbC3057] = true; whitelistedAddresses[0x577Be827A11Ec1E2f5dE2A6A05D92AC297bF56e8] = true; whitelistedAddresses[0x031F30ea86262EC24091fCCC0CF628d381c23Dd0] = true; whitelistedAddresses[0x716E9eda68773330809149934F3d1B0aAd766d72] = true; whitelistedAddresses[0xd5b8b95fD69934dfDDCD3c3755931F755bb8E0b7] = true; whitelistedAddresses[0xC75479EdEa49A0e4a12D7bFe467d7ADE156D252e] = true; whitelistedAddresses[0xD79A5d91b4510cd26103591F83Ccb2268715F664] = true; whitelistedAddresses[0x2fD932137355F5D04d7D84E13a9637739E1f2909] = true; whitelistedAddresses[0xE484a9d4E2b4Ecd2375EE77872241801dfC2aB4e] = true; whitelistedAddresses[0x7704B95D00e01016bE164a32ad37a20Ae8234b89] = true; whitelistedAddresses[0x018f190e3e63900348b9F13e37a951888C4a5a22] = true; whitelistedAddresses[0xA862A247b17797B74148219c66aa11f8B05ce9AA] = true; whitelistedAddresses[0x057C550456375Ac5eBECE93310E0a4bB0F8c973b] = true; whitelistedAddresses[0xB9E212C037D29A4afc0de955c01820Af62A18DF4] = true; whitelistedAddresses[0xee183D9E1e2D133648829b37f5a0aB6436628C55] = true; whitelistedAddresses[0xCb4E359afEdE075aA70578B34bbcCe39EdB47B3e] = true; whitelistedAddresses[0xdDe8aD73BD6BcB7194445476228444B46De05a55] = true; whitelistedAddresses[0x46D61d15C2c574163f2ec16382275A6835Dc640F] = true; whitelistedAddresses[0xe1d59D7edcE98Aa7444b7383f8C27d4ab3e19eB5] = true; whitelistedAddresses[0xE340015c155051A4362c8F8930030b9Fe0CB5950] = true; whitelistedAddresses[0x01b70d6C0b99B5374542a709B852739c00190Be8] = true; whitelistedAddresses[0xf9e4d2291c965Dbf3CE1E7d66c564CC96D0F9Cf5] = true; whitelistedAddresses[0x61BFb853794c1E7d7CfaE6374230AE4763df7247] = true; whitelistedAddresses[0xD0F061A500B0eBbfC60f563a53710013Ef0470F2] = true; whitelistedAddresses[0xAd8802f42E855E49E09503bb8bd2c43478273Ab7] = true; whitelistedAddresses[0xE5AE91c6267f22D1F5AA50aC953025a7A36ed36B] = true; whitelistedAddresses[0xfF47e41188Ed3B6598BD30730EccaCeF47985e7D] = true; whitelistedAddresses[0xcf89bdEF66A5C070691D2666855DBb5bd3aC6680] = true; whitelistedAddresses[0x5221dc2c8a9bE3e2c417de0Ecc78326bD5E3c34a] = true; whitelistedAddresses[0xF25b91D0773ee199810ea4A5899F8Ac795cFd849] = true; whitelistedAddresses[0x41E5D23dfdbf3AB6563E69B63BC74CB330f426c7] = true; whitelistedAddresses[0x9bC5536b6EDD37fCF15f5E44e0a56C68397f5CEf] = true; whitelistedAddresses[0xE6A9eb7aB060f459461F0F1D472c3350cE07Cb79] = true; whitelistedAddresses[0x648d7BF538b204c160c15733aBDB915d4D7fC822] = true; whitelistedAddresses[0x9eC51c8C70409783ce306B3bdFDa0D7E7Eede08c] = true; whitelistedAddresses[0x83b0B5266f5dB6e6C8ac226774FF41F90bb629b5] = true; whitelistedAddresses[0x368B6f9930B2306D1BA596A3aA96997bEbbFA3a8] = true; whitelistedAddresses[0x3dF9d238f6E583508c3Af0e5bB84f4308EC0D245] = true; whitelistedAddresses[0xb006168ae893A26A91c909BD09cdDD6a3135Bc99] = true; whitelistedAddresses[0x4E5DC8CaA8BD8E8aB3E5cd64623CF7432231DE2b] = true; whitelistedAddresses[0x7A3fA094a13fc9Ce247f6c4369Fca88b26954856] = true; whitelistedAddresses[0x1C00E5AECB22744Bb5968e3307C2B76Cb221fF66] = true; whitelistedAddresses[0x967604E4B0CA0A9F5F26728e0cECcca52fb173F7] = true; whitelistedAddresses[0xdCA1080f5f82ED39d8CFF736A3a48B842Db8A371] = true; whitelistedAddresses[0xfb2B667A8EB1dbB68fd2fC45a43AbB5092de42fd] = true; whitelistedAddresses[0x396D404D6Aa15D858A490cb2b2861dfD030872d9] = true; whitelistedAddresses[0x670B69e85d96c85D00DE19222c4963898d685Beb] = true; whitelistedAddresses[0x97280268dbA80f2d32683b7c0662F26Eb27DD175] = true; whitelistedAddresses[0x2F08EA7Bb0f4b13AF7ce135f73CbfA3eDA567B13] = true; whitelistedAddresses[0x54f3deaBC915EB00320a3d81A37540b3a313D5F3] = true; whitelistedAddresses[0x74b98236595Dbdd71E0CE6D628Ad20EA2300D3dE] = true; whitelistedAddresses[0x56c7a4bFDbDC57C0545413D12a30125FA651Db25] = true; whitelistedAddresses[0xD358b2131c5da0071612eFb171bbA94bf22c559b] = true; whitelistedAddresses[0x63d301648c7227C8F39DA41Cc3941FFDBb3aB08f] = true; whitelistedAddresses[0x0B6A5465f3f2D686d9A263c222a99F4AEfDe8b03] = true; whitelistedAddresses[0xb604ADF39e054243aa08840f66226a78fEeDd4B0] = true; whitelistedAddresses[0xdFb9131B0B8Bf0ADdf74104695d222c9f5E663e1] = true; whitelistedAddresses[0xFa22e911123610eFC78456e888cc682d601f6b54] = true; whitelistedAddresses[0x848a2480cD4c03dfD2217fDE2d157aCea03553Fe] = true; whitelistedAddresses[0xcab88eB7a2Db56Df92E0C117Fe516dAD872061B1] = true; whitelistedAddresses[0xa3975ebd0417283Fb9aCf2b733995B0dF9570447] = true; whitelistedAddresses[0xEadC6305572e8b396551d40E0cfeCf0B8fF8eBF3] = true; whitelistedAddresses[0x37cc6965B968bd9798C300e6086eEEca2b3B905D] = true; whitelistedAddresses[0x56D3f3a73C48391F413E1D9353165FdB0C7dda3C] = true; whitelistedAddresses[0xc83b44f273225F9438cBac3Bd0454b43851938e4] = true; whitelistedAddresses[0x6ff7af175B38973731019B5031BbC0b56755D9BE] = true; whitelistedAddresses[0xc886dB8b8CD260f5ee38Ba3d8f8E9324EE27EA33] = true; whitelistedAddresses[0x573D92340A8cA8A7D402f0eb1DD35D9077dd07E1] = true; whitelistedAddresses[0xF5CCAf60e2c9C15C7c91BDc8768657Ac0688C8Db] = true; whitelistedAddresses[0x4AA781b19597aF4f9b1f623c6c02e4124E007592] = true; whitelistedAddresses[0x7F4AAa75F03d1598B092aE0e323Bc430C015CCa9] = true; whitelistedAddresses[0xbD14b609C33c8e5A1f09a266b2AAe1096be9DdBb] = true; whitelistedAddresses[0xEB522A22dd782ddD8167E020e107292300490618] = true; whitelistedAddresses[0xF3fcE30d685BBC7a40Afa2c1C1296256B70a1477] = true; whitelistedAddresses[0xBA21f7FFfFbA579ad685f95631f09ceC7f331f03] = true; whitelistedAddresses[0xaf32e3A19A551487D0191E07C939B0ED18eDA1f0] = true; whitelistedAddresses[0x2C4e3C9FaD9c396F470655A6bb0916381d07Cbdd] = true; whitelistedAddresses[0xfaeFD394BFE03e61AbDa9e295d7c64687eE73B28] = true; whitelistedAddresses[0x52A11d57D740A0D7cEceBc53ab16440E8fD6B2B2] = true; whitelistedAddresses[0x7Af047Dc65917aCD86D24F3F2033a002473bCcCe] = true; whitelistedAddresses[0x14F64b652948Ed2FEBde2517858644d5C15a6d7f] = true; whitelistedAddresses[0x867a5a7E70457AF6C8250820589c4E4B928b1bA9] = true; whitelistedAddresses[0x3b9e1E348fF80fE79c18439103c5c53A0fEbbF43] = true; whitelistedAddresses[0x2F8FA4fb6dE5a697c3a8344Ef62A6A168a31D66a] = true; whitelistedAddresses[0xf558be7A985abc32b0b2bA8b0ed6562151000e41] = true; whitelistedAddresses[0x5FE20ab75F748c887B1875231E4A510e77Bc5910] = true; whitelistedAddresses[0x48327499E4D71ED983DC7E024DdEd4EBB19BDb28] = true; whitelistedAddresses[0xbDf7EcD3938bC86373D15709fE09DcF9Bb677ca7] = true; whitelistedAddresses[0x37b3FD2E17232d28b2b53e345e441951Ca887280] = true; whitelistedAddresses[0x9B26F0F8a259873922d57169C542306DC078782a] = true; whitelistedAddresses[0xE4eFC361F134D07634a3275ec2A585985050e1b0] = true; whitelistedAddresses[0xEDcF12b46f57207Ec537Eb73C4E2C103A32B233A] = true; whitelistedAddresses[0xA79De3041754FE0a82bF6106279B29De1F6A03Ab] = true; whitelistedAddresses[0x0C04a6db771fd8A4ae71BBdb3209c2FA9d016a9c] = true; whitelistedAddresses[0xFfc979bf6ed9785c57A262296Fe57eE666f66B01] = true; whitelistedAddresses[0x2464E1127b89257011Fa6cA06FC51b3ec0B093d5] = true; whitelistedAddresses[0x6f50bDa124024Ce6837cb73A20c8B96b7Ff69880] = true; whitelistedAddresses[0xe0ABe059bF26b130F861F3c9fe48a21A57300390] = true; whitelistedAddresses[0x2C50b665c3aCC7ecca9Cd9634C9afF5e8Ab37815] = true; whitelistedAddresses[0xb15e19ED53f82574f99CfE575Be454db09b876eD] = true; whitelistedAddresses[0xbd2c152256f33805c8581c7DD6F68DbdE150994A] = true; whitelistedAddresses[0xe3F42af201Ec36992a6B89E0AD6f814B901d1128] = true; whitelistedAddresses[0x78e55c6a3B60A903eB0D57104706B5D69fBDf4FC] = true; whitelistedAddresses[0x032Ab8112Eb491A3e56D48B836b89b1F0c78717f] = true; whitelistedAddresses[0x9788D64c39E2B104265c89CbbCa2a2350e62701d] = true; whitelistedAddresses[0xC9fE451251398F7Ba82296DD6eC2E3f43ee8d93F] = true; whitelistedAddresses[0xd532962FD7976880FDff92DB9Cbe48a7369b1fc0] = true; whitelistedAddresses[0x0da4d20e6b7Bd947419d821BfDa3D8ca079b86f1] = true; whitelistedAddresses[0x84fF759Ee0B6057506f36E5e908ab73877C9263c] = true; whitelistedAddresses[0x5C9Ce53738967e4D422f0f6914d5bE496F9EdD2b] = true; whitelistedAddresses[0xB09Cb3EC75DdbBd0bC9A715D703ea84a27a99D38] = true; whitelistedAddresses[0xB71E4596686608aA05581660187281A00efb81Ff] = true; whitelistedAddresses[0xCfD780ded0b05f508B98dBA7E27E11F4fb82837f] = true; whitelistedAddresses[0x3996A7E38fa56e0A10416430e28cc28182d4B21C] = true; whitelistedAddresses[0xdA38AFF9D34fF382F12a1De111A10491566B9876] = true; whitelistedAddresses[0x778530DEFcFe3E28C4AC55C6ca7FC69Bf7776AbE] = true; whitelistedAddresses[0xc34ED3F6677f694797AdCE1767aa3e73Cf48e1F3] = true; whitelistedAddresses[0xe37D4eA5C27017C227B6bf5a9CeDA2E02c58637f] = true; whitelistedAddresses[0xd71e4AfEDAA844E493fD612F7e9C32Cc534FAE61] = true; whitelistedAddresses[0x747A70e778985799b11a536FC716BaF3E290bB10] = true; whitelistedAddresses[0x642B15A995980eCcB49E6475f44975Ff1F50Dab8] = true; whitelistedAddresses[0x186f3481dbEBA09639e1EAd65aF3457f7EFACB9e] = true; whitelistedAddresses[0x068e9989EFF6ee3746DE4498e5Bbc0Ecc7f968Fb] = true; whitelistedAddresses[0x03F7f1aB10e8bA1f6c3B7ea588087Ee12d44Dcc8] = true; whitelistedAddresses[0xFEF87cbfd1F377A962a0EF8adDa5d407c5F14f1C] = true; whitelistedAddresses[0xD909A1e32e24E806c6206CAf07A8cB3e02858149] = true; whitelistedAddresses[0x84dDddBe34C36c894347fA3649B0E25550dEb4d6] = true; whitelistedAddresses[0x8eda5967E823C48665C797d1E35b59B5e05162Ed] = true; whitelistedAddresses[0xA386542F9144fEAFB0f035397E16Bf6D02bB999F] = true; whitelistedAddresses[0x6A4406F5be648B406c0c20334E8a5DE6B4999516] = true; whitelistedAddresses[0xD4fe5b08a436C93d076d1b0a3752C8f9b6a4abfe] = true; whitelistedAddresses[0xe5a81738DCB83CBC73440F331659F362294Bb7f1] = true; whitelistedAddresses[0xBA6b5E38eeE62aB0711DD020D9873316846566B9] = true; whitelistedAddresses[0x4891baed23E9B2490dEe4bfD09c4f98579Fc08C5] = true; whitelistedAddresses[0x764965E051b54F6695d48899506E2f26cA765edf] = true; whitelistedAddresses[0x0d917a622ed9a5773e52cCb1fAc82A75a8a6d9D9] = true; whitelistedAddresses[0x838AA6360Bd87c7d0A96b8b84ac107E0a49dc114] = true; whitelistedAddresses[0xa5B0C665E95545604f0A1DD0e3ecD857a9C2D2C9] = true; whitelistedAddresses[0x4f28E099459F200e2C6cD6cdE11d23700c208359] = true; whitelistedAddresses[0x330331eA6b3d10aaB69b87D86478D6aB643A981B] = true; whitelistedAddresses[0x32d40ef4928EfBcdc135B3359dFc4Ec66Ee4ceCC] = true; whitelistedAddresses[0x51EC15594230DDf21A7EA5A4aC392BB8Dbda527E] = true; whitelistedAddresses[0xf6A51B6c793133460B279a5E6B7ea6867FD5bd7C] = true; whitelistedAddresses[0xCdc921690f110d077dA220121D26FD198D39eeF1] = true; whitelistedAddresses[0xCE9D39958681fE1385FB7A3E23bFF730d90a9729] = true; whitelistedAddresses[0xE36F023f4d7D29D51B67986089EA0d41b643Ad4a] = true; whitelistedAddresses[0x103c887d44D81C5584053AF523002925Cc18814D] = true; whitelistedAddresses[0x490790Ddfb169857CE80248306DB24105eb55936] = true; whitelistedAddresses[0xd3e38c017d441558135549719f9f9C398A64FDab] = true; whitelistedAddresses[0xCC86c675Ac9F00E440F4F80B6D27b881de0f128A] = true; whitelistedAddresses[0xc9E7A3937CF24Ed932B69C4545a20A5966a73fB5] = true; whitelistedAddresses[0x1Ac1Edb70367f3e9C0602dcEd488a465565F256E] = true; whitelistedAddresses[0x3E2b71BF37cEfe64B9cde8Bd19b2c70113eB2785] = true; whitelistedAddresses[0x0a49De8E4f369c82b5315a40Ad0AC67d529a895F] = true; whitelistedAddresses[0xAb3034c66c30a11371E7BC05d2f2b16f8BECC110] = true; whitelistedAddresses[0x5B8F1DaaD43D779577AC05061a6B1546a29B47d1] = true; whitelistedAddresses[0xB16B708Fe3F85A99A253Ffe2Fe556ec4C4f8Eda3] = true; whitelistedAddresses[0x1EF0982991493c8F3B82c7f08A047F2ceb31EAA5] = true; whitelistedAddresses[0x0cb7a1134F45f084A060743908C468F916dA9F07] = true; whitelistedAddresses[0xE156c1d096FEc864FF641960a262b2D8929d4195] = true; whitelistedAddresses[0xDaEAdE1BceBF6C9cFB5f8bdcCC79C838FEFe6832] = true; whitelistedAddresses[0x80DDf3efe08cf6A29eB917dbd326F0D6DAd85c43] = true; whitelistedAddresses[0xAE58AA169CF8cE4Ff8FA6C24a1F434ff75c9b012] = true; whitelistedAddresses[0x5B908066aE4cDD15778796894f4a177c6FDD8509] = true; whitelistedAddresses[0x6d155C454C03909443f3Ab06Cc690900Bed6298B] = true; whitelistedAddresses[0xA9B60f88a82d7f8Af85F53379AaC4D7B34759f12] = true; whitelistedAddresses[0x9Fc48dC9e0Acc7073EAdd4F37f161EBEE41F1E99] = true; whitelistedAddresses[0x7D8EbEdDCccDBa1b070c455073aF153450C7d697] = true; whitelistedAddresses[0xB8262145c487B328fAf14127682643ce2D1DFdcC] = true; whitelistedAddresses[0x533950ab7F1E5BBEaF6100F2d823e23E0b4AeF0f] = true; whitelistedAddresses[0x20B2273561D13b4e29a0F442F3430B3D226EE289] = true; whitelistedAddresses[0x85908b2605BcF86A0d869173dF448C3afd0FE547] = true; whitelistedAddresses[0xcE970ae1ddc10C37D079C1330fD455b6654017fC] = true; whitelistedAddresses[0xce915E4a0Dbe5D8dFd054384C7d3a8f692d0428d] = true; whitelistedAddresses[0xc0b7f18839091fd334315C594ccB08D26c471Fc7] = true; whitelistedAddresses[0xba96162a8bF02b68b64e4a154617e19E4028efC4] = true; whitelistedAddresses[0xeff59EA7b39d67cb57C606E21Ed9a4a348F8A78a] = true; whitelistedAddresses[0xC458e1a4eC03C5039fBF38221C54Be4e63731E2A] = true; whitelistedAddresses[0xfD08849489f0a0E665885878EAddbE28738a38F9] = true; whitelistedAddresses[0xe54fe76a02B05d450852c49CB06427e02ac5d8B8] = true; whitelistedAddresses[0x04f47435cb9cDF59c19C9d5E5982E073900F7De3] = true; whitelistedAddresses[0xCdC4e5A89cc23f4e7f673a3a18c1Ed84abEC88b4] = true; whitelistedAddresses[0x54AE40076387A68EFa483cAfBADb053123Ac7685] = true; whitelistedAddresses[0xbf47a917254e4eFd8973a2dc270004e4e82aAA89] = true; whitelistedAddresses[0x89d5Ac566d4d0BF14daD8B0531dd4B3de47F9424] = true; whitelistedAddresses[0x74fa1bE357bC182c88BA77E771a5502e2b271F1B] = true; whitelistedAddresses[0x3ec3991c0aeFd1F5De287Ac8fCDb9eDDD0DF2f72] = true; whitelistedAddresses[0xb643c924632f71ac70a982Ebc7E4099620f076C1] = true; whitelistedAddresses[0x46234FccD57237F421070E23C509c8d7f5c97022] = true; whitelistedAddresses[0xA8a308eaff92640a33c6a075e6869e0588BE5128] = true; whitelistedAddresses[0x7F1a4E5644E1340Db15194104eF8f5A64DF1Cf78] = true; whitelistedAddresses[0xDDcB509Fe6E15ec45a35492686947afF08BF58E1] = true; whitelistedAddresses[0x22586A535b975D77f2f6Af443207215eACeA6eA4] = true; whitelistedAddresses[0x69973B44C3AE36a6803cB2D77585B8db50220Cc7] = true; whitelistedAddresses[0x31267188D920140e3015fe285F81bA163262042F] = true; whitelistedAddresses[0x1187d312074f9c017d6BeD1dF9754D03bA7B2Fd2] = true; whitelistedAddresses[0x2fe50DeaCdb83Eb8beabAbC73AC8D78cf478675f] = true; whitelistedAddresses[0x738025f325e6aB76686cC15dF07291062907092C] = true; whitelistedAddresses[0xe68c0650A819d1c4c9f541a0dADBB457CC793419] = true; whitelistedAddresses[0x1afe95013b5e4A017AC5B45A2649BC76b47B5f68] = true; whitelistedAddresses[0xd2055E892FAA32cF4ba2B5a33A8dBb4Fd64a506b] = true; whitelistedAddresses[0xe70D161C7ffF90c1127dD0A03C341d429E79D211] = true; whitelistedAddresses[0x965D5CE02c082A51A51b990b0De39857053d1F57] = true; whitelistedAddresses[0x2FA3479F42f38078943587f45D33a9BCe36b23a7] = true; whitelistedAddresses[0x9B03891a8251c448B6C5D55556c43c3E0C64b924] = true; whitelistedAddresses[0xb8D781c15858688387A594B4A34f8463b56AF8bA] = true; whitelistedAddresses[0x66ed00d2df9ee54911A90AAda0c8dfF4c169b6B1] = true; whitelistedAddresses[0x3Dadf855b9E30e63Bee10ec4D92cbFE789E5F8A8] = true; whitelistedAddresses[0x4820189e0C6Ae798186cA9ac48e70a7fc630Bb6e] = true; whitelistedAddresses[0x31249c9aD60B319EaA6FdA00A84327FfBB74aC72] = true; whitelistedAddresses[0x60670dB0663eEEa0E022ee2250aa37c6Ae427Eca] = true; whitelistedAddresses[0x8aA69753ED549De82B82F5B1B268e6c8f96d5C07] = true; whitelistedAddresses[0x20E44FcCFefC2215e8FFa6cD9cBDdD6EAaFdB999] = true; whitelistedAddresses[0xAE29BEF6Fb6B2974ce79C9914889dB65E67B7aFF] = true; whitelistedAddresses[0xECc314d8CC41438F90acAbd9A5D0c1899d143689] = true; whitelistedAddresses[0x139932823E72Fd90543547dA33854fBC39dD1A44] = true; whitelistedAddresses[0x3D139eB16d79944a98EC3Db0A862f9CE98c576F5] = true; whitelistedAddresses[0xD31DFc43E584b546C10a8B66a363c7752086D84D] = true; whitelistedAddresses[0x0aF0CC88182856aFD7f0d5D953c76673395fe85D] = true; whitelistedAddresses[0xf2A38bd2A11C743c0368DDEE1cF7E155FBf41F4B] = true; whitelistedAddresses[0x9BF89364B34A60A7935eBdb29B8Ad88Dd95C8680] = true; whitelistedAddresses[0x4E1c94F0eE40df053B190EF6Fa8709982c10F748] = true; whitelistedAddresses[0xDdA0eaC66073397f222DbA518c5231aE716F129B] = true; whitelistedAddresses[0xA77AeBFa19dD12c88E7F49a09d35290025Ff25F1] = true; whitelistedAddresses[0xf48B4C067b4816dbC0A65333E9E81CA6D8a17002] = true; whitelistedAddresses[0x7ecEf266ED9aDa13D97A18E1E4f630E3060c652F] = true; whitelistedAddresses[0x158c72c9fCaBf584C6324C732345b9e5080Fb725] = true; whitelistedAddresses[0xE36a124CaA7Ee0b75A96A934499CE68DaC6D9562] = true; whitelistedAddresses[0x0d13A9e6eA1Fcb66993C71b1ca214f350247007E] = true; whitelistedAddresses[0xB5D4187BcF2Df95b336D59d399687A101735959d] = true; whitelistedAddresses[0x6cC4A1044A6fB92b8e0338363728dFB9644879b4] = true; whitelistedAddresses[0x050EF81B1cC32f1d3EC9b175Ef9e39053c156B9E] = true; whitelistedAddresses[0x564820A33AFFF3513b28E2fA6Ca1346deE342cE1] = true; whitelistedAddresses[0x07eD493a169956c953b1704E3e27368895A57C96] = true; whitelistedAddresses[0xdf09092bAe5C265e404e0a8Ce01eBF341481F531] = true; whitelistedAddresses[0xF5fd651C3193F5fe165eeB828Fc52Ceb720c5E34] = true; whitelistedAddresses[0x156D9d0fF226B6f08D253FDcDD28A0a69e301607] = true; whitelistedAddresses[0x7464932Bd227B88cA5A5aA4903dC60Bfe2D77C5F] = true; whitelistedAddresses[0xF325Ede0886B9784FB8CdDf0a1aDD21318da126A] = true; whitelistedAddresses[0xb11dE9dbd61A5A54ef2B23A4Cb713Df85DF08E70] = true; whitelistedAddresses[0x5f419F4Fa688069e8175888045c2C51aB7A35825] = true; whitelistedAddresses[0x8b59ED2CE3731a3D4e7990CC4FA12f59a1Fa7300] = true; whitelistedAddresses[0x489F40552a9a2bc3d2718Db5417f0955675e6cF7] = true; whitelistedAddresses[0xE6e2731FD3479F5BC76F72C78b368C805abAAa1a] = true; whitelistedAddresses[0x83448a9cdCb456Bb58577C141Cd77e311244A156] = true; whitelistedAddresses[0x97341010d9DF19727f458128639Ddd81F2b6E5dE] = true; whitelistedAddresses[0xa02d34e0f2235661F4b46b8A7BEDB42c4cce104b] = true; whitelistedAddresses[0x4577Ae2d53ed0D340dff17fefa824eCbcFa2cE6A] = true; whitelistedAddresses[0x55E5C1d069Fdc0489fcfCeB0564D29acdBfAF386] = true; whitelistedAddresses[0xf3415D76F984cE7296Ca9cef0F83511388D62a30] = true; whitelistedAddresses[0xCb5A84C0fbd65B8F00E5c9ccdFD0f14813b3e6c2] = true; whitelistedAddresses[0xD7dEA37aDBF6888ef7a9a4035B0EdF36932cf0eD] = true; whitelistedAddresses[0x42F30aA6D2237248638D1c74ddfCF80F4ecd340a] = true; whitelistedAddresses[0x51384E26aabACeBb2e770cfe0E0F04f2feCB25cc] = true; whitelistedAddresses[0x43568F65705bDEEd4082153E94205e40a393b844] = true; whitelistedAddresses[0xDb5D099a6d2f2BC090Fcd258CC564861d552C387] = true; whitelistedAddresses[0x698Fa8dFa821489CF4B69225347F28A56E3c3129] = true; whitelistedAddresses[0xe9099FfeecA205007e5E34269093496723f51931] = true; whitelistedAddresses[0x7215b80FbA9c774d629Aa930baEf35E562e0Cd57] = true; whitelistedAddresses[0x0A611456392C14b0C6588712Da0955583A6d72d0] = true; whitelistedAddresses[0x22B6DCA30218E92bDcAaF33b3CeA154E850438B7] = true; whitelistedAddresses[0xBd0C1c09e3243335E9853a1892f5c6616E8A5202] = true; whitelistedAddresses[0xC2d376420b64B18328D324eE9655fED855dD87BC] = true; whitelistedAddresses[0x4476ab2c11b74576aa3abfAb19dde0aaDcFCA238] = true; whitelistedAddresses[0xb338Df12860e66EADc54Fa043302b7bC4BA3D255] = true; whitelistedAddresses[0x58828c7be7490bFcdAB241538F88C959dd7e2B12] = true; whitelistedAddresses[0x404D1938e66607D08aE9a14FA3055c66Ba814b48] = true; whitelistedAddresses[0x12B0f9a42B891ef7484557856874Bb1FbD144fE6] = true; whitelistedAddresses[0xf0a6E33Fd47F88FBA7E4fD5b05caBeF214A5A3Bf] = true; whitelistedAddresses[0xa6881ace63b4c011EC4a3EBA2ce9959e02F2a7e5] = true; whitelistedAddresses[0x060ab3B83b591a6b2615a0C3587FB8E9d684E3A5] = true; whitelistedAddresses[0xED7261A8616d6A55a3647cF71E21F8146832aEa6] = true; whitelistedAddresses[0x91F743f6752e32599aB5dE8991C0aC4C33b3cCf4] = true; whitelistedAddresses[0xb294600c5Affb4B939f3F07693ee8a8DFE1f2B0B] = true; whitelistedAddresses[0xa11435b21e0Eff08A6c2c5b8316ACC94054e8bAB] = true; whitelistedAddresses[0x1D0AE0A25b1b41d918eA2e7c519fD369678f2390] = true; whitelistedAddresses[0x3b66aaD7bf50c3De4DaEcaedEcb8425CaE897518] = true; whitelistedAddresses[0xf23c17100f4Ba7b38F4950A84A5a06b6bF851D06] = true; whitelistedAddresses[0x321A6EEbf6C0B86f9CAf123c61247327373D1144] = true; whitelistedAddresses[0x05C7Dc96Db7fE24De28690460718720B4994b497] = true; whitelistedAddresses[0x9b4cf900888549E2B75991bc1335940f1e8fe924] = true; whitelistedAddresses[0x5bC3390C8b611d4D7a3A4E89C7ce275B3054FB13] = true; whitelistedAddresses[0xE648b85C095A8A494E55E1b498A27e6d9C0aFa81] = true; whitelistedAddresses[0x567E5880fc9e3F448a5E57c4493959622b9BFe41] = true; whitelistedAddresses[0x5ACb16Ea16F180b1955112eA34F75202e388441F] = true; whitelistedAddresses[0x3C61007492d0712F22E88ea155BbB5a6bED7605a] = true; whitelistedAddresses[0x2AD858A2D668aFeC72d66b409dA1E81cd4A7Ce98] = true; whitelistedAddresses[0x0cCA1e8Db144d2E4a8F2A80828E780a1DC9C5112] = true; whitelistedAddresses[0x3B95143B53aA2Bcfa6BcC0AA2448e426F6D06Ba9] = true; whitelistedAddresses[0x6146532844c99a7c8576D1C6B42Ec88712e0CC4f] = true; whitelistedAddresses[0x3eC99927b3673E718BbbbDe1df19eeFcd0E03272] = true; whitelistedAddresses[0xEbB7Eb5046Fa95590233688a61f5A8ca0B092DA3] = true; whitelistedAddresses[0x9Ce1Ad8a58339e6696C43326C106ef7241f437E7] = true; whitelistedAddresses[0x22034f2e96953e23ab11cfC41Dc6f8C61F712cD2] = true; whitelistedAddresses[0x4394eA17D0B24F966f50c1C31bc08fFF2C8d9f1E] = true; whitelistedAddresses[0x797c7B11f619dfE9665b8e9f17F6666d3142f378] = true; whitelistedAddresses[0x13e1525b09648d8C37Fa3af38e00fb79Fd08d65E] = true; whitelistedAddresses[0x964b354D6e46326140b7EaDb6d1D21Dd96aaB2D6] = true; whitelistedAddresses[0xeE0201E07db325a5D732AeB9b9Fba7b5B8E92c2A] = true; whitelistedAddresses[0x51651b1710021A0c0F77B4889Bf6b411d88d093B] = true; whitelistedAddresses[0x06840B0Baf92D91725F77C0b44166479b7F75674] = true; whitelistedAddresses[0x8d6D26ed2C7BF4F6432934a305eF423DD5A4b0AD] = true; whitelistedAddresses[0x1799863e819999410B9B25087A79f3dEbCC69Bb1] = true; whitelistedAddresses[0xd0dB617CE892dbf6D0BD1e559AF9d06a6030642B] = true; whitelistedAddresses[0x0DB187086b2EDf7a967d62bA4d929a63aeCBF8Fa] = true; whitelistedAddresses[0x0ADf71b966e6b3640FDc2274b68743eaF06AD0FA] = true; whitelistedAddresses[0xe0B0e53a70A597eAd45D1EA0E7b873E80A9bEe08] = true; whitelistedAddresses[0x2912C69Bb58aD095d87707c30d16B585A1BC76b3] = true; whitelistedAddresses[0xeD0EEDAA8b0825d35fDeaa752e7AaD02B3ae2557] = true; whitelistedAddresses[0xd054952345f497F7A9461a202E8f1284b885eE2F] = true; whitelistedAddresses[0x64F822bd5F15f9fEf824376C192B353d425143d6] = true; whitelistedAddresses[0x2b0aa2a737A60e3c53142d4185BDBDB68f6a16D5] = true; whitelistedAddresses[0xb88E0f52cdC7791477d2878A0898989d69F4D03C] = true; whitelistedAddresses[0x94e0adDB171983acBA7b0592C0E4fB3FD68f0f90] = true; whitelistedAddresses[0x8341Cde26693629D0A9AFF24CA3F894494Ec3157] = true; whitelistedAddresses[0xeB1534b4De07C718A00a89A2dfEdAe06fab6267d] = true; whitelistedAddresses[0xbE0e177b32C751e122af49b257aDE900114AD53e] = true; whitelistedAddresses[0x9932B4975e21c0C0e4215915A03728045CFDd539] = true; whitelistedAddresses[0x7b0b49EEA48E2A2303E357Ef57850639BfA1A9c6] = true; whitelistedAddresses[0x5d40ED7197cCf53748a15D9E268080d364611E35] = true; whitelistedAddresses[0xd262EA3D4ef23e523F3343FF49C45c53E0Ec8FbE] = true; whitelistedAddresses[0xCaC229C4511CbEB6F7d3a32D35B54B39467963cd] = true; whitelistedAddresses[0x29A83f03204E68958fFABFF239cCFE771feE9D10] = true; whitelistedAddresses[0x8F538507f91445Ab5c933e1B6356b18B2bC5A4E9] = true; whitelistedAddresses[0x86995F4a229b5a6512BF46b0A65DF450F37de109] = true; whitelistedAddresses[0x8Fa0631aAE58D8751D2CE417d21187f41EF23AC6] = true; whitelistedAddresses[0x5501e4D8918a8218B3073efFDF1CcB6C078523b8] = true; whitelistedAddresses[0xac26137B0D5d12aa65154AF7cA341d92de74409f] = true; whitelistedAddresses[0x29787D68CaB5348042fBDeDD099C3BE5F84911D3] = true; whitelistedAddresses[0x1c3c5305Eeaf72B3d6D20D1c20bcbC894FFeafeE] = true; whitelistedAddresses[0x51D2c4abdf244Bc9EED0F0CA792009c5De636Fb9] = true; whitelistedAddresses[0x628995c10E7ad0983DB7c1e36835b2253cbCC534] = true; whitelistedAddresses[0x5eeC4aDaCb4E81D58B19f25bcF03f376b73567d4] = true; whitelistedAddresses[0x1Cf60c90dABbC43D1aADD0B02D5DAe44726f16cB] = true; whitelistedAddresses[0x82e45bDC0C1Bd8072FB367683F68356CD76D4cc5] = true; whitelistedAddresses[0x6E7Bc7DE434d62c2AC755c02C695c214dFB30B29] = true; whitelistedAddresses[0x9caF0b277a7568f8f0246895bedC96E62b0CF34F] = true; whitelistedAddresses[0x7C413F11A35ee3B2AF8a8592Eebfe1b38d59A632] = true; whitelistedAddresses[0x6D0502FeffC708f39F2F449d2b60cD7e72eB8d1F] = true; whitelistedAddresses[0x69F3F8085666F3b524CBb9170dcb03E7eCc4118D] = true; whitelistedAddresses[0x78F51f44Ea3ac2Ee542aEC3b1532adC823aF899E] = true; whitelistedAddresses[0xA4f96A54aEC6022308751d788e3F6782Ba897090] = true; whitelistedAddresses[0x6bca7e1EC8595B2f0F4D7Ff578F1D25643004825] = true; whitelistedAddresses[0x8DE238a576D539A7fba59a8d180203135A035d18] = true; whitelistedAddresses[0xe7E8131190636dF7f0f21e91676870c9830a262e] = true; whitelistedAddresses[0x8E0FD5f1374DAc8BfF9Ac48320aaC43DcD0678A6] = true; whitelistedAddresses[0x7f4EA72AFcCBa8401424A65Dfc9DB4d3701Be536] = true; whitelistedAddresses[0xC66A54E60A2672cF9232Ff75E98F78e68A0e16F1] = true; whitelistedAddresses[0x151eCC8423EFC2DA8AC3eE70AbFf248D617E3100] = true; whitelistedAddresses[0xcE684e3a006e16Ad5d32f6c500DD05b747a7ad3B] = true; whitelistedAddresses[0x2E3177053006AFA4205fCE9b77781aCe7399a5F7] = true; whitelistedAddresses[0xd8e46c84a4cd5F32005A99f481C3b3b36e1D68FE] = true; whitelistedAddresses[0x25D12cD8af29F7c565349C4a6c678238e04cB21e] = true; whitelistedAddresses[0x240889d7055bB22DedD8c102B6c45F5f99B8BEf8] = true; whitelistedAddresses[0x16F2bACF87654067e6b0559bC8fFC09f3Cf1C5D1] = true; whitelistedAddresses[0xCab90BB2b3a2f57f40326093de037C655c7fA8AE] = true; whitelistedAddresses[0x17D411787433fB4064326c5Dc6274991720a7571] = true; whitelistedAddresses[0xF628CDB6AFdc2f5B775BD85164164589bD53be58] = true; whitelistedAddresses[0x21A07CC609e481Ba8F243eef3ff407Be855a3Deb] = true; whitelistedAddresses[0x0f59C60A22B244aC53360c4Ed4B4A4c504Ae91b5] = true; whitelistedAddresses[0xf5b6F869D96164c323C12b7ba8739B2fb20e8EDc] = true; } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { require(!paused, "the contract is paused"); uint256 supply = totalSupply(); require(_mintAmount > 0, "need to mint at least 1 NFT"); require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded"); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); if(onlyWhitelisted == true) { require(isWhitelisted(msg.sender), "user is not whitelisted"); uint256 ownerTokenCount = addressPresaleMinted[msg.sender]; require(ownerTokenCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded"); } require(msg.value >= cost * _mintAmount, "insufficient funds"); for (uint256 i = 1; i <= _mintAmount; i++) { addressPresaleMinted[msg.sender]++; _safeMint(msg.sender, supply + i); } } function mintOnlyOwner(uint256 _mintAmount, address receiver) public onlyOwner { uint256 supply = totalSupply(); require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded"); for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(receiver, supply + i); } } function isWhitelisted(address _user) public view returns (bool) { return whitelistedAddresses[_user]; } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setNftPerAddressLimit(uint256 _limit) public onlyOwner { nftPerAddressLimit = _limit; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function pause(bool _state) public onlyOwner { paused = _state; } function setOnlyWhitelisted(bool _state) public onlyOwner { onlyWhitelisted = _state; } function whitelistUsers(address[] calldata _users) public onlyOwner { for (uint i = 0; i < _users.length; i++) { whitelistedAddresses[_users[i]] = true; } } function withdraw() public payable onlyOwner { (bool success, ) = payable(msg.sender).call{value: address(this).balance}(""); require(success); } }
File 3 of 5: X2Y2_r1
// SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import './IDelegate.sol'; import './IWETHUpgradable.sol'; import './MarketConsts.sol'; import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol'; import '@openzeppelin/contracts/utils/cryptography/ECDSA.sol'; interface IX2Y2Run { function run1( Market.Order memory order, Market.SettleShared memory shared, Market.SettleDetail memory detail ) external returns (uint256); } contract X2Y2_r1 is Initializable, ReentrancyGuardUpgradeable, OwnableUpgradeable, PausableUpgradeable, IX2Y2Run { using SafeERC20Upgradeable for IERC20Upgradeable; event EvProfit(bytes32 itemHash, address currency, address to, uint256 amount); event EvAuctionRefund( bytes32 indexed itemHash, address currency, address to, uint256 amount, uint256 incentive ); event EvInventory( bytes32 indexed itemHash, address maker, address taker, uint256 orderSalt, uint256 settleSalt, uint256 intent, uint256 delegateType, uint256 deadline, IERC20Upgradeable currency, bytes dataMask, Market.OrderItem item, Market.SettleDetail detail ); event EvSigner(address signer, bool isRemoval); event EvDelegate(address delegate, bool isRemoval); event EvFeeCapUpdate(uint256 newValue); event EvCancel(bytes32 indexed itemHash); event EvFailure(uint256 index, bytes error); mapping(address => bool) public delegates; mapping(address => bool) public signers; mapping(bytes32 => Market.InvStatus) public inventoryStatus; mapping(bytes32 => Market.OngoingAuction) public ongoingAuctions; uint256 public constant RATE_BASE = 1e6; uint256 public feeCapPct; IWETHUpgradable public weth; receive() external payable {} function pause() public onlyOwner { _pause(); } function unpause() public onlyOwner { _unpause(); } function initialize(uint256 feeCapPct_, address weth_) public initializer { feeCapPct = feeCapPct_; weth = IWETHUpgradable(weth_); __ReentrancyGuard_init_unchained(); __Pausable_init_unchained(); __Ownable_init_unchained(); } function updateFeeCap(uint256 val) public virtual onlyOwner { feeCapPct = val; emit EvFeeCapUpdate(val); } function updateSigners(address[] memory toAdd, address[] memory toRemove) public virtual onlyOwner { for (uint256 i = 0; i < toAdd.length; i++) { signers[toAdd[i]] = true; emit EvSigner(toAdd[i], false); } for (uint256 i = 0; i < toRemove.length; i++) { delete signers[toRemove[i]]; emit EvSigner(toRemove[i], true); } } function updateDelegates(address[] memory toAdd, address[] memory toRemove) public virtual onlyOwner { for (uint256 i = 0; i < toAdd.length; i++) { delegates[toAdd[i]] = true; emit EvDelegate(toAdd[i], false); } for (uint256 i = 0; i < toRemove.length; i++) { delete delegates[toRemove[i]]; emit EvDelegate(toRemove[i], true); } } function cancel( bytes32[] memory itemHashes, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual nonReentrant whenNotPaused { require(deadline > block.timestamp, 'deadline reached'); bytes32 hash = keccak256(abi.encode(itemHashes.length, itemHashes, deadline)); address signer = ECDSA.recover(hash, v, r, s); require(signers[signer], 'Input signature error'); for (uint256 i = 0; i < itemHashes.length; i++) { bytes32 h = itemHashes[i]; if (inventoryStatus[h] == Market.InvStatus.NEW) { inventoryStatus[h] = Market.InvStatus.CANCELLED; emit EvCancel(h); } } } function run(Market.RunInput memory input) public payable virtual nonReentrant whenNotPaused { require(input.shared.deadline > block.timestamp, 'input deadline reached'); require(msg.sender == input.shared.user, 'sender does not match'); _verifyInputSignature(input); uint256 amountEth = msg.value; if (input.shared.amountToWeth > 0) { uint256 amt = input.shared.amountToWeth; weth.deposit{value: amt}(); SafeERC20Upgradeable.safeTransfer(weth, msg.sender, amt); amountEth -= amt; } if (input.shared.amountToEth > 0) { uint256 amt = input.shared.amountToEth; SafeERC20Upgradeable.safeTransferFrom(weth, msg.sender, address(this), amt); weth.withdraw(amt); amountEth += amt; } for (uint256 i = 0; i < input.orders.length; i++) { _verifyOrderSignature(input.orders[i]); } for (uint256 i = 0; i < input.details.length; i++) { Market.SettleDetail memory detail = input.details[i]; Market.Order memory order = input.orders[detail.orderIdx]; if (input.shared.canFail) { try IX2Y2Run(address(this)).run1(order, input.shared, detail) returns ( uint256 ethPayment ) { amountEth -= ethPayment; } catch Error(string memory _err) { emit EvFailure(i, bytes(_err)); } catch (bytes memory _err) { emit EvFailure(i, _err); } } else { amountEth -= _run(order, input.shared, detail); } } if (amountEth > 0) { payable(msg.sender).transfer(amountEth); } } function run1( Market.Order memory order, Market.SettleShared memory shared, Market.SettleDetail memory detail ) external virtual returns (uint256) { require(msg.sender == address(this), 'unsafe call'); return _run(order, shared, detail); } function _hashItem(Market.Order memory order, Market.OrderItem memory item) internal view virtual returns (bytes32) { return keccak256( abi.encode( order.salt, order.user, order.network, order.intent, order.delegateType, order.deadline, order.currency, order.dataMask, item ) ); } function _emitInventory( bytes32 itemHash, Market.Order memory order, Market.OrderItem memory item, Market.SettleShared memory shared, Market.SettleDetail memory detail ) internal virtual { emit EvInventory( itemHash, order.user, shared.user, order.salt, shared.salt, order.intent, order.delegateType, order.deadline, order.currency, order.dataMask, item, detail ); } function _run( Market.Order memory order, Market.SettleShared memory shared, Market.SettleDetail memory detail ) internal virtual returns (uint256) { uint256 nativeAmount = 0; Market.OrderItem memory item = order.items[detail.itemIdx]; bytes32 itemHash = _hashItem(order, item); { require(itemHash == detail.itemHash, 'item hash does not match'); require(order.network == block.chainid, 'wrong network'); require( address(detail.executionDelegate) != address(0) && delegates[address(detail.executionDelegate)], 'unknown delegate' ); } bytes memory data = item.data; { if (order.dataMask.length > 0 && detail.dataReplacement.length > 0) { _arrayReplace(data, detail.dataReplacement, order.dataMask); } } if (detail.op == Market.Op.COMPLETE_SELL_OFFER) { require(inventoryStatus[itemHash] == Market.InvStatus.NEW, 'order already exists'); require(order.intent == Market.INTENT_SELL, 'intent != sell'); _assertDelegation(order, detail); require(order.deadline > block.timestamp, 'deadline reached'); require(detail.price >= item.price, 'underpaid'); nativeAmount = _takePayment(itemHash, order.currency, shared.user, detail.price); require( detail.executionDelegate.executeSell(order.user, shared.user, data), 'delegation error' ); _distributeFeeAndProfit( itemHash, order.user, order.currency, detail, detail.price, detail.price ); inventoryStatus[itemHash] = Market.InvStatus.COMPLETE; } else if (detail.op == Market.Op.COMPLETE_BUY_OFFER) { require(inventoryStatus[itemHash] == Market.InvStatus.NEW, 'order already exists'); require(order.intent == Market.INTENT_BUY, 'intent != buy'); _assertDelegation(order, detail); require(order.deadline > block.timestamp, 'deadline reached'); require(item.price == detail.price, 'price not match'); require(!_isNative(order.currency), 'native token not supported'); nativeAmount = _takePayment(itemHash, order.currency, order.user, detail.price); require( detail.executionDelegate.executeBuy(shared.user, order.user, data), 'delegation error' ); _distributeFeeAndProfit( itemHash, shared.user, order.currency, detail, detail.price, detail.price ); inventoryStatus[itemHash] = Market.InvStatus.COMPLETE; } else if (detail.op == Market.Op.CANCEL_OFFER) { require(inventoryStatus[itemHash] == Market.InvStatus.NEW, 'unable to cancel'); require(order.deadline > block.timestamp, 'deadline reached'); inventoryStatus[itemHash] = Market.InvStatus.CANCELLED; emit EvCancel(itemHash); } else if (detail.op == Market.Op.BID) { require(order.intent == Market.INTENT_AUCTION, 'intent != auction'); _assertDelegation(order, detail); bool firstBid = false; if (ongoingAuctions[itemHash].bidder == address(0)) { require(inventoryStatus[itemHash] == Market.InvStatus.NEW, 'order already exists'); require(order.deadline > block.timestamp, 'auction ended'); require(detail.price >= item.price, 'underpaid'); firstBid = true; ongoingAuctions[itemHash] = Market.OngoingAuction({ price: detail.price, netPrice: detail.price, bidder: shared.user, endAt: order.deadline }); inventoryStatus[itemHash] = Market.InvStatus.AUCTION; require( detail.executionDelegate.executeBid(order.user, address(0), shared.user, data), 'delegation error' ); } Market.OngoingAuction storage auc = ongoingAuctions[itemHash]; require(auc.endAt > block.timestamp, 'auction ended'); nativeAmount = _takePayment(itemHash, order.currency, shared.user, detail.price); if (!firstBid) { require( inventoryStatus[itemHash] == Market.InvStatus.AUCTION, 'order is not auction' ); require( detail.price - auc.price >= (auc.price * detail.aucMinIncrementPct) / RATE_BASE, 'underbid' ); uint256 bidRefund = auc.netPrice; uint256 incentive = (detail.price * detail.bidIncentivePct) / RATE_BASE; if (bidRefund + incentive > 0) { _transferTo(order.currency, auc.bidder, bidRefund + incentive); emit EvAuctionRefund( itemHash, address(order.currency), auc.bidder, bidRefund, incentive ); } require( detail.executionDelegate.executeBid(order.user, auc.bidder, shared.user, data), 'delegation error' ); auc.price = detail.price; auc.netPrice = detail.price - incentive; auc.bidder = shared.user; } if (block.timestamp + detail.aucIncDurationSecs > auc.endAt) { auc.endAt += detail.aucIncDurationSecs; } } else if ( detail.op == Market.Op.REFUND_AUCTION || detail.op == Market.Op.REFUND_AUCTION_STUCK_ITEM ) { require( inventoryStatus[itemHash] == Market.InvStatus.AUCTION, 'cannot cancel non-auction order' ); Market.OngoingAuction storage auc = ongoingAuctions[itemHash]; if (auc.netPrice > 0) { _transferTo(order.currency, auc.bidder, auc.netPrice); emit EvAuctionRefund( itemHash, address(order.currency), auc.bidder, auc.netPrice, 0 ); } _assertDelegation(order, detail); if (detail.op == Market.Op.REFUND_AUCTION) { require( detail.executionDelegate.executeAuctionRefund(order.user, auc.bidder, data), 'delegation error' ); } delete ongoingAuctions[itemHash]; inventoryStatus[itemHash] = Market.InvStatus.REFUNDED; } else if (detail.op == Market.Op.COMPLETE_AUCTION) { require( inventoryStatus[itemHash] == Market.InvStatus.AUCTION, 'cannot complete non-auction order' ); _assertDelegation(order, detail); Market.OngoingAuction storage auc = ongoingAuctions[itemHash]; require(block.timestamp >= auc.endAt, 'auction not finished yet'); require( detail.executionDelegate.executeAuctionComplete(order.user, auc.bidder, data), 'delegation error' ); _distributeFeeAndProfit( itemHash, order.user, order.currency, detail, auc.price, auc.netPrice ); inventoryStatus[itemHash] = Market.InvStatus.COMPLETE; delete ongoingAuctions[itemHash]; } else { revert('unknown op'); } _emitInventory(itemHash, order, item, shared, detail); return nativeAmount; } function _assertDelegation(Market.Order memory order, Market.SettleDetail memory detail) internal view virtual { require( detail.executionDelegate.delegateType() == order.delegateType, 'delegation type error' ); } // modifies `src` function _arrayReplace( bytes memory src, bytes memory replacement, bytes memory mask ) internal view virtual { require(src.length == replacement.length); require(src.length == mask.length); for (uint256 i = 0; i < src.length; i++) { if (mask[i] != 0) { src[i] = replacement[i]; } } } function _verifyInputSignature(Market.RunInput memory input) internal view virtual { bytes32 hash = keccak256(abi.encode(input.shared, input.details.length, input.details)); address signer = ECDSA.recover(hash, input.v, input.r, input.s); require(signers[signer], 'Input signature error'); } function _verifyOrderSignature(Market.Order memory order) internal view virtual { address orderSigner; if (order.signVersion == Market.SIGN_V1) { bytes32 orderHash = keccak256( abi.encode( order.salt, order.user, order.network, order.intent, order.delegateType, order.deadline, order.currency, order.dataMask, order.items.length, order.items ) ); orderSigner = ECDSA.recover( ECDSA.toEthSignedMessageHash(orderHash), order.v, order.r, order.s ); } else { revert('unknown signature version'); } require(orderSigner == order.user, 'Order signature does not match'); } function _isNative(IERC20Upgradeable currency) internal view virtual returns (bool) { return address(currency) == address(0); } function _takePayment( bytes32 itemHash, IERC20Upgradeable currency, address from, uint256 amount ) internal virtual returns (uint256) { if (amount > 0) { if (_isNative(currency)) { return amount; } else { currency.safeTransferFrom(from, address(this), amount); } } return 0; } function _transferTo( IERC20Upgradeable currency, address to, uint256 amount ) internal virtual { if (amount > 0) { if (_isNative(currency)) { AddressUpgradeable.sendValue(payable(to), amount); } else { currency.safeTransfer(to, amount); } } } function _distributeFeeAndProfit( bytes32 itemHash, address seller, IERC20Upgradeable currency, Market.SettleDetail memory sd, uint256 price, uint256 netPrice ) internal virtual { require(price >= netPrice, 'price error'); uint256 payment = netPrice; uint256 totalFeePct; for (uint256 i = 0; i < sd.fees.length; i++) { Market.Fee memory fee = sd.fees[i]; totalFeePct += fee.percentage; uint256 amount = (price * fee.percentage) / RATE_BASE; payment -= amount; _transferTo(currency, fee.to, amount); } require(feeCapPct >= totalFeePct, 'total fee cap exceeded'); _transferTo(currency, seller, payment); emit EvProfit(itemHash, address(currency), seller, payment); } } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; interface IDelegate { function delegateType() external view returns (uint256); function executeSell( address seller, address buyer, bytes calldata data ) external returns (bool); function executeBuy( address seller, address buyer, bytes calldata data ) external returns (bool); function executeBid( address seller, address previousBidder, address bidder, bytes calldata data ) external returns (bool); function executeAuctionComplete( address seller, address buyer, bytes calldata data ) external returns (bool); function executeAuctionRefund( address seller, address lastBidder, bytes calldata data ) external returns (bool); } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol'; interface IWETHUpgradable is IERC20Upgradeable { function deposit() external payable; function withdraw(uint256 wad) external; } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import './IDelegate.sol'; import './IWETHUpgradable.sol'; library Market { uint256 constant INTENT_SELL = 1; uint256 constant INTENT_AUCTION = 2; uint256 constant INTENT_BUY = 3; uint8 constant SIGN_V1 = 1; uint8 constant SIGN_V3 = 3; struct OrderItem { uint256 price; bytes data; } struct Order { uint256 salt; address user; uint256 network; uint256 intent; uint256 delegateType; uint256 deadline; IERC20Upgradeable currency; bytes dataMask; OrderItem[] items; // signature bytes32 r; bytes32 s; uint8 v; uint8 signVersion; } struct Fee { uint256 percentage; address to; } struct SettleDetail { Market.Op op; uint256 orderIdx; uint256 itemIdx; uint256 price; bytes32 itemHash; IDelegate executionDelegate; bytes dataReplacement; uint256 bidIncentivePct; uint256 aucMinIncrementPct; uint256 aucIncDurationSecs; Fee[] fees; } struct SettleShared { uint256 salt; uint256 deadline; uint256 amountToEth; uint256 amountToWeth; address user; bool canFail; } struct RunInput { Order[] orders; SettleDetail[] details; SettleShared shared; // signature bytes32 r; bytes32 s; uint8 v; } struct OngoingAuction { uint256 price; uint256 netPrice; uint256 endAt; address bidder; } enum InvStatus { NEW, AUCTION, COMPLETE, CANCELLED, REFUNDED } enum Op { INVALID, // off-chain COMPLETE_SELL_OFFER, COMPLETE_BUY_OFFER, CANCEL_OFFER, // auction BID, COMPLETE_AUCTION, REFUND_AUCTION, REFUND_AUCTION_STUCK_ITEM } enum DelegationType { INVALID, ERC721, ERC1155 } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../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 { __Context_init_unchained(); __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } uint256[49] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol) pragma solidity ^0.8.0; 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 a proxied contract can't have 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. * * 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 initialize the implementation contract, you can either invoke the * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() initializer {} * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { // If the contract is initializing we ignore whether _initialized is set in order to support multiple // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the // contract may have been reentered. require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} modifier, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } function _isConstructor() private view returns (bool) { return !AddressUpgradeable.isContract(address(this)); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../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 { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { 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()); } uint256[49] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../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() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } uint256[49] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable 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( IERC20Upgradeable 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( IERC20Upgradeable 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( IERC20Upgradeable 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(IERC20Upgradeable 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"); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { // Check the signature length // - case 65: r,s,v signature (standard) // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._ if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else if (signature.length == 64) { bytes32 r; bytes32 vs; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly { r := mload(add(signature, 0x20)) vs := mload(add(signature, 0x40)) } return tryRecover(hash, r, vs); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 27) } return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } if (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\\x19Ethereum Signed Message:\ 32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\\x19Ethereum Signed Message:\ ", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\\x19\\x01", domainSeparator, structHash)); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { __Context_init_unchained(); } 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; } uint256[50] private __gap; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) pragma solidity ^0.8.0; /** * @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 * ==== */ 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 Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } }
File 4 of 5: ERC721Delegate
// SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol'; import '@openzeppelin/contracts/access/AccessControl.sol'; import './MarketConsts.sol'; import './IDelegate.sol'; contract ERC721Delegate is IDelegate, AccessControl, IERC721Receiver { bytes32 public constant DELEGATION_CALLER = keccak256('DELEGATION_CALLER'); struct Pair { IERC721 token; uint256 tokenId; } constructor() { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); } function onERC721Received( address, address, uint256, bytes calldata ) external override returns (bytes4) { return this.onERC721Received.selector; } function decode(bytes calldata data) internal pure returns (Pair[] memory) { return abi.decode(data, (Pair[])); } function delegateType() external view returns (uint256) { // return uint256(Market.DelegationType.ERC721); return 1; } function executeSell( address seller, address buyer, bytes calldata data ) external onlyRole(DELEGATION_CALLER) returns (bool) { Pair[] memory pairs = decode(data); for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(seller, buyer, p.tokenId); } return true; } function executeBuy( address seller, address buyer, bytes calldata data ) external onlyRole(DELEGATION_CALLER) returns (bool) { Pair[] memory pairs = decode(data); for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(seller, buyer, p.tokenId); } return true; } function executeBid( address seller, address previousBidder, address, // bidder, bytes calldata data ) external onlyRole(DELEGATION_CALLER) returns (bool) { if (previousBidder == address(0)) { Pair[] memory pairs = decode(data); for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(seller, address(this), p.tokenId); } } return true; } function executeAuctionComplete( address, // seller, address buyer, bytes calldata data ) external onlyRole(DELEGATION_CALLER) returns (bool) { Pair[] memory pairs = decode(data); for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(address(this), buyer, p.tokenId); } return true; } function executeAuctionRefund( address seller, address, // lastBidder, bytes calldata data ) external onlyRole(DELEGATION_CALLER) returns (bool) { Pair[] memory pairs = decode(data); for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(address(this), seller, p.tokenId); } return true; } function transferBatch(Pair[] memory pairs, address to) public { for (uint256 i = 0; i < pairs.length; i++) { Pair memory p = pairs[i]; p.token.safeTransferFrom(msg.sender, to, p.tokenId); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol) 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; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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 IERC721Receiver { /** * @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 `IERC721.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import './IDelegate.sol'; import './IWETHUpgradable.sol'; library Market { uint256 constant INTENT_SELL = 1; uint256 constant INTENT_AUCTION = 2; uint256 constant INTENT_BUY = 3; uint8 constant SIGN_V1 = 1; uint8 constant SIGN_V3 = 3; struct OrderItem { uint256 price; bytes data; } struct Order { uint256 salt; address user; uint256 network; uint256 intent; uint256 delegateType; uint256 deadline; IERC20Upgradeable currency; bytes dataMask; OrderItem[] items; // signature bytes32 r; bytes32 s; uint8 v; uint8 signVersion; } struct Fee { uint256 percentage; address to; } struct SettleDetail { Market.Op op; uint256 orderIdx; uint256 itemIdx; uint256 price; bytes32 itemHash; IDelegate executionDelegate; bytes dataReplacement; uint256 bidIncentivePct; uint256 aucMinIncrementPct; uint256 aucIncDurationSecs; Fee[] fees; } struct SettleShared { uint256 salt; uint256 deadline; uint256 amountToEth; uint256 amountToWeth; address user; bool canFail; } struct RunInput { Order[] orders; SettleDetail[] details; SettleShared shared; // signature bytes32 r; bytes32 s; uint8 v; } struct OngoingAuction { uint256 price; uint256 netPrice; uint256 endAt; address bidder; } enum InvStatus { NEW, AUCTION, COMPLETE, CANCELLED, REFUNDED } enum Op { INVALID, // off-chain COMPLETE_SELL_OFFER, COMPLETE_BUY_OFFER, CANCEL_OFFER, // auction BID, COMPLETE_AUCTION, REFUND_AUCTION, REFUND_AUCTION_STUCK_ITEM } enum DelegationType { INVALID, ERC721, ERC1155 } } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; interface IDelegate { function delegateType() external view returns (uint256); function executeSell( address seller, address buyer, bytes calldata data ) external returns (bool); function executeBuy( address seller, address buyer, bytes calldata data ) external returns (bool); function executeBid( address seller, address previousBidder, address bidder, bytes calldata data ) external returns (bool); function executeAuctionComplete( address seller, address buyer, bytes calldata data ) external returns (bool); function executeAuctionRefund( address seller, address lastBidder, bytes calldata data ) external returns (bool); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface 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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol'; interface IWETHUpgradable is IERC20Upgradeable { function deposit() external payable; function withdraw(uint256 wad) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @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); }
File 5 of 5: FeeManagement
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import './TokenSplitter.sol'; import './FeeSharingSetter.sol'; import './IWETH.sol'; import '@openzeppelin/contracts/access/AccessControl.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/security/Pausable.sol'; import '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import '@openzeppelin/contracts/utils/Address.sol'; contract FeeManagement is AccessControl, Pausable, ReentrancyGuard { using SafeERC20 for IERC20; using SafeERC20 for IWETH; bytes32 public constant OPERATOR_ROLE = keccak256('OPERATOR_ROLE'); TokenSplitter public immutable tokenSplitter; FeeSharingSetter public immutable feeSetter; IWETH public immutable weth; constructor( TokenSplitter tokenSplitter_, FeeSharingSetter feeSetter_, IWETH weth_, address operator_, address admin_ ) { tokenSplitter = tokenSplitter_; feeSetter = feeSetter_; weth = weth_; if (admin_ == address(0)) { admin_ = msg.sender; } _grantRole(DEFAULT_ADMIN_ROLE, admin_); _grantRole(OPERATOR_ROLE, admin_); if (operator_ != address(0)) { _grantRole(OPERATOR_ROLE, operator_); } } receive() external payable {} function pause() external onlyRole(DEFAULT_ADMIN_ROLE) { _pause(); } function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) { _unpause(); } // withdraw tokens function withdraw(address to, IERC20[] calldata tokens) external nonReentrant whenNotPaused onlyRole(DEFAULT_ADMIN_ROLE) { require(to != address(0), 'Withdraw: address(0) cannot be recipient'); for (uint256 i = 0; i < tokens.length; i++) { IERC20 currency = tokens[i]; if (address(currency) == address(0)) { uint256 balance = address(this).balance; if (balance > 0) { Address.sendValue(payable(to), balance); } } else { uint256 balance = currency.balanceOf(address(this)); if (balance > 0) { currency.safeTransfer(to, balance); } } } } function canRelease() external view returns (bool) { return block.number > feeSetter.rewardDurationInBlocks() + feeSetter.lastRewardDistributionBlock(); } function releaseAndUpdateReward(IERC20[] memory tokens, address[] memory accounts) external nonReentrant whenNotPaused onlyRole(OPERATOR_ROLE) { _release(tokens); // release x2y2 to pools, skipped when the balance is less than 1 token (the release can be called by anyone) if (tokenSplitter.x2y2Token().balanceOf(address(tokenSplitter)) >= 1 ether) { for (uint256 i = 0; i < accounts.length; i++) { tokenSplitter.releaseTokens(accounts[i]); } } feeSetter.updateRewards(); } function release(IERC20[] memory tokens) external nonReentrant whenNotPaused onlyRole(OPERATOR_ROLE) { _release(tokens); } function _release(IERC20[] memory tokens) internal { uint256 balance = address(this).balance; if (balance > 0) { weth.deposit{value: balance}(); } balance = weth.balanceOf(address(this)); if (balance > 0) { weth.safeTransfer(address(feeSetter), balance); } for (uint256 i = 0; i < tokens.length; i++) { IERC20 currency = tokens[i]; balance = currency.balanceOf(address(this)); if (balance > 0) { currency.safeTransfer(address(feeSetter), balance); } } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol'; import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import {IERC20, SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; /** * @title TokenSplitter * @notice It splits X2Y2 to team/treasury/trading volume reward accounts based on shares. */ contract TokenSplitter is Ownable, ReentrancyGuard { using SafeERC20 for IERC20; struct AccountInfo { uint256 shares; uint256 tokensDistributedToAccount; } uint256 public immutable TOTAL_SHARES; IERC20 public immutable x2y2Token; // Total tokens distributed across all accounts uint256 public totalTokensDistributed; mapping(address => AccountInfo) public accountInfo; event NewSharesOwner(address indexed oldRecipient, address indexed newRecipient); event TokensTransferred(address indexed account, uint256 amount); /** * @notice Constructor * @param _accounts array of accounts addresses * @param _shares array of shares per account * @param _x2y2Token address of the X2Y2 token */ constructor( address[] memory _accounts, uint256[] memory _shares, address _x2y2Token ) { require(_accounts.length == _shares.length, 'Splitter: Length differ'); require(_accounts.length > 0, 'Splitter: Length must be > 0'); uint256 currentShares; for (uint256 i = 0; i < _accounts.length; i++) { require(_shares[i] > 0, 'Splitter: Shares are 0'); currentShares += _shares[i]; accountInfo[_accounts[i]].shares = _shares[i]; } TOTAL_SHARES = currentShares; x2y2Token = IERC20(_x2y2Token); } /** * @notice Release X2Y2 tokens to the account * @param account address of the account */ function releaseTokens(address account) external nonReentrant { require(accountInfo[account].shares > 0, 'Splitter: Account has no share'); // Calculate amount to transfer to the account uint256 totalTokensReceived = x2y2Token.balanceOf(address(this)) + totalTokensDistributed; uint256 pendingRewards = ((totalTokensReceived * accountInfo[account].shares) / TOTAL_SHARES) - accountInfo[account].tokensDistributedToAccount; // Revert if equal to 0 require(pendingRewards != 0, 'Splitter: Nothing to transfer'); accountInfo[account].tokensDistributedToAccount += pendingRewards; totalTokensDistributed += pendingRewards; // Transfer funds to account x2y2Token.safeTransfer(account, pendingRewards); emit TokensTransferred(account, pendingRewards); } /** * @notice Update share recipient * @param _newRecipient address of the new recipient * @param _currentRecipient address of the current recipient */ function updateSharesOwner(address _newRecipient, address _currentRecipient) external onlyOwner { require( accountInfo[_currentRecipient].shares > 0, 'Owner: Current recipient has no shares' ); require(accountInfo[_newRecipient].shares == 0, 'Owner: New recipient has existing shares'); // Copy shares to new recipient accountInfo[_newRecipient].shares = accountInfo[_currentRecipient].shares; accountInfo[_newRecipient].tokensDistributedToAccount = accountInfo[_currentRecipient] .tokensDistributedToAccount; // Reset existing shares accountInfo[_currentRecipient].shares = 0; accountInfo[_currentRecipient].tokensDistributedToAccount = 0; emit NewSharesOwner(_currentRecipient, _newRecipient); } /** * @notice Retrieve amount of X2Y2 tokens that can be transferred * @param account address of the account */ function calculatePendingRewards(address account) external view returns (uint256) { if (accountInfo[account].shares == 0) { return 0; } uint256 totalTokensReceived = x2y2Token.balanceOf(address(this)) + totalTokensDistributed; uint256 pendingRewards = ((totalTokensReceived * accountInfo[account].shares) / TOTAL_SHARES) - accountInfo[account].tokensDistributedToAccount; return pendingRewards; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol'; import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import {IERC20, SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol'; import {FeeSharingSystem} from './FeeSharingSystem.sol'; import {TokenDistributor} from './TokenDistributor.sol'; import {IRewardConvertor} from './IRewardConvertor.sol'; import {IMintableERC20} from './IMintableERC20.sol'; import {ITokenStaked} from './ITokenStaked.sol'; /** * @title FeeSharingSetter * @notice It receives exchange fees and owns the FeeSharingSystem contract. * It can plug to AMMs for converting all received currencies to WETH. */ contract FeeSharingSetter is ReentrancyGuard, AccessControl { using EnumerableSet for EnumerableSet.AddressSet; using SafeERC20 for IERC20; // Operator role bytes32 public constant OPERATOR_ROLE = keccak256('OPERATOR_ROLE'); // Min duration for each fee-sharing period (in blocks) uint256 public immutable MIN_REWARD_DURATION_IN_BLOCKS; // Max duration for each fee-sharing period (in blocks) uint256 public immutable MAX_REWARD_DURATION_IN_BLOCKS; IERC20 public immutable x2y2Token; IERC20 public immutable rewardToken; FeeSharingSystem public feeSharingSystem; TokenDistributor public immutable tokenDistributor; // Reward convertor (tool to convert other currencies to rewardToken) IRewardConvertor public rewardConvertor; // Last reward block of distribution uint256 public lastRewardDistributionBlock; // Next reward duration in blocks uint256 public nextRewardDurationInBlocks; // Reward duration in blocks uint256 public rewardDurationInBlocks; // Set of addresses that are staking only the fee sharing EnumerableSet.AddressSet private _feeStakingAddresses; mapping(address => bool) public feeStakingAddressIStaked; event ConversionToRewardToken( address indexed token, uint256 amountConverted, uint256 amountReceived ); event FeeStakingAddressesAdded(address[] feeStakingAddresses); event FeeStakingAddressesRemoved(address[] feeStakingAddresses); event NewRewardDurationInBlocks(uint256 rewardDurationInBlocks); event NewRewardConvertor(address rewardConvertor); /** * @notice Constructor * @param _feeSharingSystem address of the fee sharing system * @param _minRewardDurationInBlocks minimum reward duration in blocks * @param _maxRewardDurationInBlocks maximum reward duration in blocks * @param _rewardDurationInBlocks reward duration between two updates in blocks */ constructor( address _feeSharingSystem, uint256 _minRewardDurationInBlocks, uint256 _maxRewardDurationInBlocks, uint256 _rewardDurationInBlocks ) { require( (_rewardDurationInBlocks <= _maxRewardDurationInBlocks) && (_rewardDurationInBlocks >= _minRewardDurationInBlocks), 'Owner: Reward duration in blocks outside of range' ); MIN_REWARD_DURATION_IN_BLOCKS = _minRewardDurationInBlocks; MAX_REWARD_DURATION_IN_BLOCKS = _maxRewardDurationInBlocks; feeSharingSystem = FeeSharingSystem(_feeSharingSystem); rewardToken = feeSharingSystem.rewardToken(); x2y2Token = feeSharingSystem.x2y2Token(); tokenDistributor = feeSharingSystem.tokenDistributor(); rewardDurationInBlocks = _rewardDurationInBlocks; nextRewardDurationInBlocks = _rewardDurationInBlocks; _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); } /** * @notice Update the reward per block (in rewardToken) * @dev It automatically retrieves the number of pending WETH and adjusts * based on the balance of X2Y2 in fee-staking addresses that exist in the set. */ function updateRewards() external onlyRole(OPERATOR_ROLE) { if (lastRewardDistributionBlock > 0) { require( block.number > (rewardDurationInBlocks + lastRewardDistributionBlock), 'Reward: Too early to add' ); } // Adjust for this period if (rewardDurationInBlocks != nextRewardDurationInBlocks) { rewardDurationInBlocks = nextRewardDurationInBlocks; } lastRewardDistributionBlock = block.number; // Calculate the reward to distribute as the balance held by this address uint256 reward = rewardToken.balanceOf(address(this)); require(reward != 0, 'Reward: Nothing to distribute'); // Check if there is any address eligible for fee-sharing only uint256 numberAddressesForFeeStaking = _feeStakingAddresses.length(); // If there are eligible addresses for fee-sharing only, calculate their shares if (numberAddressesForFeeStaking > 0) { uint256[] memory x2y2Balances = new uint256[](numberAddressesForFeeStaking); (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(feeSharingSystem)); for (uint256 i = 0; i < numberAddressesForFeeStaking; i++) { address a = _feeStakingAddresses.at(i); uint256 balance = x2y2Token.balanceOf(a); if (feeStakingAddressIStaked[a]) { balance = ITokenStaked(a).getTotalStaked(); } totalAmountStaked += balance; x2y2Balances[i] = balance; } // Only apply the logic if the totalAmountStaked > 0 (to prevent division by 0) if (totalAmountStaked > 0) { uint256 adjustedReward = reward; for (uint256 i = 0; i < numberAddressesForFeeStaking; i++) { uint256 amountToTransfer = (x2y2Balances[i] * reward) / totalAmountStaked; if (amountToTransfer > 0) { adjustedReward -= amountToTransfer; rewardToken.safeTransfer(_feeStakingAddresses.at(i), amountToTransfer); } } // Adjust reward accordingly reward = adjustedReward; } } // Transfer tokens to fee sharing system rewardToken.safeTransfer(address(feeSharingSystem), reward); // Update rewards feeSharingSystem.updateRewards(reward, rewardDurationInBlocks); } /** * @notice Convert currencies to reward token * @dev Function only usable only for whitelisted currencies (where no potential side effect) * @param token address of the token to sell * @param additionalData additional data (e.g., slippage) */ function convertCurrencyToRewardToken(address token, bytes calldata additionalData) external nonReentrant onlyRole(OPERATOR_ROLE) { require(address(rewardConvertor) != address(0), 'Convert: RewardConvertor not set'); require(token != address(rewardToken), 'Convert: Cannot be reward token'); uint256 amountToConvert = IERC20(token).balanceOf(address(this)); require(amountToConvert != 0, 'Convert: Amount to convert must be > 0'); // Adjust allowance for this transaction only IERC20(token).safeIncreaseAllowance(address(rewardConvertor), amountToConvert); // Exchange token to reward token uint256 amountReceived = rewardConvertor.convert( token, address(rewardToken), amountToConvert, additionalData ); emit ConversionToRewardToken(token, amountToConvert, amountReceived); } /** * @notice Add staking addresses * @param _stakingAddresses array of addresses eligible for fee-sharing only */ function addFeeStakingAddresses( address[] calldata _stakingAddresses, bool[] calldata _addressIStaked ) external onlyRole(DEFAULT_ADMIN_ROLE) { require(_stakingAddresses.length == _addressIStaked.length, 'Owner: param length error'); for (uint256 i = 0; i < _stakingAddresses.length; i++) { require( !_feeStakingAddresses.contains(_stakingAddresses[i]), 'Owner: Address already registered' ); _feeStakingAddresses.add(_stakingAddresses[i]); if (_addressIStaked[i]) { feeStakingAddressIStaked[_stakingAddresses[i]] = true; } } emit FeeStakingAddressesAdded(_stakingAddresses); } /** * @notice Remove staking addresses * @param _stakingAddresses array of addresses eligible for fee-sharing only */ function removeFeeStakingAddresses(address[] calldata _stakingAddresses) external onlyRole(DEFAULT_ADMIN_ROLE) { for (uint256 i = 0; i < _stakingAddresses.length; i++) { require( _feeStakingAddresses.contains(_stakingAddresses[i]), 'Owner: Address not registered' ); _feeStakingAddresses.remove(_stakingAddresses[i]); if (feeStakingAddressIStaked[_stakingAddresses[i]]) { delete feeStakingAddressIStaked[_stakingAddresses[i]]; } } emit FeeStakingAddressesRemoved(_stakingAddresses); } /** * @notice Set new reward duration in blocks for next update * @param _newRewardDurationInBlocks number of blocks for new reward period */ function setNewRewardDurationInBlocks(uint256 _newRewardDurationInBlocks) external onlyRole(DEFAULT_ADMIN_ROLE) { require( (_newRewardDurationInBlocks <= MAX_REWARD_DURATION_IN_BLOCKS) && (_newRewardDurationInBlocks >= MIN_REWARD_DURATION_IN_BLOCKS), 'Owner: New reward duration in blocks outside of range' ); nextRewardDurationInBlocks = _newRewardDurationInBlocks; emit NewRewardDurationInBlocks(_newRewardDurationInBlocks); } /** * @notice Set reward convertor contract * @param _rewardConvertor address of the reward convertor (set to null to deactivate) */ function setRewardConvertor(address _rewardConvertor) external onlyRole(DEFAULT_ADMIN_ROLE) { rewardConvertor = IRewardConvertor(_rewardConvertor); emit NewRewardConvertor(_rewardConvertor); } /** * @notice See addresses eligible for fee-staking */ function viewFeeStakingAddresses() external view returns (address[] memory) { uint256 length = _feeStakingAddresses.length(); address[] memory feeStakingAddresses = new address[](length); for (uint256 i = 0; i < length; i++) { feeStakingAddresses[i] = _feeStakingAddresses.at(i); } return (feeStakingAddresses); } } // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.0; pragma abicoder v2; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IWETH is IERC20 { function deposit() external payable; function withdraw(uint256 wad) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.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 Pausable is Context { /** * @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. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { 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()); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) 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"); } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Address.sol) 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); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol) 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); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/structs/EnumerableSet.sol) pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { return _values(set._inner); } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; assembly { result := store } return result; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol'; import {IERC20, SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import {TokenDistributor} from './TokenDistributor.sol'; import {IStakeFor} from './IStakeFor.sol'; /** * @title FeeSharingSystem * @notice It handles the distribution of fees using * WETH along with the auto-compounding of X2Y2. */ contract FeeSharingSystem is ReentrancyGuard, AccessControl, IStakeFor { using SafeERC20 for IERC20; // for `depositFor` call bytes32 public constant DEPOSIT_ROLE = keccak256('DEPOSIT_ROLE'); // for `updateRewards()` bytes32 public constant REWARD_UPDATE_ROLE = keccak256('REWARD_UPDATE_ROLE'); struct UserInfo { uint256 shares; // shares of token staked uint256 userRewardPerTokenPaid; // user reward per token paid uint256 rewards; // pending rewards } // Precision factor for calculating rewards and exchange rate uint256 public constant PRECISION_FACTOR = 10**18; IERC20 public immutable x2y2Token; IERC20 public immutable rewardToken; TokenDistributor public immutable tokenDistributor; // Reward rate (block) uint256 public currentRewardPerBlock; // Last reward adjustment block number uint256 public lastRewardAdjustment; // Last update block for rewards uint256 public lastUpdateBlock; // Current end block for the current reward period uint256 public periodEndBlock; // Reward per token stored uint256 public rewardPerTokenStored; // Total existing shares uint256 public totalShares; mapping(address => UserInfo) public userInfo; event Deposit(address indexed user, uint256 amount, uint256 harvestedAmount); event Harvest(address indexed user, uint256 harvestedAmount); event NewRewardPeriod(uint256 numberBlocks, uint256 rewardPerBlock, uint256 reward); event Withdraw(address indexed user, uint256 amount, uint256 harvestedAmount); /** * @notice Constructor * @param _x2y2Token address of the token staked * @param _rewardToken address of the reward token * @param _tokenDistributor address of the token distributor contract */ constructor( address _x2y2Token, address _rewardToken, address _tokenDistributor ) { rewardToken = IERC20(_rewardToken); x2y2Token = IERC20(_x2y2Token); tokenDistributor = TokenDistributor(_tokenDistributor); _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); } /** * @notice deposit on behalf of `user`, must be called on fresh deposit only * @param user deposit user * @param amount amount to deposit */ function depositFor(address user, uint256 amount) external override nonReentrant onlyRole(DEPOSIT_ROLE) returns (bool) { require(amount >= PRECISION_FACTOR, 'Deposit: Amount must be >= 1 X2Y2'); // Auto compounds for everyone tokenDistributor.harvestAndCompound(); // Update reward for user _updateReward(user); // Retrieve total amount staked by this contract (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(this)); // transfer stakingToken from **sender** x2y2Token.safeTransferFrom(msg.sender, address(this), amount); uint256 currentShares; // Calculate the number of shares to issue for the user if (totalShares != 0) { currentShares = (amount * totalShares) / totalAmountStaked; // This is a sanity check to prevent deposit for 0 shares require(currentShares != 0, 'Deposit: Fail'); } else { currentShares = amount; } // Adjust internal shares userInfo[user].shares += currentShares; totalShares += currentShares; // Verify X2Y2 token allowance and adjust if necessary _checkAndAdjustX2Y2TokenAllowanceIfRequired(amount, address(tokenDistributor)); // Deposit user amount in the token distributor contract tokenDistributor.deposit(amount); emit Deposit(user, amount, 0); return true; } /** * @notice Deposit staked tokens (and collect reward tokens if requested) * @param amount amount to deposit (in X2Y2) * @param claimRewardToken whether to claim reward tokens * @dev There is a limit of 1 X2Y2 per deposit to prevent potential manipulation of current shares */ function deposit(uint256 amount, bool claimRewardToken) external nonReentrant { require(amount >= PRECISION_FACTOR, 'Deposit: Amount must be >= 1 X2Y2'); // Auto compounds for everyone tokenDistributor.harvestAndCompound(); // Update reward for user _updateReward(msg.sender); // Retrieve total amount staked by this contract (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(this)); // Transfer X2Y2 tokens to this address x2y2Token.safeTransferFrom(msg.sender, address(this), amount); uint256 currentShares; // Calculate the number of shares to issue for the user if (totalShares != 0) { currentShares = (amount * totalShares) / totalAmountStaked; // This is a sanity check to prevent deposit for 0 shares require(currentShares != 0, 'Deposit: Fail'); } else { currentShares = amount; } // Adjust internal shares userInfo[msg.sender].shares += currentShares; totalShares += currentShares; uint256 pendingRewards; if (claimRewardToken) { // Fetch pending rewards pendingRewards = userInfo[msg.sender].rewards; if (pendingRewards > 0) { userInfo[msg.sender].rewards = 0; rewardToken.safeTransfer(msg.sender, pendingRewards); } } // Verify X2Y2 token allowance and adjust if necessary _checkAndAdjustX2Y2TokenAllowanceIfRequired(amount, address(tokenDistributor)); // Deposit user amount in the token distributor contract tokenDistributor.deposit(amount); emit Deposit(msg.sender, amount, pendingRewards); } /** * @notice Harvest reward tokens that are pending */ function harvest() external nonReentrant { // Auto compounds for everyone tokenDistributor.harvestAndCompound(); // Update reward for user _updateReward(msg.sender); // Retrieve pending rewards uint256 pendingRewards = userInfo[msg.sender].rewards; // If pending rewards are null, revert require(pendingRewards > 0, 'Harvest: Pending rewards must be > 0'); // Adjust user rewards and transfer userInfo[msg.sender].rewards = 0; // Transfer reward token to sender rewardToken.safeTransfer(msg.sender, pendingRewards); emit Harvest(msg.sender, pendingRewards); } /** * @notice Withdraw staked tokens (and collect reward tokens if requested) * @param shares shares to withdraw * @param claimRewardToken whether to claim reward tokens */ function withdraw(uint256 shares, bool claimRewardToken) external nonReentrant { require( (shares > 0) && (shares <= userInfo[msg.sender].shares), 'Withdraw: Shares equal to 0 or larger than user shares' ); _withdraw(shares, claimRewardToken); } /** * @notice Withdraw all staked tokens (and collect reward tokens if requested) * @param claimRewardToken whether to claim reward tokens */ function withdrawAll(bool claimRewardToken) external nonReentrant { _withdraw(userInfo[msg.sender].shares, claimRewardToken); } /** * @notice Update the reward per block (in rewardToken) * @dev Only callable by owner. Owner is meant to be another smart contract. */ function updateRewards(uint256 reward, uint256 rewardDurationInBlocks) external onlyRole(REWARD_UPDATE_ROLE) { // Adjust the current reward per block if (block.number >= periodEndBlock) { currentRewardPerBlock = reward / rewardDurationInBlocks; } else { currentRewardPerBlock = (reward + ((periodEndBlock - block.number) * currentRewardPerBlock)) / rewardDurationInBlocks; } lastUpdateBlock = block.number; periodEndBlock = block.number + rewardDurationInBlocks; emit NewRewardPeriod(rewardDurationInBlocks, currentRewardPerBlock, reward); } /** * @notice Calculate pending rewards (WETH) for a user * @param user address of the user */ function calculatePendingRewards(address user) external view returns (uint256) { return _calculatePendingRewards(user); } /** * @notice Calculate value of X2Y2 for a user given a number of shares owned * @param user address of the user */ function calculateSharesValueInX2Y2(address user) external view returns (uint256) { // Retrieve amount staked (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(this)); // Adjust for pending rewards totalAmountStaked += tokenDistributor.calculatePendingRewards(address(this)); // Return user pro-rata of total shares return userInfo[user].shares == 0 ? 0 : (totalAmountStaked * userInfo[user].shares) / totalShares; } /** * @notice Calculate price of one share (in X2Y2 token) * Share price is expressed times 1e18 */ function calculateSharePriceInX2Y2() external view returns (uint256) { (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(this)); // Adjust for pending rewards totalAmountStaked += tokenDistributor.calculatePendingRewards(address(this)); return totalShares == 0 ? PRECISION_FACTOR : (totalAmountStaked * PRECISION_FACTOR) / (totalShares); } /** * @notice Return last block where trading rewards were distributed */ function lastRewardBlock() external view returns (uint256) { return _lastRewardBlock(); } /** * @notice Calculate pending rewards for a user * @param user address of the user */ function _calculatePendingRewards(address user) internal view returns (uint256) { return ((userInfo[user].shares * (_rewardPerToken() - (userInfo[user].userRewardPerTokenPaid))) / PRECISION_FACTOR) + userInfo[user].rewards; } /** * @notice Check current allowance and adjust if necessary * @param _amount amount to transfer * @param _to token to transfer */ function _checkAndAdjustX2Y2TokenAllowanceIfRequired(uint256 _amount, address _to) internal { if (x2y2Token.allowance(address(this), _to) < _amount) { x2y2Token.approve(_to, type(uint256).max); } } /** * @notice Return last block where rewards must be distributed */ function _lastRewardBlock() internal view returns (uint256) { return block.number < periodEndBlock ? block.number : periodEndBlock; } /** * @notice Return reward per token */ function _rewardPerToken() internal view returns (uint256) { if (totalShares == 0) { return rewardPerTokenStored; } return rewardPerTokenStored + ((_lastRewardBlock() - lastUpdateBlock) * (currentRewardPerBlock * PRECISION_FACTOR)) / totalShares; } /** * @notice Update reward for a user account * @param _user address of the user */ function _updateReward(address _user) internal { if (block.number != lastUpdateBlock) { rewardPerTokenStored = _rewardPerToken(); lastUpdateBlock = _lastRewardBlock(); } userInfo[_user].rewards = _calculatePendingRewards(_user); userInfo[_user].userRewardPerTokenPaid = rewardPerTokenStored; } /** * @notice Withdraw staked tokens (and collect reward tokens if requested) * @param shares shares to withdraw * @param claimRewardToken whether to claim reward tokens */ function _withdraw(uint256 shares, bool claimRewardToken) internal { // Auto compounds for everyone tokenDistributor.harvestAndCompound(); // Update reward for user _updateReward(msg.sender); // Retrieve total amount staked and calculated current amount (in X2Y2) (uint256 totalAmountStaked, ) = tokenDistributor.userInfo(address(this)); uint256 currentAmount = (totalAmountStaked * shares) / totalShares; userInfo[msg.sender].shares -= shares; totalShares -= shares; // Withdraw amount equivalent in shares tokenDistributor.withdraw(currentAmount); uint256 pendingRewards; if (claimRewardToken) { // Fetch pending rewards pendingRewards = userInfo[msg.sender].rewards; if (pendingRewards > 0) { userInfo[msg.sender].rewards = 0; rewardToken.safeTransfer(msg.sender, pendingRewards); } } // Transfer X2Y2 tokens to sender x2y2Token.safeTransfer(msg.sender, currentAmount); emit Withdraw(msg.sender, currentAmount, pendingRewards); } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import {IERC20, SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import {IMintableERC20} from './IMintableERC20.sol'; /** * @title TokenDistributor * @notice It handles the distribution of X2Y2 token. * It auto-adjusts block rewards over a set number of periods. */ contract TokenDistributor is ReentrancyGuard { using SafeERC20 for IERC20; using SafeERC20 for IMintableERC20; struct StakingPeriod { uint256 rewardPerBlockForStaking; uint256 rewardPerBlockForOthers; uint256 periodLengthInBlock; } struct UserInfo { uint256 amount; // Amount of staked tokens provided by user uint256 rewardDebt; // Reward debt } // Precision factor for calculating rewards uint256 public constant PRECISION_FACTOR = 10**12; IMintableERC20 public immutable x2y2Token; address public immutable tokenSplitter; // Number of reward periods uint256 public immutable NUMBER_PERIODS; // Block number when rewards start uint256 public immutable START_BLOCK; // Accumulated tokens per share uint256 public accTokenPerShare; // Current phase for rewards uint256 public currentPhase; // Block number when rewards end uint256 public endBlock; // Block number of the last update uint256 public lastRewardBlock; // Tokens distributed per block for other purposes (team + treasury + trading rewards) uint256 public rewardPerBlockForOthers; // Tokens distributed per block for staking uint256 public rewardPerBlockForStaking; // Total amount staked uint256 public totalAmountStaked; mapping(uint256 => StakingPeriod) public stakingPeriod; mapping(address => UserInfo) public userInfo; event Compound(address indexed user, uint256 harvestedAmount); event Deposit(address indexed user, uint256 amount, uint256 harvestedAmount); event NewRewardsPerBlock( uint256 indexed currentPhase, uint256 startBlock, uint256 rewardPerBlockForStaking, uint256 rewardPerBlockForOthers ); event Withdraw(address indexed user, uint256 amount, uint256 harvestedAmount); /** * @notice Constructor * @param _x2y2Token token address * @param _tokenSplitter token splitter contract address (for team and trading rewards) * @param _startBlock start block for reward program * @param _rewardsPerBlockForStaking array of rewards per block for staking * @param _rewardsPerBlockForOthers array of rewards per block for other purposes (team + treasury + trading rewards) * @param _periodLengthesInBlocks array of period lengthes * @param _numberPeriods number of periods with different rewards/lengthes (e.g., if 3 changes --> 4 periods) */ constructor( address _x2y2Token, address _tokenSplitter, uint256 _startBlock, uint256[] memory _rewardsPerBlockForStaking, uint256[] memory _rewardsPerBlockForOthers, uint256[] memory _periodLengthesInBlocks, uint256 _numberPeriods ) { require( (_periodLengthesInBlocks.length == _numberPeriods) && (_rewardsPerBlockForStaking.length == _numberPeriods) && (_rewardsPerBlockForStaking.length == _numberPeriods), 'Distributor: Lengthes must match numberPeriods' ); // 1. Operational checks for supply uint256 nonCirculatingSupply = IMintableERC20(_x2y2Token).SUPPLY_CAP() - IMintableERC20(_x2y2Token).totalSupply(); uint256 amountTokensToBeMinted; for (uint256 i = 0; i < _numberPeriods; i++) { amountTokensToBeMinted += (_rewardsPerBlockForStaking[i] * _periodLengthesInBlocks[i]) + (_rewardsPerBlockForOthers[i] * _periodLengthesInBlocks[i]); stakingPeriod[i] = StakingPeriod({ rewardPerBlockForStaking: _rewardsPerBlockForStaking[i], rewardPerBlockForOthers: _rewardsPerBlockForOthers[i], periodLengthInBlock: _periodLengthesInBlocks[i] }); } require( amountTokensToBeMinted == nonCirculatingSupply, 'Distributor: Wrong reward parameters' ); // 2. Store values x2y2Token = IMintableERC20(_x2y2Token); tokenSplitter = _tokenSplitter; rewardPerBlockForStaking = _rewardsPerBlockForStaking[0]; rewardPerBlockForOthers = _rewardsPerBlockForOthers[0]; START_BLOCK = _startBlock; endBlock = _startBlock + _periodLengthesInBlocks[0]; NUMBER_PERIODS = _numberPeriods; // Set the lastRewardBlock as the startBlock lastRewardBlock = _startBlock; } /** * @notice Deposit staked tokens and compounds pending rewards * @param amount amount to deposit (in X2Y2) */ function deposit(uint256 amount) external nonReentrant { require(amount > 0, 'Deposit: Amount must be > 0'); require(block.number >= START_BLOCK, 'Deposit: Not started yet'); // Update pool information _updatePool(); // Transfer X2Y2 tokens to this contract x2y2Token.safeTransferFrom(msg.sender, address(this), amount); uint256 pendingRewards; // If not new deposit, calculate pending rewards (for auto-compounding) if (userInfo[msg.sender].amount > 0) { pendingRewards = ((userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR) - userInfo[msg.sender].rewardDebt; } // Adjust user information userInfo[msg.sender].amount += (amount + pendingRewards); userInfo[msg.sender].rewardDebt = (userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR; // Increase totalAmountStaked totalAmountStaked += (amount + pendingRewards); emit Deposit(msg.sender, amount, pendingRewards); } /** * @notice Compound based on pending rewards */ function harvestAndCompound() external nonReentrant { // Update pool information _updatePool(); // Calculate pending rewards uint256 pendingRewards = ((userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR) - userInfo[msg.sender].rewardDebt; // Return if no pending rewards if (pendingRewards == 0) { // It doesn't throw revertion (to help with the fee-sharing auto-compounding contract) return; } // Adjust user amount for pending rewards userInfo[msg.sender].amount += pendingRewards; // Adjust totalAmountStaked totalAmountStaked += pendingRewards; // Recalculate reward debt based on new user amount userInfo[msg.sender].rewardDebt = (userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR; emit Compound(msg.sender, pendingRewards); } /** * @notice Update pool rewards */ function updatePool() external nonReentrant { _updatePool(); } /** * @notice Withdraw staked tokens and compound pending rewards * @param amount amount to withdraw */ function withdraw(uint256 amount) external nonReentrant { require( (userInfo[msg.sender].amount >= amount) && (amount > 0), 'Withdraw: Amount must be > 0 or lower than user balance' ); // Update pool _updatePool(); // Calculate pending rewards uint256 pendingRewards = ((userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR) - userInfo[msg.sender].rewardDebt; // Adjust user information userInfo[msg.sender].amount = userInfo[msg.sender].amount + pendingRewards - amount; userInfo[msg.sender].rewardDebt = (userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR; // Adjust total amount staked totalAmountStaked = totalAmountStaked + pendingRewards - amount; // Transfer X2Y2 tokens to the sender x2y2Token.safeTransfer(msg.sender, amount); emit Withdraw(msg.sender, amount, pendingRewards); } /** * @notice Withdraw all staked tokens and collect tokens */ function withdrawAll() external nonReentrant { require(userInfo[msg.sender].amount > 0, 'Withdraw: Amount must be > 0'); // Update pool _updatePool(); // Calculate pending rewards and amount to transfer (to the sender) uint256 pendingRewards = ((userInfo[msg.sender].amount * accTokenPerShare) / PRECISION_FACTOR) - userInfo[msg.sender].rewardDebt; uint256 amountToTransfer = userInfo[msg.sender].amount + pendingRewards; // Adjust total amount staked totalAmountStaked = totalAmountStaked - userInfo[msg.sender].amount; // Adjust user information userInfo[msg.sender].amount = 0; userInfo[msg.sender].rewardDebt = 0; // Transfer X2Y2 tokens to the sender x2y2Token.safeTransfer(msg.sender, amountToTransfer); emit Withdraw(msg.sender, amountToTransfer, pendingRewards); } /** * @notice Calculate pending rewards for a user * @param user address of the user * @return Pending rewards */ function calculatePendingRewards(address user) external view returns (uint256) { if ((block.number > lastRewardBlock) && (totalAmountStaked != 0)) { uint256 multiplier = _getMultiplier(lastRewardBlock, block.number); uint256 tokenRewardForStaking = multiplier * rewardPerBlockForStaking; uint256 adjustedEndBlock = endBlock; uint256 adjustedCurrentPhase = currentPhase; // Check whether to adjust multipliers and reward per block while ( (block.number > adjustedEndBlock) && (adjustedCurrentPhase < (NUMBER_PERIODS - 1)) ) { // Update current phase adjustedCurrentPhase++; // Update rewards per block uint256 adjustedRewardPerBlockForStaking = stakingPeriod[adjustedCurrentPhase] .rewardPerBlockForStaking; // Calculate adjusted block number uint256 previousEndBlock = adjustedEndBlock; // Update end block adjustedEndBlock = previousEndBlock + stakingPeriod[adjustedCurrentPhase].periodLengthInBlock; // Calculate new multiplier uint256 newMultiplier = (block.number <= adjustedEndBlock) ? (block.number - previousEndBlock) : stakingPeriod[adjustedCurrentPhase].periodLengthInBlock; // Adjust token rewards for staking tokenRewardForStaking += (newMultiplier * adjustedRewardPerBlockForStaking); } uint256 adjustedTokenPerShare = accTokenPerShare + (tokenRewardForStaking * PRECISION_FACTOR) / totalAmountStaked; return (userInfo[user].amount * adjustedTokenPerShare) / PRECISION_FACTOR - userInfo[user].rewardDebt; } else { return (userInfo[user].amount * accTokenPerShare) / PRECISION_FACTOR - userInfo[user].rewardDebt; } } /** * @notice Update reward variables of the pool */ function _updatePool() internal { if (block.number <= lastRewardBlock) { return; } if (totalAmountStaked == 0) { lastRewardBlock = block.number; return; } // Calculate multiplier uint256 multiplier = _getMultiplier(lastRewardBlock, block.number); // Calculate rewards for staking and others uint256 tokenRewardForStaking = multiplier * rewardPerBlockForStaking; uint256 tokenRewardForOthers = multiplier * rewardPerBlockForOthers; // Check whether to adjust multipliers and reward per block while ((block.number > endBlock) && (currentPhase < (NUMBER_PERIODS - 1))) { // Update rewards per block _updateRewardsPerBlock(endBlock); uint256 previousEndBlock = endBlock; // Adjust the end block endBlock += stakingPeriod[currentPhase].periodLengthInBlock; // Adjust multiplier to cover the missing periods with other lower inflation schedule uint256 newMultiplier = _getMultiplier(previousEndBlock, block.number); // Adjust token rewards tokenRewardForStaking += (newMultiplier * rewardPerBlockForStaking); tokenRewardForOthers += (newMultiplier * rewardPerBlockForOthers); } // Mint tokens only if token rewards for staking are not null if (tokenRewardForStaking > 0) { // It allows protection against potential issues to prevent funds from being locked bool mintStatus = x2y2Token.mint(address(this), tokenRewardForStaking); if (mintStatus) { accTokenPerShare = accTokenPerShare + ((tokenRewardForStaking * PRECISION_FACTOR) / totalAmountStaked); } x2y2Token.mint(tokenSplitter, tokenRewardForOthers); } // Update last reward block only if it wasn't updated after or at the end block if (lastRewardBlock <= endBlock) { lastRewardBlock = block.number; } } /** * @notice Update rewards per block * @dev Rewards are halved by 2 (for staking + others) */ function _updateRewardsPerBlock(uint256 _newStartBlock) internal { // Update current phase currentPhase++; // Update rewards per block rewardPerBlockForStaking = stakingPeriod[currentPhase].rewardPerBlockForStaking; rewardPerBlockForOthers = stakingPeriod[currentPhase].rewardPerBlockForOthers; emit NewRewardsPerBlock( currentPhase, _newStartBlock, rewardPerBlockForStaking, rewardPerBlockForOthers ); } /** * @notice Return reward multiplier over the given "from" to "to" block. * @param from block to start calculating reward * @param to block to finish calculating reward * @return the multiplier for the period */ function _getMultiplier(uint256 from, uint256 to) internal view returns (uint256) { if (to <= endBlock) { return to - from; } else if (from >= endBlock) { return 0; } else { return endBlock - from; } } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IRewardConvertor { function convert( address tokenToSell, address tokenToBuy, uint256 amount, bytes calldata additionalData ) external returns (uint256); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IMintableERC20 is IERC20 { function SUPPLY_CAP() external view returns (uint256); function mint(address account, uint256 amount) external returns (bool); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITokenStaked { function getTotalStaked() external view returns (uint256); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface 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); } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IStakeFor { function depositFor(address user, uint256 amount) external returns (bool); }