Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- FeeDistributorChannelWH1
- Optimization enabled
- true
- Compiler version
- v0.8.24+commit.e11b9ed9
- Optimization runs
- 200
- EVM Version
- paris
- Verified at
- 2025-02-12T00:02:29.916670Z
contracts/fee/channels/fee-distributor-channels/FeeDistributorChannelWH1.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol"; import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import { NetworkGuardian } from "../../../network-guardian/NetworkGuardian.sol"; import { RecoverableUpgradeable } from "../../../utils/upgradeable/RecoverableUpgradeable.sol"; import { Address } from "../../../utils/Address.sol"; import { IFeeDistributor } from "../../../governance/interfaces/IFeeDistributor.sol"; import { IWH1 } from "../../../tokens/interfaces/IWH1.sol"; import { IFeeDistributorChannel } from "../../interfaces/IFeeDistributorChannel.sol"; /** * @title FeeDistributorChannelWH1 * * @author The Haven1 Development Team * * @notice This contract serves as a channel for distributing WH1 to the Fee * Distributor contract. * * It handles the process of receiving native H1 tokens, wrapping them into WH1 * tokens, and forwarding them to the Fee Distributor contract, enabling efficient * distribution of rewards across the network. * * @dev This contract inherits from, and initialises, the `RecoverableUpgradeable` * contract. It exposes the ability for an admin the recover HRC20 tokens from * the contract in the event that they were mistakenly sent in. The admin cannot * recover native H1. * * This contract inherits from, and initialises, the `NetworkGuardian` contract. * * Calls to `distribute` and `distributePartial` are non-reentrant calls. * * For a call to any of the distribute functions in this contract to be * successful: * - WH1 must be enabled for claiming on the Fee Distributor contract. * - The current `block.timestamp` must be greater than the start time on * the `FeeDistributor` contract. */ contract FeeDistributorChannelWH1 is ReentrancyGuardUpgradeable, NetworkGuardian, RecoverableUpgradeable, IFeeDistributorChannel { /* TYPE DECLARATIONS ==================================================*/ using Address for address; /* STATE ==================================================*/ /** * @dev The address of the `FeeDistributor` contract. Will be the recipient * of the forwarded `WH1`. */ IFeeDistributor private _feeDistributor; /** * @dev The `WH1` contract. */ IWH1 private _WH1; /** * @dev The timestamp of the last distribution. */ uint256 internal _lastDistribution; /* ERRORS ==================================================*/ /** * @dev Error raised when trying to distribute an amount of H1 that exceeds * the contract's balance. * * @param amt The amount attempted to be sent. * @param available The amount available to send. */ error FeeDistributorChannel__InsufficientH1(uint256 amt, uint256 available); /* FUNCTIONS ==================================================*/ /* Init ========================================*/ /** * @custom:oz-upgrades-unsafe-allow constructor */ constructor() { _disableInitializers(); } /** * @notice Initializes the contract. * * @param association_ The Haven1 Association address. * @param guardianController_ The Network Guardian Controller address. * @param feeDistributor_ The Fee Distributor address. * @param WH1_ The WH1 address. */ function initialize( address association_, address guardianController_, address feeDistributor_, address WH1_ ) external initializer { feeDistributor_.assertNotZero(); WH1_.assertNotZero(); __ReentrancyGuard_init(); __NetworkGuardian_init(association_, guardianController_); __Recoverable_init(); _feeDistributor = IFeeDistributor(feeDistributor_); _WH1 = IWH1(WH1_); } /* Receive and Fallback ========================================*/ receive() external payable { _deposit(); } fallback() external payable { _deposit(); } /* External ========================================*/ /** * @inheritdoc IFeeDistributorChannel */ function deposit() external payable { _deposit(); } /** * @inheritdoc IFeeDistributorChannel */ function distribute() external nonReentrant onlyRole(OPERATOR_ROLE) { uint256 amt = address(this).balance; _distribute(amt); } /** * @inheritdoc IFeeDistributorChannel */ function distributePartial( uint256 amt ) external nonReentrant onlyRole(OPERATOR_ROLE) { _distribute(amt); } /** * @inheritdoc IFeeDistributorChannel */ function recoverHRC20( address token, address to, uint256 amount ) external onlyRole(DEFAULT_ADMIN_ROLE) { _recoverHRC20(token, to, amount); } /** * @inheritdoc IFeeDistributorChannel */ function setFeeDistributor( address addr ) external onlyRole(DEFAULT_ADMIN_ROLE) { addr.assertNotZero(); address prev = address(_feeDistributor); _feeDistributor = IFeeDistributor(addr); emit FeeDistributorUpdated(prev, addr); } /** * @inheritdoc IFeeDistributorChannel */ function setWH1(address addr) external onlyRole(DEFAULT_ADMIN_ROLE) { addr.assertNotZero(); address prev = address(_WH1); _WH1 = IWH1(addr); emit WH1Updated(prev, addr); } /** * @inheritdoc IFeeDistributorChannel */ function feeDistributor() external view returns (address) { return address(_feeDistributor); } /** * @inheritdoc IFeeDistributorChannel */ function WH1() external view returns (address) { return address(_WH1); } /** * @inheritdoc IFeeDistributorChannel */ function lastDistribution() external view returns (uint256) { return _lastDistribution; } /* Private ========================================*/ /** * @notice Distributes an amount of rewards to the Fee Distributor contract * in the form of WH1. * * @param amt The amount of H1 tokens to distribute. * * @dev Requirements: * - The amount to distribute must be less than, or equal to, the amount * of H1 stored in the contract. * - WH1 must be enabled for claiming on the Fee Distributor contract. * - The current `block.timestamp` must be greater than the start time on * the `FeeDistributor` contract. * * @dev Emits a `RewardsDistributed` event. */ function _distribute(uint256 amt) internal { uint256 bal = address(this).balance; if (amt > bal) { revert FeeDistributorChannel__InsufficientH1(amt, bal); } _lastDistribution = block.timestamp; address feeDistAddr = address(_feeDistributor); address wh1Addr = address(_WH1); _WH1.deposit{ value: amt }(); _WH1.approve(feeDistAddr, amt); _feeDistributor.depositToken(IERC20Upgradeable(wh1Addr), amt); uint256 allowance = _WH1.allowance(address(this), feeDistAddr); assert(allowance == 0); emit RewardsDistributed(feeDistAddr, wh1Addr, amt); } /** * @notice Encapsulates the deposit logic. */ function _deposit() private { emit H1Received(msg.sender, msg.value); } }
@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMathUpgradeable { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../interfaces/IERC1967Upgradeable.sol"; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import {Initializable} from "../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._ */ abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable { // 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; function __ERC1967Upgrade_init() internal onlyInitializing { } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } /** * @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) { AddressUpgradeable.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 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 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) { AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), 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; }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import {Initializable} from "./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 { /// @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"); _; } function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /** * @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. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeTo(address newImplementation) public 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. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public 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; }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
contracts/governance/interfaces/IVotingEscrow.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; interface IVotingEscrow { struct Point { int128 bias; int128 slope; // # -dweight / dt uint256 ts; uint256 blk; // block } function point_history( uint256 timestamp ) external view returns (Point memory); function user_point_history( address user, uint256 timestamp ) external view returns (Point memory); function epoch() external view returns (uint256); function user_point_epoch(address user) external view returns (uint256); /// @notice Add address to whitelist smart contract depositors `addr` /// @param addr Address to be whitelisted function add_to_whitelist(address addr) external; /// @notice Remove a smart contract address from whitelist /// @param addr Address to be removed from whitelist function remove_from_whitelist(address addr) external; /// @notice Unlock all locked balances function unlock() external; /// @notice Get the most recently recorded rate of voting power decrease for `_addr` /// @param addr Address of the user wallet /// @return Value of the slope function get_last_user_slope(address addr) external view returns (int128); /// @notice Get the timestamp for checkpoint `_idx` for `_addr` /// @param _addr User wallet address /// @param _idx User epoch number /// @return Epoch time of the checkpoint function user_point_history__ts( address _addr, uint256 _idx ) external view returns (uint); /// @notice Get timestamp when `_addr`'s lock finishes /// @param _addr User wallet address /// @return Epoch time of the lock end function locked__end(address _addr) external view returns (uint); /// @notice Record global data to checkpoint function checkpoint() external; /// @notice Deposit `_value` tokens for `_addr` and add to the lock /// @dev Anyone (even a smart contract) can deposit for someone else, but /// cannot extend their locktime and deposit for a brand new user /// @param _addr User's wallet address /// @param _value Amount to add to user's lock /// @param _deposit_token The token to be deposited. function deposit_for( address _addr, uint256 _value, address _deposit_token ) external payable; /// @notice Deposit `_value` tokens for `_addr` and add to the lock /// @dev Anyone (even a smart contract) can deposit for someone else, but /// cannot extend their locktime and deposit for a brand new user /// @dev Like `deposit_for` expect it does not require the fee. /// @param _addr User's wallet address /// @param _value Amount to add to user's lock /// @param _deposit_token The token to be deposited. /// @param _transfer_from The address from which the token will be transferred. function deposit_for_admin( address _addr, uint256 _value, address _deposit_token, address _transfer_from ) external payable; /// @notice External function for _create_lock /// @param _value Amount to deposit /// @param _unlock_time Epoch time when tokens unlock, rounded down to whole weeks /// @param _deposit_token The token to be deposited. function create_lock( uint256 _value, uint256 _unlock_time, address _deposit_token ) external payable; /// @notice Deposit `_value` additional tokens for `msg.sender` without modifying the unlock time /// @param _value Amount of tokens to deposit and add to the lock /// @param _deposit_token The token to be deposited. function increase_amount( uint256 _value, address _deposit_token ) external payable; /// @notice Extend the unlock time for `msg.sender` to `_unlock_time` /// @param _unlock_time New epoch time for unlocking function increase_unlock_time(uint256 _unlock_time) external payable; /// @notice Extend the unlock time and/or for `msg.sender` to `_unlock_time` /// @param _unlock_time New epoch time for unlocking /// @param _deposit_token The token to be deposited. function increase_amount_and_time( uint256 _value, uint256 _unlock_time, address _deposit_token ) external payable; /// @notice Withdraw all tokens for `msg.sender`. function withdraw() external payable; /// @notice Returns the voting power of an address at time `_t`. /// @param addr The address to check. /// @param _t The ts to check. /// @return The voting power of `addr` at time `_t`. function balanceOfAtT( address addr, uint256 _t ) external view returns (uint); /// @notice Returns the voting power of `addr`. /// @param addr The address to check. /// @return The voting power of `addr`. function balanceOf(address addr) external view returns (uint); /// @notice Measure voting power of `addr` at block height `_block` /// @dev Adheres to MiniMe `balanceOfAt` interface: https://github.com/Giveth/minime /// @param addr User's wallet address /// @param _block Block to calculate the voting power at /// @return Voting power function balanceOfAt( address addr, uint256 _block ) external view returns (uint); /// @notice Calculates the total voting power at time `t` in the past. /// @param t The ts in the past to check. /// @return Total voting power at some time `t` in the past. function totalSupplyAtT(uint256 t) external view returns (uint); /// @notice Calculates the current total voting power. /// @return The current total voting power. function totalSupply() external view returns (uint); /// @notice Calculate total voting power at some point in the past /// @param _block Block to calculate the total voting power at /// @return Total voting power at `_block` function totalSupplyAt(uint256 _block) external view returns (uint); /// @notice Adds `addr` as an approved deposit token. /// @param addr The token address to add. function add_deposit_token(address addr) external; /// @notice Removes `addr` as an approved deposit token. /// @param addr The token address to add. function remove_deposit_token(address addr) external; /// @notice Returns the list of currently active deposit token addresses. /// @return The list of currently active deposit token addresses. function active_deposit_tokens() external view returns (address[] memory); /// @notice Whitelist of tokens that can be deposited. /// @param tkn The token address to check. /// @return True if the token is a valid deposit token, false otherwise. function deposit_tokens(address tkn) external view returns (bool); /// @notice A historical list of all deposit token addresses. /// @return The historical list of all deposit token addresses. function historical_deposit_tokens() external view returns (address[] memory); }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// 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); }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. 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: * ```solidity * 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`, `uint256`._ * _Available since v4.9 for `string`, `bytes`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes 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 } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
contracts/network-guardian/lib/Errors.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice Raised when an attempt is made to register an already registered * contract. * * @param addr The address of the already registered contract. */ error NetworkGuardianController__AlreadyRegistered(address addr); /** * @notice Raised when an attempt is made to register an address that does not * support the `NetworkGuardian` interface. * * @param addr The invalid address. */ error NetworkGuardianController__UnsupportedInterface(address addr); /** * @notice Raised when an attempt is made to iterate over an array with a length * greater than the maximum allowed. * * @param len The length of the given array. * @param max The max allowed length. */ error NetworkGuardianController__MaxIterations(uint256 len, uint256 max); /** * @notice Raised when an attempt is made to iterate over an invalid range of an * array. */ error NetworkGuardianController__InvalidRange(); /** * @notice Raised when an attempt is made to access an item in an array at an * invalid index. */ error NetworkGuardianController__IndexOutOfBounds(); /** * @notice Raised when an attempt is made to iterate over an array with zero * elements. */ error NetworkGuardianController__ZeroLength(); /** * @notice Raised when an attempt is made to pause a contract and it fails. */ error NetworkGuardianController__PauseFailed(); /** * @notice Raised when an attempt is made to unpause a contract and it fails. */ error NetworkGuardianController__UnpauseFailed(); /** * @notice Raised when an invalid iteration count is supplied. */ error NetworkGuardianController__InvalidIterationCount();
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.sol"; import "./math/SignedMathUpgradeable.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 `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value)))); } /** * @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); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
contracts/network-guardian/lib/Array.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { NetworkGuardianController__ZeroLength, NetworkGuardianController__InvalidRange } from "./Errors.sol"; /** * @dev Start is inclusive, end is exclusive. */ struct Range { uint256 start; uint256 end; } library Array { /** * @notice Returns a list of ranges, split into `chunkSize` chunks. * * @param chunkSize The size of each chunk. * @param len The total length to be divided into chunks. * * @return An array of `Range` structs representing the valid ranges. */ function ranges( uint256 chunkSize, uint256 len ) internal pure returns (Range[] memory) { if (len <= chunkSize) { Range[] memory range = new Range[](1); range[0] = Range({ start: 0, end: len }); return range; } // Length is now known to be greater than the chunk size. uint256 mod = len % chunkSize; uint256 rounds = len / chunkSize; uint256 rangeCount = rounds; uint256 start = 0; uint256 end = chunkSize; if (mod > 0) { rangeCount++; assert(rangeCount * chunkSize > len); } Range[] memory out = new Range[](rangeCount); for (uint256 i; i < rounds; i++) { Range memory range = Range({ start: start, end: end }); out[i] = range; start = end; end = end + chunkSize; } if (mod > 0) { Range memory range = Range({ start: start, end: start + mod }); out[rounds] = range; } return out; } /** * @notice Asserts that a given range is valid. * * @param start The start index. * @param end The end index. * @param len The length of the array. * * @dev Start is inclusive, end is exclusive. * * Requirements: * - The length must be greater than zero. * - Start must not be greater than end. * - Start must not be greater than or equal to the length. * - End must not be greater than the length. */ function assertValidRange( uint256 start, uint256 end, uint256 len ) internal pure { if (len == 0) { revert NetworkGuardianController__ZeroLength(); } if (start > end || start >= len || end > len) { revert NetworkGuardianController__InvalidRange(); } } }
contracts/utils/upgradeable/RecoverableUpgradeable.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; /** * @title RecoverableUpgradeable * * @notice Allows the inheriting contract to recover H1 and HRC-20s. * * @dev Note that this contract only exposes functions with internal visibility * and does not implement any access control or reentrancy guards. It is up to * the inheriting contract to implement these details. * * @dev This contract does not contain any state variables. Even so, a very * small gap has been provided to accommodate the addition of state variables * should the need arise. */ abstract contract RecoverableUpgradeable is Initializable { /* TYPE DECLARATIONS ==================================================*/ using SafeERC20Upgradeable for IERC20Upgradeable; /* EVENTS ==================================================*/ /** * @notice Emitted when H1 is recovered from the contract. Emits the address * to which the tokens were sent and the amount of tokens that were sent. * * @param to The address to which the tokens were sent. * @param amount The amount of tokens that were sent. */ event H1Recovered(address indexed to, uint256 amount); /** * @notice Emitted when an HRC-20 is recovered from the contract. Emits the * address of the token that was recovered, the address to which the tokens * were sent, and the amount of tokens that were sent. * * @param token The address of the token recovered. * @param to The address to which the tokens were sent. * @param amount The amount of tokens that were sent. */ event HRC20Recovered( address indexed token, address indexed to, uint256 amount ); /* ERRORS ==================================================*/ /** * @dev Error raised when trying to recover funds to an invalid address. */ error Recoverable__InvalidAddress(); /** * @dev Error raised when the recovery of H1 fails. */ error Recoverable__H1RecoveryFailed(); /** * @dev Error raised when trying to recover zero tokens. */ error Recoverable__ZeroAmountProvided(); /** * @dev Error raised when trying to recover an amount of H1 that exceeds * the contract's balance. * * @param amount The amount attempted to be sent. * @param available The amount available to send. */ error Recoverable__InsufficientH1(uint256 amount, uint256 available); /** * @dev Error raised when trying to recover an amount of an HRC-20 that * exceeds the contract's balance. * @param token The address of the token. * @param amount The amount attempted to be sent. * @param available The amount available to send. */ error Recoverable__InsufficientHRC20( address token, uint256 amount, uint256 available ); /* FUNCTIONS ==================================================*/ /* Internal ========================================*/ /** * @notice Initializes the `RecoverableUpgradeable` contract. */ function __Recoverable_init() internal onlyInitializing { __Recoverable_init_unchained(); } /** * @dev see {RecoverableUpgradeable-__Recoverable_init} * @dev Although this function contains no init logic, it is included * by convention. See the following for further information: * https://docs.openzeppelin.com/contracts/5.x/upgradeable#multiple-inheritance */ function __Recoverable_init_unchained() internal onlyInitializing {} /** * @notice Allows for the recovery of an amount of H1 to a given address. * @param to The address to which the H1 will be sent. * @param amount The amount of H1 to send. * * @dev May revert with `Recoverable__InvalidAddress`. * @dev May revert with `Recoverable__InsufficientH1`. * @dev May revert with `Recoverable__H1RecoveryFailed`. * @dev May emit an `H1Recovered` event. */ function _recoverH1(address payable to, uint256 amount) internal { if (to == address(0)) { revert Recoverable__InvalidAddress(); } if (amount == 0) { revert Recoverable__ZeroAmountProvided(); } uint256 bal = address(this).balance; if (amount > bal) { revert Recoverable__InsufficientH1(amount, bal); } (bool success, ) = to.call{ value: amount }(""); if (!success) { revert Recoverable__H1RecoveryFailed(); } emit H1Recovered(to, amount); } /** * @notice Allows for the recovery of an amount of an HRC-20 token to a * given address. * * @param token The address of the HRC-20 token to recover. * @param to The address to which the tokens will be sent. * @param amount The amount of tokens to send. * * @dev May revert with `Recoverable__InvalidAddress`. * @dev May revert with `Recoverable__InsufficientHRC20`. * @dev May revert with `SafeERC20: low-level call failed`. * @dev May revert with `SafeERC20: ERC20 operation did not succeed`. * @dev May emit an `HRC20Recovered` event. */ function _recoverHRC20(address token, address to, uint256 amount) internal { if (to == address(0)) { revert Recoverable__InvalidAddress(); } if (amount == 0) { revert Recoverable__ZeroAmountProvided(); } uint256 bal = IERC20Upgradeable(token).balanceOf(address(this)); if (amount > bal) { revert Recoverable__InsufficientHRC20(token, amount, bal); } IERC20Upgradeable(token).safeTransfer(to, amount); emit HRC20Recovered(token, to, amount); } /* GAP ==================================================*/ /** * @dev This empty reserved space allows new state variables to be added * without compromising the storage compatibility with existing deployments. * * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps * * As new variables are added, be sure to reduce the gap as required. * For e.g., if the starting `__gap` is `25` and a new variable is added * (256 bits in size or part thereof), the gap must now be reduced to `24`. */ uint256[25] private __gap; }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.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); }
@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20Upgradeable.sol";
@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/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; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ 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)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ 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"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ 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"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) { // 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 cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token)); } }
contracts/tokens/interfaces/IWH1.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; /** * @title IWH1 * * @author The Haven1 Development Team * * @dev The interface for the WH1 contract. */ interface IWH1 { /** * @notice Emitted when an approval is made. * * @param src The source address. * @param guy The approved address. * @param wad The approval amount. */ event Approval(address indexed src, address indexed guy, uint256 wad); /** * @notice Emitted when WH1 is transferred. * * @param src The source address. * @param dst The destination address. * @param wad The transfer amount. */ event Transfer(address indexed src, address indexed dst, uint256 wad); /** * @notice Emitted when H1 is deposited into the contract. * * @param dst The destination address. * @param wad The transfer amount. */ event Deposit(address indexed dst, uint256 wad); /** * @notice Emitted when H1 is withdrawn from the contract. * * @param src The source address. * @param wad The transfer amount. */ event Withdrawal(address indexed src, uint256 wad); /** * @notice Deposits an amount of H1 into the contract and mints an * equivalent amount of wH1 to the depositor. * * @dev Requirements: * - The contract must not be paused. * - The caller must not be blacklisted. * * Emits a `Deposit` event. */ function deposit() external payable; /** * Returns whether a spender has the maximum allowance over the spender's * wH1. * * @param owner The owner's address. * @param spender The spender's address. * * @return True if the spender has the maximum allowance over the spender's * wH1, false otherwise. */ function hasMaxAllowance( address owner, address spender ) external view returns (bool); /** * @notice Withdraws an amount of H1 from the contract. * * @param wad The amount to withdraw. * * @dev Requirements: * - The contract must not be paused. * - The caller must not be blacklisted. * - The amount withdrawn must not exceed the caller's balance. * * Emits a `Withdrawal` event. */ function withdraw(uint256 wad) external; /** * @notice Returns the total amount of tokens in existence. * * @return The total amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @notice Approves an address to spend an amount of wH1 on behalf of the * caller. * * @param guy The address to approve. * @param wad The amount to approve. * * @return Will always return `true` if the call does not revert. * * @dev Requirements: * - The contract must not be paused. * - The caller must not be blacklisted. * - The address being approved must not be blacklisted. * * Emits an `Approval` event. */ function approve(address guy, uint256 wad) external returns (bool); /** * @notice Atomically increases the allowance granted to `guy` by the caller. * * @param guy The address for which the allowance is increased. * @param amt The allowance to grant. * * @dev Requirements: * * - The contract must not be paused. * - The caller must not be blacklisted. * - The address whose allownce is being increased must not be blacklisted. * * Emits an `Approval` event. */ function increaseAllowance( address guy, uint256 amt ) external returns (bool); /** * @notice Atomically decreases the allowance granted to `guy` by the caller. * * @param guy The address for which the allowance is decreased. * @param amt The allowance to grant. * * @dev Requirements: * * - The contract must not be paused. * - The caller must not be blacklisted. * - The address whose allownce is being decreased must not be blacklisted. * - The address whose allowance is being decreased must have allowance * for the caller of at least `amt`. * * Emits an `Approval` event. */ function decreaseAllowance( address guy, uint256 amt ) external returns (bool); /** * @notice Transfers an amount of wH1 from the caller to the destination * address. * * @param dst The destination address. * @param wad The amount to transfer. * * @return Will always return `true` if the call does not revert. * * @dev Requirements: * - The contract must not be paused. * - The caller must not be blacklisted. * - The destination address must not be blacklisted. * - The transfer amount must not exceed the caller's balance. * * Emits an `Transfer` event. */ function transfer(address dst, uint256 wad) external returns (bool); /** * @notice Transfers an amount of wH1 from the source address to the * destination address. * * @param src The source address. * @param dst The destination address. * @param wad The amount to transfer. * * @return Will always return `true` if the call does not revert. * * @dev Requirements: * - The contract must not be paused. * - The caller must not be blacklisted. * - The source address must not be blacklisted. * - The destination address must not be blacklisted. * - The transfer amount must not exceed the source's balance. * - If the source address is not the caller, then the caller's allowance * over the source address' tokens must not exceed the transfer amount. * * Emits an `Transfer` event. */ function transferFrom( address src, address dst, uint256 wad ) external returns (bool); /** * @notice Allows an admin to ransfers an amount of wH1 from the source * address to the destination address. * * @param src The source address. * @param dst The destination address. * @param wad The amount to transfer. * * @return Will always return `true` if the call does not revert. * * @dev Requirements: * - The transfer amount must not exceed the source's balance. * * Emits an `Transfer` event. */ function transferFromAdmin( address src, address dst, uint256 wad ) external returns (bool); /** * @notice Returns the token's name. * @return The token's name. */ function name() external pure returns (string memory); /** * @notice Returns the token's symbol. * @return The token's symbol. */ function symbol() external pure returns (string memory); /** * @notice Returns the token's decimals. * @return The token's decimals. */ function decimals() external pure returns (uint8); /** * @notice Returns the wH1 balance of the given address. * * @param guy The address to check. * * @return The balance of the given address. */ function balanceOf(address guy) external view returns (uint256); /** * @notice Returns the spender's allowance of the owner's tokens. * * @param owner The owner's address. * @param spender The spender's address. */ function allowance( address owner, address spender ) external view returns (uint256); /** * @notice Allows for the recovery of an amount of an HRC-20 token to a * given address. * * @param token The address of the HRC-20 token to recover. * @param to The address to which the tokens will be sent. * @param amount The amount of tokens to send. * * @dev Requirements: * - The caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The contract must not be paused. * - The to address must not be the zero address. * - The contract must have at least `amount` of `token` balance. */ function recoverHRC20(address token, address to, uint256 amount) external; /** * @notice Allows for the recovery of this contract's balance of an HRC-20 * token to a given address. * * @param token The address of the HRC-20 token to recover. * @param to The address to which the tokens will be sent. * * @dev Requirements: * - The caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The contract must not be paused. * - The to address must not be the zero address. */ function recoverAllHRC20(address token, address to) external; /** * @notice Blacklists an address. * * @param addr The address to blacklist. * * @dev Requirements: * - The caller must have the role: `OPERATOR_ROLE`. * - The contract must not be paused. * - The address must not be the zero address. * - The address must not already be blacklisted. * * Emits a `Blacklisted` event. */ function addToBlacklist(address addr) external; /** * @notice Removes an address' blacklist. * * @param addr The address for which the blacklist will be removed. * * @dev Requirements: * - The caller must have the role: `OPERATOR_ROLE`. * - The contract must not be paused. * - The address must not be the zero address. * - The address must be blacklisted. * * Emits a `BlacklistRemoved` event. */ function removeFromBlacklist(address addr) external; }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol) pragma solidity ^0.8.0; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.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) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 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 256, 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 << 3) < value ? 1 : 0); } } }
contracts/utils/Address.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @notice Raised when an attempt is made to use the zero address in a * situation that is not allowed. */ error Address__ZeroAddress(); /** * @title Address * * @author The Haven1 Development Team * * @dev A library that contains collection of functions related to addresses */ library Address { /** * @notice Asserts that the given address is not the zero address. * * @param addr The address to check. */ function assertNotZero(address addr) internal pure { if (addr == address(0)) { revert Address__ZeroAddress(); } } }
@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol
// 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); }
contracts/governance/interfaces/IFeeDistributor.sol
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.24; import "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol"; import "./IVotingEscrow.sol"; /** * @title Fee Distributor * @author Balancer Labs. Original version: * https://github.com/balancer/balancer-v2-monorepo/blob/master/pkg * /liquidity-mining/contracts/fee-distribution/FeeDistributor.sol * * @notice Distributes any tokens transferred to the contract (e.g. Protocol fees) * among veH1 holders proportionally based on a snapshot of the week at which the * tokens are sent to the FeeDistributor contract. * * @dev Supports distributing arbitrarily many different tokens. In order to * start distributing a new token to veH1 holders call `depositToken`. */ interface IFeeDistributor { event TokenCheckpointed( IERC20Upgradeable indexed token, uint256 amount, uint256 lastCheckpointTimestamp ); event TokensClaimed( address indexed user, IERC20Upgradeable indexed token, uint256 amount, uint256 userTokenTimeCursor, bool indexed compounded ); event TokenWithdrawn( IERC20Upgradeable indexed token, uint256 amount, address indexed recipient ); event TokenClaimingEnabled(IERC20Upgradeable indexed token, bool enabled); event Whitelisted(address indexed addr, bool status); /** * @notice Returns the VotingEscrow (veH1) token contract */ function getVotingEscrow() external view returns (IVotingEscrow); /** * @notice Returns the time when fee distribution starts. */ function getStartTime() external view returns (uint256); /** * @notice Returns the global time cursor representing the most earliest * uncheckpointed week. */ function getTimeCursor() external view returns (uint256); /** * @notice Returns the user-level start time representing the first week * they're eligible to claim tokens. * @param user - The address of the user to query. */ function getUserStartTime(address user) external view returns (uint256); /** * @notice Returns the user-level time cursor representing the most earliest * uncheckpointed week. * @param user - The address of the user to query. */ function getUserTimeCursor(address user) external view returns (uint256); /** * @notice Returns the user-level last checkpointed epoch. * @param user - The address of the user to query. */ function getUserLastEpochCheckpointed( address user ) external view returns (uint256); /** * @notice True if the given token can be claimed, false otherwise. * @param token - The ERC20 token address to query. */ function canTokenBeClaimed( IERC20Upgradeable token ) external view returns (bool); /** * @notice Returns the token-level start time representing the timestamp * users could start claiming this token * @param token - The ERC20 token address to query. */ function getTokenStartTime( IERC20Upgradeable token ) external view returns (uint256); /** * @notice Returns the token-level time cursor storing the timestamp at up * to which tokens have been distributed. * @param token - The ERC20 token address to query. */ function getTokenTimeCursor( IERC20Upgradeable token ) external view returns (uint256); /** * @notice Returns the token-level cached balance. * @param token - The ERC20 token address to query. */ function getTokenCachedBalance( IERC20Upgradeable token ) external view returns (uint256); /** * @notice Returns the user-level time cursor storing the timestamp of the * latest token distribution claimed. * @param user - The address of the user to query. * @param token - The ERC20 token address to query. */ function getUserTokenTimeCursor( address user, IERC20Upgradeable token ) external view returns (uint256); /** * @notice Returns the user's cached balance of veH1 as of the provided * timestamp. * * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return * correct values. This function requires `user` to have been checkpointed * past `timestamp` so that their balance is cached. * * @param user - The address of the user of which to read the cached balance * of. * * @param timestamp - The timestamp at which to read the `user`'s cached * balance at. */ function getUserBalanceAtTimestamp( address user, uint256 timestamp ) external view returns (uint256); /** * @notice Returns the cached total supply of veH1 as of the provided * timestamp. * * @dev Only timestamps which fall on Thursdays 00:00:00 UTC will return * correct values. This function requires the contract to have been * checkpointed past `timestamp` so that the supply is cached. * * @param timestamp - The timestamp at which to read the cached total supply * at. */ function getTotalSupplyAtTimestamp( uint256 timestamp ) external view returns (uint256); /** * @notice Returns the amount of `token` which the FeeDistributor received * in the week beginning at `timestamp`. * * @param token - The ERC20 token address to query. * * @param timestamp - The timestamp corresponding to the beginning of the * week of interest. */ function getTokensDistributedInWeek( IERC20Upgradeable token, uint256 timestamp ) external view returns (uint256); // Depositing /** * @notice Deposits tokens to be distributed in the current week. * @dev Sending tokens directly to the FeeDistributor instead of using * `depositToken` may result in tokens being retroactively distributed to * past weeks, or for the distribution to carry over to future weeks. * * If for some reason `depositToken` cannot be called, in order to ensure * that all tokens are correctly distributed manually call `checkpointToken` * before and after the token transfer. * * @param token - The ERC20 token address to distribute. * @param amount - The amount of tokens to deposit. */ function depositToken(IERC20Upgradeable token, uint256 amount) external; /** * @notice Deposits tokens to be distributed in the current week. * * @dev A version of `depositToken` which supports depositing multiple * `tokens` at once. See `depositToken` for more details. * * @param tokens - An array of ERC20 token addresses to distribute. * @param amounts - An array of token amounts to deposit. */ function depositTokens( IERC20Upgradeable[] calldata tokens, uint256[] calldata amounts ) external; // Checkpointing /** * @notice Caches the total supply of veH1 at the beginning of each week. * This function will be called automatically before claiming tokens to * ensure the contract is properly updated. */ function checkpoint() external; /** * @notice Caches the user's balance of veH1 at the beginning of each week. * This function will be called automatically before claiming tokens to * ensure the contract is properly updated. * @param user - The address of the user to be checkpointed. */ function checkpointUser(address user) external; /** * @notice Assigns any newly-received tokens held by the FeeDistributor to * weekly distributions. * * @dev Any `token` balance held by the FeeDistributor above that which is * returned by `getTokenLastBalance` will be distributed evenly across the * time period since `token` was last checkpointed. * * This function will be called automatically before claiming tokens to * ensure the contract is properly updated. * * @param token - The ERC20 token address to be checkpointed. */ function checkpointToken(IERC20Upgradeable token) external; /** * @notice Assigns any newly-received tokens held by the FeeDistributor to * weekly distributions. * * @dev A version of `checkpointToken` which supports checkpointing multiple * tokens. * * See `checkpointToken` for more details. * * @param tokens - An array of ERC20 token addresses to be checkpointed. */ function checkpointTokens(IERC20Upgradeable[] calldata tokens) external; // Claiming /** * @notice Claims all pending distributions of the provided token for a user. * * @dev It's not necessary to explicitly checkpoint before calling this * function, it will ensure the FeeDistributor is up to date before * calculating the amount of tokens to be claimed. * * @param user - The user on behalf of which to claim. * @param token - The ERC20 token address to be claimed. * @return The amount of `token` sent to `user` as a result of claiming. */ function claimToken( address user, IERC20Upgradeable token ) external payable returns (uint256); /** * @notice Claims a number of tokens on behalf of a user. * @dev A version of `claimToken` which supports claiming multiple `tokens` * on behalf of `user`. * * See `claimToken` for more details. * * @param user - The user on behalf of which to claim. * @param tokens - An array of ERC20 token addresses to be claimed. * * @return An array of the amounts of each token in `tokens` sent to `user` * as a result of claiming. */ function claimTokens( address user, IERC20Upgradeable[] calldata tokens ) external payable returns (uint256[] memory); // Governance /** * @notice Withdraws the specified `amount` of the `token` from the contract * to the `recipient`. Can be called only by the Haven1 Association. * * @param token - The token to withdraw. * @param amount - The amount to withdraw. * @param recipient - The address to transfer the tokens to. */ function withdrawToken( IERC20Upgradeable token, uint256 amount, address recipient ) external; /** * @notice Enables or disables claiming of the given token. Can be called * only by the Haven1 Association. * * @param token - The token to enable or disable claiming. * @param enable - True if the token can be claimed, false otherwise. */ function enableTokenClaiming(IERC20Upgradeable token, bool enable) external; /** * @notice Like `claimToken` but rather than sending the reward token to the * user, it will compound the reward token in the `VotingEscrow` contract. * Does not incur a Native Application Fee. * * @param user The user on behalf of which to claim. * @param token The ERC20 token address to be claimed. * * @return The amount of `token` compounded into the `user`'s ve balance. * * @dev Requirements: * - The token being claimed is a valid deposit token on the * `VotingEscrow` contract. * - The user must have approved this `FeeDistributor` contract to * deposit on their behalf. * - The user must have have an active lock. * * If any of these statements are not true, the transaction will revert. */ function claimTokenAndCompound( address user, IERC20Upgradeable token ) external returns (uint256); /** * @notice Like `claimTokens`, but rather than sending the reward tokens to * the user, it will compound the reward token in the `VotingEscrow` * contract. Does not incur a Native Application Fee. * * @param user The user on behalf of which to claim. * @param tokens An array of ERC20 token addresses to be claimed. * * @return An array of the amounts of each token in `tokens` sent to `user` * as a result of claiming. * * @dev Requirements: * - The token being claimed is a valid deposit token on the * `VotingEscrow` contract. * - The user must have approved this `FeeDistributor` contract to * deposit on their behalf. * - The user must have have an active lock. * * If any of these statements are not true, the transaction will revert. */ function claimTokensAndCompound( address user, IERC20Upgradeable[] calldata tokens ) external returns (uint256[] memory); /** * @notice Sets the whitelist status for a given address. * * @param addr The address for which the whitelist status is set. * @param status The status to set. * * @dev Requirements: * - Only callable by an account with the role: `DEFAULT_ADMIN_ROLE`. * * Emits a `Whitelisted` event. */ function setWhitelisted(address addr, bool status) external; /** * @notice Returns whether a given address is whitelisted to claim on * behalf of a user. * * @param addr The address to check. * * @return True if the address can claim on behalf of the user, false * otherwise. */ function whitelisted(address addr) external view returns (bool); }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(account), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _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; }
contracts/network-guardian/interfaces/INetworkGuardian.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title INetworkGuardian * * @author The Haven1 Development Team. * * @notice Interface for the `NetworkGuardian`. */ interface INetworkGuardian { /** * @dev Emitted when the pause is triggered by `account`. * * @param account The address that triggered the pause. */ event GuardianPaused(address account); /** * @dev Emitted when the pause is lifted by `account`. * * @param account The address that lifted the pause. */ event GuardianUnpaused(address account); /** * @dev Emitted when the Association address is updated. * * @param prev The previous Association address. * @param curr The new Association address. */ event AssociationUpdated(address indexed prev, address indexed curr); /** * @dev Emitted when the Controller address is updated. * * @param prev The previous Controller address. * @param curr The new Controller address. */ event ControllerUpdated(address indexed prev, address indexed curr); /** * @notice Registers this contract with the Network Guardian Controller. * * @dev Requirements: * - Must not already be registered. * * As this contract is upgradeable, we cannot include registration as * part of contract initialization. Before initialization, there is no * appropriate way to permission the call or for the Network Guardian * Controller to confirm interface support. * * No event is emitted here. Rather, it is standardized in the Network * Guardian Controller. See {NetworkGuardianController-register}. */ function register() external; /** * @notice Allows a Network Guardian to pause operation of this contract. * * @dev Requirements: * - Caller must have the role: `NETWORK_GUARDIAN`. * - The contract must not already be paused. * * Is named `guardianPause` to leave the `pause` namespace available * for inheriting contracts. * */ function guardianPause() external; /** * @notice Allows the admin to resume the operation of this contract. * * @dev Requirements: * - Caller must have the role: `NETWORK_GUARDIAN`. * - The contract must already be paused. * * Takes `unpause` namespace and cannot be overridden. */ function guardianUnpause() external; /** * @notice Sets the association address and updates permissions. * * @param addr The address to set. * * @dev Requirements: * - Caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The address supplied must not be the zero address. */ function setAssociation(address addr) external; /** * @notice Sets the Network Guardian Controller address and updates * permissions. * * @param addr The address to set. * * @dev Requirements: * - Caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The address supplied must not be the zero address. */ function setController(address addr) external; /** * @dev See {IERC165-supportsInterface}. * * @dev Must be overridden by the inheriting contract. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); /** * @notice Returns the `NetworkGuardianController` address. * * @return The `NetworkGuardianController` address. */ function controller() external view returns (address); /** * @notice Returns the Haven1 Association address. * * @return The Haven1 Association address. */ function association() external view returns (address); /** * @dev Returns true if the contract is Guardian paused, and false otherwise. * * @return True if the contract is Guardian paused, and false otherwise. */ function guardianPaused() external view returns (bool); }
contracts/fee/interfaces/IReceiver.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; /** * @title IReceiver * * @author The Haven1 Development Team */ interface IReceiver { /** * @notice Emitted when H1 is received into the contract. * * @param from The address that sent the H1. * @param amount The amount of H1 that was received. */ event H1Received(address indexed from, uint256 amount); /** * Allows H1 to be deposited into the contract. */ function deposit() external payable; }
@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/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. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ 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]. * * CAUTION: See Security Considerations above. */ 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); }
contracts/network-guardian/NetworkGuardian.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import { ERC165Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; import { ContextUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import { INetworkGuardianController } from "./interfaces/INetworkGuardianController.sol"; import { INetworkGuardian } from "./interfaces/INetworkGuardian.sol"; import { Address } from "../utils/Address.sol"; /** * @title NetworkGuardian * * @author The Haven1 Development Team * * @notice An abstract contract that: * - Establishes the Network Guardian role (`NETWORK_GUARDIAN`). Will only * be assigned to the Network Guardian Controller and the Haven1 * Association. This role is responsible for pausing and unpausing the * inheriting contract. * * - Establishes the Operator role (`OPERATOR_ROLE`). On deployment, it will * be assigned to the Haven1 Association. This role is responsible for * executing restricted actions that do not require approval by the admin. * * - Standardizes the registration of the inheriting contract with the * Network Guardian Controller. * * - Standardizes upgrading the inheriting contract. * * - Exposes protected APIs for pausing and unpausing the contract. These * actions are callable only by an account with the `NETWORK_GUARDIAN` * role. * * - Declares the Haven1 Association address for use in all inheriting * contracts. * * @dev Must be implemented by all native and developed contracts. Because of * this, this contract can be thought of as a "base" upon which all Haven1 * contracts are built. Standardizing aspects such as the assignment of the * Haven1 Association address and the `OPERATOR_ROLE` will greatly reduce * boilerplate in the inheriting contracts. * * Inheriting contracts __must__ add the `whenNotGuardianPaused` modifier to all * public or external functions that modify state. * * Note that inheriting contracts will also gain access to: * - Initializable; * - UUPSUpgradeable; * - ContextUpgradeable; * - ERC165Upgradeable; and * - AccessControlUpgradeable. * * Inheriting contracts that are not written by the Haven1 Association * __must not__ assign the following roles to any address: * - `DEFAULT_ADMIN_ROLE`; * - `OPERATOR_ROLE`; or * - `NETWORK_GUARDIAN`. * * Inheriting contracts must override `supportsInterface`. * * Typically, the last contract in the inheritance chain should call * `__NetworkGuardian_init`. */ abstract contract NetworkGuardian is Initializable, UUPSUpgradeable, ContextUpgradeable, ERC165Upgradeable, AccessControlUpgradeable, INetworkGuardian { /* TYPE DECLARATIONS ==================================================*/ using Address for address; /* STATE ==================================================*/ /** * @notice The Network Guardian role. * * @dev Permissioned to pause and unpause the operation of the inheriting * contract. Assigned only to the Haven1 Association and the Network * Guardian Controller. */ bytes32 public constant NETWORK_GUARDIAN = keccak256("NETWORK_GUARDIAN"); /** * @notice The Network Operator role. * * @dev Responsible for executing restricted actions that do not require * approval by the admin. */ bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); /** * @notice The Haven1 Association address. */ address private _association; /** * @notice The `NetworkGuardianController` address. */ INetworkGuardianController private _controller; /** * @notice Whether this contract has been paused by a Network Guardian. */ bool private _guardianPaused; /* ERRORS ==================================================*/ /** * @notice Raised when an attempt is made to register an already registered * contract. */ error NetworkGuardian__AlreadyRegistered(); /** * @notice Raised when an attempt is made to access a feature that requres * the contract to be active, but it is paused. */ error NetworkGuardian__Paused(); /** * @notice Raised when an attempt is made to access a feature that requres * the contract to be paused, but it is active. */ error NetworkGuardian__NotPaused(); /* MODIFIERS ==================================================*/ /** * @dev Modifier to make a function callable only when the contract is not * Guardian paused. * * Requirements: * * - The contract must not be Guardian paused. */ modifier whenNotGuardianPaused() { _requireNotGuardianPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is * Guardian paused. * * Requirements: * * - The contract must be Guardian paused. */ modifier whenGuardianPaused() { _requireGuardianPaused(); _; } /* FUNCTIONS ==================================================*/ /* Init ========================================*/ /** * @notice Initializes the `NetworkGuardian` contract. * * @param association_ The Haven1 Association address. * @param controller_ The Network Guardian Controller address. */ function __NetworkGuardian_init( address association_, address controller_ ) internal onlyInitializing { __AccessControl_init(); __Context_init(); __ERC165_init(); __UUPSUpgradeable_init(); __NetworkGuardian_init_unchained(association_, controller_); } /** * @param association_ The Haven1 Association address. * @param controller_ The Network Guardian Controller address. * * @dev Requirements: * - The provided addresses must not be the zero address. * * @dev For more information on the "unchained" method and multiple * inheritance see: * https://docs.openzeppelin.com/contracts/4.x/upgradeable#multiple-inheritance */ function __NetworkGuardian_init_unchained( address association_, address controller_ ) internal onlyInitializing { association_.assertNotZero(); controller_.assertNotZero(); _association = association_; _controller = INetworkGuardianController(controller_); _grantRole(DEFAULT_ADMIN_ROLE, association_); _grantRole(OPERATOR_ROLE, association_); _grantRole(NETWORK_GUARDIAN, association_); _grantRole(NETWORK_GUARDIAN, controller_); _guardianPaused = false; } /* External ========================================*/ /** * @inheritdoc INetworkGuardian */ function register() external { _controller.register(address(this)); } /** * @inheritdoc INetworkGuardian */ function guardianPause() external onlyRole(NETWORK_GUARDIAN) { _guardianPause(); } /** * @inheritdoc INetworkGuardian */ function guardianUnpause() external onlyRole(NETWORK_GUARDIAN) { _guardianUnpause(); } /** * @inheritdoc INetworkGuardian */ function setAssociation( address addr ) external onlyRole(DEFAULT_ADMIN_ROLE) { addr.assertNotZero(); if (_association == addr) return; _grantRole(DEFAULT_ADMIN_ROLE, addr); _grantRole(OPERATOR_ROLE, addr); _grantRole(NETWORK_GUARDIAN, addr); _revokeRole(NETWORK_GUARDIAN, _association); _revokeRole(OPERATOR_ROLE, _association); _revokeRole(DEFAULT_ADMIN_ROLE, _association); address prev = _association; _association = addr; emit AssociationUpdated(prev, addr); } /** * @inheritdoc INetworkGuardian */ function setController(address addr) external onlyRole(DEFAULT_ADMIN_ROLE) { addr.assertNotZero(); _revokeRole(NETWORK_GUARDIAN, address(_controller)); _grantRole(NETWORK_GUARDIAN, addr); address prev = address(_controller); _controller = INetworkGuardianController(addr); emit ControllerUpdated(prev, addr); } /* Public ========================================*/ /** * @inheritdoc INetworkGuardian */ function supportsInterface( bytes4 interfaceId ) public view virtual override(AccessControlUpgradeable, ERC165Upgradeable, INetworkGuardian) returns (bool) { return interfaceId == type(INetworkGuardian).interfaceId || super.supportsInterface(interfaceId); } /** * @inheritdoc INetworkGuardian */ function controller() public view returns (address) { return address(_controller); } /** * @inheritdoc INetworkGuardian */ function association() public view returns (address) { return _association; } /** * @inheritdoc INetworkGuardian */ function guardianPaused() public view returns (bool) { return _guardianPaused; } /* Internal ========================================*/ /** * @notice This function is overridden to protect the contract by only * allowing the admin to upgrade it. * * @param newImplementation new implementation address. */ function _authorizeUpgrade( address newImplementation ) internal override onlyRole(DEFAULT_ADMIN_ROLE) {} /** * @dev Will revert if the contract is paused. */ function _requireNotGuardianPaused() internal view { if (guardianPaused()) { revert NetworkGuardian__Paused(); } } /** * @dev Will revert if the contract is not paused. */ function _requireGuardianPaused() internal view { if (!guardianPaused()) { revert NetworkGuardian__NotPaused(); } } /* Private ========================================*/ /** * @dev Pauses the contract. * * Requirements: * * - The contract must not be paused. */ function _guardianPause() private whenNotGuardianPaused { _guardianPaused = true; emit GuardianPaused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _guardianUnpause() private whenGuardianPaused { _guardianPaused = false; emit GuardianUnpaused(_msgSender()); } /* GAP ==================================================*/ /** * @dev This empty reserved space allows new state variables to be added * without compromising the storage compatibility with existing deployments. * * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps * * As new variables are added, be sure to reduce the gap as required. * For e.g., if the starting `__gap` is `50` and a new variable is added * (256 bits in size or part thereof), the gap must now be reduced to `49`. */ uint256[50] private __gap; }
contracts/fee/interfaces/IDistributor.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; /** * @title IDistributor * * @author The Haven1 Development Team */ interface IDistributor { /** * @notice Emitted when a reward distribution occurred. * * @param to The address of the recipient. * @param token The address of the token that was distributed. * @param amount The amount that was distributed. */ event RewardsDistributed( address indexed to, address indexed token, uint256 amount ); /** * @dev Distributes tokens or assets according to the implemented logic. */ function distribute() external; }
contracts/fee/interfaces/IFeeDistributorChannel.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import { IDistributor } from "./IDistributor.sol"; import { IReceiver } from "./IReceiver.sol"; /** * @title IFeeDistributorChannel * * @author The Haven1 Development Team * * @dev The interface for the FeeDistributorChannel contract. */ interface IFeeDistributorChannel is IDistributor, IReceiver { /** * @notice Emitted when the Fee Distributor contract address is updated. * * @param prev The previous address. * @param curr The current address. */ event FeeDistributorUpdated(address indexed prev, address indexed curr); /** * @notice Emitted when the Wrapped H1 contract address is updated. * * @param prev The previous address. * @param curr The current address. */ event WH1Updated(address indexed prev, address indexed curr); /** * @notice Allows H1 to be deposited into the contract. * * Emits an `H1Received` event. */ function deposit() external payable override(IReceiver); /** * @notice Distributes all accrued rewards to the `FeeDistributor` contract * in the form of WH1 tokens. * * @dev Requirements: * - Only callable by an account with the role: `OPERATOR_ROLE`. * * Emits a `RewardsDistributed` event. */ function distribute() external override(IDistributor); /** * @notice Distributes an amount of the accrued rewards to the Fee Distributor * contract in the form of WH1 tokens. * * @param amt The amount to distribute. * * @dev Requirements: * - Only callable by an account with the role: `OPERATOR_ROLE`. * - The amount to distribute must be less than, or equal to, the amount * of H1 stored in the contract. * * Emits a `RewardsDistributed` event. */ function distributePartial(uint256 amt) external; /** * @notice Allows the admin to recover HRC20 tokens from this contract. * * @param token The token to recover. * @param to The recipient of the recovered tokens. * @param amount The amount of tokens to recover. * * @dev Requirements: * - Only callable by an account with the role `DEFAULT_ADMIN_ROLE`. * * Emits an `HRC20Recovered` event. */ function recoverHRC20(address token, address to, uint256 amount) external; /** * @notice Updates the `FeeDistributor` contract address. * * @param addr The new contract address. * * @dev Requirements: * - Only callable by an account with the role `DEFAULT_ADMIN_ROLE`. * * Emits a `FeeDistributorUpdated` event. */ function setFeeDistributor(address addr) external; /** * @notice Updates the `WH1` contract address. * * @param addr The new contract address. * * @dev Requirements: * - Only callable by an account with the role `DEFAULT_ADMIN_ROLE`. * * Emits a `FeeDistributorUpdated` event. */ function setWH1(address addr) external; /** * @notice Returns the address of the `FeeDistributor` contract. * * @return The `FeeDistributor` contract address. */ function feeDistributor() external view returns (address); /** * @notice Returns the address of the `WH1` contract. * * @return The `WH1` contract address. */ function WH1() external view returns (address); /** * @notice Returns the timestamp of the last distribution. * * @return The timestamp of the last distribution. */ function lastDistribution() external view returns (uint256); }
contracts/network-guardian/interfaces/INetworkGuardianController.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "./INetworkGuardian.sol"; import { Range } from "../lib/Array.sol"; /** * @title INetworkGuardianController * * @author The Haven1 Development Team. * * @notice Interface for the `NetworkGuardianController`. */ interface INetworkGuardianController { /* EVENTS ==================================================*/ /** * @notice Emitted when a contract is registered with this contract. * * @param addr The newly registered contract. */ event Registered(address indexed addr); /** * @notice Emitted when a contract is paused. * * @param paused The contract that was paused. * @param pausedBy The Network Guardian that initiated the pause. */ event Paused(address indexed paused, address indexed pausedBy); /** * @notice Emitted when a contract is unpaused. * * @param unpaused The contract that was paused. * @param unpausedBy The Network Guardian that initiated the pause. */ event Unpaused(address indexed unpaused, address indexed unpausedBy); /** * @notice Emitted when an attempt to pause a contract fails. * * @param addr The address of the contract that was not paused. */ event PauseFailed(address indexed addr); /** * @notice Emitted when an attempt to un;pause a contract fails. * * @param addr The address of the contract that was not unpaused. */ event UnpauseFailed(address indexed addr); /** * @notice Emitted when the Haven1 Association address is updated. * * @param prev The previous address. * @param curr The new address. */ event AssociationUpdated(address indexed prev, address indexed curr); /** * @notice Emitted when the maximum iteration count is updated. * * @param prev The previous iteration count. * @param curr The new iteration count. */ event MaxItersUpdated(uint256 prev, uint256 curr); /* FUNCTIONS ==================================================*/ /** @notice Registers a contract with this contract. * * @param addr The address to register. * * @dev Requirements: * - The contract address must not be the zero address. * - The contract address must not already be registered. * - The contract must support the `NetworkGuardian` interface. * * Emits a `Registered` event. */ function register(address addr) external; /** * @notice Allows a Network Guardian to pause the operation of a contract. * * @param addr The address of the contract to pause. * @param safe Whether the pause should be called safely. * * @dev Requirements: * - The caller must have the role: `NETWORK_GUARDIAN`. * - The contract must support the `NetworkGuardian` interface. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must not already be paused. * * Emits a `Paused` event. */ function pause(INetworkGuardian addr, bool safe) external; /** * @notice Allows a Network Guardian to pause the operation of multiple * contracts. * * @param addrs An array of contract addresses to pause. * @param safe Whether the pause should be called safely. * * @dev Requirements: * - The caller must have the role: `NETWORK_GUARDIAN`. * - The contract must support the `NetworkGuardian` interface. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must not already be paused. * * Emits a `Paused` event for each contract that is successfully paused. */ function pauseMultiple(INetworkGuardian[] memory addrs, bool safe) external; /** * @notice Allows a Network Guardian to pause the operation of multiple * contracts. Similar to `pauseMultiple`, but rather than supplying an array * of addresses, this function takes a range (start and end indexes within * the `_registeredAddresses` array). * * @param start The start index (inclusive). * @param end The end index (exclusive). * @param safe Whether the pause should be called safely. * * @dev Requirements: * - The caller must have the role: `NETWORK_GUARDIAN`. * - The contract must support the `NetworkGuardian` interface. * - The supplied range must be valid. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must not already be paused. * * Emits a `Paused` event for each contract that is successfully paused. */ function pauseRange(uint256 start, uint256 end, bool safe) external; /** * @notice Allows the admin to resume the operation of a contract. * * @param addr The address of the contract to unpause. * @param safe Whether the unpause should be called safely. * * @dev Requirements: * - The caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The contract must support the `NetworkGuardian` interface. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must be paused. * * @dev Will emit an `Unpaused` event. */ function unpause(INetworkGuardian addr, bool safe) external; /** * @notice Allows the admin to resume the operation of multiple contracts. * * @param addrs An array of contract addresses to unpause. * @param safe Whether the unpause should be called safely. * * @dev Requirements: * - The caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The contract must support the `NetworkGuardian` interface. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must be paused. * * Emits an `Unpaused` event for each contract that is successfully unpaused. */ function unpauseMultiple( INetworkGuardian[] memory addrs, bool safe ) external; /** * @notice Allows the admin to resume the operation of multiple contracts. * Similar to `unpauseMultiple`, but rather than supplying an array of * addresses, this function takes a range (start and end indexes within the * `_registeredAddresses` array). * * @param start The start index (inclusive). * @param end The end index (exclusive). * @param safe Whether the unpause should be called safely. * * @dev Requirements: * - The caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The contract must support the `NetworkGuardian` interface. * - The supplied range must be valid. * - If `safe` is `true`, the address must not be the zero address. * - If `safe` is `true`, contract must not already be unpaused. * * Emits an `Unpaused` event for each contract that is successfully paused. */ function unpauseRange(uint256 start, uint256 end, bool safe) external; /** * @notice Sets the association address. * * @param addr The new address to set. * * @dev Requirements: * - Caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The address supplied must not be the zero address. * * Emits an `AssociationUpdated` event. */ function setAssociation(address addr) external; /** * @notice Sets maximum iteration count. * * @param n The new iteration count. * * @dev Requirements: * - Caller must have the role: `DEFAULT_ADMIN_ROLE`. * - The maximum iteration count must be greater than zero. * * Emits a `MaxItersUpdated` event. */ function setMaxIters(uint256 n) external; /** * @notice Returns the Haven1 Association address. * * @return The Haven1 Association address. */ function association() external view returns (address); /** * @notice Returns the maximum number of iterations possible for a bulk * action. * * @return The maximum number of iterations possible for a bulk action. */ function maxIters() external view returns (uint256); /** * @notice Returns whether an address is registered with this controller. * * @param addr The address to check. * * @return True if the address is registered, false otherwise. */ function isRegistered(address addr) external view returns (bool); /** * @notice Returns the number of contracts registered with this controller. * * @return The number of contracts registered with this controller. */ function registeredCount() external view returns (uint256); /** * @notice Returns an array of all the currently registered addresses. * * @return An array of all the currently registered addresses. */ function registeredAddresses() external view returns (INetworkGuardian[] memory); /** * @notice Retrieves a registered address from the `_registeredAddresses` * array by its index. * * @param idx The index of the address to return. * * @return The address located at the specified index within the * `_registeredAddresses` array. * * @dev Requirements: * - The index must be within bounds. */ function registeredAddressByIndex( uint256 idx ) external view returns (INetworkGuardian); /** * @notice Retrieves all registered contract addresses within a specified * range from the `_registeredAddresses` array. * * @param start The start index (inclusive). * @param end The end index (exclusive). * * @return An array containing all registered contract addresses within the * specified range. * * @dev Requirements: * - The provided range must be valid. */ function registeredAddressByRange( uint256 start, uint256 end ) external view returns (INetworkGuardian[] memory); /** * @notice Returns an array of ranges that may be used to safely iterate * over the `_registeredAddresses` array. * * @return An array of ranges that may be used to safely iterate over the * `_registeredAddresses` array. */ function getRanges() external view returns (Range[] memory); }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/interfaces/IERC1967Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol) pragma solidity ^0.8.0; /** * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC. * * _Available since v4.8.3._ */ interface IERC1967Upgradeable { /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); }
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true,"details":{"yul":true}},"libraries":{},"evmVersion":"paris"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"error","name":"Address__ZeroAddress","inputs":[]},{"type":"error","name":"FeeDistributorChannel__InsufficientH1","inputs":[{"type":"uint256","name":"amt","internalType":"uint256"},{"type":"uint256","name":"available","internalType":"uint256"}]},{"type":"error","name":"NetworkGuardian__AlreadyRegistered","inputs":[]},{"type":"error","name":"NetworkGuardian__NotPaused","inputs":[]},{"type":"error","name":"NetworkGuardian__Paused","inputs":[]},{"type":"error","name":"Recoverable__H1RecoveryFailed","inputs":[]},{"type":"error","name":"Recoverable__InsufficientH1","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"available","internalType":"uint256"}]},{"type":"error","name":"Recoverable__InsufficientHRC20","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"available","internalType":"uint256"}]},{"type":"error","name":"Recoverable__InvalidAddress","inputs":[]},{"type":"error","name":"Recoverable__ZeroAmountProvided","inputs":[]},{"type":"event","name":"AdminChanged","inputs":[{"type":"address","name":"previousAdmin","internalType":"address","indexed":false},{"type":"address","name":"newAdmin","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"AssociationUpdated","inputs":[{"type":"address","name":"prev","internalType":"address","indexed":true},{"type":"address","name":"curr","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"BeaconUpgraded","inputs":[{"type":"address","name":"beacon","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ControllerUpdated","inputs":[{"type":"address","name":"prev","internalType":"address","indexed":true},{"type":"address","name":"curr","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"FeeDistributorUpdated","inputs":[{"type":"address","name":"prev","internalType":"address","indexed":true},{"type":"address","name":"curr","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"GuardianPaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"GuardianUnpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"H1Received","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"H1Recovered","inputs":[{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"HRC20Recovered","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"RewardsDistributed","inputs":[{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"WH1Updated","inputs":[{"type":"address","name":"prev","internalType":"address","indexed":true},{"type":"address","name":"curr","internalType":"address","indexed":true}],"anonymous":false},{"type":"fallback","stateMutability":"payable"},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"NETWORK_GUARDIAN","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"OPERATOR_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"WH1","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"association","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"controller","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[],"name":"deposit","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distribute","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distributePartial","inputs":[{"type":"uint256","name":"amt","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"feeDistributor","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"guardianPause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"guardianPaused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"guardianUnpause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"association_","internalType":"address"},{"type":"address","name":"guardianController_","internalType":"address"},{"type":"address","name":"feeDistributor_","internalType":"address"},{"type":"address","name":"WH1_","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastDistribution","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"recoverHRC20","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"register","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setAssociation","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setController","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setFeeDistributor","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setWH1","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"upgradeTo","inputs":[{"type":"address","name":"newImplementation","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x60a06040523060805234801561001457600080fd5b5061001d610022565b6100e1565b600054610100900460ff161561008e5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff908116146100df576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6080516123fc6200011960003960008181610768015281816107a80152818161089a015281816108da015261096901526123fc6000f3fe6080604052600436106101d15760003560e01c806374062f4d116100f7578063d0e30db011610095578063f5b541a611610064578063f5b541a6146104fd578063f77c47911461051f578063f8c8765e1461053e578063fc7e29bd1461055e576101e0565b8063d0e30db0146104ab578063d4593872146104b3578063d547741f146104c8578063e4fc6b6d146104e8576101e0565b8063a217fddf116100d1578063a217fddf14610441578063a717639c14610456578063b4d610451461046c578063ccfc2e8d1461048b576101e0565b806374062f4d146103e157806391d148541461040157806392eefe9b14610421576101e0565b806336568abe1161016f5780634f1ef2861161013e5780634f1ef2861461037757806352d1902d1461038a5780636246cd5d1461039f57806367fd762f146103bf576101e0565b806336568abe146103025780633659cfe6146103225780633de8643014610342578063435720a314610362576101e0565b80631aa3a008116101ab5780631aa3a0081461026f578063227ff18914610284578063248a9ca3146102a45780632f2ff15d146102e2576101e0565b806301ffc9a7146101e8578063050d4f781461021d5780630d43e8ad14610250576101e0565b366101e0576101de61057e565b005b6101de61057e565b3480156101f457600080fd5b50610208610203366004611ea8565b6105b5565b60405190151581526020015b60405180910390f35b34801561022957600080fd5b5061012d546001600160a01b03165b6040516001600160a01b039091168152602001610214565b34801561025c57600080fd5b5061017a546001600160a01b0316610238565b34801561027b57600080fd5b506101de6105e0565b34801561029057600080fd5b506101de61029f366004611eee565b610640565b3480156102b057600080fd5b506102d46102bf366004611f09565b600090815260fb602052604090206001015490565b604051908152602001610214565b3480156102ee57600080fd5b506101de6102fd366004611f22565b6106b1565b34801561030e57600080fd5b506101de61031d366004611f22565b6106db565b34801561032e57600080fd5b506101de61033d366004611eee565b61075e565b34801561034e57600080fd5b506101de61035d366004611f09565b61083d565b34801561036e57600080fd5b506101de610870565b6101de610385366004611f64565b610890565b34801561039657600080fd5b506102d461095c565b3480156103ab57600080fd5b506101de6103ba366004612026565b610a0f565b3480156103cb57600080fd5b506102d46000805160206123a783398151915281565b3480156103ed57600080fd5b506101de6103fc366004611eee565b610a25565b34801561040d57600080fd5b5061020861041c366004611f22565b610b4c565b34801561042d57600080fd5b506101de61043c366004611eee565b610b77565b34801561044d57600080fd5b506102d4600081565b34801561046257600080fd5b5061017c546102d4565b34801561047857600080fd5b5061017b546001600160a01b0316610238565b34801561049757600080fd5b506101de6104a6366004611eee565b610c26565b6101de610c97565b3480156104bf57600080fd5b506101de610ca1565b3480156104d457600080fd5b506101de6104e3366004611f22565b610cc1565b3480156104f457600080fd5b506101de610ce6565b34801561050957600080fd5b506102d460008051602061236083398151915281565b34801561052b57600080fd5b5061012e546001600160a01b0316610238565b34801561054a57600080fd5b506101de610559366004612062565b610d1b565b34801561056a57600080fd5b5061012e54600160a01b900460ff16610208565b60405134815233907f92fdc01558625a7ae5f86737255a59364181ffb61b08858cdafec8c5ef7fe2189060200160405180910390a2565b60006001600160e01b0319821663192d607f60e21b14806105da57506105da82610e98565b92915050565b61012e54604051632210724360e11b81523060048201526001600160a01b0390911690634420e48690602401600060405180830381600087803b15801561062657600080fd5b505af115801561063a573d6000803e3d6000fd5b50505050565b600061064b81610ecd565b61065d826001600160a01b0316610ed7565b61017b80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f965fb41ab295fbc56c6df7c122d4c49cbce634490ead2ccb0e49972cc569d53390600090a3505050565b600082815260fb60205260409020600101546106cc81610ecd565b6106d68383610efe565b505050565b6001600160a01b03811633146107505760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b61075a8282610f84565b5050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036107a65760405162461bcd60e51b8152600401610747906120b6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166107ef600080516020612340833981519152546001600160a01b031690565b6001600160a01b0316146108155760405162461bcd60e51b815260040161074790612102565b61081e81610feb565b6040805160008082526020820190925261083a91839190610ff6565b50565b610845611161565b60008051602061236083398151915261085d81610ecd565b610866826111ba565b5061083a60018055565b6000805160206123a783398151915261088881610ecd565b61083a61141a565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036108d85760405162461bcd60e51b8152600401610747906120b6565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610921600080516020612340833981519152546001600160a01b031690565b6001600160a01b0316146109475760405162461bcd60e51b815260040161074790612102565b61095082610feb565b61075a82826001610ff6565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109fc5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610747565b5060008051602061234083398151915290565b6000610a1a81610ecd565b61063a848484611470565b6000610a3081610ecd565b610a42826001600160a01b0316610ed7565b61012d546001600160a01b0383811691161461075a57610a63600083610efe565b610a7b60008051602061236083398151915283610efe565b610a936000805160206123a783398151915283610efe565b61012d54610ab9906000805160206123a7833981519152906001600160a01b0316610f84565b61012d54610adf90600080516020612360833981519152906001600160a01b0316610f84565b61012d54610af8906000906001600160a01b0316610f84565b61012d80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f3512d38fc6ad446f1bf69f367c25f409612ad1c52b19405d5f945877093ed64590600090a3505050565b600091825260fb602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000610b8281610ecd565b610b94826001600160a01b0316610ed7565b61012e54610bba906000805160206123a7833981519152906001600160a01b0316610f84565b610bd26000805160206123a783398151915283610efe565b61012e80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f1c87e2bbc4e5fa5d7f6f8c44d66cb241dff224b8602eb5435ca2076d2a5c6fc290600090a3505050565b6000610c3181610ecd565b610c43826001600160a01b0316610ed7565b61017a80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907fbb470d12faa974cbae56bc3c345446451b4d504aa13806836f3df6d032fa9a9190600090a3505050565b610c9f61057e565b565b6000805160206123a7833981519152610cb981610ecd565b61083a6115c6565b600082815260fb6020526040902060010154610cdc81610ecd565b6106d68383610f84565b610cee611161565b600080516020612360833981519152610d0681610ecd565b47610d10816111ba565b5050610c9f60018055565b600054610100900460ff1615808015610d3b5750600054600160ff909116105b80610d555750303b158015610d55575060005460ff166001145b610db85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610747565b6000805460ff191660011790558015610ddb576000805461ff0019166101001790555b610ded836001600160a01b0316610ed7565b610dff826001600160a01b0316610ed7565b610e0761160a565b610e118585611639565b610e1961168a565b61017a80546001600160a01b038086166001600160a01b03199283161790925561017b8054928516929091169190911790558015610e91576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b60006001600160e01b03198216637965db0b60e01b14806105da57506301ffc9a760e01b6001600160e01b03198316146105da565b61083a81336116b9565b6001600160a01b03811661083a57604051637121a22160e11b815260040160405180910390fd5b610f088282610b4c565b61075a57600082815260fb602090815260408083206001600160a01b03851684529091529020805460ff19166001179055610f403390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b610f8e8282610b4c565b1561075a57600082815260fb602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600061075a81610ecd565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611029576106d683611712565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611083575060408051601f3d908101601f191682019092526110809181019061214e565b60015b6110e65760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610747565b60008051602061234083398151915281146111555760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610747565b506106d68383836117ae565b6002600154036111b35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610747565b6002600155565b47808211156111e65760405163116e71c960e31b81526004810183905260248101829052604401610747565b4261017c5561017a5461017b5460408051630d0e30db60e41b815290516001600160a01b039384169390921691829163d0e30db091879160048082019260009290919082900301818588803b15801561123e57600080fd5b505af1158015611252573d6000803e3d6000fd5b505061017b5460405163095ea7b360e01b81526001600160a01b038781166004830152602482018a9052909116935063095ea7b3925060440190506020604051808303816000875af11580156112ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d09190612167565b5061017a546040516319c5aef560e11b81526001600160a01b038381166004830152602482018790529091169063338b5dea90604401600060405180830381600087803b15801561132057600080fd5b505af1158015611334573d6000803e3d6000fd5b505061017b54604051636eb1769f60e11b81523060048201526001600160a01b03868116602483015260009450909116915063dd62ed3e90604401602060405180830381865afa15801561138c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b0919061214e565b905080156113c0576113c0612189565b816001600160a01b0316836001600160a01b03167f92d8e67e11e35152e7b525077fc4cf66393423d128ce3b803453b22533c576418760405161140591815260200190565b60405180910390a35050505050565b60018055565b6114226117d3565b61012e805460ff60a01b191690557f6d6c7798fb84cad538cee67f2a9aa4bf0cbc343f23d6ab9ff5799a30e6e517bd335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b03821661149757604051636952320d60e11b815260040160405180910390fd5b806000036114b85760405163ca12747360e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa1580156114ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611523919061214e565b90508082111561155f576040516309b32c4160e41b81526001600160a01b03851660048201526024810183905260448101829052606401610747565b6115736001600160a01b03851684846117fe565b826001600160a01b0316846001600160a01b03167f49f3fee59469255505876c4bd96e894c8f151a4eb87a52a86dbb0759b6eff2b2846040516115b891815260200190565b60405180910390a350505050565b6115ce611850565b61012e805460ff60a01b1916600160a01b1790557fd5354f32595d4786b7a234166bc1e34f4ee58f9e9d534b0fc5abd8e122f25fd56114533390565b600054610100900460ff166116315760405162461bcd60e51b81526004016107479061219f565b610c9f61187c565b600054610100900460ff166116605760405162461bcd60e51b81526004016107479061219f565b6116686118a3565b6116706118a3565b6116786118a3565b6116806118a3565b61075a82826118ca565b600054610100900460ff166116b15760405162461bcd60e51b81526004016107479061219f565b610c9f6118a3565b6116c38282610b4c565b61075a576116d0816119ac565b6116db8360206119be565b6040516020016116ec92919061220e565b60408051601f198184030181529082905262461bcd60e51b825261074791600401612283565b6001600160a01b0381163b61177f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610747565b60008051602061234083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6117b783611b61565b6000825111806117c45750805b156106d65761063a8383611ba1565b61012e54600160a01b900460ff16610c9f57604051634ada2f8560e11b815260040160405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526106d6908490611bc6565b61012e54600160a01b900460ff1615610c9f5760405163060a4ceb60e41b815260040160405180910390fd5b600054610100900460ff166114145760405162461bcd60e51b81526004016107479061219f565b600054610100900460ff16610c9f5760405162461bcd60e51b81526004016107479061219f565b600054610100900460ff166118f15760405162461bcd60e51b81526004016107479061219f565b611903826001600160a01b0316610ed7565b611915816001600160a01b0316610ed7565b61012d80546001600160a01b038085166001600160a01b03199283161790925561012e805492841692909116919091179055611952600083610efe565b61196a60008051602061236083398151915283610efe565b6119826000805160206123a783398151915283610efe565b61199a6000805160206123a783398151915282610efe565b505061012e805460ff60a01b19169055565b60606105da6001600160a01b03831660145b606060006119cd8360026122cc565b6119d89060026122e3565b67ffffffffffffffff8111156119f0576119f0611f4e565b6040519080825280601f01601f191660200182016040528015611a1a576020820181803683370190505b509050600360fc1b81600081518110611a3557611a356122f6565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611a6457611a646122f6565b60200101906001600160f81b031916908160001a9053506000611a888460026122cc565b611a939060016122e3565b90505b6001811115611b0b576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611ac757611ac76122f6565b1a60f81b828281518110611add57611add6122f6565b60200101906001600160f81b031916908160001a90535060049490941c93611b048161230c565b9050611a96565b508315611b5a5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610747565b9392505050565b611b6a81611712565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060611b5a838360405180606001604052806027815260200161238060279139611c9b565b6000611c1b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611d139092919063ffffffff16565b9050805160001480611c3c575080806020019051810190611c3c9190612167565b6106d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610747565b6060600080856001600160a01b031685604051611cb89190612323565b600060405180830381855af49150503d8060008114611cf3576040519150601f19603f3d011682016040523d82523d6000602084013e611cf8565b606091505b5091509150611d0986838387611d2a565b9695505050505050565b6060611d228484600085611da3565b949350505050565b60608315611d99578251600003611d92576001600160a01b0385163b611d925760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610747565b5081611d22565b611d228383611e7e565b606082471015611e045760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610747565b600080866001600160a01b03168587604051611e209190612323565b60006040518083038185875af1925050503d8060008114611e5d576040519150601f19603f3d011682016040523d82523d6000602084013e611e62565b606091505b5091509150611e7387838387611d2a565b979650505050505050565b815115611e8e5781518083602001fd5b8060405162461bcd60e51b81526004016107479190612283565b600060208284031215611eba57600080fd5b81356001600160e01b031981168114611b5a57600080fd5b80356001600160a01b0381168114611ee957600080fd5b919050565b600060208284031215611f0057600080fd5b611b5a82611ed2565b600060208284031215611f1b57600080fd5b5035919050565b60008060408385031215611f3557600080fd5b82359150611f4560208401611ed2565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060408385031215611f7757600080fd5b611f8083611ed2565b9150602083013567ffffffffffffffff80821115611f9d57600080fd5b818501915085601f830112611fb157600080fd5b813581811115611fc357611fc3611f4e565b604051601f8201601f19908116603f01168101908382118183101715611feb57611feb611f4e565b8160405282815288602084870101111561200457600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b60008060006060848603121561203b57600080fd5b61204484611ed2565b925061205260208501611ed2565b9150604084013590509250925092565b6000806000806080858703121561207857600080fd5b61208185611ed2565b935061208f60208601611ed2565b925061209d60408601611ed2565b91506120ab60608601611ed2565b905092959194509250565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b60006020828403121561216057600080fd5b5051919050565b60006020828403121561217957600080fd5b81518015158114611b5a57600080fd5b634e487b7160e01b600052600160045260246000fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b838110156122055781810151838201526020016121ed565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516122468160178501602088016121ea565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516122778160288401602088016121ea565b01602801949350505050565b60208152600082518060208401526122a28160408501602087016121ea565b601f01601f19169190910160400192915050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176105da576105da6122b6565b808201808211156105da576105da6122b6565b634e487b7160e01b600052603260045260246000fd5b60008161231b5761231b6122b6565b506000190190565b600082516123358184602087016121ea565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c656426efabf51dccc571fac63168d694611e87cbe05fa0f0a5b41da6bfcde36bc146a2646970667358221220f60dc5f52434ce65920197cc763a5553a23bc9164d94539e39e49019f82b530f64736f6c63430008180033
Deployed ByteCode
0x6080604052600436106101d15760003560e01c806374062f4d116100f7578063d0e30db011610095578063f5b541a611610064578063f5b541a6146104fd578063f77c47911461051f578063f8c8765e1461053e578063fc7e29bd1461055e576101e0565b8063d0e30db0146104ab578063d4593872146104b3578063d547741f146104c8578063e4fc6b6d146104e8576101e0565b8063a217fddf116100d1578063a217fddf14610441578063a717639c14610456578063b4d610451461046c578063ccfc2e8d1461048b576101e0565b806374062f4d146103e157806391d148541461040157806392eefe9b14610421576101e0565b806336568abe1161016f5780634f1ef2861161013e5780634f1ef2861461037757806352d1902d1461038a5780636246cd5d1461039f57806367fd762f146103bf576101e0565b806336568abe146103025780633659cfe6146103225780633de8643014610342578063435720a314610362576101e0565b80631aa3a008116101ab5780631aa3a0081461026f578063227ff18914610284578063248a9ca3146102a45780632f2ff15d146102e2576101e0565b806301ffc9a7146101e8578063050d4f781461021d5780630d43e8ad14610250576101e0565b366101e0576101de61057e565b005b6101de61057e565b3480156101f457600080fd5b50610208610203366004611ea8565b6105b5565b60405190151581526020015b60405180910390f35b34801561022957600080fd5b5061012d546001600160a01b03165b6040516001600160a01b039091168152602001610214565b34801561025c57600080fd5b5061017a546001600160a01b0316610238565b34801561027b57600080fd5b506101de6105e0565b34801561029057600080fd5b506101de61029f366004611eee565b610640565b3480156102b057600080fd5b506102d46102bf366004611f09565b600090815260fb602052604090206001015490565b604051908152602001610214565b3480156102ee57600080fd5b506101de6102fd366004611f22565b6106b1565b34801561030e57600080fd5b506101de61031d366004611f22565b6106db565b34801561032e57600080fd5b506101de61033d366004611eee565b61075e565b34801561034e57600080fd5b506101de61035d366004611f09565b61083d565b34801561036e57600080fd5b506101de610870565b6101de610385366004611f64565b610890565b34801561039657600080fd5b506102d461095c565b3480156103ab57600080fd5b506101de6103ba366004612026565b610a0f565b3480156103cb57600080fd5b506102d46000805160206123a783398151915281565b3480156103ed57600080fd5b506101de6103fc366004611eee565b610a25565b34801561040d57600080fd5b5061020861041c366004611f22565b610b4c565b34801561042d57600080fd5b506101de61043c366004611eee565b610b77565b34801561044d57600080fd5b506102d4600081565b34801561046257600080fd5b5061017c546102d4565b34801561047857600080fd5b5061017b546001600160a01b0316610238565b34801561049757600080fd5b506101de6104a6366004611eee565b610c26565b6101de610c97565b3480156104bf57600080fd5b506101de610ca1565b3480156104d457600080fd5b506101de6104e3366004611f22565b610cc1565b3480156104f457600080fd5b506101de610ce6565b34801561050957600080fd5b506102d460008051602061236083398151915281565b34801561052b57600080fd5b5061012e546001600160a01b0316610238565b34801561054a57600080fd5b506101de610559366004612062565b610d1b565b34801561056a57600080fd5b5061012e54600160a01b900460ff16610208565b60405134815233907f92fdc01558625a7ae5f86737255a59364181ffb61b08858cdafec8c5ef7fe2189060200160405180910390a2565b60006001600160e01b0319821663192d607f60e21b14806105da57506105da82610e98565b92915050565b61012e54604051632210724360e11b81523060048201526001600160a01b0390911690634420e48690602401600060405180830381600087803b15801561062657600080fd5b505af115801561063a573d6000803e3d6000fd5b50505050565b600061064b81610ecd565b61065d826001600160a01b0316610ed7565b61017b80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f965fb41ab295fbc56c6df7c122d4c49cbce634490ead2ccb0e49972cc569d53390600090a3505050565b600082815260fb60205260409020600101546106cc81610ecd565b6106d68383610efe565b505050565b6001600160a01b03811633146107505760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b61075a8282610f84565b5050565b6001600160a01b037f00000000000000000000000035a59dac969d582173bd528d4af1baa6b15c9bd81630036107a65760405162461bcd60e51b8152600401610747906120b6565b7f00000000000000000000000035a59dac969d582173bd528d4af1baa6b15c9bd86001600160a01b03166107ef600080516020612340833981519152546001600160a01b031690565b6001600160a01b0316146108155760405162461bcd60e51b815260040161074790612102565b61081e81610feb565b6040805160008082526020820190925261083a91839190610ff6565b50565b610845611161565b60008051602061236083398151915261085d81610ecd565b610866826111ba565b5061083a60018055565b6000805160206123a783398151915261088881610ecd565b61083a61141a565b6001600160a01b037f00000000000000000000000035a59dac969d582173bd528d4af1baa6b15c9bd81630036108d85760405162461bcd60e51b8152600401610747906120b6565b7f00000000000000000000000035a59dac969d582173bd528d4af1baa6b15c9bd86001600160a01b0316610921600080516020612340833981519152546001600160a01b031690565b6001600160a01b0316146109475760405162461bcd60e51b815260040161074790612102565b61095082610feb565b61075a82826001610ff6565b6000306001600160a01b037f00000000000000000000000035a59dac969d582173bd528d4af1baa6b15c9bd816146109fc5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610747565b5060008051602061234083398151915290565b6000610a1a81610ecd565b61063a848484611470565b6000610a3081610ecd565b610a42826001600160a01b0316610ed7565b61012d546001600160a01b0383811691161461075a57610a63600083610efe565b610a7b60008051602061236083398151915283610efe565b610a936000805160206123a783398151915283610efe565b61012d54610ab9906000805160206123a7833981519152906001600160a01b0316610f84565b61012d54610adf90600080516020612360833981519152906001600160a01b0316610f84565b61012d54610af8906000906001600160a01b0316610f84565b61012d80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f3512d38fc6ad446f1bf69f367c25f409612ad1c52b19405d5f945877093ed64590600090a3505050565b600091825260fb602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000610b8281610ecd565b610b94826001600160a01b0316610ed7565b61012e54610bba906000805160206123a7833981519152906001600160a01b0316610f84565b610bd26000805160206123a783398151915283610efe565b61012e80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f1c87e2bbc4e5fa5d7f6f8c44d66cb241dff224b8602eb5435ca2076d2a5c6fc290600090a3505050565b6000610c3181610ecd565b610c43826001600160a01b0316610ed7565b61017a80546001600160a01b038481166001600160a01b0319831681179093556040519116919082907fbb470d12faa974cbae56bc3c345446451b4d504aa13806836f3df6d032fa9a9190600090a3505050565b610c9f61057e565b565b6000805160206123a7833981519152610cb981610ecd565b61083a6115c6565b600082815260fb6020526040902060010154610cdc81610ecd565b6106d68383610f84565b610cee611161565b600080516020612360833981519152610d0681610ecd565b47610d10816111ba565b5050610c9f60018055565b600054610100900460ff1615808015610d3b5750600054600160ff909116105b80610d555750303b158015610d55575060005460ff166001145b610db85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610747565b6000805460ff191660011790558015610ddb576000805461ff0019166101001790555b610ded836001600160a01b0316610ed7565b610dff826001600160a01b0316610ed7565b610e0761160a565b610e118585611639565b610e1961168a565b61017a80546001600160a01b038086166001600160a01b03199283161790925561017b8054928516929091169190911790558015610e91576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5050505050565b60006001600160e01b03198216637965db0b60e01b14806105da57506301ffc9a760e01b6001600160e01b03198316146105da565b61083a81336116b9565b6001600160a01b03811661083a57604051637121a22160e11b815260040160405180910390fd5b610f088282610b4c565b61075a57600082815260fb602090815260408083206001600160a01b03851684529091529020805460ff19166001179055610f403390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b610f8e8282610b4c565b1561075a57600082815260fb602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600061075a81610ecd565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611029576106d683611712565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611083575060408051601f3d908101601f191682019092526110809181019061214e565b60015b6110e65760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610747565b60008051602061234083398151915281146111555760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610747565b506106d68383836117ae565b6002600154036111b35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610747565b6002600155565b47808211156111e65760405163116e71c960e31b81526004810183905260248101829052604401610747565b4261017c5561017a5461017b5460408051630d0e30db60e41b815290516001600160a01b039384169390921691829163d0e30db091879160048082019260009290919082900301818588803b15801561123e57600080fd5b505af1158015611252573d6000803e3d6000fd5b505061017b5460405163095ea7b360e01b81526001600160a01b038781166004830152602482018a9052909116935063095ea7b3925060440190506020604051808303816000875af11580156112ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112d09190612167565b5061017a546040516319c5aef560e11b81526001600160a01b038381166004830152602482018790529091169063338b5dea90604401600060405180830381600087803b15801561132057600080fd5b505af1158015611334573d6000803e3d6000fd5b505061017b54604051636eb1769f60e11b81523060048201526001600160a01b03868116602483015260009450909116915063dd62ed3e90604401602060405180830381865afa15801561138c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113b0919061214e565b905080156113c0576113c0612189565b816001600160a01b0316836001600160a01b03167f92d8e67e11e35152e7b525077fc4cf66393423d128ce3b803453b22533c576418760405161140591815260200190565b60405180910390a35050505050565b60018055565b6114226117d3565b61012e805460ff60a01b191690557f6d6c7798fb84cad538cee67f2a9aa4bf0cbc343f23d6ab9ff5799a30e6e517bd335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b03821661149757604051636952320d60e11b815260040160405180910390fd5b806000036114b85760405163ca12747360e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa1580156114ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611523919061214e565b90508082111561155f576040516309b32c4160e41b81526001600160a01b03851660048201526024810183905260448101829052606401610747565b6115736001600160a01b03851684846117fe565b826001600160a01b0316846001600160a01b03167f49f3fee59469255505876c4bd96e894c8f151a4eb87a52a86dbb0759b6eff2b2846040516115b891815260200190565b60405180910390a350505050565b6115ce611850565b61012e805460ff60a01b1916600160a01b1790557fd5354f32595d4786b7a234166bc1e34f4ee58f9e9d534b0fc5abd8e122f25fd56114533390565b600054610100900460ff166116315760405162461bcd60e51b81526004016107479061219f565b610c9f61187c565b600054610100900460ff166116605760405162461bcd60e51b81526004016107479061219f565b6116686118a3565b6116706118a3565b6116786118a3565b6116806118a3565b61075a82826118ca565b600054610100900460ff166116b15760405162461bcd60e51b81526004016107479061219f565b610c9f6118a3565b6116c38282610b4c565b61075a576116d0816119ac565b6116db8360206119be565b6040516020016116ec92919061220e565b60408051601f198184030181529082905262461bcd60e51b825261074791600401612283565b6001600160a01b0381163b61177f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610747565b60008051602061234083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6117b783611b61565b6000825111806117c45750805b156106d65761063a8383611ba1565b61012e54600160a01b900460ff16610c9f57604051634ada2f8560e11b815260040160405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526106d6908490611bc6565b61012e54600160a01b900460ff1615610c9f5760405163060a4ceb60e41b815260040160405180910390fd5b600054610100900460ff166114145760405162461bcd60e51b81526004016107479061219f565b600054610100900460ff16610c9f5760405162461bcd60e51b81526004016107479061219f565b600054610100900460ff166118f15760405162461bcd60e51b81526004016107479061219f565b611903826001600160a01b0316610ed7565b611915816001600160a01b0316610ed7565b61012d80546001600160a01b038085166001600160a01b03199283161790925561012e805492841692909116919091179055611952600083610efe565b61196a60008051602061236083398151915283610efe565b6119826000805160206123a783398151915283610efe565b61199a6000805160206123a783398151915282610efe565b505061012e805460ff60a01b19169055565b60606105da6001600160a01b03831660145b606060006119cd8360026122cc565b6119d89060026122e3565b67ffffffffffffffff8111156119f0576119f0611f4e565b6040519080825280601f01601f191660200182016040528015611a1a576020820181803683370190505b509050600360fc1b81600081518110611a3557611a356122f6565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611a6457611a646122f6565b60200101906001600160f81b031916908160001a9053506000611a888460026122cc565b611a939060016122e3565b90505b6001811115611b0b576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611ac757611ac76122f6565b1a60f81b828281518110611add57611add6122f6565b60200101906001600160f81b031916908160001a90535060049490941c93611b048161230c565b9050611a96565b508315611b5a5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610747565b9392505050565b611b6a81611712565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060611b5a838360405180606001604052806027815260200161238060279139611c9b565b6000611c1b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611d139092919063ffffffff16565b9050805160001480611c3c575080806020019051810190611c3c9190612167565b6106d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610747565b6060600080856001600160a01b031685604051611cb89190612323565b600060405180830381855af49150503d8060008114611cf3576040519150601f19603f3d011682016040523d82523d6000602084013e611cf8565b606091505b5091509150611d0986838387611d2a565b9695505050505050565b6060611d228484600085611da3565b949350505050565b60608315611d99578251600003611d92576001600160a01b0385163b611d925760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610747565b5081611d22565b611d228383611e7e565b606082471015611e045760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610747565b600080866001600160a01b03168587604051611e209190612323565b60006040518083038185875af1925050503d8060008114611e5d576040519150601f19603f3d011682016040523d82523d6000602084013e611e62565b606091505b5091509150611e7387838387611d2a565b979650505050505050565b815115611e8e5781518083602001fd5b8060405162461bcd60e51b81526004016107479190612283565b600060208284031215611eba57600080fd5b81356001600160e01b031981168114611b5a57600080fd5b80356001600160a01b0381168114611ee957600080fd5b919050565b600060208284031215611f0057600080fd5b611b5a82611ed2565b600060208284031215611f1b57600080fd5b5035919050565b60008060408385031215611f3557600080fd5b82359150611f4560208401611ed2565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060408385031215611f7757600080fd5b611f8083611ed2565b9150602083013567ffffffffffffffff80821115611f9d57600080fd5b818501915085601f830112611fb157600080fd5b813581811115611fc357611fc3611f4e565b604051601f8201601f19908116603f01168101908382118183101715611feb57611feb611f4e565b8160405282815288602084870101111561200457600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b60008060006060848603121561203b57600080fd5b61204484611ed2565b925061205260208501611ed2565b9150604084013590509250925092565b6000806000806080858703121561207857600080fd5b61208185611ed2565b935061208f60208601611ed2565b925061209d60408601611ed2565b91506120ab60608601611ed2565b905092959194509250565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b60006020828403121561216057600080fd5b5051919050565b60006020828403121561217957600080fd5b81518015158114611b5a57600080fd5b634e487b7160e01b600052600160045260246000fd5b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60005b838110156122055781810151838201526020016121ed565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516122468160178501602088016121ea565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516122778160288401602088016121ea565b01602801949350505050565b60208152600082518060208401526122a28160408501602087016121ea565b601f01601f19169190910160400192915050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176105da576105da6122b6565b808201808211156105da576105da6122b6565b634e487b7160e01b600052603260045260246000fd5b60008161231b5761231b6122b6565b506000190190565b600082516123358184602087016121ea565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c656426efabf51dccc571fac63168d694611e87cbe05fa0f0a5b41da6bfcde36bc146a2646970667358221220f60dc5f52434ce65920197cc763a5553a23bc9164d94539e39e49019f82b530f64736f6c63430008180033