Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0x60a08060 | 16997942 | 454 days ago | IN | Create: NativeRouter | 0 ETH | 0.09119872 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
NativeRouter
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; pragma abicoder v2; import "./interfaces/INativeRouter.sol"; import "./interfaces/INativePool.sol"; import "./libraries/SafeCast.sol"; import "./libraries/CallbackValidation.sol"; import "./libraries/Order.sol"; import "./libraries/PeripheryPayments.sol"; import "./libraries/TransferHelper.sol"; import "./libraries/Multicall.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol"; import "./storage/NativeRouterStorage.sol"; contract NativeRouter is INativeRouter, PeripheryPayments, ReentrancyGuardUpgradeable, OwnableUpgradeable, UUPSUpgradeable, EIP712Upgradeable, Multicall, NativeRouterStorage { using Orders for bytes; using SafeCast for uint256; uint public constant TEN_THOUSAND_DENOMINATOR = 10000; bytes32 private constant WIDGET_FEE_SIGNATURE_HASH = keccak256("WidgetFee(address signer,address feeRecipient,uint256 feeRate)"); struct SwapCallbackData { bytes orders; address payer; } event SwapCalculations(uint256 amountIn, address recipient); function initialize( address factory, address weth9, address _widgetFeeSigner ) public initializer { initializeState(factory, weth9); __EIP712_init("native router", "1"); __ReentrancyGuard_init(); __Ownable_init(); __UUPSUpgradeable_init(); setWidgetFeeSigner(_widgetFeeSigner); } function getImplementation() public view returns (address) { return _getImplementation(); } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} function setWeth9Unwrapper(address payable _weth9Unwrapper) public override onlyOwner { weth9Unwrapper = _weth9Unwrapper; } function swapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata _data ) external override { require(amount0Delta > 0 || amount1Delta > 0, "Delta is negative"); SwapCallbackData memory data = abi.decode(_data, (SwapCallbackData)); (Orders.Order memory order, ) = data.orders.decodeFirstOrder(); require(msg.sender == order.buyer, "callback is not from order buyer"); CallbackValidation.verifyCallback(factory, order.buyer); uint256 amountToPay = amount0Delta < 0 ? uint256(amount1Delta) : uint256(amount0Delta); pay(order.sellerToken, data.payer, msg.sender, amountToPay); } function exactInputSingle( ExactInputSingleParams memory params ) external payable override nonReentrant returns (uint256 amountOut) { require(!params.orders.hasMultiplePools(), "exactInputSingle: multiple orders"); require( verifyWidgetFeeSignature(params.widgetFee, params.widgetFeeSignature), "widget fee signature is invalid" ); require(params.widgetFee.feeRate <= TEN_THOUSAND_DENOMINATOR, "invalid widget fee"); bool hasAlreadyPaid; (Orders.Order memory order, ) = params.orders.decodeFirstOrder(); if (params.amountIn == 0) { hasAlreadyPaid = true; params.amountIn = IERC20(order.sellerToken).balanceOf(address(this)); } require(order.seller == msg.sender, "seller is not correct"); uint widgetFeeAmount = (params.amountIn * params.widgetFee.feeRate) / TEN_THOUSAND_DENOMINATOR; TransferHelper.safeTransferFrom( order.sellerToken, msg.sender, params.widgetFee.feeRecipient, widgetFeeAmount ); emit WidgetFeeTransfer( params.widgetFee.feeRecipient, params.widgetFee.feeRate, widgetFeeAmount ); params.amountIn -= widgetFeeAmount; emit SwapCalculations(params.amountIn, params.recipient); amountOut = exactInputInternal( params.amountIn, params.recipient, SwapCallbackData({ orders: params.orders, payer: hasAlreadyPaid ? address(this) : msg.sender }) ); require(amountOut >= params.amountOutMinimum, "Too little received"); if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance); } /// @inheritdoc INativeRouter function exactInput( ExactInputParams memory params ) external payable override nonReentrant returns (uint256 amountOut) { require( verifyWidgetFeeSignature(params.widgetFee, params.widgetFeeSignature), "widget fee signature is invalid" ); require(params.widgetFee.feeRate <= 10000, "invalid widget fee"); bool hasAlreadyPaid; (Orders.Order memory order, ) = params.orders.decodeFirstOrder(); if (params.amountIn == 0) { hasAlreadyPaid = true; params.amountIn = IERC20(order.sellerToken).balanceOf(address(this)); } require(order.seller == msg.sender, "seller is not correct"); address payer = hasAlreadyPaid ? address(this) : msg.sender; uint widgetFeeAmount = (params.amountIn * params.widgetFee.feeRate) / TEN_THOUSAND_DENOMINATOR; TransferHelper.safeTransferFrom( order.sellerToken, msg.sender, params.widgetFee.feeRecipient, widgetFeeAmount ); emit WidgetFeeTransfer( params.widgetFee.feeRecipient, params.widgetFee.feeRate, widgetFeeAmount ); params.amountIn -= widgetFeeAmount; while (true) { bool hasMultiplePools = params.orders.hasMultiplePools(); // the outputs of prior swaps become the inputs to subsequent ones params.amountIn = exactInputInternal( params.amountIn, hasMultiplePools ? address(this) : params.recipient, SwapCallbackData({ orders: params.orders.getFirstOrder(), // only the first pool in the path is necessary payer: payer }) ); // decide whether to continue or terminate if (hasMultiplePools) { payer = address(this); params.orders = params.orders.skipOrder(); } else { amountOut = params.amountIn; break; } } require(amountOut >= params.amountOutMinimum, "Too little received"); if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance); } function setWidgetFeeSigner(address _widgetFeeSigner) public onlyOwner { require( _widgetFeeSigner != address(0), "Widget fee signer address specified should not be zero address" ); widgetFeeSigner = _widgetFeeSigner; emit SetWidgetFeeSigner(widgetFeeSigner); } // private methods /// @dev Performs a single exact input swap function exactInputInternal( uint256 amountIn, address recipient, SwapCallbackData memory data ) private returns (uint256 amountOut) { (Orders.Order memory order, bytes memory signature) = data.orders.decodeFirstOrder(); require(order.txOrigin == tx.origin, "txOrigin is wrong"); CallbackValidation.verifyCallback(factory, order.buyer); (int256 amount0Delta, int256 amount1Delta) = INativePool(order.buyer).swap( abi.encode(order), signature, amountIn, recipient, abi.encode(data) ); return uint256(-(amount0Delta > 0 ? amount1Delta : amount0Delta)); } function getWidgetFeeMessageHash( WidgetFee memory widgetFeeData ) internal pure returns (bytes32) { bytes32 hash = keccak256( abi.encode( WIDGET_FEE_SIGNATURE_HASH, widgetFeeData.signer, widgetFeeData.feeRecipient, widgetFeeData.feeRate ) ); return hash; } function verifyWidgetFeeSignature( WidgetFee memory widgetFeeData, bytes memory signature ) internal view returns (bool) { require(widgetFeeData.signer == widgetFeeSigner, "Signer is invalid"); bytes32 digest = _hashTypedDataV4(getWidgetFeeMessageHash(widgetFeeData)); address recoveredSigner = ECDSAUpgradeable.recover(digest, signature); return widgetFeeData.signer == recoveredSigner; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (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 { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions 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); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822ProxiableUpgradeable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.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 ERC1967UpgradeUpgradeable is Initializable { function __ERC1967Upgrade_init() internal onlyInitializing { } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // 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 StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall( address newImplementation, bytes memory data, bool forceCall ) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { _functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS( address newImplementation, bytes memory data, bool forceCall ) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.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"); StorageSlotUpgradeable.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 StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall( address newBeacon, bytes memory data, bool forceCall ) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.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 AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Internal function that returns the initialized version. Returns `_initialized` */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Internal function that returns the initialized version. Returns `_initializing` */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall"); _; } /** * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual override notDelegated returns (bytes32) { return _IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeTo(address newImplementation) external virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (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 { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (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() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20PermitUpgradeable { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/draft-IERC20PermitUpgradeable.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)); } } function safePermit( IERC20PermitUpgradeable token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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 (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../StringsUpgradeable.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 ECDSAUpgradeable { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } 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"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", StringsUpgradeable.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol) pragma solidity ^0.8.0; import "./ECDSAUpgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ * * @custom:storage-size 52 */ abstract contract EIP712Upgradeable is Initializable { /* solhint-disable var-name-mixedcase */ bytes32 private _HASHED_NAME; bytes32 private _HASHED_VERSION; bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ function __EIP712_init(string memory name, string memory version) internal onlyInitializing { __EIP712_init_unchained(name, version); } function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash()); } function _buildDomainSeparator( bytes32 typeHash, bytes32 nameHash, bytes32 versionHash ) private view returns (bytes32) { return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return ECDSAUpgradeable.toTypedDataHash(_domainSeparatorV4(), structHash); } /** * @dev The hash of the name parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712NameHash() internal virtual view returns (bytes32) { return _HASHED_NAME; } /** * @dev The hash of the version parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712VersionHash() internal virtual view returns (bytes32) { return _HASHED_VERSION; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol) pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ``` * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.sol"; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = MathUpgradeable.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, MathUpgradeable.log256(value) + 1); } } /** * @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] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; /** * @title Blacklistable Token * @dev Allows accounts to be blacklisted by a "blacklister" role */ contract Blacklistable is OwnableUpgradeable { address public blacklister; mapping(address => bool) internal blacklisted; event Blacklisted(address indexed _account); event UnBlacklisted(address indexed _account); event BlacklisterChanged(address indexed newBlacklister); /** * @dev Throws if called by any account other than the blacklister */ modifier onlyBlacklister() { require( msg.sender == blacklister, "Blacklistable: caller is not the blacklister" ); _; } /** * @dev Throws if argument account is blacklisted * @param _account The address to check */ modifier notBlacklisted(address _account) { require( !blacklisted[_account], "Blacklistable: account is blacklisted" ); _; } /** * @dev Checks if account is blacklisted * @param _account The address to check */ function isBlacklisted(address _account) external view returns (bool) { return blacklisted[_account]; } /** * @dev Adds account to blacklist * @param _account The address to blacklist */ function blacklist(address _account) external onlyBlacklister { blacklisted[_account] = true; emit Blacklisted(_account); } /** * @dev Removes account from blacklist * @param _account The address to remove from the blacklist */ function unBlacklist(address _account) external onlyBlacklister { blacklisted[_account] = false; emit UnBlacklisted(_account); } function updateBlacklister(address _newBlacklister) external onlyOwner { require( _newBlacklister != address(0), "Blacklistable: new blacklister is the zero address" ); blacklister = _newBlacklister; emit BlacklisterChanged(blacklister); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[48] private __gap; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; pragma abicoder v2; /// @title Multicall interface /// @notice Enables calling multiple methods in a single call to the contract interface IMulticall { /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed /// @dev The `msg.value` should not be trusted for any method callable from multicall. /// @param data The encoded function data for each of the calls to make to this contract /// @return results The results from each of the calls passed in via data function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed /// @dev The `msg.value` should not be trusted for any method callable from multicall. /// @param deadline The time by which this function must be called before failing /// @param data The encoded function data for each of the calls to make to this contract /// @return results The results from each of the calls passed in via data function multicall(uint256 deadline, bytes[] calldata data) external payable returns (bytes[] memory results); }
// SPDX-License-Identifier: GPL-3.0 import {Orders} from "../libraries/Order.sol"; pragma solidity ^0.8.0; interface INativePool { struct Pair { uint256 fee; bool isExist; uint256 pricingModelId; } struct SwapParam { uint256 buyerTokenAmount; uint256 sellerTokenAmount; Orders.Order _order; address recipient; bytes callback; uint256 pricingModelId; } function initialize( address _treasury, address _treasuryOwner, address _signer, address _pricingModelRegistry, address _router, uint256[] memory _fees, address[] memory _tokenAs, address[] memory _tokenBs, uint256[] memory _pricingModelIds ) external; function addSigner(address _signer) external; function removeSigner(address _signer) external; function swap( bytes memory _order, bytes calldata signature, uint256 flexibleAmount, address recipient, bytes calldata callback ) external returns (int256, int256); event Swap( address indexed sender, address indexed recipient, address tokenIn, address tokenOut, int256 amountIn, int256 amountOut, uint256 fee, bytes16 quoteId ); event UpdatePair( address indexed tokenA, address indexed tokenB, uint256 feeOld, uint256 feeNew, uint256 pricingModelIdOld, uint256 pricingModelIdNew ); event RemovePair( address tokenA, address tokenB ); event AddSigner( address signer ); event RemoveSigner( address signer ); event SetRouter( address router ); event SetTreasury( address treasury ); event SetTreasuryOwner( address treasuryOwner ); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "../NativePool.sol"; import "../interfaces/INativePool.sol"; error AlreadyMultiPoolTreasury(); error NotMultiPoolTreasury(); error NotMultiPoolTreasuryAndBindedToOtherPool(address treasuryAddress); error ZeroAddressInput(); error RegistryAlreadySet(); error RegistryNotSet(); error InputArrayLengthMismatch(); error PoolUpgradeFailed(); interface INativePoolFactory { /// @notice Emitted when a pool is created /// @param treasury The address of treasury for the pool /// @param owner The address of owner of the pool /// @param pool The address of the created pool event PoolCreated(address treasury, address owner, address signer, address pool, address impl); event PoolUpgraded(address pool, address impl); event AddPoolCreator(address poolCreater); event RemovePoolCreator(address poolCreater); event AddMultiPoolTreasury(address treasury); event RemoveMultiPoolTreasury(address treasury); function createNewPool( address poolImplementation, address treasuryAddress, address poolOwnerAddress, address signerAddress, address routerAddress, uint256[] memory fees, address[] memory tokenAs, address[] memory tokenBs, uint256[] memory pricingModelIds ) external returns (address pool); function upgradePools(address[] calldata _pools, address[] calldata _impls) external; function upgradePool(address pool, address impl) external; function getPool(address treasuryAddress) external view returns (address); function verifyPool(address poolAddress) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "./ISwapCallback.sol"; /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Native interface INativeRouter is ISwapCallback { struct WidgetFee { address signer; address feeRecipient; uint256 feeRate; } struct ExactInputSingleParams { bytes orders; address recipient; uint256 amountIn; uint256 amountOutMinimum; WidgetFee widgetFee; bytes widgetFeeSignature; } event SetWidgetFeeSigner(address widgetFeeSigner); event WidgetFeeTransfer( address widgetFeeRecipient, uint256 widgetFeeRate, uint256 widgetFeeAmount ); function setWidgetFeeSigner(address _widgetFeeSigner) external; /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @dev Setting `amountIn` to 0 will cause the contract to look up its own balance, /// and swap the entire amount, enabling contracts to send tokens before calling this function. /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle( ExactInputSingleParams calldata params ) external payable returns (uint256 amountOut); struct ExactInputParams { bytes orders; address recipient; uint256 amountIn; uint256 amountOutMinimum; WidgetFee widgetFee; bytes widgetFeeSignature; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @dev Setting `amountIn` to 0 will cause the contract to look up its own balance, /// and swap the entire amount, enabling contracts to send tokens before calling this function. /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput( ExactInputParams calldata params ) external payable returns (uint256 amountOut); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken(address token, uint256 amountMinimum, address recipient) external payable; /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between /// 0 (exclusive), and 1 (inclusive) going to feeRecipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. function unwrapWETH9WithFee( uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) external payable; /// @notice Transfers the full amount of a token held by this contract to recipient, with a percentage between /// 0 (exclusive) and 1 (inclusive) going to feeRecipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users function sweepTokenWithFee( address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) external payable; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryState { /// @return Returns the address of the Native factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; interface IPricer { function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut, uint256 fee ) external pure returns (uint); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface ISwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param _data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function swapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata _data) external; }
// SPDX-License-Identifier: GPL-3.0 /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity ^0.8.0; library BytesLib { function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, "slice_overflow"); require(_bytes.length >= _start + _length, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) { require(_bytes.length >= _start + 3, "toUint24_outOfBounds"); uint24 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x3), _start)) } return tempUint; } function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= _start + 32, "toUint256_outOfBounds"); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "../interfaces/INativePoolFactory.sol"; import "../interfaces/INativePool.sol"; /// @notice Provides validation for callbacks from Native Pools library CallbackValidation { /// @notice Returns the address of a valid Native Pool /// @param factory The contract address of the Native factory /// @param pool The contract address of a Pool /// @return verifiedPool The Native pool contract address function verifyCallback(address factory, address pool) internal view returns (INativePool) { require(INativePoolFactory(factory).verifyPool(pool), "Invalid pool address"); return INativePool(pool); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0, "FullMath: mulDiv: denominator must be greater then zero"); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1, "FullMath: mulDiv: result greater than 2**256"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. // uint256 twos = -denominator & denominator; uint256 twos = denominator & (~denominator + 1); // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max, "FullMath: mulDivRoundingUp: result greater than 2**256"); result++; } } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /// @title Interface for WETH9 interface IWETH9 is IERC20 { event Deposit(address indexed dst, uint wad); event Withdrawal(address indexed src, uint wad); /// @notice Deposit ether to get wrapped ether function deposit() external payable; /// @notice Withdraw wrapped ether to get ether function withdraw(uint256) external; function symbol() external view returns (string memory); function decimals() external view returns (uint8); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; pragma abicoder v2; import "./PeripheryValidation.sol"; import "../interfaces/IMulticall.sol"; /// @title Multicall /// @notice Enables calling multiple methods in a single call to the contract abstract contract Multicall is IMulticall, PeripheryValidation { /// @inheritdoc IMulticall function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; ) { (bool success, bytes memory result) = address(this).delegatecall(data[i]); if (!success) { // Next 5 lines from https://ethereum.stackexchange.com/a/83577 if (result.length < 68) revert(); assembly { result := add(result, 0x04) } revert(abi.decode(result, (string))); } results[i] = result; unchecked { i++; } } } /// @inheritdoc IMulticall function multicall(uint256 deadline, bytes[] calldata data) external payable override checkDeadline(deadline) returns (bytes[] memory) { return multicall(data); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /// @title Prevents delegatecall to a contract /// @notice Base contract that provides a modifier for preventing delegatecall to methods in a child contract abstract contract NoDelegateCallUpgradable is Initializable { /// @dev The original address of this contract address private original; function __NoDelegateCall_init() internal onlyInitializing { __NoDelegateCall_init_unchained(); } function __NoDelegateCall_init_unchained() internal onlyInitializing { original = address(this); } /// @dev Private method is used instead of inlining into modifier because modifiers are copied into each method, /// and the use of immutable means the address bytes are copied in every place the modifier is used. function checkNotDelegateCall() private view { require(address(this) == original, "delegate call check violation"); } /// @notice Prevents delegatecall into the modified method modifier noDelegateCall() { checkNotDelegateCall(); _; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; pragma abicoder v2; import "./BytesLib.sol"; //import "hardhat/console.sol"; library Orders { using BytesLib for bytes; struct Order { uint256 id; address signer; address buyer; address seller; address buyerToken; address sellerToken; uint256 buyerTokenAmount; uint256 sellerTokenAmount; uint256 deadlineTimestamp; address txOrigin; bytes16 quoteId; } uint256 private constant ADDR_SIZE = 20; uint256 private constant UINT256_SIZE = 32; uint256 private constant UUID_SIZE = 16; uint256 private constant ORDER_SIZE = ADDR_SIZE * 6 + UINT256_SIZE * 4 + UUID_SIZE; uint256 private constant SIG_SIZE = 65; uint256 private constant HOP_SIZE = SIG_SIZE + ORDER_SIZE; function hasMultiplePools(bytes memory orders) internal pure returns (bool) { return orders.length > HOP_SIZE; } function numPools(bytes memory orders) internal pure returns (uint256) { // Ignore the first token address. From then on every fee and token offset indicates a pool. return (orders.length / HOP_SIZE); } function decodeFirstOrder( bytes memory orders ) internal pure returns (Order memory order, bytes memory signature) { require( orders.length != 0 && orders.length % HOP_SIZE == 0, "Orders: decodeFirstOrder: invalid bytes length" ); order.id = orders.toUint256(0); order.signer = orders.toAddress(UINT256_SIZE); order.buyer = orders.toAddress(UINT256_SIZE + ADDR_SIZE); order.seller = orders.toAddress(UINT256_SIZE + ADDR_SIZE * 2); order.buyerToken = orders.toAddress(UINT256_SIZE + ADDR_SIZE * 3); order.sellerToken = orders.toAddress(UINT256_SIZE + ADDR_SIZE * 4); order.buyerTokenAmount = orders.toUint256(UINT256_SIZE + ADDR_SIZE * 5); order.sellerTokenAmount = orders.toUint256(UINT256_SIZE * 2 + ADDR_SIZE * 5); order.deadlineTimestamp = orders.toUint256(UINT256_SIZE * 3 + ADDR_SIZE * 5); order.txOrigin = orders.toAddress(UINT256_SIZE * 4 + ADDR_SIZE * 5); order.quoteId = bytes16(orders.slice(UINT256_SIZE * 4 + ADDR_SIZE * 6, UUID_SIZE)); signature = orders.slice(ORDER_SIZE, SIG_SIZE); } function getFirstOrder(bytes memory orders) internal pure returns (bytes memory) { return orders.slice(0, HOP_SIZE); } function skipOrder(bytes memory orders) internal pure returns (bytes memory) { require( orders.length != 0 && orders.length % HOP_SIZE == 0, "Orders: decodeFirstOrder: invalid bytes length" ); return orders.slice(HOP_SIZE, orders.length - HOP_SIZE); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "../interfaces/IPeripheryPayments.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "./TransferHelper.sol"; import "./IWETH9.sol"; import "./PeripheryState.sol"; import "./Weth9Unwrapper.sol"; abstract contract PeripheryPayments is IPeripheryPayments, PeripheryState { receive() external payable { require(msg.sender == WETH9, "Not WETH9"); } // public methods /// @inheritdoc IPeripheryPayments function unwrapWETH9(uint256 amountMinimum, address recipient) public payable override { uint256 balanceWETH9 = IWETH9(WETH9).balanceOf(address(this)); require(balanceWETH9 >= amountMinimum, "Insufficient WETH9"); if (balanceWETH9 > 0) { TransferHelper.safeTransfer(WETH9, weth9Unwrapper, balanceWETH9); Weth9Unwrapper(weth9Unwrapper).unwrapWeth9(balanceWETH9, recipient); } } /// @inheritdoc IPeripheryPayments function sweepToken( address token, uint256 amountMinimum, address recipient ) public payable override { uint256 balanceToken = IERC20Upgradeable(token).balanceOf(address(this)); require(balanceToken >= amountMinimum, "Insufficient token"); if (balanceToken > 0) { TransferHelper.safeTransfer(token, recipient, balanceToken); } } /// @inheritdoc IPeripheryPayments function unwrapWETH9WithFee( uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) public payable override { require(feeBips > 0 && feeBips <= 100, "Fee out of range"); uint256 balanceWETH9 = IWETH9(WETH9).balanceOf(address(this)); require(balanceWETH9 >= amountMinimum, "Insufficient WETH9"); if (balanceWETH9 > 0) { IWETH9(WETH9).withdraw(balanceWETH9); uint256 feeAmount = (balanceWETH9 * feeBips) / 100_00; if (feeAmount > 0) TransferHelper.safeTransferETH(feeRecipient, feeAmount); TransferHelper.safeTransferETH(recipient, balanceWETH9 - feeAmount); } } /// @inheritdoc IPeripheryPayments function sweepTokenWithFee( address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) public payable override { require(feeBips > 0 && feeBips <= 100, "Fee out of range"); uint256 balanceToken = IERC20Upgradeable(token).balanceOf(address(this)); require(balanceToken >= amountMinimum, "Insufficient token"); if (balanceToken > 0) { uint256 feeAmount = (balanceToken * feeBips) / 100_00; if (feeAmount > 0) TransferHelper.safeTransfer(token, feeRecipient, feeAmount); TransferHelper.safeTransfer(token, recipient, balanceToken - feeAmount); } } // external methods /// @inheritdoc IPeripheryPayments function refundETH() external payable override { if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance); } function refundETHRecipient(address recipient) public payable { if (address(this).balance > 0) TransferHelper.safeTransferETH(recipient, address(this).balance); } function unwrapWETH9(uint256 amountMinimum) external payable { unwrapWETH9(amountMinimum, msg.sender); } function wrapETH(uint256 value) external payable { IWETH9(WETH9).deposit{value: value}(); } function sweepToken(address token, uint256 amountMinimum) external payable { sweepToken(token, amountMinimum, msg.sender); } function pull(address token, uint256 value) external payable { TransferHelper.safeTransferFrom(token, msg.sender, address(this), value); } // internal methods /// @param token The token to pay /// @param payer The entity that must pay /// @param recipient The entity that will receive payment /// @param value The amount to pay function pay(address token, address payer, address recipient, uint256 value) internal { if (token == WETH9 && address(this).balance >= value) { //require(address(this).balance >= value, "Insufficient native token value"); // pay with WETH9 IWETH9(WETH9).deposit{value: value}(); // wrap only what is needed to pay IWETH9(WETH9).transfer(recipient, value); } else if (payer == address(this)) { // pay with tokens already in the contract (for the exact input multihop case) TransferHelper.safeTransfer(token, recipient, value); } else { // pull payment TransferHelper.safeTransferFrom(token, payer, recipient, value); } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "../interfaces/IPeripheryState.sol"; import "../storage/NativeRouterStorage.sol"; abstract contract PeripheryState is IPeripheryState { address public override factory; address public override WETH9; address payable public weth9Unwrapper; function initializeState(address _factory, address _WETH9) internal { require(_factory != address(0), "PeripheryState: factory address cannot be 0"); require(_WETH9 != address(0), "PeripheryState: WETH9 address cannot be 0"); factory = _factory; WETH9 = _WETH9; } function setWeth9Unwrapper(address payable _weth9Unwrapper) virtual public; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[47] private __gap; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; abstract contract PeripheryValidation { modifier checkDeadline(uint256 deadline) { require(block.timestamp <= deadline, "Transaction too old"); _; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); z = int256(y); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; library TransferHelper { using SafeERC20Upgradeable for IERC20Upgradeable; /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom(address token, address from, address to, uint256 value) internal { IERC20Upgradeable(token).safeTransferFrom(from, to, value); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer(address token, address to, uint256 value) internal { IERC20Upgradeable(token).safeTransfer(to, value); } function safeIncreaseAllowance(address token, address to, uint256 value) internal { IERC20Upgradeable(token).safeIncreaseAllowance(to, value); } function safeDecreaseAllowance(address token, address to, uint256 value) internal { IERC20Upgradeable(token).safeDecreaseAllowance(to, value); } /// @notice Transfers ETH to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, "STE"); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "./IWETH9.sol"; import "./TransferHelper.sol"; contract Weth9Unwrapper { address immutable public weth9; address immutable public nativeRouter; constructor (address _weth9, address _router) { weth9 = _weth9; nativeRouter = _router; } receive() external payable {} function unwrapWeth9(uint256 amount, address recipient) public { require(msg.sender == nativeRouter, "only NativeRouter can call this function"); IWETH9(weth9).withdraw(amount); TransferHelper.safeTransferETH(recipient, amount); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import {INativePool} from "./interfaces/INativePool.sol"; import {INativeRouter} from "./interfaces/INativeRouter.sol"; import {IWETH9} from "./libraries/IWETH9.sol"; import {Orders} from "./libraries/Order.sol"; import {Blacklistable} from "./Blacklistable.sol"; import {Registry} from "./Registry.sol"; import {NativeRouter} from "./NativeRouter.sol"; import "./libraries/TransferHelper.sol"; import "./libraries/FullMath.sol"; import "./libraries/NoDelegateCallUpgradable.sol"; import "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "./storage/NativePoolStorage.sol"; contract NativePool is INativePool, EIP712Upgradeable, ReentrancyGuardUpgradeable, OwnableUpgradeable, PausableUpgradeable, NoDelegateCallUpgradable, Blacklistable, UUPSUpgradeable, NativePoolStorage { using SafeERC20Upgradeable for IERC20Upgradeable; using SafeERC20Upgradeable for IWETH9; uint256 public constant FIXED_PRICE_MODEL_ID = 99; uint256 public constant PMM_PRICE_MODEL_ID = 100; uint256 internal constant TEN_THOUSAND_DENOMINATOR = 10000; bytes32 private constant ORDER_SIGNATURE_HASH = keccak256( "Order(uint256 id,address signer,address buyer,address seller,address buyerToken,address sellerToken,uint256 buyerTokenAmount,uint256 sellerTokenAmount,uint256 deadlineTimestamp,address txOrigin,bytes16 quoteId)" ); modifier onlyRouter() { require(msg.sender == router, "Message sender should only be the router"); _; } modifier onlyNotPmm() { require(!isPmm, "Not allowed to call this function when PMM is used"); _; } constructor() { _disableInitializers(); } /** * pure function: * isSigner * getTreasury * getTreasuryOwner * getUserOrderId */ // Payable fallback to allow this contract to receive protocol fee refunds. // receive() external payable {} function initialize( address _treasury, address _treasuryOwner, address _signer, address _pricingModelRegistry, address _router, uint256[] memory _fees, address[] memory _tokenAs, address[] memory _tokenBs, uint256[] memory _pricingModelIds ) external override initializer { __EIP712_init("native pool", "1"); __ReentrancyGuard_init(); __Ownable_init(); __Pausable_init(); __NoDelegateCall_init(); require(_treasury != address(0), "treasury address specified should not be zero address"); require( _treasuryOwner != address(0), "treasuryOwner address specified should not be zero address" ); require(_signer != address(0), "signer address specified should not be zero address"); require( _pricingModelRegistry != address(0), "pricingModelRegistry address specified should not be zero address" ); treasury = _treasury; treasuryOwner = _treasuryOwner; isSigner[_signer] = true; pricingModelRegistry = _pricingModelRegistry; setRouter(_router); executeUpdatePairs(_fees, _tokenAs, _tokenBs, _pricingModelIds); poolFactory = msg.sender; emit SetTreasury(treasury); emit SetTreasuryOwner(treasuryOwner); emit AddSigner(_signer); } function _authorizeUpgrade(address) internal view override { require(msg.sender == poolFactory, "only PoolFactory can call this"); } function getImplementation() public view returns (address) { return _getImplementation(); } function setRouter(address _router) internal { require(_router != address(0), "router address specified should not be zero address"); require(router == address(0), "router address is already set"); router = _router; emit SetRouter(router); } function pause() external onlyOwner { _pause(); } function unpause() external onlyOwner { _unpause(); } function addSigner(address _signer) external override onlyOwner whenNotPaused onlyNotPmm { require(!isSigner[_signer], "Signer is already added"); isSigner[_signer] = true; emit AddSigner(_signer); } function removeSigner(address _signer) external override onlyOwner whenNotPaused onlyNotPmm { require(isSigner[_signer], "Signer has not added"); isSigner[_signer] = false; emit RemoveSigner(_signer); } function swap( bytes memory order, bytes calldata signature, uint256 flexibleAmount, address recipient, bytes calldata callback ) external override nonReentrant whenNotPaused onlyRouter noDelegateCall returns (int256, int256) { Orders.Order memory _order = abi.decode(order, (Orders.Order)); require(verifySignature(_order, signature), "Signature is invalid"); require(_order.deadlineTimestamp > block.timestamp, "Order is expired"); require(_order.id == nonce[_order.txOrigin] + 1, "Incorrect nonce"); nonce[_order.txOrigin]++; require(pairExist(_order.sellerToken, _order.buyerToken), "Pair not exist"); require(flexibleAmount != 0, "Flexible amount cannot be 0"); require(!blacklisted[_order.txOrigin], "Account is blacklisted"); uint256 buyerTokenAmount; uint256 sellerTokenAmount; uint256 pricingModelId; pricingModelId = getPairPricingModel(_order.sellerToken, _order.buyerToken); { (buyerTokenAmount, sellerTokenAmount) = calculateTokenAmount( flexibleAmount, _order, pricingModelId ); } { (int256 amount0Delta, int256 amount1Delta) = executeSwap( SwapParam({ buyerTokenAmount: buyerTokenAmount, sellerTokenAmount: sellerTokenAmount, _order: _order, recipient: recipient, callback: callback, pricingModelId: pricingModelId }) ); uint256 fee = getPairFee(_order.sellerToken, _order.buyerToken); if (amount0Delta < 0) { emit Swap( msg.sender, recipient, _order.sellerToken, _order.buyerToken, amount1Delta, amount0Delta, FullMath.mulDivRoundingUp(uint256(amount1Delta), fee, TEN_THOUSAND_DENOMINATOR), _order.quoteId ); } else { emit Swap( msg.sender, recipient, _order.sellerToken, _order.buyerToken, amount0Delta, amount1Delta, FullMath.mulDivRoundingUp(uint256(amount0Delta), fee, TEN_THOUSAND_DENOMINATOR), _order.quoteId ); } return (amount0Delta, amount1Delta); } } function pairExist(address tokenIn, address tokenOut) public view returns (bool exist) { (address token0, address token1) = tokenIn < tokenOut ? (tokenIn, tokenOut) : (tokenOut, tokenIn); return pairs[token0][token1].isExist; } function getTokenAs() public view returns (address[] memory) { return tokenAs; } function getTokenBs() public view returns (address[] memory) { return tokenBs; } function getPairPricingModel( address tokenIn, address tokenOut ) public view returns (uint256 pricingModelId) { require(pairExist(tokenIn, tokenOut), "Pair not exist"); (address token0, address token1) = tokenIn < tokenOut ? (tokenIn, tokenOut) : (tokenOut, tokenIn); return pairs[token0][token1].pricingModelId; } function getPairFee(address tokenIn, address tokenOut) public view returns (uint256 fee) { require(pairExist(tokenIn, tokenOut), "Pair not exist"); (address token0, address token1) = tokenIn < tokenOut ? (tokenIn, tokenOut) : (tokenOut, tokenIn); return pairs[token0][token1].fee; } function executeUpdatePairs( uint256[] memory _fees, address[] memory _tokenAs, address[] memory _tokenBs, uint256[] memory _pricingModelIds ) private { require( _fees.length == _tokenAs.length && _fees.length == _tokenBs.length && _fees.length == _pricingModelIds.length, "Pair array length mismatch" ); for (uint i = 0; i < _fees.length; ) { require(_tokenAs[i] != _tokenBs[i], "Identical addresses"); require( (_fees[i] >= 0) && (_fees[i] <= 10000), "Fee should be between 0 and 10k basis points" ); (address token0, address token1) = _tokenAs[i] < _tokenBs[i] ? (_tokenAs[i], _tokenBs[i]) : (_tokenBs[i], _tokenAs[i]); require(token0 != address(0), "Zero address in pair"); bool isPairExist = pairExist(token0, token1); if (isPmm) { require( _pricingModelIds[i] == PMM_PRICE_MODEL_ID, "Can only add PMM pairs to pool using PMM" ); } else { require( pairCount == 0 || isPairExist, "Can not have more than 1 pair for non PMM pool" ); } uint256 pricingModelIdOld = 0; uint256 feeOld = 0; if (!isPairExist) { tokenAs.push(token0); tokenBs.push(token1); pairCount++; } else { pricingModelIdOld = pairs[token0][token1].pricingModelId; feeOld = pairs[token0][token1].fee; } pairs[token0][token1] = Pair({ fee: _fees[i], isExist: true, pricingModelId: _pricingModelIds[i] }); if (!isPmm && _pricingModelIds[i] == PMM_PRICE_MODEL_ID) { isPmm = true; } emit UpdatePair( token0, token1, feeOld, _fees[i], pricingModelIdOld, _pricingModelIds[i] ); unchecked { i++; } } } function updatePairs( uint256[] calldata _fees, address[] calldata _tokenAs, address[] calldata _tokenBs, uint256[] calldata _pricingModelIds ) public whenNotPaused { require(msg.sender == treasuryOwner, "Unauthorized to whitelist pairs"); executeUpdatePairs(_fees, _tokenAs, _tokenBs, _pricingModelIds); } function removePair(address tokenIn, address tokenOut) public whenNotPaused { require(msg.sender == treasuryOwner, "Unauthorized to whitelist pairs"); require(pairExist(tokenIn, tokenOut), "Pair not exist"); (address token0, address token1) = tokenIn < tokenOut ? (tokenIn, tokenOut) : (tokenOut, tokenIn); delete pairs[token0][token1]; uint tokenAsLength = tokenAs.length; for (uint i = 0; i < tokenAsLength; ) { if (tokenAs[i] == token0 && tokenBs[i] == token1) { tokenAs[i] = tokenAs[tokenAs.length - 1]; tokenAs.pop(); tokenBs[i] = tokenBs[tokenBs.length - 1]; tokenBs.pop(); pairCount--; break; } unchecked { i++; } } emit RemovePair(token0, token1); } function getNonce(address txOrigin) public view returns (uint256) { return nonce[txOrigin]; } function increaseNonce(address txOrigin) public whenNotPaused returns (uint256) { require( msg.sender == treasury || msg.sender == treasuryOwner, "Unauthorized to change nonce" ); nonce[txOrigin]++; return nonce[txOrigin]; } function getAmountOut( uint256 amountIn, address _tokenIn, address _tokenOut ) public view returns (uint amountOut) { uint256 pricingModelId = getPairPricingModel(_tokenIn, _tokenOut); require( pricingModelId != FIXED_PRICE_MODEL_ID && pricingModelId != PMM_PRICE_MODEL_ID, "Off-chain pricing unsupported" ); Registry registry = Registry(pricingModelRegistry); address tokenIn = _tokenIn; address tokenOut = _tokenOut; uint256 fee = getPairFee(tokenIn, tokenOut); return registry.getAmountOut(amountIn, fee, pricingModelId, treasury, tokenIn, tokenOut); } function getPricingModelRegistry() public view returns (address) { return pricingModelRegistry; } // private methods function calculateTokenAmount( uint256 flexibleAmount, Orders.Order memory _order, uint256 pricingModelId ) private view returns (uint256, uint256) { uint256 buyerTokenAmount; uint256 sellerTokenAmount; sellerTokenAmount = flexibleAmount >= _order.sellerTokenAmount ? _order.sellerTokenAmount : flexibleAmount; if (pricingModelId != FIXED_PRICE_MODEL_ID && pricingModelId != PMM_PRICE_MODEL_ID) { buyerTokenAmount = getAmountOut( sellerTokenAmount, _order.sellerToken, _order.buyerToken ); } else { require( _order.sellerTokenAmount > 0 && _order.buyerTokenAmount > 0, "Non-zero amount required" ); buyerTokenAmount = FullMath.mulDiv( sellerTokenAmount, _order.buyerTokenAmount, _order.sellerTokenAmount ); } return (buyerTokenAmount, sellerTokenAmount); } function executeSwap(SwapParam memory swapParam) private returns (int256, int256) { // Transfer token from treasury to user / router executeSwapFromTreasury(swapParam.buyerTokenAmount, swapParam._order, swapParam.recipient); // Transfer token from user / router, to pool, then to treasury return executeSwapToTreasury( swapParam._order, swapParam.sellerTokenAmount, swapParam.buyerTokenAmount, swapParam.callback ); } // internal methods function getMessageHash(Orders.Order memory _order) internal pure returns (bytes32) { bytes32 hash = keccak256( abi.encode( ORDER_SIGNATURE_HASH, _order.id, _order.signer, _order.buyer, _order.seller, _order.buyerToken, _order.sellerToken, _order.buyerTokenAmount, _order.sellerTokenAmount, _order.deadlineTimestamp, _order.txOrigin, _order.quoteId ) ); return hash; } function verifySignature( Orders.Order memory _order, bytes calldata signature ) internal view returns (bool) { require(isSigner[_order.signer], "Signer is invalid"); bytes32 digest = _hashTypedDataV4(getMessageHash(_order)); address recoveredSigner = ECDSAUpgradeable.recover(digest, signature); return _order.signer == recoveredSigner; } function executeSwapFromTreasury( uint256 amount, Orders.Order memory _order, address recipient ) internal { address buyerToken = _order.buyerToken; uint256 treasuryBalanceInitial = IERC20Upgradeable(buyerToken).balanceOf(address(treasury)); require(treasuryBalanceInitial >= amount, "Insufficient fund in treasury"); TransferHelper.safeTransferFrom(_order.buyerToken, treasury, recipient, amount); uint256 treasuryBalanceFinal = IERC20Upgradeable(buyerToken).balanceOf(address(treasury)); require((treasuryBalanceInitial - treasuryBalanceFinal) == amount, "Swap amount not match"); } function executeSwapToTreasury( Orders.Order memory _order, uint256 sellerTokenAmount, uint256 buyerTokenAmount, bytes memory callback ) internal returns (int256, int256) { require( sellerTokenAmount <= type(uint256).max / 2, "sellerTokenAmount is too large and would cause an overflow error" ); require( buyerTokenAmount <= type(uint256).max / 2, "buyerTokenAmount is too large and would cause an overflow error" ); int256 outputSellerTokenAmount = int256(sellerTokenAmount); int256 outputBuyerTokenAmount = -1 * int256(buyerTokenAmount); address sellerToken = _order.sellerToken; uint256 treasuryBalanceInitial = IERC20Upgradeable(sellerToken).balanceOf( address(treasury) ); uint256 treasuryBalanceFinal; INativeRouter(msg.sender).swapCallback( outputBuyerTokenAmount, outputSellerTokenAmount, callback ); TransferHelper.safeTransfer(sellerToken, treasury, sellerTokenAmount); treasuryBalanceFinal = IERC20Upgradeable(sellerToken).balanceOf(address(treasury)); require( (treasuryBalanceFinal - treasuryBalanceInitial) == sellerTokenAmount, "Swap amount not match" ); return (outputBuyerTokenAmount, outputSellerTokenAmount); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./interfaces/IPricer.sol"; contract Registry is Ownable { using SafeMath for uint256; mapping(uint256 => address) public pricer; // constructor constructor(address[] memory pricers) Ownable() { for (uint256 i = 0; i < pricers.length; ) { pricer[i] = pricers[i]; unchecked { i++; } } } // public methods function registerPricer(uint256 id, address addr) public onlyOwner { require(pricer[id] == address(0), "pricer already set for this id"); pricer[id] = addr; } function getAmountOut( uint256 amountIn, uint256 fee, uint256 id, address treasury, address tokenIn, address tokenOut ) public view returns (uint amountOut) { require(amountIn > 0, "Non-zero amount required"); uint reserveIn = IERC20(tokenIn).balanceOf(address(treasury)); uint reserveOut = IERC20(tokenOut).balanceOf(address(treasury)); amountOut = _getAmountOut(amountIn, reserveIn, reserveOut, fee, id); } function _getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut, uint256 fee, uint256 id ) internal view returns (uint amountOut) { require(reserveIn > 0 && reserveOut > 0, "Registry: INSUFFICIENT_LIQUIDITY"); amountOut = IPricer(pricer[id]).getAmountOut(amountIn, reserveIn, reserveOut, fee); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; import {INativePool} from "../interfaces/INativePool.sol"; abstract contract NativePoolStorage { bool public isPmm; address public router; address public poolFactory; address public treasury; address public treasuryOwner; address public pricingModelRegistry; address[] public tokenAs; address[] public tokenBs; uint256 public pairCount; mapping(address => mapping(address => INativePool.Pair)) internal pairs; mapping(address => bool) public isSigner; mapping(address => uint256) internal nonce; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; // just a placeholder now in case there is any future state variables abstract contract NativeRouterStorage { address public widgetFeeSigner; }
{ "viaIR": true, "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"widgetFeeSigner","type":"address"}],"name":"SetWidgetFeeSigner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"SwapCalculations","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"widgetFeeRecipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"widgetFeeRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"widgetFeeAmount","type":"uint256"}],"name":"WidgetFeeTransfer","type":"event"},{"inputs":[],"name":"TEN_THOUSAND_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"orders","type":"bytes"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"components":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"feeRate","type":"uint256"}],"internalType":"struct INativeRouter.WidgetFee","name":"widgetFee","type":"tuple"},{"internalType":"bytes","name":"widgetFeeSignature","type":"bytes"}],"internalType":"struct INativeRouter.ExactInputParams","name":"params","type":"tuple"}],"name":"exactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"orders","type":"bytes"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"components":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"feeRate","type":"uint256"}],"internalType":"struct INativeRouter.WidgetFee","name":"widgetFee","type":"tuple"},{"internalType":"bytes","name":"widgetFeeSignature","type":"bytes"}],"internalType":"struct INativeRouter.ExactInputSingleParams","name":"params","type":"tuple"}],"name":"exactInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"factory","type":"address"},{"internalType":"address","name":"weth9","type":"address"},{"internalType":"address","name":"_widgetFeeSigner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"pull","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"refundETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"refundETHRecipient","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_weth9Unwrapper","type":"address"}],"name":"setWeth9Unwrapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_widgetFeeSigner","type":"address"}],"name":"setWidgetFeeSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"swapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"feeBips","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"}],"name":"sweepTokenWithFee","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"unwrapWETH9","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"}],"name":"unwrapWETH9","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"feeBips","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"}],"name":"unwrapWETH9WithFee","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"weth9Unwrapper","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"widgetFeeSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"wrapETH","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60a080604052346100315730608052613cc89081610037823960805181818161091a01528181610b800152610d270152f35b600080fdfe60806040526004361015610023575b361561001957600080fd5b6100216135ed565b005b60003560e01c8063086eae401461027b57806312210e8a146102725780631c58db4f146102695780632794949c146102605780633659cfe614610257578063372a771b1461024e57806349404b7c14610245578063496169971461023c5780634aa4a4fc146102335780634f1ef2861461022a5780635131e1fb1461022157806352d1902d146102185780635ae401dc1461020f57806368ab0bdb14610206578063715018a6146101fd57806372a8ddc9146101f45780637aed3f02146101eb5780638da5cb5b146101e25780639b2c0a37146101d9578063aaf10f42146101d0578063ac9650d8146101c7578063b2730c7b146101be578063c0c53b8b146101b5578063c45a0155146101ac578063df2ab5bb146101a3578063e0e189a01461019a578063e90a182f14610191578063f2d5d56b14610188578063f2fde38b1461017f5763fa483e720361000e5761017a6118ba565b61000e565b5061017a611812565b5061017a6117e9565b5061017a6117c2565b5061017a6116c4565b5061017a611692565b5061017a61166a565b5061017a61155f565b5061017a611534565b5061017a6114fb565b5061017a6114b4565b5061017a611330565b5061017a611308565b5061017a6112ea565b5061017a6111fb565b5061017a61119e565b5061017a610f51565b5061017a610ebd565b5061017a610d0b565b5061017a610ce3565b5061017a610b3a565b5061017a610b12565b5061017a610af9565b5061017a610ad5565b5061017a610a90565b5061017a6108f0565b5061017a6105d9565b5061017a6102db565b5061017a6102bd565b5061017a610294565b600091031261028f57565b600080fd5b503461028f57600036600319011261028f5760206001600160a01b036101615416604051908152f35b50600036600319011261028f57476102d157005b6100214733613c27565b506000602036600319011261033f576001600160a01b036001541681813b1561033f5760049160405192838092630d0e30db60e41b82528235905af18015610332575b610326575080f35b61032f90610359565b80f35b61033a611bdc565b61031e565b80fd5b50634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161036d57604052565b610375610342565b604052565b6040810190811067ffffffffffffffff82111761036d57604052565b6060810190811067ffffffffffffffff82111761036d57604052565b60a0810190811067ffffffffffffffff82111761036d57604052565b6080810190811067ffffffffffffffff82111761036d57604052565b90601f8019910116810190811067ffffffffffffffff82111761036d57604052565b6040519060c0820182811067ffffffffffffffff82111761036d57604052565b604051906104398261037a565b565b60209067ffffffffffffffff8111610459575b601f01601f19160190565b610461610342565b61044e565b81601f8201121561028f5780359061047d8261043b565b9261048b60405194856103ea565b8284526020838301011161028f57816000926020809301838601378301015290565b6001600160a01b0381160361028f57565b3590610439826104ad565b919082606091031261028f576040516060810181811067ffffffffffffffff82111761051f575b60405260408082948035610503816104ad565b84526020810135610513816104ad565b60208501520135910152565b610527610342565b6104f0565b60031960208282011261028f576004359167ffffffffffffffff9182841161028f5761010090848303011261028f5761056361040c565b92806004013583811161028f5782600461057f92840101610466565b845261058d602482016104be565b602085015260448101356040850152606481013560608501526105b382608483016104c9565b608085015260e481013592831161028f576105d19201600401610466565b60a082015290565b506107f66105e63661052c565b6105ee612511565b61060b610606610602835161014990511190565b1590565b612335565b60808101610627610622825160a085015190612908565b6123a6565b6107d860606107cd604093610644612710868351015111156123f1565b600090610651875161312e565b50908688019187835115610812575b7fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761079d936106fd846106e56106d46106cc60a0976106bf8f6106af9061073c9c01516001600160a01b031690565b6001600160a01b0316331461243c565b8b5190875101519061249e565b612710900490565b95869201516001600160a01b031690565b8351602001516001600160a01b03165b903390613a30565b518a61071360208301516001600160a01b031690565b9101518b516001600160a01b039092168252602082015260408101839052606090a183516124b9565b918281527f598150b82ea875d58e1d8f33db4ac9f8c9d57a83bda9a42d63a50ad741296df260208a019361077785516001600160a01b031690565b8a519182526001600160a01b03166020820152604090a15191516001600160a01b031690565b90875192600014610809576107c8305b6107b561042c565b9485526001600160a01b03166020850152565b61279c565b9301518310156124c6565b476107fa575b6107e86001603355565b519081529081906020820190565b0390f35b6108044733613c27565b6107de565b6107c8336107ad565b935060a07fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761079d936106fd61073c946106e56106d46106cc60019b6108736108676108678b8801516001600160a01b031690565b6001600160a01b031690565b81516370a0823160e01b815230600482015290602090829060249082905afa9081156108e3575b6000916108b5575b508c529750505050945050935050610660565b6108d6915060203d81116108dc575b6108ce81836103ea565b810190611bcd565b386108a2565b503d6108c4565b6108eb611bdc565b61089a565b503461028f57602036600319011261028f5760043561090e816104ad565b6001600160a01b0390817f0000000000000000000000000000000000000000000000000000000000000000169161094783301415611ab4565b6109767f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc938285541614611b25565b61097e611a14565b610986611b96565b906109b27f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1690565b156109c35750506100219150611c5a565b6020600491604094939451928380926352d1902d60e01b825286165afa60009181610a70575b50610a5d5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152608490fd5b0390fd5b61002193610a6b9114611be9565b611d07565b610a8991925060203d81116108dc576108ce81836103ea565b90386109e9565b503461028f57602036600319011261028f576001600160a01b03600435610ab6816104ad565b610abe611a14565b166001600160a01b03196002541617600255600080f35b50604036600319011261028f57610021602435610af1816104ad565b600435613690565b50602036600319011261028f5761002133600435613690565b503461028f57600036600319011261028f5760206001600160a01b0360015416604051908152f35b50604036600319011261028f57600435610b53816104ad565b60243567ffffffffffffffff811161028f57610b73903690600401610466565b906001600160a01b0391827f00000000000000000000000000000000000000000000000000000000000000001692610bad84301415611ab4565b610bdc7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc948286541614611b25565b610be4611a14565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615610c1a5750506100219150611c5a565b6020600491604094939451928380926352d1902d60e01b825286165afa60009181610cc3575b50610cb05760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152608490fd5b61002193610cbe9114611be9565b611e4c565b610cdc91925060203d81116108dc576108ce81836103ea565b9038610c40565b503461028f57600036600319011261028f5760206001600160a01b0360025416604051908152f35b503461028f57600036600319011261028f576001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610d78576040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152602090f35b608460405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152fd5b9181601f8401121561028f5782359167ffffffffffffffff831161028f576020808501948460051b01011161028f57565b60005b838110610e265750506000910152565b8181015183820152602001610e16565b90602091610e4f81518092818552858086019101610e13565b601f01601f1916010190565b602080820190808352835180925260408301928160408460051b8301019501936000915b848310610e8f5750505050505090565b9091929394958480610ead600193603f198682030187528a51610e36565b9801930193019194939290610e7f565b50604036600319011261028f5760243567ffffffffffffffff811161028f57610eea903690600401610de2565b906004354211610f0d576107f691610f0191612f42565b60405191829182610e5b565b606460405162461bcd60e51b815260206004820152601360248201527f5472616e73616374696f6e20746f6f206f6c64000000000000000000000000006044820152fd5b50610f5b3661052c565b610f63612511565b60009060808101610f7d610622825160a085015190612908565b604090610f92612710838351015111156123f1565b6110ba8491610fa1855161312e565b50928486019687511561111e575b610fc66106af60608701516001600160a01b031690565b501561111257919050611078305b917fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761101d60a061100e6106cc8b518a8a5101519061249e565b9301516001600160a01b031690565b9461103a836020976106f5898551016001600160a01b0390511690565b518661104f878301516001600160a01b031690565b91015187516001600160a01b039092168252602082015260408101839052606090a186516124b9565b85525b6110ba845191610149835111928751846000146110f3576107c861109f30936134db565b936110a861042c565b9485526001600160a01b031687850152565b80865290156110dd57506110ba30916110d38551613528565b855291905061107b565b83836107d860606107f6949301518310156124c6565b6107c861109f61110c888b01516001600160a01b031690565b936134db565b91905061107833610fd4565b905060019061113d61086761086760a08801516001600160a01b031690565b86516370a0823160e01b815230600482015290602090829060249082905afa908115611191575b8291611173575b508852610faf565b61118b915060203d81116108dc576108ce81836103ea565b3861116b565b611199611bdc565b611164565b503461028f5760008060031936011261033f576111b9611a14565b806001600160a01b036097546001600160a01b03198116609755167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461028f57602036600319011261028f576001600160a01b03600435611221816104ad565b611229611a14565b1680156112805761016180546001600160a01b031916821790556040516001600160a01b0390911681527f39c7a830dbd5669f23ad7f1320ac9e96d275f9d97d54c7a428cd3a02b9588f709080602081015b0390a1005b608460405162461bcd60e51b815260206004820152603e60248201527f57696467657420666565207369676e657220616464726573732073706563696660448201527f6965642073686f756c64206e6f74206265207a65726f206164647265737300006064820152fd5b503461028f57600036600319011261028f5760206040516127108152f35b503461028f57600036600319011261028f5760206001600160a01b0360975416604051908152f35b50608036600319011261028f57602435611349816104ad565b60443590606435611359816104ad565b821515806114a9575b61136b9061389a565b6113836108676108676001546001600160a01b031690565b6040516370a0823160e01b8152306004820152909190602081602481865afa90811561149c575b60009161147e575b506113c1600435821015613645565b806113c857005b823b1561028f576114336106cc6100219661144295600060405180927f2e1a7d4d00000000000000000000000000000000000000000000000000000000825281838161141c8b600483019190602083019252565b03925af18015611471575b611458575b508361249e565b918280611448575b50506124b9565b90613c27565b61145191613c27565b388261143b565b8061146561146b92610359565b80610284565b3861142c565b611479611bdc565b611427565b611496915060203d81116108dc576108ce81836103ea565b386113b2565b6114a4611bdc565b6113aa565b506064831115611362565b503461028f57600036600319011261028f5760206001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416604051908152f35b50602036600319011261028f5760043567ffffffffffffffff811161028f57610f0161152e6107f6923690600401610de2565b90612f42565b50602036600319011261028f5760043561154d816104ad565b4761155457005b610021904790613c27565b503461028f57606036600319011261028f5760043561157d816104ad565b6115da60243561158c816104ad565b60443590611599826104ad565b603254936115be60ff8660081c16158096819761165c575b811561163c575b50611f37565b846115d1600160ff196032541617603255565b6116235761201a565b6115e057005b6115f061ff001960325416603255565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890806020810161127b565b61163761010061ff00196032541617603255565b61201a565b303b1591508161164e575b50386115b8565b6001915060ff161438611647565b600160ff82161091506115b1565b503461028f57600036600319011261028f5760206001600160a01b0360005416604051908152f35b50606036600319011261028f576100216004356116ae816104ad565b604435906116bb826104ad565b60243590613812565b5060a036600319011261028f576004356116dd816104ad565b604435906116ea826104ad565b608435916064356116fa846104ad565b801515806117b7575b61170c9061389a565b6040516370a0823160e01b8152306004820152936020856024816001600160a01b0388165afa9485156117aa575b60009561178a575b506117516024358610156137c7565b8461175857005b8461176c6106cc61177a946100219861249e565b9182806117805750506124b9565b91613bea565b6114519187613bea565b6117a391955060203d81116108dc576108ce81836103ea565b9338611742565b6117b2611bdc565b61173a565b506064811115611703565b50604036600319011261028f576100216004356117de816104ad565b339060243590613812565b50604036600319011261028f57610021600435611805816104ad565b6024359030903390613a30565b503461028f57602036600319011261028f57600435611830816104ad565b611838611a14565b6001600160a01b038116156118505761002190611a6c565b608460405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152fd5b503461028f57606036600319011261028f5760443560243560043567ffffffffffffffff80841161028f573660238501121561028f57836004013590811161028f5783016024019136831161028f576000938483138015611a0b575b156119c75760a061193061032f9560246119a49401612271565b9261193b845161312e565b509461198a6040870161196261195b61086783516001600160a01b031690565b33146122ea565b6119846119768b546001600160a01b031690565b91516001600160a01b031690565b90612cfe565b50878112156119bf5750935b01516001600160a01b031690565b6119b96020339301516001600160a01b031690565b906138e5565b905093611996565b606460405162461bcd60e51b815260206004820152601160248201527f44656c7461206973206e656761746976650000000000000000000000000000006044820152fd5b50848213611916565b6001600160a01b03609754163303611a2857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b609754906001600160a01b0380911691826001600160a01b0319821617609755167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15611abb57565b608460405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152fd5b15611b2c57565b608460405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152fd5b6040516020810181811067ffffffffffffffff821117611bc0575b60405260008152906000368137565b611bc8610342565b611bb1565b9081602091031261028f575190565b506040513d6000823e3d90fd5b15611bf057565b608460405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f7860448201527f6961626c655555494400000000000000000000000000000000000000000000006064820152fd5b803b15611c9d576001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc91166001600160a01b0319825416179055565b608460405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152fd5b611d1081611c5a565b6040516001600160a01b0382167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611e44575b611d5657505050565b813b15611ddc575060008281926020611dd995519201905af4611d77611ea2565b60405191611d8483610396565b602783527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c60208401527f206661696c6564000000000000000000000000000000000000000000000000006040840152611ed2565b50565b8062461bcd60e51b6084925260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f60448201527f6e747261637400000000000000000000000000000000000000000000000000006064820152fd5b506000611d4d565b611e5581611c5a565b6040516001600160a01b0382167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611e9a57611d5657505050565b506001611d4d565b3d15611ecd573d90611eb38261043b565b91611ec160405193846103ea565b82523d6000602084013e565b606090565b909160609115611ee157505090565b610439919392611f00565b906020611efd928181520190610e36565b90565b805190925015611f135750805190602001fd5b610a599060405191829162461bcd60e51b8352602060048401526024830190610e36565b15611f3e57565b608460405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b60405190611fb58261037a565b600d82527f6e617469766520726f75746572000000000000000000000000000000000000006020830152565b60405190611fee8261037a565b600182527f31000000000000000000000000000000000000000000000000000000000000006020830152565b9190916001600160a01b0380821615612117578316156120ad576104399261205b612077926001600160a01b03166001600160a01b03196000541617600055565b6001600160a01b03166001600160a01b03196001541617600155565b612090612082611fa8565b61208a611fe1565b90612242565b612098612226565b6120a06121f2565b6120a8612215565b612566565b608460405162461bcd60e51b815260206004820152602960248201527f50657269706865727953746174653a205745544839206164647265737320636160448201527f6e6e6f74206265203000000000000000000000000000000000000000000000006064820152fd5b608460405162461bcd60e51b815260206004820152602b60248201527f50657269706865727953746174653a20666163746f727920616464726573732060448201527f63616e6e6f7420626520300000000000000000000000000000000000000000006064820152fd5b1561218857565b608460405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b61220c60ff60325460081c1661220781612181565b612181565b61043933611a6c565b61043960ff60325460081c16612181565b61223b60ff60325460081c1661220781612181565b6001603355565b61225760ff60325460081c1661220781612181565b6020815191012090602081519101209061012d5561012e55565b9060208282031261028f57813567ffffffffffffffff9283821161028f570160408183031261028f576040519260408401848110828211176122dd575b604052813590811161028f576020926122c8918301610466565b835201356122d5816104ad565b602082015290565b6122e5610342565b6122ae565b156122f157565b606460405162461bcd60e51b815260206004820152602060248201527f63616c6c6261636b206973206e6f742066726f6d206f726465722062757965726044820152fd5b1561233c57565b608460405162461bcd60e51b815260206004820152602160248201527f6578616374496e70757453696e676c653a206d756c7469706c65206f7264657260448201527f73000000000000000000000000000000000000000000000000000000000000006064820152fd5b156123ad57565b606460405162461bcd60e51b815260206004820152601f60248201527f77696467657420666565207369676e617475726520697320696e76616c6964006044820152fd5b156123f857565b606460405162461bcd60e51b815260206004820152601260248201527f696e76616c6964207769646765742066656500000000000000000000000000006044820152fd5b1561244357565b606460405162461bcd60e51b815260206004820152601560248201527f73656c6c6572206973206e6f7420636f727265637400000000000000000000006044820152fd5b50634e487b7160e01b600052601160045260246000fd5b818102929181159184041417156124b157565b610439612487565b919082039182116124b157565b156124cd57565b606460405162461bcd60e51b815260206004820152601360248201527f546f6f206c6974746c65207265636569766564000000000000000000000000006044820152fd5b600260335414612522576002603355565b606460405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b6001600160a01b0390612577611a14565b1680156112805760207f39c7a830dbd5669f23ad7f1320ac9e96d275f9d97d54c7a428cd3a02b9588f7091610161816001600160a01b0319825416179055604051908152a1565b156125c557565b606460405162461bcd60e51b815260206004820152601160248201527f74784f726967696e2069732077726f6e670000000000000000000000000000006044820152fd5b815181526020808301516001600160a01b0316908201526101608101929161043991906040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a0818101516001600160a01b03169083015260c081015160c083015260e081015160e083015261010080820151908301526126b261012080830151908401906001600160a01b03169052565b610140908101516fffffffffffffffffffffffffffffffff1916910152565b6020815260406001600160a01b0360206126f5855184838701526060860190610e36565b9401511691015290565b919082604091031261028f576020825192015190565b9193612748611efd96949561273a6001600160a01b039460a0875260a0870190610e36565b908582036020870152610e36565b9460408401521660608201526080818403910152610e36565b7f8000000000000000000000000000000000000000000000000000000000000000811461278f575b60000390565b612797612487565b612789565b91611efd9261281d6127ae835161312e565b92906127d86127c86101208301516001600160a01b031690565b6001600160a01b031632146125be565b6000938461283a61289d61285c6128686127f985546001600160a01b031690565b9a61282b61086761086760409e8f9d8e8d019161198483516001600160a01b031690565b50516001600160a01b031690565b978a5195869160208301612609565b039061284e601f19928381018852876103ea565b8a51938491602083016126d1565b039081018352826103ea565b87519a8b97889687957fd025fdfa00000000000000000000000000000000000000000000000000000000875260048701612715565b03925af19283156128fb575b819282946128c8575b50508113156128c15750612761565b9050612761565b80919294506128ec9350903d106128f4575b6128e481836103ea565b8101906126ff565b9138806128b2565b503d6128da565b612903611bdc565b6128a9565b906001600160a01b039081835116826101615416036129a75761299f612991839261298c848751168560208901511660408901516040519160208301937ff9f99be7c6fc811299ccb466f1a6e033e571f786a60f628d90c261b7145e3390855260408401526060830152608082015260808152612984816103b2565b519020612c23565b6129eb565b93516001600160a01b031690565b921691161490565b606460405162461bcd60e51b815260206004820152601160248201527f5369676e657220697320696e76616c69640000000000000000000000000000006044820152fd5b611efd916129f891612b5b565b919091612a20565b60051115612a0a57565b634e487b7160e01b600052602160045260246000fd5b612a2981612a00565b80612a315750565b612a3a81612a00565b60018103612a875760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b612a9081612a00565b60028103612add5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b80612ae9600392612a00565b14612af057565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608490fd5b906041815114600014612b8957612b85916020820151906060604084015193015160001a90612b93565b9091565b5050600090600290565b9291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311612c175791608094939160ff602094604051948552168484015260408301526060820152600093849182805260015afa15612c0a575b81516001600160a01b03811615612c04579190565b50600190565b612c12611bdc565b612bef565b50505050600090600390565b61012d5461012e54916040519260208401927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604085015260608401524660808401523060a084015260a0835261010260c084019284841067ffffffffffffffff851117612cd9575b83604052845190209360e08101947f1901000000000000000000000000000000000000000000000000000000000000865260e2820152015260428152612cd3816103ce565b51902090565b612ce1610342565b612c8e565b9081602091031261028f5751801515810361028f5790565b906020602491604051928380927f6cdff9480000000000000000000000000000000000000000000000000000000082526001600160a01b0380911696876004840152165afa908115612dce575b600091612da0575b5015612d5c5790565b606460405162461bcd60e51b815260206004820152601460248201527f496e76616c696420706f6f6c20616464726573730000000000000000000000006044820152fd5b612dc1915060203d8111612dc7575b612db981836103ea565b810190612ce6565b38612d53565b503d612daf565b612dd6611bdc565b612d4b565b60209067ffffffffffffffff8111612df5575b60051b0190565b612dfd610342565b612dee565b90612e0c82612ddb565b612e1960405191826103ea565b8281528092612e2a601f1991612ddb565b019060005b828110612e3b57505050565b806060602080938501015201612e2f565b50634e487b7160e01b600052603260045260246000fd5b9190811015612ea6575b60051b81013590601e198136030182121561028f57019081359167ffffffffffffffff831161028f57602001823603811361028f579190565b612eae612e4c565b612e6d565b908092918237016000815290565b60208183031261028f5780519067ffffffffffffffff821161028f570181601f8201121561028f578051612ef48161043b565b92612f0260405194856103ea565b8184526020828401011161028f57611efd9160208085019101610e13565b6020918151811015612f35575b60051b010190565b612f3d612e4c565b612f2d565b919091612f4e83612e02565b9260005b818110612f5e57505050565b600080612f6c838587612e63565b60409391612f7e855180938193612eb3565b0390305af490612f8c611ea2565b91829015612fb657505090600191612fa48288612f20565b52612faf8187612f20565b5001612f52565b6044839293511061028f57612fdc610a5991600480940160248091518301019101612ec1565b925192839262461bcd60e51b84528301611eec565b90601f82018092116124b157565b906101499182018092116124b157565b60405190610160820182811067ffffffffffffffff821117613075575b604052816101406000918281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e082015282610100820152826101208201520152565b61307d610342565b61302c565b1561308957565b608460405162461bcd60e51b815260206004820152602e60248201527f4f72646572733a206465636f646546697273744f726465723a20696e76616c6960448201527f64206279746573206c656e6774680000000000000000000000000000000000006064820152fd5b90602082519201516fffffffffffffffffffffffffffffffff1990818116936010811061311f57505050565b60100360031b82901b16169150565b90611efd61313a61300f565b9261315081518015159081613263575b50613082565b61315981613457565b8452613177613167826133a0565b6001600160a01b03166020860152565b613193613183826133f7565b6001600160a01b03166040860152565b6131af61319f8261340a565b6001600160a01b03166060860152565b6131cb6131bb8261341d565b6001600160a01b03166080860152565b6131e76131d782613430565b6001600160a01b031660a0860152565b6131f0816134ab565b60c08501526131fe816134bb565b60e085015261320c816134cb565b61010085015261322f61321e82613443565b6001600160a01b0316610120860152565b61325e61324361323e83613306565b6130f3565b6fffffffffffffffffffffffffffffffff1916610140860152565b613352565b610149915006153861314a565b1561327757565b606460405162461bcd60e51b815260206004820152600e60248201527f736c6963655f6f766572666c6f770000000000000000000000000000000000006044820152fd5b156132c257565b606460405162461bcd60e51b815260206004820152601160248201527f736c6963655f6f75744f66426f756e64730000000000000000000000000000006044820152fd5b61010861331681835110156132bb565b6040519160108301910160208084015b8084106133415750506010835250601f01601f191660405290565b825184529281019291810191613326565b613361610149825110156132bb565b60405190600182019061010901604283015b80831061338d57505060418252601f01601f191660405290565b9091825181526020809101920190613373565b60348151106133b3576040015160601c90565b606460405162461bcd60e51b815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e647300000000000000000000006044820152fd5b60488151106133b3576054015160601c90565b605c8151106133b3576068015160601c90565b60708151106133b357607c015160601c90565b60848151106133b3576090015160601c90565b60f88151106133b357610104015160601c90565b6020815110613467576020015190565b606460405162461bcd60e51b815260206004820152601560248201527f746f55696e743235365f6f75744f66426f756e647300000000000000000000006044820152fd5b60a48151106134675760a4015190565b60c48151106134675760c4015190565b60e48151106134675760e4015190565b610149906134ec82825110156132bb565b604051916009808401920161015284015b8084106135155750508252601f01601f191660405290565b90928351815260208091019301906134fd565b61353c815180151590816132635750613082565b80516101481991828201908282116135e0575b6135638261355c81612ff1565b1015613270565b613578815161357184612fff565b11156132bb565b610149838103613598575050505050604051600081526020810160405290565b60405194601f8416801560051b9182828901019687010193010101905b8084106135cd5750508252601f01601f191660405290565b90928351815260208091019301906135b5565b6135e8612487565b61354f565b6001600160a01b0360015416330361360157565b606460405162461bcd60e51b815260206004820152600960248201527f4e6f7420574554483900000000000000000000000000000000000000000000006044820152fd5b1561364c57565b606460405162461bcd60e51b815260206004820152601260248201527f496e73756666696369656e7420574554483900000000000000000000000000006044820152fd5b6001546040516370a0823160e01b8152306004820152916001600160a01b0390911690602083602481855afa9283156137ba575b600093613796575b506136d990831015613645565b816136e357505050565b81613703916136fd6108676002546001600160a01b031690565b90613bea565b61371b6108676108676002546001600160a01b031690565b91823b1561028f576040517fb2b5285200000000000000000000000000000000000000000000000000000000815260048101929092526001600160a01b03166024820152906000908290604490829084905af18015613789575b61377c5750565b8061146561043992610359565b613791611bdc565b613775565b6136d99193506137b39060203d81116108dc576108ce81836103ea565b92906136cc565b6137c2611bdc565b6136c4565b156137ce57565b606460405162461bcd60e51b815260206004820152601260248201527f496e73756666696369656e7420746f6b656e00000000000000000000000000006044820152fd5b91604051916370a0823160e01b83523060048401526020836024816001600160a01b0388165afa92831561388d575b600093613869575b50613856908310156137c7565b8161386057505050565b61043992613bea565b6138569193506138869060203d81116108dc576108ce81836103ea565b9290613849565b613895611bdc565b613841565b156138a157565b606460405162461bcd60e51b815260206004820152601060248201527f466565206f7574206f662072616e6765000000000000000000000000000000006044820152fd5b909291926138fe6108676001546001600160a01b031690565b6001600160a01b03908184161480613a26575b15613a08575050506139316108676108676001546001600160a01b031690565b90813b1561028f576139b292816000602094600460405180948193630d0e30db60e41b83525af180156139fb575b6139e8575b5061397d6108676108676001546001600160a01b031690565b90600060405180968195829463a9059cbb60e01b845260048401602090939291936001600160a01b0360408201951681520152565b03925af180156139db575b6139c45750565b611dd99060203d8111612dc757612db981836103ea565b6139e3611bdc565b6139bd565b806114656139f592610359565b38613964565b613a03611bdc565b61395f565b91939181163003613a1d575061043992613bea565b61043993613a30565b5083471015613911565b61043993929192604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526001600160a01b0393848092166024870152166044850152606484015260648352613a8b836103b2565b16604051613aea916001600160a01b0316613aa58261037a565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af1613ae4611ea2565b91613b79565b80519081613af757505050565b8280613b07938301019101612ce6565b15613b0f5750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b919260609115613bdd575050815115613b90575090565b3b15613b995790565b606460405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b9093926104399250611f00565b60405163a9059cbb60e01b60208201526001600160a01b039283166024820152604480820194909452928352610439929190613a8b6064846103ea565b6000918291613c34611b96565b91602083519301915af1613c46611ea2565b5015613c4e57565b606460405162461bcd60e51b815260206004820152600360248201527f53544500000000000000000000000000000000000000000000000000000000006044820152fdfea26469706673582212207867a11a9acbfaa54f909e0cf73e2cf501c1a57687fd896460058a44f29526ff64736f6c63430008110033
Deployed Bytecode
0x60806040526004361015610023575b361561001957600080fd5b6100216135ed565b005b60003560e01c8063086eae401461027b57806312210e8a146102725780631c58db4f146102695780632794949c146102605780633659cfe614610257578063372a771b1461024e57806349404b7c14610245578063496169971461023c5780634aa4a4fc146102335780634f1ef2861461022a5780635131e1fb1461022157806352d1902d146102185780635ae401dc1461020f57806368ab0bdb14610206578063715018a6146101fd57806372a8ddc9146101f45780637aed3f02146101eb5780638da5cb5b146101e25780639b2c0a37146101d9578063aaf10f42146101d0578063ac9650d8146101c7578063b2730c7b146101be578063c0c53b8b146101b5578063c45a0155146101ac578063df2ab5bb146101a3578063e0e189a01461019a578063e90a182f14610191578063f2d5d56b14610188578063f2fde38b1461017f5763fa483e720361000e5761017a6118ba565b61000e565b5061017a611812565b5061017a6117e9565b5061017a6117c2565b5061017a6116c4565b5061017a611692565b5061017a61166a565b5061017a61155f565b5061017a611534565b5061017a6114fb565b5061017a6114b4565b5061017a611330565b5061017a611308565b5061017a6112ea565b5061017a6111fb565b5061017a61119e565b5061017a610f51565b5061017a610ebd565b5061017a610d0b565b5061017a610ce3565b5061017a610b3a565b5061017a610b12565b5061017a610af9565b5061017a610ad5565b5061017a610a90565b5061017a6108f0565b5061017a6105d9565b5061017a6102db565b5061017a6102bd565b5061017a610294565b600091031261028f57565b600080fd5b503461028f57600036600319011261028f5760206001600160a01b036101615416604051908152f35b50600036600319011261028f57476102d157005b6100214733613c27565b506000602036600319011261033f576001600160a01b036001541681813b1561033f5760049160405192838092630d0e30db60e41b82528235905af18015610332575b610326575080f35b61032f90610359565b80f35b61033a611bdc565b61031e565b80fd5b50634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161036d57604052565b610375610342565b604052565b6040810190811067ffffffffffffffff82111761036d57604052565b6060810190811067ffffffffffffffff82111761036d57604052565b60a0810190811067ffffffffffffffff82111761036d57604052565b6080810190811067ffffffffffffffff82111761036d57604052565b90601f8019910116810190811067ffffffffffffffff82111761036d57604052565b6040519060c0820182811067ffffffffffffffff82111761036d57604052565b604051906104398261037a565b565b60209067ffffffffffffffff8111610459575b601f01601f19160190565b610461610342565b61044e565b81601f8201121561028f5780359061047d8261043b565b9261048b60405194856103ea565b8284526020838301011161028f57816000926020809301838601378301015290565b6001600160a01b0381160361028f57565b3590610439826104ad565b919082606091031261028f576040516060810181811067ffffffffffffffff82111761051f575b60405260408082948035610503816104ad565b84526020810135610513816104ad565b60208501520135910152565b610527610342565b6104f0565b60031960208282011261028f576004359167ffffffffffffffff9182841161028f5761010090848303011261028f5761056361040c565b92806004013583811161028f5782600461057f92840101610466565b845261058d602482016104be565b602085015260448101356040850152606481013560608501526105b382608483016104c9565b608085015260e481013592831161028f576105d19201600401610466565b60a082015290565b506107f66105e63661052c565b6105ee612511565b61060b610606610602835161014990511190565b1590565b612335565b60808101610627610622825160a085015190612908565b6123a6565b6107d860606107cd604093610644612710868351015111156123f1565b600090610651875161312e565b50908688019187835115610812575b7fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761079d936106fd846106e56106d46106cc60a0976106bf8f6106af9061073c9c01516001600160a01b031690565b6001600160a01b0316331461243c565b8b5190875101519061249e565b612710900490565b95869201516001600160a01b031690565b8351602001516001600160a01b03165b903390613a30565b518a61071360208301516001600160a01b031690565b9101518b516001600160a01b039092168252602082015260408101839052606090a183516124b9565b918281527f598150b82ea875d58e1d8f33db4ac9f8c9d57a83bda9a42d63a50ad741296df260208a019361077785516001600160a01b031690565b8a519182526001600160a01b03166020820152604090a15191516001600160a01b031690565b90875192600014610809576107c8305b6107b561042c565b9485526001600160a01b03166020850152565b61279c565b9301518310156124c6565b476107fa575b6107e86001603355565b519081529081906020820190565b0390f35b6108044733613c27565b6107de565b6107c8336107ad565b935060a07fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761079d936106fd61073c946106e56106d46106cc60019b6108736108676108678b8801516001600160a01b031690565b6001600160a01b031690565b81516370a0823160e01b815230600482015290602090829060249082905afa9081156108e3575b6000916108b5575b508c529750505050945050935050610660565b6108d6915060203d81116108dc575b6108ce81836103ea565b810190611bcd565b386108a2565b503d6108c4565b6108eb611bdc565b61089a565b503461028f57602036600319011261028f5760043561090e816104ad565b6001600160a01b0390817f0000000000000000000000007a27bbd83b5065eeff85411dfe048eaac9be2a9d169161094783301415611ab4565b6109767f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc938285541614611b25565b61097e611a14565b610986611b96565b906109b27f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1690565b156109c35750506100219150611c5a565b6020600491604094939451928380926352d1902d60e01b825286165afa60009181610a70575b50610a5d5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152608490fd5b0390fd5b61002193610a6b9114611be9565b611d07565b610a8991925060203d81116108dc576108ce81836103ea565b90386109e9565b503461028f57602036600319011261028f576001600160a01b03600435610ab6816104ad565b610abe611a14565b166001600160a01b03196002541617600255600080f35b50604036600319011261028f57610021602435610af1816104ad565b600435613690565b50602036600319011261028f5761002133600435613690565b503461028f57600036600319011261028f5760206001600160a01b0360015416604051908152f35b50604036600319011261028f57600435610b53816104ad565b60243567ffffffffffffffff811161028f57610b73903690600401610466565b906001600160a01b0391827f0000000000000000000000007a27bbd83b5065eeff85411dfe048eaac9be2a9d1692610bad84301415611ab4565b610bdc7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc948286541614611b25565b610be4611a14565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615610c1a5750506100219150611c5a565b6020600491604094939451928380926352d1902d60e01b825286165afa60009181610cc3575b50610cb05760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201527f6f6e206973206e6f7420555550530000000000000000000000000000000000006064820152608490fd5b61002193610cbe9114611be9565b611e4c565b610cdc91925060203d81116108dc576108ce81836103ea565b9038610c40565b503461028f57600036600319011261028f5760206001600160a01b0360025416604051908152f35b503461028f57600036600319011261028f576001600160a01b037f0000000000000000000000007a27bbd83b5065eeff85411dfe048eaac9be2a9d163003610d78576040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152602090f35b608460405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152fd5b9181601f8401121561028f5782359167ffffffffffffffff831161028f576020808501948460051b01011161028f57565b60005b838110610e265750506000910152565b8181015183820152602001610e16565b90602091610e4f81518092818552858086019101610e13565b601f01601f1916010190565b602080820190808352835180925260408301928160408460051b8301019501936000915b848310610e8f5750505050505090565b9091929394958480610ead600193603f198682030187528a51610e36565b9801930193019194939290610e7f565b50604036600319011261028f5760243567ffffffffffffffff811161028f57610eea903690600401610de2565b906004354211610f0d576107f691610f0191612f42565b60405191829182610e5b565b606460405162461bcd60e51b815260206004820152601360248201527f5472616e73616374696f6e20746f6f206f6c64000000000000000000000000006044820152fd5b50610f5b3661052c565b610f63612511565b60009060808101610f7d610622825160a085015190612908565b604090610f92612710838351015111156123f1565b6110ba8491610fa1855161312e565b50928486019687511561111e575b610fc66106af60608701516001600160a01b031690565b501561111257919050611078305b917fe138d451ddd99d43e902dd57cf46d9aa0ac68d44bc7e50397325ba69670fd13761101d60a061100e6106cc8b518a8a5101519061249e565b9301516001600160a01b031690565b9461103a836020976106f5898551016001600160a01b0390511690565b518661104f878301516001600160a01b031690565b91015187516001600160a01b039092168252602082015260408101839052606090a186516124b9565b85525b6110ba845191610149835111928751846000146110f3576107c861109f30936134db565b936110a861042c565b9485526001600160a01b031687850152565b80865290156110dd57506110ba30916110d38551613528565b855291905061107b565b83836107d860606107f6949301518310156124c6565b6107c861109f61110c888b01516001600160a01b031690565b936134db565b91905061107833610fd4565b905060019061113d61086761086760a08801516001600160a01b031690565b86516370a0823160e01b815230600482015290602090829060249082905afa908115611191575b8291611173575b508852610faf565b61118b915060203d81116108dc576108ce81836103ea565b3861116b565b611199611bdc565b611164565b503461028f5760008060031936011261033f576111b9611a14565b806001600160a01b036097546001600160a01b03198116609755167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b503461028f57602036600319011261028f576001600160a01b03600435611221816104ad565b611229611a14565b1680156112805761016180546001600160a01b031916821790556040516001600160a01b0390911681527f39c7a830dbd5669f23ad7f1320ac9e96d275f9d97d54c7a428cd3a02b9588f709080602081015b0390a1005b608460405162461bcd60e51b815260206004820152603e60248201527f57696467657420666565207369676e657220616464726573732073706563696660448201527f6965642073686f756c64206e6f74206265207a65726f206164647265737300006064820152fd5b503461028f57600036600319011261028f5760206040516127108152f35b503461028f57600036600319011261028f5760206001600160a01b0360975416604051908152f35b50608036600319011261028f57602435611349816104ad565b60443590606435611359816104ad565b821515806114a9575b61136b9061389a565b6113836108676108676001546001600160a01b031690565b6040516370a0823160e01b8152306004820152909190602081602481865afa90811561149c575b60009161147e575b506113c1600435821015613645565b806113c857005b823b1561028f576114336106cc6100219661144295600060405180927f2e1a7d4d00000000000000000000000000000000000000000000000000000000825281838161141c8b600483019190602083019252565b03925af18015611471575b611458575b508361249e565b918280611448575b50506124b9565b90613c27565b61145191613c27565b388261143b565b8061146561146b92610359565b80610284565b3861142c565b611479611bdc565b611427565b611496915060203d81116108dc576108ce81836103ea565b386113b2565b6114a4611bdc565b6113aa565b506064831115611362565b503461028f57600036600319011261028f5760206001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416604051908152f35b50602036600319011261028f5760043567ffffffffffffffff811161028f57610f0161152e6107f6923690600401610de2565b90612f42565b50602036600319011261028f5760043561154d816104ad565b4761155457005b610021904790613c27565b503461028f57606036600319011261028f5760043561157d816104ad565b6115da60243561158c816104ad565b60443590611599826104ad565b603254936115be60ff8660081c16158096819761165c575b811561163c575b50611f37565b846115d1600160ff196032541617603255565b6116235761201a565b6115e057005b6115f061ff001960325416603255565b604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890806020810161127b565b61163761010061ff00196032541617603255565b61201a565b303b1591508161164e575b50386115b8565b6001915060ff161438611647565b600160ff82161091506115b1565b503461028f57600036600319011261028f5760206001600160a01b0360005416604051908152f35b50606036600319011261028f576100216004356116ae816104ad565b604435906116bb826104ad565b60243590613812565b5060a036600319011261028f576004356116dd816104ad565b604435906116ea826104ad565b608435916064356116fa846104ad565b801515806117b7575b61170c9061389a565b6040516370a0823160e01b8152306004820152936020856024816001600160a01b0388165afa9485156117aa575b60009561178a575b506117516024358610156137c7565b8461175857005b8461176c6106cc61177a946100219861249e565b9182806117805750506124b9565b91613bea565b6114519187613bea565b6117a391955060203d81116108dc576108ce81836103ea565b9338611742565b6117b2611bdc565b61173a565b506064811115611703565b50604036600319011261028f576100216004356117de816104ad565b339060243590613812565b50604036600319011261028f57610021600435611805816104ad565b6024359030903390613a30565b503461028f57602036600319011261028f57600435611830816104ad565b611838611a14565b6001600160a01b038116156118505761002190611a6c565b608460405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152fd5b503461028f57606036600319011261028f5760443560243560043567ffffffffffffffff80841161028f573660238501121561028f57836004013590811161028f5783016024019136831161028f576000938483138015611a0b575b156119c75760a061193061032f9560246119a49401612271565b9261193b845161312e565b509461198a6040870161196261195b61086783516001600160a01b031690565b33146122ea565b6119846119768b546001600160a01b031690565b91516001600160a01b031690565b90612cfe565b50878112156119bf5750935b01516001600160a01b031690565b6119b96020339301516001600160a01b031690565b906138e5565b905093611996565b606460405162461bcd60e51b815260206004820152601160248201527f44656c7461206973206e656761746976650000000000000000000000000000006044820152fd5b50848213611916565b6001600160a01b03609754163303611a2857565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b609754906001600160a01b0380911691826001600160a01b0319821617609755167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b15611abb57565b608460405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f64656c656761746563616c6c00000000000000000000000000000000000000006064820152fd5b15611b2c57565b608460405162461bcd60e51b815260206004820152602c60248201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060448201527f6163746976652070726f787900000000000000000000000000000000000000006064820152fd5b6040516020810181811067ffffffffffffffff821117611bc0575b60405260008152906000368137565b611bc8610342565b611bb1565b9081602091031261028f575190565b506040513d6000823e3d90fd5b15611bf057565b608460405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f7860448201527f6961626c655555494400000000000000000000000000000000000000000000006064820152fd5b803b15611c9d576001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc91166001600160a01b0319825416179055565b608460405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152fd5b611d1081611c5a565b6040516001600160a01b0382167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611e44575b611d5657505050565b813b15611ddc575060008281926020611dd995519201905af4611d77611ea2565b60405191611d8483610396565b602783527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c60208401527f206661696c6564000000000000000000000000000000000000000000000000006040840152611ed2565b50565b8062461bcd60e51b6084925260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f60448201527f6e747261637400000000000000000000000000000000000000000000000000006064820152fd5b506000611d4d565b611e5581611c5a565b6040516001600160a01b0382167fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2825115801590611e9a57611d5657505050565b506001611d4d565b3d15611ecd573d90611eb38261043b565b91611ec160405193846103ea565b82523d6000602084013e565b606090565b909160609115611ee157505090565b610439919392611f00565b906020611efd928181520190610e36565b90565b805190925015611f135750805190602001fd5b610a599060405191829162461bcd60e51b8352602060048401526024830190610e36565b15611f3e57565b608460405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b60405190611fb58261037a565b600d82527f6e617469766520726f75746572000000000000000000000000000000000000006020830152565b60405190611fee8261037a565b600182527f31000000000000000000000000000000000000000000000000000000000000006020830152565b9190916001600160a01b0380821615612117578316156120ad576104399261205b612077926001600160a01b03166001600160a01b03196000541617600055565b6001600160a01b03166001600160a01b03196001541617600155565b612090612082611fa8565b61208a611fe1565b90612242565b612098612226565b6120a06121f2565b6120a8612215565b612566565b608460405162461bcd60e51b815260206004820152602960248201527f50657269706865727953746174653a205745544839206164647265737320636160448201527f6e6e6f74206265203000000000000000000000000000000000000000000000006064820152fd5b608460405162461bcd60e51b815260206004820152602b60248201527f50657269706865727953746174653a20666163746f727920616464726573732060448201527f63616e6e6f7420626520300000000000000000000000000000000000000000006064820152fd5b1561218857565b608460405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b61220c60ff60325460081c1661220781612181565b612181565b61043933611a6c565b61043960ff60325460081c16612181565b61223b60ff60325460081c1661220781612181565b6001603355565b61225760ff60325460081c1661220781612181565b6020815191012090602081519101209061012d5561012e55565b9060208282031261028f57813567ffffffffffffffff9283821161028f570160408183031261028f576040519260408401848110828211176122dd575b604052813590811161028f576020926122c8918301610466565b835201356122d5816104ad565b602082015290565b6122e5610342565b6122ae565b156122f157565b606460405162461bcd60e51b815260206004820152602060248201527f63616c6c6261636b206973206e6f742066726f6d206f726465722062757965726044820152fd5b1561233c57565b608460405162461bcd60e51b815260206004820152602160248201527f6578616374496e70757453696e676c653a206d756c7469706c65206f7264657260448201527f73000000000000000000000000000000000000000000000000000000000000006064820152fd5b156123ad57565b606460405162461bcd60e51b815260206004820152601f60248201527f77696467657420666565207369676e617475726520697320696e76616c6964006044820152fd5b156123f857565b606460405162461bcd60e51b815260206004820152601260248201527f696e76616c6964207769646765742066656500000000000000000000000000006044820152fd5b1561244357565b606460405162461bcd60e51b815260206004820152601560248201527f73656c6c6572206973206e6f7420636f727265637400000000000000000000006044820152fd5b50634e487b7160e01b600052601160045260246000fd5b818102929181159184041417156124b157565b610439612487565b919082039182116124b157565b156124cd57565b606460405162461bcd60e51b815260206004820152601360248201527f546f6f206c6974746c65207265636569766564000000000000000000000000006044820152fd5b600260335414612522576002603355565b606460405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152fd5b6001600160a01b0390612577611a14565b1680156112805760207f39c7a830dbd5669f23ad7f1320ac9e96d275f9d97d54c7a428cd3a02b9588f7091610161816001600160a01b0319825416179055604051908152a1565b156125c557565b606460405162461bcd60e51b815260206004820152601160248201527f74784f726967696e2069732077726f6e670000000000000000000000000000006044820152fd5b815181526020808301516001600160a01b0316908201526101608101929161043991906040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a0818101516001600160a01b03169083015260c081015160c083015260e081015160e083015261010080820151908301526126b261012080830151908401906001600160a01b03169052565b610140908101516fffffffffffffffffffffffffffffffff1916910152565b6020815260406001600160a01b0360206126f5855184838701526060860190610e36565b9401511691015290565b919082604091031261028f576020825192015190565b9193612748611efd96949561273a6001600160a01b039460a0875260a0870190610e36565b908582036020870152610e36565b9460408401521660608201526080818403910152610e36565b7f8000000000000000000000000000000000000000000000000000000000000000811461278f575b60000390565b612797612487565b612789565b91611efd9261281d6127ae835161312e565b92906127d86127c86101208301516001600160a01b031690565b6001600160a01b031632146125be565b6000938461283a61289d61285c6128686127f985546001600160a01b031690565b9a61282b61086761086760409e8f9d8e8d019161198483516001600160a01b031690565b50516001600160a01b031690565b978a5195869160208301612609565b039061284e601f19928381018852876103ea565b8a51938491602083016126d1565b039081018352826103ea565b87519a8b97889687957fd025fdfa00000000000000000000000000000000000000000000000000000000875260048701612715565b03925af19283156128fb575b819282946128c8575b50508113156128c15750612761565b9050612761565b80919294506128ec9350903d106128f4575b6128e481836103ea565b8101906126ff565b9138806128b2565b503d6128da565b612903611bdc565b6128a9565b906001600160a01b039081835116826101615416036129a75761299f612991839261298c848751168560208901511660408901516040519160208301937ff9f99be7c6fc811299ccb466f1a6e033e571f786a60f628d90c261b7145e3390855260408401526060830152608082015260808152612984816103b2565b519020612c23565b6129eb565b93516001600160a01b031690565b921691161490565b606460405162461bcd60e51b815260206004820152601160248201527f5369676e657220697320696e76616c69640000000000000000000000000000006044820152fd5b611efd916129f891612b5b565b919091612a20565b60051115612a0a57565b634e487b7160e01b600052602160045260246000fd5b612a2981612a00565b80612a315750565b612a3a81612a00565b60018103612a875760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b612a9081612a00565b60028103612add5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b80612ae9600392612a00565b14612af057565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608490fd5b906041815114600014612b8957612b85916020820151906060604084015193015160001a90612b93565b9091565b5050600090600290565b9291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311612c175791608094939160ff602094604051948552168484015260408301526060820152600093849182805260015afa15612c0a575b81516001600160a01b03811615612c04579190565b50600190565b612c12611bdc565b612bef565b50505050600090600390565b61012d5461012e54916040519260208401927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604085015260608401524660808401523060a084015260a0835261010260c084019284841067ffffffffffffffff851117612cd9575b83604052845190209360e08101947f1901000000000000000000000000000000000000000000000000000000000000865260e2820152015260428152612cd3816103ce565b51902090565b612ce1610342565b612c8e565b9081602091031261028f5751801515810361028f5790565b906020602491604051928380927f6cdff9480000000000000000000000000000000000000000000000000000000082526001600160a01b0380911696876004840152165afa908115612dce575b600091612da0575b5015612d5c5790565b606460405162461bcd60e51b815260206004820152601460248201527f496e76616c696420706f6f6c20616464726573730000000000000000000000006044820152fd5b612dc1915060203d8111612dc7575b612db981836103ea565b810190612ce6565b38612d53565b503d612daf565b612dd6611bdc565b612d4b565b60209067ffffffffffffffff8111612df5575b60051b0190565b612dfd610342565b612dee565b90612e0c82612ddb565b612e1960405191826103ea565b8281528092612e2a601f1991612ddb565b019060005b828110612e3b57505050565b806060602080938501015201612e2f565b50634e487b7160e01b600052603260045260246000fd5b9190811015612ea6575b60051b81013590601e198136030182121561028f57019081359167ffffffffffffffff831161028f57602001823603811361028f579190565b612eae612e4c565b612e6d565b908092918237016000815290565b60208183031261028f5780519067ffffffffffffffff821161028f570181601f8201121561028f578051612ef48161043b565b92612f0260405194856103ea565b8184526020828401011161028f57611efd9160208085019101610e13565b6020918151811015612f35575b60051b010190565b612f3d612e4c565b612f2d565b919091612f4e83612e02565b9260005b818110612f5e57505050565b600080612f6c838587612e63565b60409391612f7e855180938193612eb3565b0390305af490612f8c611ea2565b91829015612fb657505090600191612fa48288612f20565b52612faf8187612f20565b5001612f52565b6044839293511061028f57612fdc610a5991600480940160248091518301019101612ec1565b925192839262461bcd60e51b84528301611eec565b90601f82018092116124b157565b906101499182018092116124b157565b60405190610160820182811067ffffffffffffffff821117613075575b604052816101406000918281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e082015282610100820152826101208201520152565b61307d610342565b61302c565b1561308957565b608460405162461bcd60e51b815260206004820152602e60248201527f4f72646572733a206465636f646546697273744f726465723a20696e76616c6960448201527f64206279746573206c656e6774680000000000000000000000000000000000006064820152fd5b90602082519201516fffffffffffffffffffffffffffffffff1990818116936010811061311f57505050565b60100360031b82901b16169150565b90611efd61313a61300f565b9261315081518015159081613263575b50613082565b61315981613457565b8452613177613167826133a0565b6001600160a01b03166020860152565b613193613183826133f7565b6001600160a01b03166040860152565b6131af61319f8261340a565b6001600160a01b03166060860152565b6131cb6131bb8261341d565b6001600160a01b03166080860152565b6131e76131d782613430565b6001600160a01b031660a0860152565b6131f0816134ab565b60c08501526131fe816134bb565b60e085015261320c816134cb565b61010085015261322f61321e82613443565b6001600160a01b0316610120860152565b61325e61324361323e83613306565b6130f3565b6fffffffffffffffffffffffffffffffff1916610140860152565b613352565b610149915006153861314a565b1561327757565b606460405162461bcd60e51b815260206004820152600e60248201527f736c6963655f6f766572666c6f770000000000000000000000000000000000006044820152fd5b156132c257565b606460405162461bcd60e51b815260206004820152601160248201527f736c6963655f6f75744f66426f756e64730000000000000000000000000000006044820152fd5b61010861331681835110156132bb565b6040519160108301910160208084015b8084106133415750506010835250601f01601f191660405290565b825184529281019291810191613326565b613361610149825110156132bb565b60405190600182019061010901604283015b80831061338d57505060418252601f01601f191660405290565b9091825181526020809101920190613373565b60348151106133b3576040015160601c90565b606460405162461bcd60e51b815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e647300000000000000000000006044820152fd5b60488151106133b3576054015160601c90565b605c8151106133b3576068015160601c90565b60708151106133b357607c015160601c90565b60848151106133b3576090015160601c90565b60f88151106133b357610104015160601c90565b6020815110613467576020015190565b606460405162461bcd60e51b815260206004820152601560248201527f746f55696e743235365f6f75744f66426f756e647300000000000000000000006044820152fd5b60a48151106134675760a4015190565b60c48151106134675760c4015190565b60e48151106134675760e4015190565b610149906134ec82825110156132bb565b604051916009808401920161015284015b8084106135155750508252601f01601f191660405290565b90928351815260208091019301906134fd565b61353c815180151590816132635750613082565b80516101481991828201908282116135e0575b6135638261355c81612ff1565b1015613270565b613578815161357184612fff565b11156132bb565b610149838103613598575050505050604051600081526020810160405290565b60405194601f8416801560051b9182828901019687010193010101905b8084106135cd5750508252601f01601f191660405290565b90928351815260208091019301906135b5565b6135e8612487565b61354f565b6001600160a01b0360015416330361360157565b606460405162461bcd60e51b815260206004820152600960248201527f4e6f7420574554483900000000000000000000000000000000000000000000006044820152fd5b1561364c57565b606460405162461bcd60e51b815260206004820152601260248201527f496e73756666696369656e7420574554483900000000000000000000000000006044820152fd5b6001546040516370a0823160e01b8152306004820152916001600160a01b0390911690602083602481855afa9283156137ba575b600093613796575b506136d990831015613645565b816136e357505050565b81613703916136fd6108676002546001600160a01b031690565b90613bea565b61371b6108676108676002546001600160a01b031690565b91823b1561028f576040517fb2b5285200000000000000000000000000000000000000000000000000000000815260048101929092526001600160a01b03166024820152906000908290604490829084905af18015613789575b61377c5750565b8061146561043992610359565b613791611bdc565b613775565b6136d99193506137b39060203d81116108dc576108ce81836103ea565b92906136cc565b6137c2611bdc565b6136c4565b156137ce57565b606460405162461bcd60e51b815260206004820152601260248201527f496e73756666696369656e7420746f6b656e00000000000000000000000000006044820152fd5b91604051916370a0823160e01b83523060048401526020836024816001600160a01b0388165afa92831561388d575b600093613869575b50613856908310156137c7565b8161386057505050565b61043992613bea565b6138569193506138869060203d81116108dc576108ce81836103ea565b9290613849565b613895611bdc565b613841565b156138a157565b606460405162461bcd60e51b815260206004820152601060248201527f466565206f7574206f662072616e6765000000000000000000000000000000006044820152fd5b909291926138fe6108676001546001600160a01b031690565b6001600160a01b03908184161480613a26575b15613a08575050506139316108676108676001546001600160a01b031690565b90813b1561028f576139b292816000602094600460405180948193630d0e30db60e41b83525af180156139fb575b6139e8575b5061397d6108676108676001546001600160a01b031690565b90600060405180968195829463a9059cbb60e01b845260048401602090939291936001600160a01b0360408201951681520152565b03925af180156139db575b6139c45750565b611dd99060203d8111612dc757612db981836103ea565b6139e3611bdc565b6139bd565b806114656139f592610359565b38613964565b613a03611bdc565b61395f565b91939181163003613a1d575061043992613bea565b61043993613a30565b5083471015613911565b61043993929192604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526001600160a01b0393848092166024870152166044850152606484015260648352613a8b836103b2565b16604051613aea916001600160a01b0316613aa58261037a565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af1613ae4611ea2565b91613b79565b80519081613af757505050565b8280613b07938301019101612ce6565b15613b0f5750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b919260609115613bdd575050815115613b90575090565b3b15613b995790565b606460405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b9093926104399250611f00565b60405163a9059cbb60e01b60208201526001600160a01b039283166024820152604480820194909452928352610439929190613a8b6064846103ea565b6000918291613c34611b96565b91602083519301915af1613c46611ea2565b5015613c4e57565b606460405162461bcd60e51b815260206004820152600360248201527f53544500000000000000000000000000000000000000000000000000000000006044820152fdfea26469706673582212207867a11a9acbfaa54f909e0cf73e2cf501c1a57687fd896460058a44f29526ff64736f6c63430008110033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.