Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
0x60808060 | 18083534 | 400 days ago | IN | 0 ETH | 0.04793 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
BribeRewarderFactory
Compiler Version
v0.8.18+commit.87f61d96
Optimization Enabled:
Yes with 1000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.15; import '@openzeppelin/contracts/proxy/beacon/IBeacon.sol'; import '@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol'; import '@openzeppelin/contracts/utils/Address.sol'; import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import '@openzeppelin/contracts/utils/structs/EnumerableSet.sol'; import '../../wombat-core/interfaces/IAsset.sol'; import '../interfaces/IBribeRewarderFactory.sol'; import '../interfaces/IBoostedMasterWombat.sol'; import '../interfaces/IVoter.sol'; import '../rewarders/BoostedMultiRewarder.sol'; import './BribeV2.sol'; contract BribeRewarderFactory is IBribeRewarderFactory, Initializable, OwnableUpgradeable { using EnumerableSet for EnumerableSet.AddressSet; IBoostedMasterWombat public masterWombat; IBeacon public rewarderBeacon; IVoter public voter; IBeacon public bribeBeacon; /// @notice Rewarder deployer is able to deploy rewarders, and it will become the rewarder operator mapping(IAsset => address) public rewarderDeployers; /// @notice Bribe deployer is able to deploy bribe, and it will become the bribe operator mapping(IAsset => address) public bribeDeployers; /// @notice whitelisted reward tokens can be added to rewarders and bribes EnumerableSet.AddressSet internal whitelistedRewardTokens; event DeployRewarderContract( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec, address rewarder ); event SetRewarderContract(IAsset _lpToken, address rewarder); event SetRewarderBeacon(IBeacon beacon); event SetRewarderDeployer(IAsset token, address deployer); event DeployBribeContract( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec, address bribe ); event SetBribeContract(IAsset _lpToken, address bribe); event SetBribeBeacon(IBeacon beacon); event SetBribeDeployer(IAsset token, address deployer); event WhitelistRewardTokenUpdated(IERC20 token, bool isAdded); event SetVoter(IVoter voter); function initialize( IBeacon _rewarderBeacon, IBeacon _bribeBeacon, IBoostedMasterWombat _masterWombat, IVoter _voter ) public initializer { require(Address.isContract(address(_rewarderBeacon)), 'initialize: _rewarderBeacon must be a valid contract'); require(Address.isContract(address(_bribeBeacon)), 'initialize: _bribeBeacon must be a valid contract'); require(Address.isContract(address(_masterWombat)), 'initialize: mw must be a valid contract'); rewarderBeacon = _rewarderBeacon; bribeBeacon = _bribeBeacon; masterWombat = _masterWombat; voter = _voter; __Ownable_init(); } function isRewardTokenWhitelisted(IERC20 _token) public view returns (bool) { return whitelistedRewardTokens.contains(address(_token)); } function getWhitelistedRewardTokens() external view returns (address[] memory) { return whitelistedRewardTokens.values(); } /// @notice Deploy bribe contract behind a beacon proxy, and add it to the voter function deployRewarderContractAndSetRewarder( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) external returns (address rewarder) { uint256 pid = masterWombat.getAssetPid(address(_lpToken)); require(address(masterWombat.boostedRewarders(pid)) == address(0), 'rewarder contract alrealdy exists'); rewarder = address(_deployRewarderContract(_lpToken, pid, _startTimestamp, _rewardToken, _tokenPerSec)); masterWombat.setBoostedRewarder(pid, BoostedMultiRewarder(payable(rewarder))); emit SetRewarderContract(_lpToken, rewarder); } /// @notice Deploy bribe contract behind a beacon proxy, and add it to the voter function deployRewarderContract( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) external returns (address rewarder) { uint256 pid = masterWombat.getAssetPid(address(_lpToken)); rewarder = address(_deployRewarderContract(_lpToken, pid, _startTimestamp, _rewardToken, _tokenPerSec)); } function _deployRewarderContract( IAsset _lpToken, uint256 _pid, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) internal returns (BoostedMultiRewarder rewarder) { if (Address.isContract(address(voter))) { (, , , , , IGauge gaugeManager, ) = voter.infos(_lpToken); require(address(gaugeManager) != address(0), 'gauge does not exist'); } require(address(masterWombat.boostedRewarders(_pid)) == address(0), 'rewarder contract alrealdy exists'); require(rewarderDeployers[_lpToken] == msg.sender, 'Not authurized.'); require(isRewardTokenWhitelisted(_rewardToken), 'reward token is not whitelisted'); // deploy a rewarder contract behind a proxy // BoostedMultiRewarder rewarder = new BoostedMultiRewarder() rewarder = BoostedMultiRewarder(payable(new BeaconProxy(address(rewarderBeacon), bytes('')))); rewarder.initialize(this, masterWombat, _lpToken, _startTimestamp, _rewardToken, _tokenPerSec); rewarder.addOperator(msg.sender); rewarder.transferOwnership(owner()); emit DeployRewarderContract(_lpToken, _startTimestamp, _rewardToken, _tokenPerSec, address(rewarder)); } /// @notice Deploy bribe contract behind a beacon proxy, and add it to the voter function deployBribeContractAndSetBribe( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) external returns (address bribe) { (, , , , bool whitelist, IGauge gaugeManager, IBribe currentBribe) = voter.infos(_lpToken); require(address(currentBribe) == address(0), 'bribe contract already exists for gauge'); require(address(gaugeManager) != address(0), 'gauge does not exist'); require(whitelist, 'bribe contract is paused'); bribe = address(_deployBribeContract(_lpToken, _startTimestamp, _rewardToken, _tokenPerSec)); voter.setBribe(_lpToken, IBribe(address(bribe))); emit SetBribeContract(_lpToken, bribe); } /// @notice Deploy bribe contract behind a beacon proxy, and add it to the voter function deployBribeContract( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) external returns (address bribe) { bribe = address(_deployBribeContract(_lpToken, _startTimestamp, _rewardToken, _tokenPerSec)); } function _deployBribeContract( IAsset _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) internal returns (BribeV2 bribe) { (, , , , , IGauge gaugeManager, ) = voter.infos(_lpToken); require(address(gaugeManager) != address(0), 'gauge does not exist'); require(bribeDeployers[_lpToken] == msg.sender, 'Not authurized.'); require(isRewardTokenWhitelisted(_rewardToken), 'reward token is not whitelisted'); // deploy a bribe contract behind a proxy // BribeV2 bribe = new BribeV2(); bribe = BribeV2(payable(new BeaconProxy(address(bribeBeacon), bytes('')))); bribe.initialize(this, address(voter), _lpToken, _startTimestamp, _rewardToken, _tokenPerSec); bribe.addOperator(msg.sender); bribe.transferOwnership(owner()); emit DeployBribeContract(_lpToken, _startTimestamp, _rewardToken, _tokenPerSec, address(bribe)); } function setVoter(IVoter _voter) external onlyOwner { require(Address.isContract(address(_voter)), 'invalid address'); voter = _voter; emit SetVoter(_voter); } function setRewarderBeacon(IBeacon _rewarderBeacon) external onlyOwner { require(Address.isContract(address(_rewarderBeacon)), 'invalid address'); rewarderBeacon = _rewarderBeacon; emit SetRewarderBeacon(_rewarderBeacon); } function setBribeBeacon(IBeacon _bribeBeacon) external onlyOwner { require(Address.isContract(address(_bribeBeacon)), 'invalid address'); bribeBeacon = _bribeBeacon; emit SetBribeBeacon(_bribeBeacon); } function setRewarderDeployer(IAsset _token, address _deployer) external onlyOwner { require(rewarderDeployers[_token] != _deployer, 'already set as deployer'); rewarderDeployers[_token] = _deployer; emit SetRewarderDeployer(_token, _deployer); } function setBribeDeployer(IAsset _token, address _deployer) external onlyOwner { require(bribeDeployers[_token] != _deployer, 'already set as deployer'); bribeDeployers[_token] = _deployer; emit SetBribeDeployer(_token, _deployer); } function whitelistRewardToken(IERC20 _token) external onlyOwner { require(!isRewardTokenWhitelisted(_token), 'already whitelisted'); whitelistedRewardTokens.add(address(_token)); emit WhitelistRewardTokenUpdated(_token, true); } function revokeRewardToken(IERC20 _token) external onlyOwner { require(isRewardTokenWhitelisted(_token), 'reward token is not whitelisted'); whitelistedRewardTokens.remove(address(_token)); emit WhitelistRewardTokenUpdated(_token, false); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlEnumerableUpgradeable.sol"; import "./AccessControlUpgradeable.sol"; import "../utils/structs/EnumerableSetUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Extension of {AccessControl} that allows enumerating the members of each role. */ abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable { function __AccessControlEnumerable_init() internal onlyInitializing { } function __AccessControlEnumerable_init_unchained() internal onlyInitializing { } using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) { return _roleMembers[role].at(index); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) { return _roleMembers[role].length(); } /** * @dev Overload {_grantRole} to track enumerable memberships */ function _grantRole(bytes32 role, address account) internal virtual override { super._grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {_revokeRole} to track enumerable memberships */ function _revokeRole(bytes32 role, address account) internal virtual override { super._revokeRole(role, account); _roleMembers[role].remove(account); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.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 "../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 { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } 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); _; } /** * @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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface 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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// 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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev 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; }
// 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); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../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; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.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); } } }
// 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); } } }
// 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)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ```solidity * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSetUpgradeable { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.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 IERC1967 { /** * @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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/beacon/BeaconProxy.sol) pragma solidity ^0.8.0; import "./IBeacon.sol"; import "../Proxy.sol"; import "../ERC1967/ERC1967Upgrade.sol"; /** * @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}. * * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't * conflict with the storage layout of the implementation behind the proxy. * * _Available since v3.4._ */ contract BeaconProxy is Proxy, ERC1967Upgrade { /** * @dev Initializes the proxy with `beacon`. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This * will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity * constructor. * * Requirements: * * - `beacon` must be a contract with the interface {IBeacon}. */ constructor(address beacon, bytes memory data) payable { _upgradeBeaconToAndCall(beacon, data, false); } /** * @dev Returns the current beacon address. */ function _beacon() internal view virtual returns (address) { return _getBeacon(); } /** * @dev Returns the current implementation address of the associated beacon. */ function _implementation() internal view virtual override returns (address) { return IBeacon(_getBeacon()).implementation(); } /** * @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}. * * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. * * Requirements: * * - `beacon` must be a contract. * - The implementation returned by `beacon` must be a contract. */ function _setBeacon(address beacon, bytes memory data) internal virtual { _upgradeBeaconToAndCall(beacon, data, false); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeacon.sol"; import "../../interfaces/IERC1967.sol"; import "../../interfaces/draft-IERC1822.sol"; import "../../utils/Address.sol"; import "../../utils/StorageSlot.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ */ abstract contract ERC1967Upgrade is IERC1967 { // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { Address.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol) pragma solidity ^0.8.0; /** * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to * be specified by overriding the virtual {_implementation} function. * * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a * different contract through the {_delegate} function. * * The success and return data of the delegated call will be returned back to the caller of the proxy. */ abstract contract Proxy { /** * @dev Delegates the current call to `implementation`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _delegate(address implementation) internal virtual { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize()) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize()) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) } } } /** * @dev This is a virtual function that should be overridden so it returns the address to which the fallback function * and {_fallback} should delegate. */ function _implementation() internal view virtual returns (address); /** * @dev Delegates the current call to the address returned by `_implementation()`. * * This function does not return to its internal call site, it will return directly to the external caller. */ function _fallback() internal virtual { _beforeFallback(); _delegate(_implementation()); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * function in the contract matches the call data. */ fallback() external payable virtual { _fallback(); } /** * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * is empty. */ receive() external payable virtual { _fallback(); } /** * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` * call, or as part of the Solidity `fallback` or `receive` functions. * * If overridden should call `super._beforeFallback()`. */ function _beforeFallback() internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (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. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @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(IERC20 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(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @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(IERC20 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(IERC20 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(IERC20 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( IERC20Permit 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(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 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(IERC20 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))) && Address.isContract(address(token)); } }
// 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 Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * 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); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.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 StorageSlot { 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 } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ```solidity * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.5; import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IAsset is IERC20 { function underlyingToken() external view returns (address); function pool() external view returns (address); function cash() external view returns (uint120); function liability() external view returns (uint120); function decimals() external view returns (uint8); function underlyingTokenDecimals() external view returns (uint8); function setPool(address pool_) external; function underlyingTokenBalance() external view returns (uint256); function transferUnderlyingToken(address to, uint256 amount) external; function mint(address to, uint256 amount) external; function burn(address to, uint256 amount) external; function addCash(uint256 amount) external; function removeCash(uint256 amount) external; function addLiability(uint256 amount) external; function removeLiability(uint256 amount) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.15; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import '../interfaces/IBribeRewarderFactory.sol'; import '../interfaces/IBribe.sol'; import '../interfaces/IVoter.sol'; import '../rewarders/MultiRewarderPerSecV2.sol'; /** * Simple bribe per sec. Distribute bribe rewards to voters * Bribe.onVote->updateReward() is a bit different from SimpleRewarder. * Here we reduce the original total amount of share */ contract BribeV2 is IBribe, MultiRewarderPerSecV2 { using SafeERC20 for IERC20; function onVote( address _user, uint256 _newVote, uint256 _originalTotalVotes ) external override onlyMaster nonReentrant returns (uint256[] memory rewards) { _updateReward(_originalTotalVotes); return _onReward(_user, _newVote); } function onReward(address, uint256) external override onlyMaster nonReentrant returns (uint256[] memory) { revert('Call BribeV2.onVote instead'); } function _getTotalShare() internal view override returns (uint256 voteWeight) { (, voteWeight) = IVoter(master).weights(lpToken); } function rewardLength() public view override(IBribe, MultiRewarderPerSecV2) returns (uint256) { return MultiRewarderPerSecV2.rewardLength(); } function rewardTokens() public view override(IBribe, MultiRewarderPerSecV2) returns (IERC20[] memory tokens) { return MultiRewarderPerSecV2.rewardTokens(); } function pendingTokens( address _user ) public view override(IBribe, MultiRewarderPerSecV2) returns (uint256[] memory tokens) { return MultiRewarderPerSecV2.pendingTokens(_user); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import './IMasterWombatV3.sol'; import './IBoostedMultiRewarder.sol'; /** * @dev Interface of BoostedMasterWombat */ interface IBoostedMasterWombat is IMasterWombatV3 { function getSumOfFactors(uint256 pid) external view returns (uint256 sum); function basePartition() external view returns (uint16); function add(IERC20 _lpToken, IBoostedMultiRewarder _boostedRewarder) external; function boostedRewarders(uint256 _pid) external view returns (IBoostedMultiRewarder); function setBoostedRewarder(uint256 _pid, IBoostedMultiRewarder _boostedRewarder) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IBoostedMultiRewarder { function lpToken() external view returns (IERC20 lpToken); function onReward( address _user, uint256 _newLpAmount, uint256 _newFactor ) external returns (uint256[] memory rewards); function addRewardToken(IERC20 _rewardToken, uint40 _startTimestamp, uint96 _tokenPerSec) external; function pendingTokens(address _user) external view returns (uint256[] memory rewards); function rewardTokens() external view returns (IERC20[] memory tokens); function rewardLength() external view returns (uint256); function onUpdateFactor(address _user, uint256 _newFactor) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.15; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IBribe { function onVote( address user, uint256 newVote, uint256 originalTotalVotes ) external returns (uint256[] memory rewards); function pendingTokens(address _user) external view returns (uint256[] memory rewards); function rewardTokens() external view returns (IERC20[] memory tokens); function rewardLength() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.15; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IBribeRewarderFactory { function isRewardTokenWhitelisted(IERC20 _token) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; /** * @dev Interface of the MasterWombatV3 */ interface IMasterWombatV3 { function getAssetPid(address asset) external view returns (uint256 pid); function poolLength() external view returns (uint256); function pendingTokens( uint256 _pid, address _user ) external view returns ( uint256 pendingRewards, IERC20[] memory bonusTokenAddresses, string[] memory bonusTokenSymbols, uint256[] memory pendingBonusRewards ); function rewarderBonusTokenInfo( uint256 _pid ) external view returns (IERC20[] memory bonusTokenAddresses, string[] memory bonusTokenSymbols); function massUpdatePools() external; function updatePool(uint256 _pid) external; function deposit(uint256 _pid, uint256 _amount) external returns (uint256, uint256[] memory); function multiClaim( uint256[] memory _pids ) external returns (uint256 transfered, uint256[] memory rewards, uint256[][] memory additionalRewards); function withdraw(uint256 _pid, uint256 _amount) external returns (uint256, uint256[] memory); function emergencyWithdraw(uint256 _pid) external; function migrate(uint256[] calldata _pids) external; function depositFor(uint256 _pid, uint256 _amount, address _user) external; function updateFactor(address _user, uint256 _newVeWomBalance) external; function notifyRewardAmount(address _lpToken, uint256 _amount) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IMultiRewarderV2 { function lpToken() external view returns (IERC20 lpToken); function onReward(address _user, uint256 _lpAmount) external returns (uint256[] memory rewards); function addRewardToken(IERC20 _rewardToken, uint40 _startTimestamp, uint96 _tokenPerSec) external; function pendingTokens(address _user) external view returns (uint256[] memory rewards); function rewardTokens() external view returns (IERC20[] memory tokens); function rewardLength() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.15; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import './IBribe.sol'; interface IGauge { function notifyRewardAmount(IERC20 token, uint256 amount) external; } interface IVoter { struct GaugeWeight { uint128 allocPoint; uint128 voteWeight; // total amount of votes for an LP-token } function infos( IERC20 _lpToken ) external view returns ( uint104 supplyBaseIndex, uint104 supplyVoteIndex, uint40 nextEpochStartTime, uint128 claimable, bool whitelist, IGauge gaugeManager, IBribe bribe ); // lpToken => weight, equals to sum of votes for a LP token function weights(IERC20 _lpToken) external view returns (uint128 allocPoint, uint128 voteWeight); // user address => lpToken => votes function votes(address _user, IERC20 _lpToken) external view returns (uint256); function setBribe(IERC20 _lpToken, IBribe _bribe) external; function distribute(IERC20 _lpToken) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.5; import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import '@openzeppelin/contracts/utils/Address.sol'; import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import '../interfaces/IBribeRewarderFactory.sol'; import '../interfaces/IBoostedMultiRewarder.sol'; import '../interfaces/IBoostedMasterWombat.sol'; /** * This is a sample contract to be used in the Master Wombat contract for partners to reward * stakers with their native token alongside WOM. * * It assumes no minting rights, so requires a set amount of reward tokens to be transferred to this contract prior. * E.g. say you've allocated 100,000 XYZ to the WOM-XYZ farm over 30 days. Then you would need to transfer * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days. * * This contract has no knowledge on the LP amount and factor. Master Wombat is responsible to pass these values to this contract * Change log (since MultiRewarderPerSecV2): * - Rewarders are now boosted by veWom balance! */ contract BoostedMultiRewarder is IBoostedMultiRewarder, Initializable, OwnableUpgradeable, AccessControlEnumerableUpgradeable, ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; bytes32 public constant ROLE_OPERATOR = keccak256('operator'); uint256 public constant ACC_TOKEN_PRECISION = 1e18; uint256 public constant TOTAL_PARTITION = 1000; uint256 public constant MAX_TOKEN_RATE = 10000e18; uint256 public constant MAX_REWARD_TOKENS = 10; struct UserBalanceInfo { uint128 amount; // 20.18 fixed point. uint128 factor; // 20.18 fixed point. } struct UserRewardInfo { uint128 rewardDebt; // 20.18 fixed point. distributed reward per weight // if the pool is activated, rewardDebt must be > 0 uint128 unpaidRewards; // 20.18 fixed point. } /// @notice Info of each reward token. struct RewardInfo { /// slot IERC20 rewardToken; // if rewardToken is 0, native token is used as reward token uint96 tokenPerSec; // 10.18 fixed point. The emission rate in tokens per second. // This rate may not reflect the current rate in cases where emission has not started or has stopped due to surplus <= 0. /// slot uint128 accTokenPerShare; // 20.18 fixed point. Amount of reward token each LP token is worth. // This value increases when rewards are being distributed. uint128 accTokenPerFactorShare; // 20.18 fixed point. Accumulated WOM per factor share /// slot uint128 distributedAmount; // 20.18 fixed point, depending on the decimals of the reward token. This value is used to // track the amount of distributed tokens. If `distributedAmount` is closed to the amount of total received // tokens, we should refill reward or prepare to stop distributing reward. uint128 claimedAmount; // 20.18 fixed point. Total amount claimed by all users. // We can derive the unclaimed amount: distributedAmount - claimedAmount /// slot uint40 lastRewardTimestamp; // The timestamp up to which rewards have already been distributed. // If set to a future value, it indicates that the emission has not started yet. } /** * Visualization of the relationship between distributedAmount, claimedAmount, rewardToDistribute, availableReward, surplus and balance: * * Case: emission is active. rewardToDistribute is growing at the rate of tokenPerSec. * |<--------------distributedAmount------------->|<--rewardToDistribute*-->| * |<-----claimedAmount----->|<-------------------------balance------------------------->| * |<-----------availableReward*--------->| * |<-unclaimedAmount*->| |<-surplus*->| * * Case: reward running out. rewardToDistribute stopped growing. it is capped at availableReward. * |<--------------distributedAmount------------->|<---------rewardToDistribute*-------->| * |<-----claimedAmount----->|<-------------------------balance------------------------->| * |<-----------availableReward*--------->| * |<-unclaimedAmount*->| surplus* = 0 * * Case: balance emptied after emergencyWithdraw. * |<--------------distributedAmount------------->| rewardToDistribute* = 0 * |<-----claimedAmount----->| balance = 0, availableReward* = 0 * |<-unclaimedAmount*->| surplus* = - unclaimedAmount* (negative to indicate deficit) * * (Variables with * are not in the RewardInfo state, but can be derived from it.) * * balance, is the amount of reward token in this contract. Not all of them are available for distribution as some are reserved for * unclaimed rewards. * distributedAmount, is the amount of reward token that has been distributed up to lastRewardTimestamp. * claimedAmount, is the amount of reward token that has been claimed by users. claimedAmount always <= distributedAmount. * unclaimedAmount = distributedAmount - claimedAmount, is the amount of reward token in balance that is reserved to be claimed by users. * availableReward = balance - unclaimedAmount, is the amount inside balance that is available for distribution (not reserved for * unclaimed rewards). * rewardToDistribute is the accumulated reward from [lastRewardTimestamp, now] that is yet to be distributed. as distributedAmount only * accounts for the distributed amount up to lastRewardTimestamp. it is used in _updateReward(), and to be added to distributedAmount. * to prevent bad debt, rewardToDistribute is capped at availableReward. as we cannot distribute more than the availableReward. * rewardToDistribute = min(tokenPerSec * (now - lastRewardTimestamp), availableReward) * surplus = availableReward - rewardToDistribute, is the amount inside balance that is available for future distribution. */ IERC20 public lpToken; IBoostedMasterWombat public masterWombat; /// @notice Info of the reward tokens. RewardInfo[] public rewardInfos; /// @notice userAddr => UserBalanceInfo mapping(address => UserBalanceInfo) public userBalanceInfo; /// @notice tokenId => userAddr => UserRewardInfo mapping(uint256 => mapping(address => UserRewardInfo)) public userRewardInfo; IBribeRewarderFactory public bribeFactory; bool public isDeprecated; event OnReward(address indexed rewardToken, address indexed user, uint256 amount); event RewardRateUpdated(address indexed rewardToken, uint256 oldRate, uint256 newRate); event StartTimeUpdated(address indexed rewardToken, uint40 newStartTime); event IsDeprecatedUpdated(bool isDeprecated); modifier onlyMasterWombat() { require( msg.sender == address(masterWombat), 'BoostedMultiRewarderPerSec: only Master Wombat can call this function' ); _; } /// @notice payable function needed to receive BNB receive() external payable {} /** * @notice Initializes pool. Dev is set to be the account calling this function. */ function initialize( IBribeRewarderFactory _bribeFactory, IBoostedMasterWombat _masterWombat, IERC20 _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) public virtual initializer { require( Address.isContract(address(_rewardToken)) || address(_rewardToken) == address(0), 'constructor: reward token must be a valid contract' ); require(Address.isContract(address(_lpToken)), 'constructor: LP token must be a valid contract'); require(Address.isContract(address(_masterWombat)), 'constructor: Master Wombat must be a valid contract'); require(_startTimestamp >= block.timestamp, 'constructor: invalid _startTimestamp'); __Ownable_init(); __AccessControlEnumerable_init_unchained(); __ReentrancyGuard_init_unchained(); bribeFactory = _bribeFactory; // bribeFactory can be 0 address masterWombat = _masterWombat; lpToken = _lpToken; // use non-zero amount for accTokenPerShare as we want to check if user // has activated the pool by checking rewardDebt > 0 RewardInfo memory reward = RewardInfo({ rewardToken: _rewardToken, tokenPerSec: _tokenPerSec, accTokenPerShare: 1e18, accTokenPerFactorShare: 0, distributedAmount: 0, claimedAmount: 0, lastRewardTimestamp: uint40(_startTimestamp) }); emit RewardRateUpdated(address(reward.rewardToken), 0, _tokenPerSec); emit StartTimeUpdated(address(reward.rewardToken), uint40(_startTimestamp)); rewardInfos.push(reward); } function addOperator(address _operator) external onlyOwner { _grantRole(ROLE_OPERATOR, _operator); } function removeOperator(address _operator) external onlyOwner { _revokeRole(ROLE_OPERATOR, _operator); } function setIsDeprecated(bool _isDeprecated) external onlyOwner { isDeprecated = _isDeprecated; emit IsDeprecatedUpdated(_isDeprecated); } function addRewardToken(IERC20 _rewardToken, uint40 _startTimestampOrNow, uint96 _tokenPerSec) external override { require(hasRole(ROLE_OPERATOR, msg.sender) || msg.sender == owner(), 'not authorized'); // Check `bribeFactory.isRewardTokenWhitelisted` if needed require( address(bribeFactory) == address(0) || bribeFactory.isRewardTokenWhitelisted(_rewardToken), 'reward token must be whitelisted by bribe factory' ); _addRewardToken(_rewardToken, _startTimestampOrNow, _tokenPerSec); } function _addRewardToken(IERC20 _rewardToken, uint40 _startTimestampOrNow, uint96 _tokenPerSec) internal { require( Address.isContract(address(_rewardToken)) || address(_rewardToken) == address(0), 'reward token must be a valid contract' ); require(_startTimestampOrNow == 0 || _startTimestampOrNow >= block.timestamp, 'invalid _startTimestamp'); uint256 length = rewardInfos.length; require(length < MAX_REWARD_TOKENS, 'reward token length exceeded'); for (uint256 i; i < length; ++i) { require(rewardInfos[i].rewardToken != _rewardToken, 'token has already been added'); } _updateReward(); uint40 startTimestamp = _startTimestampOrNow == 0 ? uint40(block.timestamp) : _startTimestampOrNow; // use non-zero amount for accTokenPerShare as we want to check if user // has activated the pool by checking rewardDebt > 0 RewardInfo memory reward = RewardInfo({ rewardToken: _rewardToken, tokenPerSec: _tokenPerSec, accTokenPerShare: 1e18, accTokenPerFactorShare: 0, distributedAmount: 0, claimedAmount: 0, lastRewardTimestamp: startTimestamp }); rewardInfos.push(reward); emit StartTimeUpdated(address(reward.rewardToken), startTimestamp); emit RewardRateUpdated(address(reward.rewardToken), 0, _tokenPerSec); } function updateReward() public { _updateReward(); } /// @dev This function should be called before lpSupply and sumOfFactors update function _updateReward() internal { uint256 lpSupply = _getTotalShare(); uint256 pid = masterWombat.getAssetPid(address(lpToken)); uint256 sumOfFactors = masterWombat.getSumOfFactors(pid); uint256[] memory toDistribute = _rewardsToDistribute(); uint256 length = rewardInfos.length; for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; uint256 rewardToDistribute = toDistribute[i]; if (rewardToDistribute > 0) { (uint256 tokenPerShare, uint256 tokenPerFactorShare) = _getRewardsToDistributeFor( rewardToDistribute, lpSupply, sumOfFactors ); info.accTokenPerShare += toUint128(tokenPerShare); info.accTokenPerFactorShare += toUint128(tokenPerFactorShare); info.distributedAmount += toUint128(rewardToDistribute); } // update lastRewardTimestamp even if no reward is distributed. if (info.lastRewardTimestamp < block.timestamp) { // but don't update if info.lastRewardTimestamp is set in the future, // otherwise we would be starting the emission earlier than it's supposed to. info.lastRewardTimestamp = uint40(block.timestamp); } } } /// @notice Sets the distribution reward rate, and updates the emission start time if specified. /// @param _tokenId The token id /// @param _tokenPerSec The number of tokens to distribute per second /// @param _startTimestampToOverride the start time for the token emission. A value of 0 indicates no changes, while a future /// timestamp starts the emission at the specified time. function setRewardRate(uint256 _tokenId, uint96 _tokenPerSec, uint40 _startTimestampToOverride) external { require(hasRole(ROLE_OPERATOR, msg.sender) || msg.sender == owner(), 'not authorized'); require(_tokenId < rewardInfos.length, 'invalid _tokenId'); require( _startTimestampToOverride == 0 || _startTimestampToOverride >= block.timestamp, 'invalid _startTimestampToOverride' ); require(_tokenPerSec <= MAX_TOKEN_RATE, 'reward rate too high'); // in case of accTokenPerShare overflow _updateReward(); RewardInfo storage info = rewardInfos[_tokenId]; uint256 oldRate = info.tokenPerSec; info.tokenPerSec = _tokenPerSec; if (_startTimestampToOverride > 0) { info.lastRewardTimestamp = _startTimestampToOverride; emit StartTimeUpdated(address(info.rewardToken), _startTimestampToOverride); } emit RewardRateUpdated(address(rewardInfos[_tokenId].rewardToken), oldRate, _tokenPerSec); } /// @notice Function called by Master Wombat whenever staker claims WOM harvest. /// @notice Allows staker to also receive a 2nd reward token. /// @dev Assume `_getTotalShare` isn't updated yet when this function is called /// @param _user Address of user /// @param _newLpAmount The new amount of LP /// @param _newFactor The new factor of LP function onReward( address _user, uint256 _newLpAmount, uint256 _newFactor ) external virtual override onlyMasterWombat nonReentrant returns (uint256[] memory rewards) { _updateReward(); return _onReward(_user, _newLpAmount, _newFactor); } /// @notice Function called by Master Wombat when factor is updated /// @dev Assume lpSupply and sumOfFactors isn't updated yet when this function is called /// @notice user.unpaidRewards will be updated function onUpdateFactor(address _user, uint256 _newFactor) external override onlyMasterWombat { if (basePartition() == TOTAL_PARTITION) { // base partition only return; } updateReward(); uint256 length = rewardInfos.length; for (uint256 i; i < length; ++i) { RewardInfo storage pool = rewardInfos[i]; UserRewardInfo storage user = userRewardInfo[i][_user]; if (user.rewardDebt > 0) { // rewardDebt > 0 indicates the user has activated the pool and we should calculate rewards user.unpaidRewards += toUint128( _getRewardDebt( userBalanceInfo[_user].amount, pool.accTokenPerShare, userBalanceInfo[_user].factor, pool.accTokenPerFactorShare ) - user.rewardDebt ); } user.rewardDebt = toUint128( _getRewardDebt( userBalanceInfo[_user].amount, pool.accTokenPerShare, _newFactor, pool.accTokenPerFactorShare ) ); } userBalanceInfo[_user].factor = toUint128(_newFactor); } function basePartition() public view returns (uint256) { return masterWombat.basePartition(); } function _onReward( address _user, uint256 _newLpAmount, uint256 _newFactor ) internal virtual returns (uint256[] memory rewards) { uint256 length = rewardInfos.length; rewards = new uint256[](length); for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; UserRewardInfo storage user = userRewardInfo[i][_user]; IERC20 rewardToken = info.rewardToken; if (user.rewardDebt > 0 || user.unpaidRewards > 0) { // rewardDebt > 0 indicates the user has activated the pool and we should distribute rewards uint256 pending = _getRewardDebt( userBalanceInfo[_user].amount, info.accTokenPerShare, userBalanceInfo[_user].factor, info.accTokenPerFactorShare ) + user.unpaidRewards - user.rewardDebt; if (address(rewardToken) == address(0)) { // is native token uint256 tokenBalance = address(this).balance; if (pending > tokenBalance) { // Note: this line may fail if the receiver is a contract and refuse to receive BNB (bool success, ) = _user.call{value: tokenBalance}(''); require(success, 'Transfer failed'); rewards[i] = tokenBalance; info.claimedAmount += toUint128(tokenBalance); user.unpaidRewards = toUint128(pending - tokenBalance); } else { (bool success, ) = _user.call{value: pending}(''); require(success, 'Transfer failed'); rewards[i] = pending; info.claimedAmount += toUint128(pending); user.unpaidRewards = 0; } } else { // ERC20 token uint256 tokenBalance = rewardToken.balanceOf(address(this)); if (pending > tokenBalance) { rewardToken.safeTransfer(_user, tokenBalance); rewards[i] = tokenBalance; info.claimedAmount += toUint128(tokenBalance); user.unpaidRewards = toUint128(pending - tokenBalance); } else { rewardToken.safeTransfer(_user, pending); rewards[i] = pending; info.claimedAmount += toUint128(pending); user.unpaidRewards = 0; } } } user.rewardDebt = toUint128( _getRewardDebt(_newLpAmount, info.accTokenPerShare, _newFactor, info.accTokenPerFactorShare) ); emit OnReward(address(rewardToken), _user, rewards[i]); } userBalanceInfo[_user].amount = toUint128(_newLpAmount); userBalanceInfo[_user].factor = toUint128(_newFactor); } function emergencyClaimReward() external nonReentrant returns (uint256[] memory rewards) { _updateReward(); require(isDeprecated, 'rewarder / bribe is not deprecated'); return _onReward(msg.sender, 0, 0); } /// @notice returns reward length function rewardLength() external view virtual override returns (uint256) { return rewardInfos.length; } /// @notice View function to see pending tokens that have been distributed but not claimed by the user yet. /// @param _user Address of user. /// @return rewards_ reward for a given user. function pendingTokens(address _user) external view virtual override returns (uint256[] memory rewards_) { return _pendingTokens(_user, userBalanceInfo[_user].amount, userBalanceInfo[_user].factor); } function _pendingTokens( address _user, uint256 _lpAmount, uint256 _factor ) internal view returns (uint256[] memory rewards_) { uint256 pid = masterWombat.getAssetPid(address(lpToken)); uint256 sumOfFactors = masterWombat.getSumOfFactors(pid); uint256 length = rewardInfos.length; rewards_ = new uint256[](length); uint256[] memory toDistribute = _rewardsToDistribute(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; UserRewardInfo storage user = userRewardInfo[i][_user]; uint256 accTokenPerShare = info.accTokenPerShare; uint256 accTokenPerFactorShare = info.accTokenPerFactorShare; uint256 lpSupply = _getTotalShare(); if (lpSupply > 0) { (uint256 tokenPerShare, uint256 tokenPerFactorShare) = _getRewardsToDistributeFor( toDistribute[i], lpSupply, sumOfFactors ); accTokenPerShare += tokenPerShare; accTokenPerFactorShare += tokenPerFactorShare; } rewards_[i] = _getRewardDebt(_lpAmount, accTokenPerShare, _factor, accTokenPerFactorShare) + user.unpaidRewards - user.rewardDebt; } } function _getRewardsToDistributeFor( uint256 rewardToDistribute, uint256 lpSupply, uint256 sumOfFactors ) internal view returns (uint256 tokenPerShare, uint256 tokenPerFactorShare) { // use `max(totalShare, 1e18)` in case of overflow uint256 _basePartition = basePartition(); tokenPerShare = (rewardToDistribute * ACC_TOKEN_PRECISION * _basePartition) / max(lpSupply, 1e18) / TOTAL_PARTITION; if (sumOfFactors > 0) { tokenPerFactorShare = (rewardToDistribute * ACC_TOKEN_PRECISION * (TOTAL_PARTITION - _basePartition)) / sumOfFactors / TOTAL_PARTITION; } } function _getRewardDebt( uint256 userAmount, uint256 accTokenPerShare, uint256 userFactor, uint256 accTokenPerFactorShare ) internal pure returns (uint256) { return (userAmount * accTokenPerShare + userFactor * accTokenPerFactorShare) / ACC_TOKEN_PRECISION; } /// @notice the amount of reward accumulated since the lastRewardTimestamp and is to be distributed. function rewardsToDistribute() public view returns (uint256[] memory rewards_) { return _rewardsToDistribute(); } /// @notice the amount of reward accumulated since the lastRewardTimestamp and is to be distributed. /// the case that lastRewardTimestamp is in the future is also handled function _rewardsToDistribute() internal view returns (uint256[] memory rewards_) { uint256 length = rewardInfos.length; rewards_ = new uint256[](length); uint256[] memory rewardBalances = _balances(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; // if (block.timestamp < info.lastRewardTimestamp), then emission has not started yet. if (block.timestamp < info.lastRewardTimestamp) continue; uint40 timeElapsed = uint40(block.timestamp) - info.lastRewardTimestamp; uint256 accumulatedReward = uint256(info.tokenPerSec) * timeElapsed; // To prevent bad debt, need to cap at availableReward uint256 availableReward; // this is to handle the underflow case if claimedAmount + balance < distributedAmount, // which happens only if balance was emergencyWithdrawn. if (info.claimedAmount + rewardBalances[i] > info.distributedAmount) { availableReward = info.claimedAmount + rewardBalances[i] - info.distributedAmount; } rewards_[i] = min(accumulatedReward, availableReward); } } function _getTotalShare() internal view virtual returns (uint256) { return lpToken.balanceOf(address(masterWombat)); } /// @notice return an array of reward tokens function _rewardTokens() internal view returns (IERC20[] memory tokens_) { uint256 length = rewardInfos.length; tokens_ = new IERC20[](length); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; tokens_[i] = info.rewardToken; } } function rewardTokens() external view virtual override returns (IERC20[] memory tokens) { return _rewardTokens(); } /// @notice View function to see surplus of each reward, i.e. reward balance - unclaimed amount /// it would be negative if there's bad debt/deficit, which would happend only if some token was emergencyWithdrawn. /// @return surpluses_ surpluses of the reward tokens. // override. function rewardTokenSurpluses() external view virtual returns (int256[] memory surpluses_) { return _rewardTokenSurpluses(); } /// @notice View function to see surplus of each reward, i.e. reward balance - unclaimed amount /// surplus = claimed amount + balance - distributed amount - rewardToDistribute /// @return surpluses_ surpluses of the reward tokens. function _rewardTokenSurpluses() internal view returns (int256[] memory surpluses_) { uint256 length = rewardInfos.length; surpluses_ = new int256[](length); uint256[] memory toDistribute = _rewardsToDistribute(); uint256[] memory rewardBalances = _balances(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; surpluses_[i] = int256(uint256(info.claimedAmount)) + int256(rewardBalances[i]) - int256(uint256(info.distributedAmount)) - int256(toDistribute[i]); } } function isEmissionActive() external view returns (bool[] memory isActive_) { return _isEmissionActive(); } function _isEmissionActive() internal view returns (bool[] memory isActive_) { uint256 length = rewardInfos.length; isActive_ = new bool[](length); int256[] memory surpluses = _rewardTokenSurpluses(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; // conditions for emission to be active: // 1. surplus > 0 // 2. tokenPerSec > 0 // 3. lastRewardTimestamp <= block.timestamp isActive_[i] = surpluses[i] > 0 && info.tokenPerSec > 0 && info.lastRewardTimestamp <= block.timestamp; } } /// @notice In case rewarder is stopped before emissions finished, this function allows /// withdrawal of remaining tokens. /// there will be deficit which is equal to the unclaimed amount function emergencyWithdraw() external onlyOwner { uint256 length = rewardInfos.length; for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; info.tokenPerSec = 0; info.lastRewardTimestamp = uint40(block.timestamp); emergencyTokenWithdraw(address(info.rewardToken)); } } /// @notice avoids loosing funds in case there is any tokens sent to this contract /// the reward token will not be stopped and keep accumulating debts /// @dev only to be called by owner function emergencyTokenWithdraw(address token) public onlyOwner { // send that balance back to owner if (token == address(0)) { // is native token (bool success, ) = msg.sender.call{value: address(this).balance}(''); require(success, 'Transfer failed'); } else { IERC20(token).safeTransfer(msg.sender, IERC20(token).balanceOf(address(this))); } } /// @notice View function to see the timestamp when the reward will runout based on current emission rate and balance left. /// a timestamp of 0 indicates that the token is not emitting or already run out. /// also works for the case that emission start time (lastRewardTimestamp) is in the future. function runoutTimestamps() external view returns (uint40[] memory timestamps_) { uint256 length = rewardInfos.length; timestamps_ = new uint40[](length); uint256[] memory rewardBalances = _balances(); int256[] memory surpluses = _rewardTokenSurpluses(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; if (surpluses[i] > 0 && info.tokenPerSec > 0) { // we have: surplus = claimedAmount + balance - distributedAmount - tokenPerSec * (block.timestamp - lastRewardTimestamp) // surplus would reach 0 at runoutTimestamp. therefore, we have the formula: // 0 = claimedAmount + balance - distributedAmount - tokenPerSec * (runoutTimestamp - lastRewardTimestamp) // Solving for runoutTimestamp: // runoutTimestamp = (claimedAmount + balance - distributedAmount + tokenPerSec * lastRewardTimestamp) / tokenPerSec timestamps_[i] = uint40( (info.claimedAmount + rewardBalances[i] - info.distributedAmount + info.tokenPerSec * info.lastRewardTimestamp) / info.tokenPerSec ); } } } /// @notice View function to preserve backward compatibility, as the previous version uses rewardInfo instead of rewardInfos function rewardInfo(uint256 i) external view returns (RewardInfo memory info) { return rewardInfos[i]; } /// @notice View function to see balances of reward token. function balances() external view returns (uint256[] memory balances_) { return _balances(); } function _balances() internal view returns (uint256[] memory balances_) { uint256 length = rewardInfos.length; balances_ = new uint256[](length); for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; if (address(info.rewardToken) == address(0)) { // is native token balances_[i] = address(this).balance; } else { balances_[i] = info.rewardToken.balanceOf(address(this)); } } } function toUint128(uint256 val) internal pure returns (uint128) { if (val > type(uint128).max) revert('uint128 overflow'); return uint128(val); } function max(uint256 x, uint256 y) internal pure returns (uint256) { return x >= y ? x : y; } function min(uint256 x, uint256 y) internal pure returns (uint256) { return x <= y ? x : y; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.5; import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol'; import '@openzeppelin/contracts/utils/Address.sol'; import '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import '../interfaces/IBribeRewarderFactory.sol'; import '../interfaces/IMultiRewarderV2.sol'; /** * This is a sample contract to be used in the Master contract for partners to reward * stakers with their native token alongside WOM. * * It assumes no minting rights, so requires a set amount of reward tokens to be transferred to this contract prior. * E.g. say you've allocated 100,000 XYZ to the WOM-XYZ farm over 30 days. Then you would need to transfer * 100,000 XYZ and set the block reward accordingly so it's fully distributed after 30 days. * * - This contract has no knowledge on the LP amount and Master is * responsible to pass the amount into this contract * - Supports multiple reward tokens * - Supports bribe rewarder factory */ contract MultiRewarderPerSecV2 is IMultiRewarderV2, Initializable, OwnableUpgradeable, AccessControlEnumerableUpgradeable, ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; bytes32 public constant ROLE_OPERATOR = keccak256('operator'); uint256 public constant ACC_TOKEN_PRECISION = 1e18; uint256 public constant MAX_REWARD_TOKENS = 10; struct UserBalanceInfo { uint256 amount; } struct UserRewardInfo { // if the pool is activated, rewardDebt should be > 0 uint128 rewardDebt; // 20.18 fixed point. distributed reward per weight uint128 unpaidRewards; // 20.18 fixed point. } /// @notice Info of each reward token. struct RewardInfo { /// slot IERC20 rewardToken; // if rewardToken is 0, native token is used as reward token uint96 tokenPerSec; // 10.18 fixed point. The emission rate in tokens per second. // This rate may not reflect the current rate in cases where emission has not started or has stopped due to surplus <= 0. /// slot uint128 accTokenPerShare; // 26.12 fixed point. Amount of reward token each LP token is worth. // This value increases when rewards are being distributed. uint128 distributedAmount; // 20.18 fixed point, depending on the decimals of the reward token. This value is used to // track the amount of distributed tokens. If `distributedAmount` is closed to the amount of total received // tokens, we should refill reward or prepare to stop distributing reward. /// slot uint128 claimedAmount; // 20.18 fixed point. Total amount claimed by all users. // We can derive the unclaimed amount: distributedAmount - claimedAmount uint40 lastRewardTimestamp; // The timestamp up to which rewards have already been distributed. // If set to a future value, it indicates that the emission has not started yet. } /** * Visualization of the relationship between distributedAmount, claimedAmount, rewardToDistribute, availableReward, surplus and balance: * * Case: emission is active. rewardToDistribute is growing at the rate of tokenPerSec. * |<--------------distributedAmount------------->|<--rewardToDistribute*-->| * |<-----claimedAmount----->|<-------------------------balance------------------------->| * |<-----------availableReward*--------->| * |<-unclaimedAmount*->| |<-surplus*->| * * Case: reward running out. rewardToDistribute stopped growing. it is capped at availableReward. * |<--------------distributedAmount------------->|<---------rewardToDistribute*-------->| * |<-----claimedAmount----->|<-------------------------balance------------------------->| * |<-----------availableReward*--------->| * |<-unclaimedAmount*->| surplus* = 0 * * Case: balance emptied after emergencyWithdraw. * |<--------------distributedAmount------------->| rewardToDistribute* = 0 * |<-----claimedAmount----->| balance = 0, availableReward* = 0 * |<-unclaimedAmount*->| surplus* = - unclaimedAmount* (negative to indicate deficit) * * (Variables with * are not in the RewardInfo state, but can be derived from it.) * * balance, is the amount of reward token in this contract. Not all of them are available for distribution as some are reserved * for unclaimed rewards. * distributedAmount, is the amount of reward token that has been distributed up to lastRewardTimestamp. * claimedAmount, is the amount of reward token that has been claimed by users. claimedAmount always <= distributedAmount. * unclaimedAmount = distributedAmount - claimedAmount, is the amount of reward token in balance that is reserved to be claimed by users. * availableReward = balance - unclaimedAmount, is the amount inside balance that is available for distribution (not reserved for * unclaimed rewards). * rewardToDistribute is the accumulated reward from [lastRewardTimestamp, now] that is yet to be distributed. as distributedAmount only * accounts for the distributed amount up to lastRewardTimestamp. it is used in _updateReward(), and to be added to distributedAmount. * to prevent bad debt, rewardToDistribute is capped at availableReward. as we cannot distribute more than the availableReward. * rewardToDistribute = min(tokenPerSec * (now - lastRewardTimestamp), availableReward) * surplus = availableReward - rewardToDistribute, is the amount inside balance that is available for future distribution. */ IERC20 public lpToken; address public master; /// @notice Info of the reward tokens. RewardInfo[] public rewardInfos; /// @notice userAddr => UserBalanceInfo mapping(address => UserBalanceInfo) public userBalanceInfo; /// @notice tokenId => userId => UserRewardInfo mapping(uint256 => mapping(address => UserRewardInfo)) public userRewardInfo; IBribeRewarderFactory public bribeFactory; bool public isDeprecated; event OnReward(address indexed rewardToken, address indexed user, uint256 amount); event RewardRateUpdated(address indexed rewardToken, uint256 oldRate, uint256 newRate); event StartTimeUpdated(address indexed rewardToken, uint40 newStartTime); event IsDeprecatedUpdated(bool isDeprecated); modifier onlyMaster() { require(msg.sender == address(master), 'onlyMaster: only Master can call this function'); _; } /// @notice payable function needed to receive BNB receive() external payable {} /** * @notice Initializes pool. Dev is set to be the account calling this function. */ function initialize( IBribeRewarderFactory _bribeFactory, address _master, IERC20 _lpToken, uint256 _startTimestamp, IERC20 _rewardToken, uint96 _tokenPerSec ) public virtual initializer { require( Address.isContract(address(_rewardToken)) || address(_rewardToken) == address(0), 'constructor: reward token must be a valid contract' ); require(Address.isContract(address(_lpToken)), 'constructor: LP token must be a valid contract'); require(Address.isContract(address(_master)), 'constructor: Master must be a valid contract'); require(_startTimestamp >= block.timestamp, 'constructor: invalid _startTimestamp'); __Ownable_init(); __AccessControlEnumerable_init_unchained(); __ReentrancyGuard_init_unchained(); bribeFactory = _bribeFactory; // bribeFactory can be 0 address master = _master; lpToken = _lpToken; // use non-zero amount for accTokenPerShare as we want to check if user // has activated the pool by checking rewardDebt > 0 RewardInfo memory reward = RewardInfo({ rewardToken: _rewardToken, tokenPerSec: _tokenPerSec, accTokenPerShare: 1e18, distributedAmount: 0, claimedAmount: 0, lastRewardTimestamp: uint40(_startTimestamp) }); emit RewardRateUpdated(address(reward.rewardToken), 0, _tokenPerSec); emit StartTimeUpdated(address(reward.rewardToken), uint40(_startTimestamp)); rewardInfos.push(reward); } function addOperator(address _operator) external onlyOwner { _grantRole(ROLE_OPERATOR, _operator); } function removeOperator(address _operator) external onlyOwner { _revokeRole(ROLE_OPERATOR, _operator); } function setIsDeprecated(bool _isDeprecated) external onlyOwner { isDeprecated = _isDeprecated; emit IsDeprecatedUpdated(_isDeprecated); } function addRewardToken(IERC20 _rewardToken, uint40 _startTimestampOrNow, uint96 _tokenPerSec) external virtual { require(hasRole(ROLE_OPERATOR, msg.sender) || msg.sender == owner(), 'not authorized'); // Check `bribeFactory.isRewardTokenWhitelisted` if needed require( address(bribeFactory) == address(0) || bribeFactory.isRewardTokenWhitelisted(_rewardToken), 'reward token must be whitelisted by bribe factory' ); _addRewardToken(_rewardToken, _startTimestampOrNow, _tokenPerSec); } function _addRewardToken(IERC20 _rewardToken, uint40 _startTimestampOrNow, uint96 _tokenPerSec) internal { require( Address.isContract(address(_rewardToken)) || address(_rewardToken) == address(0), 'reward token must be a valid contract' ); require(_startTimestampOrNow == 0 || _startTimestampOrNow >= block.timestamp, 'invalid _startTimestamp'); uint256 length = rewardInfos.length; require(length < MAX_REWARD_TOKENS, 'reward token length exceeded'); for (uint256 i; i < length; ++i) { require(rewardInfos[i].rewardToken != _rewardToken, 'token has already been added'); } _updateReward(); uint40 startTimestamp = _startTimestampOrNow == 0 ? uint40(block.timestamp) : _startTimestampOrNow; // use non-zero amount for accTokenPerShare as we want to check if user // has activated the pool by checking rewardDebt > 0 RewardInfo memory reward = RewardInfo({ rewardToken: _rewardToken, tokenPerSec: _tokenPerSec, accTokenPerShare: 1e18, distributedAmount: 0, claimedAmount: 0, lastRewardTimestamp: startTimestamp }); rewardInfos.push(reward); emit StartTimeUpdated(address(reward.rewardToken), startTimestamp); emit RewardRateUpdated(address(reward.rewardToken), 0, _tokenPerSec); } function updateReward() public { _updateReward(); } /// @dev This function should be called before lpSupply and sumOfFactors update function _updateReward() internal { _updateReward(_getTotalShare()); } function _updateReward(uint256 totalShare) internal { uint256 length = rewardInfos.length; uint256[] memory toDistribute = rewardsToDistribute(); for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; uint256 rewardToDistribute = toDistribute[i]; if (rewardToDistribute > 0) { // use `max(totalShare, 1e18)` in case of overflow info.accTokenPerShare += toUint128((rewardToDistribute * ACC_TOKEN_PRECISION) / max(totalShare, 1e18)); info.distributedAmount += toUint128(rewardToDistribute); } // update lastRewardTimestamp even if no reward is distributed. if (info.lastRewardTimestamp < block.timestamp) { // but don't update if info.lastRewardTimestamp is set in the future, // otherwise we would be starting the emission earlier than it's supposed to. info.lastRewardTimestamp = uint40(block.timestamp); } } } /// @notice Sets the distribution reward rate, and updates the emission start time if specified. /// @param _tokenId The token id /// @param _tokenPerSec The number of tokens to distribute per second /// @param _startTimestampToOverride the start time for the token emission. /// A value of 0 indicates no changes, while a future timestamp starts the emission at the specified time. function setRewardRate(uint256 _tokenId, uint96 _tokenPerSec, uint40 _startTimestampToOverride) external { require(hasRole(ROLE_OPERATOR, msg.sender) || msg.sender == owner(), 'not authorized'); require(_tokenId < rewardInfos.length, 'invalid _tokenId'); require( _startTimestampToOverride == 0 || _startTimestampToOverride >= block.timestamp, 'invalid _startTimestampToOverride' ); require(_tokenPerSec <= 10000e18, 'reward rate too high'); // in case of accTokenPerShare overflow _updateReward(); RewardInfo storage info = rewardInfos[_tokenId]; uint256 oldRate = info.tokenPerSec; info.tokenPerSec = _tokenPerSec; if (_startTimestampToOverride > 0) { info.lastRewardTimestamp = _startTimestampToOverride; emit StartTimeUpdated(address(info.rewardToken), _startTimestampToOverride); } emit RewardRateUpdated(address(rewardInfos[_tokenId].rewardToken), oldRate, _tokenPerSec); } /// @notice Function called by Master whenever staker claims WOM harvest. /// @notice Allows staker to also receive a 2nd reward token. /// @dev Assume `_getTotalShare` isn't updated yet when this function is called /// @param _user Address of user /// @param _lpAmount The new amount of LP function onReward( address _user, uint256 _lpAmount ) external virtual override onlyMaster nonReentrant returns (uint256[] memory rewards) { _updateReward(); return _onReward(_user, _lpAmount); } function _onReward(address _user, uint256 _lpAmount) internal virtual returns (uint256[] memory rewards) { uint256 length = rewardInfos.length; rewards = new uint256[](length); for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; UserRewardInfo storage user = userRewardInfo[i][_user]; IERC20 rewardToken = info.rewardToken; if (user.rewardDebt > 0 || user.unpaidRewards > 0) { // rewardDebt > 0 indicates the user has activated the pool and we should distribute rewards uint256 pending = ((userBalanceInfo[_user].amount * uint256(info.accTokenPerShare)) / ACC_TOKEN_PRECISION) + user.unpaidRewards - user.rewardDebt; if (address(rewardToken) == address(0)) { // is native token uint256 tokenBalance = address(this).balance; if (pending > tokenBalance) { // Note: this line may fail if the receiver is a contract and refuse to receive BNB (bool success, ) = _user.call{value: tokenBalance}(''); require(success, 'Transfer failed'); rewards[i] = tokenBalance; info.claimedAmount += toUint128(tokenBalance); user.unpaidRewards = toUint128(pending - tokenBalance); } else { (bool success, ) = _user.call{value: pending}(''); require(success, 'Transfer failed'); rewards[i] = pending; info.claimedAmount += toUint128(pending); user.unpaidRewards = 0; } } else { // ERC20 token uint256 tokenBalance = rewardToken.balanceOf(address(this)); if (pending > tokenBalance) { rewardToken.safeTransfer(_user, tokenBalance); rewards[i] = tokenBalance; info.claimedAmount += toUint128(tokenBalance); user.unpaidRewards = toUint128(pending - tokenBalance); } else { rewardToken.safeTransfer(_user, pending); rewards[i] = pending; info.claimedAmount += toUint128(pending); user.unpaidRewards = 0; } } } user.rewardDebt = toUint128((_lpAmount * info.accTokenPerShare) / ACC_TOKEN_PRECISION); emit OnReward(address(rewardToken), _user, rewards[i]); } userBalanceInfo[_user].amount = toUint128(_lpAmount); } function emergencyClaimReward() external nonReentrant returns (uint256[] memory rewards) { _updateReward(); require(isDeprecated, 'rewarder / bribe is not deprecated'); return _onReward(msg.sender, 0); } /// @notice returns reward length function rewardLength() public view virtual override returns (uint256) { return rewardInfos.length; } /// @notice View function to see pending tokens that have been distributed but not claimed by the user yet. /// @param _user Address of user. /// @return rewards_ reward for a given user. function pendingTokens(address _user) public view virtual override returns (uint256[] memory rewards_) { uint256 length = rewardInfos.length; rewards_ = new uint256[](length); uint256[] memory toDistribute = rewardsToDistribute(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; UserRewardInfo storage user = userRewardInfo[i][_user]; uint256 accTokenPerShare = info.accTokenPerShare; uint256 totalShare = _getTotalShare(); if (totalShare > 0) { uint256 rewardToDistribute = toDistribute[i]; // use `max(totalShare, 1e18)` in case of overflow accTokenPerShare += (rewardToDistribute * ACC_TOKEN_PRECISION) / max(totalShare, 1e18); } rewards_[i] = ((userBalanceInfo[_user].amount * uint256(accTokenPerShare)) / ACC_TOKEN_PRECISION) - user.rewardDebt + user.unpaidRewards; } } /// @notice the amount of reward accumulated since the lastRewardTimestamp and is to be distributed. /// the case that lastRewardTimestamp is in the future is also handled function rewardsToDistribute() public view returns (uint256[] memory rewards_) { uint256 length = rewardInfos.length; rewards_ = new uint256[](length); uint256[] memory rewardBalances = balances(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; // if (block.timestamp < info.lastRewardTimestamp), then emission has not started yet. if (block.timestamp < info.lastRewardTimestamp) continue; uint40 timeElapsed = uint40(block.timestamp) - info.lastRewardTimestamp; uint256 accumulatedReward = uint256(info.tokenPerSec) * timeElapsed; // To prevent bad debt, need to cap at availableReward uint256 availableReward; // this is to handle the underflow case if claimedAmount + balance < distributedAmount, // which could happend only if balance was emergencyWithdrawn. if (info.claimedAmount + rewardBalances[i] > info.distributedAmount) { availableReward = info.claimedAmount + rewardBalances[i] - info.distributedAmount; } rewards_[i] = min(accumulatedReward, availableReward); } } function _getTotalShare() internal view virtual returns (uint256) { return lpToken.balanceOf(address(master)); } /// @notice return an array of reward tokens function rewardTokens() public view virtual override returns (IERC20[] memory tokens_) { uint256 length = rewardInfos.length; tokens_ = new IERC20[](length); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; tokens_[i] = info.rewardToken; } } /// @notice View function to see surplus of each reward, i.e. reward balance - unclaimed amount /// it would be negative if there's bad debt/deficit, which would happend only if some token was emergencyWithdrawn. /// @return surpluses_ surpluses of the reward tokens. // override. function rewardTokenSurpluses() external view virtual returns (int256[] memory surpluses_) { return _rewardTokenSurpluses(); } /// @notice View function to see surplus of each reward, i.e. reward balance - unclaimed amount /// surplus = claimed amount + balance - distributed amount - rewardToDistribute /// @return surpluses_ surpluses of the reward tokens. function _rewardTokenSurpluses() internal view returns (int256[] memory surpluses_) { uint256 length = rewardInfos.length; surpluses_ = new int256[](length); uint256[] memory toDistribute = rewardsToDistribute(); uint256[] memory rewardBalances = balances(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; surpluses_[i] = int256(uint256(info.claimedAmount)) + int256(rewardBalances[i]) - int256(uint256(info.distributedAmount)) - int256(toDistribute[i]); } } function isEmissionActive() external view returns (bool[] memory isActive_) { return _isEmissionActive(); } function _isEmissionActive() internal view returns (bool[] memory isActive_) { uint256 length = rewardInfos.length; isActive_ = new bool[](length); int256[] memory surpluses = _rewardTokenSurpluses(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; // conditions for emission to be active: // 1. surplus > 0 // 2. tokenPerSec > 0 // 3. lastRewardTimestamp <= block.timestamp isActive_[i] = surpluses[i] > 0 && info.tokenPerSec > 0 && info.lastRewardTimestamp <= block.timestamp; } } /// @notice In case rewarder is stopped before emissions finished, this function allows /// withdrawal of remaining tokens. /// there will be deficit which is equal to the unclaimed amount function emergencyWithdraw() external onlyOwner { uint256 length = rewardInfos.length; for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; info.tokenPerSec = 0; info.lastRewardTimestamp = uint40(block.timestamp); emergencyTokenWithdraw(address(info.rewardToken)); } } /// @notice avoids loosing funds in case there is any tokens sent to this contract /// the reward token will not be stopped and keep accumulating debts /// @dev only to be called by owner function emergencyTokenWithdraw(address token) public onlyOwner { // send that balance back to owner if (token == address(0)) { // is native token (bool success, ) = msg.sender.call{value: address(this).balance}(''); require(success, 'Transfer failed'); } else { IERC20(token).safeTransfer(msg.sender, IERC20(token).balanceOf(address(this))); } } /// @notice View function to see the timestamp when the reward will runout based on current emission rate and balance left. /// a timestamp of 0 indicates that the token is not emitting or already run out. /// also works for the case that emission start time (lastRewardTimestamp) is in the future. function runoutTimestamps() external view returns (uint40[] memory timestamps_) { uint256 length = rewardInfos.length; timestamps_ = new uint40[](length); uint256[] memory rewardBalances = balances(); int256[] memory surpluses = _rewardTokenSurpluses(); for (uint256 i; i < length; ++i) { RewardInfo memory info = rewardInfos[i]; if (surpluses[i] > 0 && info.tokenPerSec > 0) { // we have: surplus = claimedAmount + balance - distributedAmount - tokenPerSec * (block.timestamp - lastRewardTimestamp) // surplus would reach 0 at runoutTimestamp. therefore, we have the formula: // 0 = claimedAmount + balance - distributedAmount - tokenPerSec * (runoutTimestamp - lastRewardTimestamp) // Solving for runoutTimestamp: // runoutTimestamp = (claimedAmount + balance - distributedAmount + tokenPerSec * lastRewardTimestamp) / tokenPerSec timestamps_[i] = uint40( (info.claimedAmount + rewardBalances[i] - info.distributedAmount + info.tokenPerSec * info.lastRewardTimestamp) / info.tokenPerSec ); } } } /// @notice View function to preserve backward compatibility, as the previous version uses rewardInfo instead of rewardInfos function rewardInfo(uint256 i) external view returns (RewardInfo memory info) { return rewardInfos[i]; } /// @notice View function to see balances of reward token. function balances() public view returns (uint256[] memory balances_) { uint256 length = rewardInfos.length; balances_ = new uint256[](length); for (uint256 i; i < length; ++i) { RewardInfo storage info = rewardInfos[i]; if (address(info.rewardToken) == address(0)) { // is native token balances_[i] = address(this).balance; } else { balances_[i] = info.rewardToken.balanceOf(address(this)); } } } function toUint128(uint256 val) internal pure returns (uint128) { if (val > type(uint128).max) revert('uint128 overflow'); return uint128(val); } function max(uint256 x, uint256 y) internal pure returns (uint256) { return x >= y ? x : y; } function min(uint256 x, uint256 y) internal pure returns (uint256) { return x <= y ? x : y; } uint256[50] private __gap; }
{ "viaIR": true, "optimizer": { "enabled": true, "runs": 1000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"indexed":false,"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"indexed":false,"internalType":"uint96","name":"_tokenPerSec","type":"uint96"},{"indexed":false,"internalType":"address","name":"bribe","type":"address"}],"name":"DeployBribeContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"indexed":false,"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"indexed":false,"internalType":"uint96","name":"_tokenPerSec","type":"uint96"},{"indexed":false,"internalType":"address","name":"rewarder","type":"address"}],"name":"DeployRewarderContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBeacon","name":"beacon","type":"address"}],"name":"SetBribeBeacon","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"indexed":false,"internalType":"address","name":"bribe","type":"address"}],"name":"SetBribeContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"deployer","type":"address"}],"name":"SetBribeDeployer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IBeacon","name":"beacon","type":"address"}],"name":"SetRewarderBeacon","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"indexed":false,"internalType":"address","name":"rewarder","type":"address"}],"name":"SetRewarderContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IAsset","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"deployer","type":"address"}],"name":"SetRewarderDeployer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IVoter","name":"voter","type":"address"}],"name":"SetVoter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"bool","name":"isAdded","type":"bool"}],"name":"WhitelistRewardTokenUpdated","type":"event"},{"inputs":[],"name":"bribeBeacon","outputs":[{"internalType":"contract IBeacon","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"","type":"address"}],"name":"bribeDeployers","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"internalType":"uint96","name":"_tokenPerSec","type":"uint96"}],"name":"deployBribeContract","outputs":[{"internalType":"address","name":"bribe","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"internalType":"uint96","name":"_tokenPerSec","type":"uint96"}],"name":"deployBribeContractAndSetBribe","outputs":[{"internalType":"address","name":"bribe","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"internalType":"uint96","name":"_tokenPerSec","type":"uint96"}],"name":"deployRewarderContract","outputs":[{"internalType":"address","name":"rewarder","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_lpToken","type":"address"},{"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"internalType":"contract IERC20","name":"_rewardToken","type":"address"},{"internalType":"uint96","name":"_tokenPerSec","type":"uint96"}],"name":"deployRewarderContractAndSetRewarder","outputs":[{"internalType":"address","name":"rewarder","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getWhitelistedRewardTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IBeacon","name":"_rewarderBeacon","type":"address"},{"internalType":"contract IBeacon","name":"_bribeBeacon","type":"address"},{"internalType":"contract IBoostedMasterWombat","name":"_masterWombat","type":"address"},{"internalType":"contract IVoter","name":"_voter","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"isRewardTokenWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"masterWombat","outputs":[{"internalType":"contract IBoostedMasterWombat","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"revokeRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewarderBeacon","outputs":[{"internalType":"contract IBeacon","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"","type":"address"}],"name":"rewarderDeployers","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IBeacon","name":"_bribeBeacon","type":"address"}],"name":"setBribeBeacon","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_token","type":"address"},{"internalType":"address","name":"_deployer","type":"address"}],"name":"setBribeDeployer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IBeacon","name":"_rewarderBeacon","type":"address"}],"name":"setRewarderBeacon","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAsset","name":"_token","type":"address"},{"internalType":"address","name":"_deployer","type":"address"}],"name":"setRewarderDeployer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IVoter","name":"_voter","type":"address"}],"name":"setVoter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"voter","outputs":[{"internalType":"contract IVoter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"whitelistRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6080806040523461001657612b7d908161001c8239f35b600080fdfe604060808152600490813610156200001657600080fd5b600091823560e01c80630230ed15146200105057806302b2ed7d1462000e245780630bbe70b91462000c425780633bd61ba81462000c18578063400b119e1462000b995780634538c1a21462000b6d57806346c96aac1462000b435780634bc2a6571462000ac45780635a2480d81462000a03578063715018a614620009a457806373217954146200097a5780638bd9eeb614620008b35780638da5cb5b1462000889578063b9565c7414620007f8578063bbe78b3814620007ad578063c83ade29146200076f578063d45d959314620006f0578063d8f67495146200062c578063e4890d3b1462000573578063ec458adb1462000535578063f2cd05741462000507578063f2fde38b14620004565763f8c8765e146200013657600080fd5b346200045257608036600319011262000452576200015362001122565b906200015e6200118f565b6044356001600160a01b03928382168092036200044e57606435938085168095036200044a5787549560ff8760081c1615968780986200043c575b801562000423575b15620003ba5760ff1981166001178a5582919088620003a8575b501693843b156200033f571690813b15620002d657823b156200026d57506001600160a01b03199283606654161760665582606854161760685581606554161760655560675416176067556200022360ff845460081c166200021d8162001247565b62001247565b6200022e33620011ff565b62000237575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b608490602088519162461bcd60e51b8352820152602760248201527f696e697469616c697a653a206d77206d75737420626520612076616c6964206360448201527f6f6e7472616374000000000000000000000000000000000000000000000000006064820152fd5b608490602088519162461bcd60e51b8352820152603160248201527f696e697469616c697a653a205f6272696265426561636f6e206d75737420626560448201527f20612076616c696420636f6e74726163740000000000000000000000000000006064820152fd5b60848360208a519162461bcd60e51b8352820152603460248201527f696e697469616c697a653a205f7265776172646572426561636f6e206d75737460448201527f20626520612076616c696420636f6e74726163740000000000000000000000006064820152fd5b61ffff1916610101178a5538620001bb565b60848460208b519162461bcd60e51b8352820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b50303b158015620001a15750600160ff821614620001a1565b50600160ff82161062000199565b8780fd5b8680fd5b8280fd5b50346200045257602036600319011262000452576200047462001122565b916200047f620011a6565b6001600160a01b038316156200049e57836200049b84620011ff565b80f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152fd5b50503462000531578160031936011262000531576020906001600160a01b03606854169051908152f35b5080fd5b505034620005315760203660031901126200053157602091816001600160a01b0391826200056262001122565b168152606985522054169051908152f35b5034620004525762000585366200113e565b9590926001600160a01b03946020866065541691602489518094819363015f253560e71b83528b8816908301525afa92831562000621578093620005df575b505091620005d7939160209793620015aa565b169051908152f35b909192506020823d821162000618575b81620005fe6020938362001301565b81010312620006155750519080620005d7620005c4565b80fd5b3d9150620005ef565b8751903d90823e3d90fd5b8284346200061557806003193601126200061557908051918290606b549182855260208095018093606b84527fbd43cb8ece8cd1863bcd6082d65c5b0d25665b1ce17980f0da43c0ed545f98b490845b818110620006db57505050816200069591038262001301565b83519485948186019282875251809352850193925b828110620006ba57505050500390f35b83516001600160a01b031685528695509381019392810192600101620006aa565b8254845292880192600192830192016200067c565b50503462000531576020366003190112620005315760207fb19ac9fc755934d25cfd8812f8a5618131674ab42a6066a6c6a865ead9071ca8916001600160a01b036200073b62001122565b62000745620011a6565b169062000755823b151562001b79565b816001600160a01b0319606654161760665551908152a180f35b505034620005315760203660031901126200053157602091816001600160a01b0391826200079c62001122565b168152606a85522054169051908152f35b505034620005315760203660031901126200053157602090620007ef6001600160a01b03620007db62001122565b16600052606c602052604060002054151590565b90519015158152f35b5050346200053157602036600319011262000531577fcc3e3e12ea0f2694156ab3b7583e608291a16e8ad1c2451ac1fe7d4baace9d07906001600160a01b036200084162001122565b6200084b620011a6565b166200086e6200086882600052606c602052604060002054151590565b62001501565b620008798162001ce6565b508151908152836020820152a180f35b50503462000531578160031936011262000531576020906001600160a01b03603354169051908152f35b50503462000531578060031936011262000531577f37a098f2ac54298d7d2f2167e2c4217733ee6f1f050c56e842a0eb912864251890620008f362001122565b62000974620009016200118f565b926200090c620011a6565b6001600160a01b03808416808852606a6020526200093682848a2054169287168093141562001bc5565b8752606a602052818720906001600160a01b031982541617905551928392839060209093929360408301946001600160a01b03809216845216910152565b0390a180f35b50503462000531578160031936011262000531576020906001600160a01b03606654169051908152f35b83346200061557806003193601126200061557620009c1620011a6565b806001600160a01b036033546001600160a01b03198116603355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503462000531578060031936011262000531577f79d402d5bdae48d5c5e135bb5d79217c6763dcfd2635f6a2bb5af36a562180199062000a4362001122565b6200097462000a516200118f565b9262000a5c620011a6565b6001600160a01b03808416808852606960205262000a8682848a2054169287168093141562001bc5565b87526069602052818720906001600160a01b031982541617905551928392839060209093929360408301946001600160a01b03809216845216910152565b50503462000531576020366003190112620005315760207fc6ff127433b785c51da9ae4088ee184c909b1a55b9afd82ae6c64224d3bc15d2916001600160a01b0362000b0f62001122565b62000b19620011a6565b169062000b29823b151562001b79565b816001600160a01b0319606754161760675551908152a180f35b50503462000531578160031936011262000531576020906001600160a01b03606754169051908152f35b50503462000531576020906001600160a01b03620005d762000b8f366200113e565b929190916200190a565b50503462000531576020366003190112620005315760207f2d1daa4d94a2a11c36dc42698e0f605a7fd463d1d2aceed2fd9616171a9044a9916001600160a01b0362000be462001122565b62000bee620011a6565b169062000bfe823b151562001b79565b816001600160a01b0319606854161760685551908152a180f35b50503462000531578160031936011262000531576020906001600160a01b03606554169051908152f35b509034620004525762000c55366200113e565b94916001600160a01b039691969586606554169786519263015f253560e71b8452888716868501526020998a85602481845afa94851562000dde57908b91879662000de8575b50906024918a519283809263ca6f309d60e01b8252898c8301525afa90811562000dde579162000ce18b62000ce995938197958f8b9262000daa575b5050161562001345565b8589620015aa565b16956065541692833b156200045257906044839283885196879485937f2f8759290000000000000000000000000000000000000000000000000000000085528401528a60248401525af190811562000d9f57509184917f776955300e1eeb6ea4fb35a0884fa45b7c71d09b62c24280c2f4d088674b2cfb9362000d8d575b5083516001600160a01b0391821681529116602082015280604081015b0390a151908152f35b62000d9890620012b9565b3862000d67565b8451903d90823e3d90fd5b62000dce9250803d1062000dd6575b62000dc5818362001301565b81019062001324565b388f62000cd7565b503d62000db9565b89513d88823e3d90fd5b8281939297503d831162000e1c575b62000e03818362001301565b8101031262000e185751938a90602462000c9b565b8580fd5b503d62000df7565b50919034620005315762000e38366200113e565b6001600160a01b039693969592918660675416928760e08a60248a518094819363636edb2160e11b83521698898c8301525afa90811562001046578987928892899162001003575b501662000f9a578962000e969116151562001469565b1562000f57579162000eab9188938a6200190a565b16946067541692833b156200045257906044839283875196879485937fb6da5b200000000000000000000000000000000000000000000000000000000085528401528960248401525af190811562000f4c57506020947f822c906e0424ff0ca967644b8f8431648e14afe4170fa2eeec92ae109301943192859262000d8d575083516001600160a01b03918216815291166020820152806040810162000d84565b8351903d90823e3d90fd5b606486602089519162461bcd60e51b8352820152601860248201527f627269626520636f6e74726163742069732070617573656400000000000000006044820152fd5b60848860208b519162461bcd60e51b8352820152602760248201527f627269626520636f6e747261637420616c72656164792065786973747320666f60448201527f72206761756765000000000000000000000000000000000000000000000000006064820152fd5b919350506200102d915060e03d81116200103e575b62001024818362001301565b810190620013d2565b955095935091505092913862000e80565b503d62001018565b88513d88823e3d90fd5b50346200045257602036600319011262000452576001600160a01b036200107662001122565b62001080620011a6565b16906200109a82600052606c602052604060002054151590565b620010df57509081620010ce7fcc3e3e12ea0f2694156ab3b7583e608291a16e8ad1c2451ac1fe7d4baace9d079362001c5f565b50815190815260016020820152a180f35b606490602084519162461bcd60e51b8352820152601360248201527f616c72656164792077686974656c6973746564000000000000000000000000006044820152fd5b600435906001600160a01b03821682036200113957565b600080fd5b608090600319011262001139576001600160a01b0360043581811681036200113957916024359160443590811681036200113957906064356bffffffffffffffffffffffff81168103620011395790565b602435906001600160a01b03821682036200113957565b6001600160a01b03603354163303620011bb57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b603354906001600160a01b0380911691826001600160a01b0319821617603355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b156200124f57565b608460405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b67ffffffffffffffff8111620012ce57604052565b634e487b7160e01b600052604160045260246000fd5b6020810190811067ffffffffffffffff821117620012ce57604052565b90601f8019910116810190811067ffffffffffffffff821117620012ce57604052565b908160209103126200113957516001600160a01b0381168103620011395790565b156200134d57565b608460405162461bcd60e51b815260206004820152602160248201527f726577617264657220636f6e747261637420616c7265616c647920657869737460448201527f73000000000000000000000000000000000000000000000000000000000000006064820152fd5b51906cffffffffffffffffffffffffff821682036200113957565b908160e09103126200113957620013e981620013b7565b91620013f860208301620013b7565b91604081015164ffffffffff8116810362001139579160608201516fffffffffffffffffffffffffffffffff811681036200113957916080810151801515810362001139579160a08201516001600160a01b03908181168103620011395760c0909301519081168103620011395790565b156200147157565b606460405162461bcd60e51b815260206004820152601460248201527f676175676520646f6573206e6f742065786973740000000000000000000000006044820152fd5b15620014bd57565b606460405162461bcd60e51b815260206004820152600f60248201527f4e6f7420617574687572697a65642e00000000000000000000000000000000006044820152fd5b156200150957565b606460405162461bcd60e51b815260206004820152601f60248201527f72657761726420746f6b656e206973206e6f742077686974656c6973746564006044820152fd5b906001600160a01b039093929316815260209260408483015280519081604084015260005b8281106200159557505060609293506000838284010152601f8019910116010190565b81810186015184820160600152850162001572565b919294939094606754956000966001600160a01b03809116803b6200188d575b5080606554166020604093602485518094819363ca6f309d60e01b835260048301525afa90811562001883576200160e9183918b9162001860575b50161562001345565b8085169788815260696020526200162c8284832054163314620014b5565b818416986200164c620008688b600052606c602052604060002054151590565b826066541684516200165e81620012e4565b8381528551916106b58084019084821067ffffffffffffffff8311176200184c5791849391620016949362001dde86396200154d565b039083f080156200183e578316998360655416908b3b1562001848579160c48492838e8d968a519788968795631cc6653f60e21b875230600488015260248701526044860152606485015260848401526bffffffffffffffffffffffff8c1660a48401525af180156200183e576200182c575b5090883b1562000531578251634c386bff60e11b81523360048201528281602481838e5af1801562001822579083916200180a575b505060335416883b15620005315782519063f2fde38b60e01b825260048201528181602481838d5af18015620018005790899594939291620017de575b5050516001600160a01b0394851681526020810195909552831660408501526bffffffffffffffffffffffff1660608401521660808201527f91d9c5d230809fb439d9c3efbcd0ec64cbf4505732e75068ea0818df77e13a80908060a081015b0390a1565b819293949550620017ef90620012b9565b620006155790818894939262001779565b83513d84823e3d90fd5b6200181590620012b9565b620005315781386200173c565b84513d85823e3d90fd5b6200183790620012b9565b3862001707565b84513d84823e3d90fd5b8380fd5b602487634e487b7160e01b81526041600452fd5b6200187c915060203d811162000dd65762000dc5818362001301565b3862001605565b83513d8b823e3d90fd5b60e06024916040519283809263636edb2160e11b8252868b1660048301525afa908115620018ff57620018ce9183918b91620018d5575b5016151562001469565b38620015ca565b620018f1915060e03d81116200103e5762001024818362001301565b5094505050505038620018c4565b6040513d8b823e3d90fd5b9091939260675494600060409081519063636edb2160e11b82526001600160a01b039160e08160248186808c169e8f6004840152165afa9081156200183e57620019619184918491620018d5575016151562001469565b888152606a6020526200197b8284832054163314620014b5565b818416986200199b620008688b600052606c602052604060002054151590565b82606854168451620019ad81620012e4565b8381528551916106b58084019084821067ffffffffffffffff8311176200184c5791849391620019e3936200249386396200154d565b039083f080156200183e578316998360675416908b3b1562001848579160c48492838e8d968a519788968795631cc6653f60e21b875230600488015260248701526044860152606485015260848401526bffffffffffffffffffffffff8c1660a48401525af180156200183e5762001b67575b5090883b1562000531578251634c386bff60e11b81523360048201528281602481838e5af18015620018225790839162001b4f575b505060335416883b15620005315782519063f2fde38b60e01b825260048201528181602481838d5af1801562001800579089959493929162001b2d575b5050516001600160a01b0394851681526020810195909552831660408501526bffffffffffffffffffffffff1660608401521660808201527f4d795085a40d5e3d6ea5309a4afb6dc4a8fdac8171f2d493d21caed3742cb097908060a08101620017d9565b81929394955062001b3e90620012b9565b620006155790818894939262001ac8565b62001b5a90620012b9565b6200053157813862001a8b565b62001b7290620012b9565b3862001a56565b1562001b8157565b606460405162461bcd60e51b815260206004820152600f60248201527f696e76616c6964206164647265737300000000000000000000000000000000006044820152fd5b1562001bcd57565b606460405162461bcd60e51b815260206004820152601760248201527f616c726561647920736574206173206465706c6f7965720000000000000000006044820152fd5b606b5481101562001c4957606b6000527fbd43cb8ece8cd1863bcd6082d65c5b0d25665b1ce17980f0da43c0ed545f98b40190600090565b634e487b7160e01b600052603260045260246000fd5b6000818152606c602052604081205462001ce157606b546801000000000000000081101562001ccd57908262001cb962001ca284600160409601606b5562001c11565b819391549060031b91821b91600019901b19161790565b9055606b54928152606c6020522055600190565b602482634e487b7160e01b81526041600452fd5b905090565b6000818152606c6020526040812054909190801562001dd8576000199080820181811162001dc457606b549083820191821162001db05780820362001d76575b505050606b54801562001d625781019062001d418262001c11565b909182549160031b1b19169055606b558152606c6020526040812055600190565b602484634e487b7160e01b81526031600452fd5b62001d9962001d8962001ca29362001c11565b90549060031b1c92839262001c11565b90558452606c602052604084205538808062001d26565b602486634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b50509056fe60806040908082526106b580380380916100198285610350565b8339810190828183031261034b5761003081610373565b6020828101516001600160401b039391929184821161034b57019084601f8301121561034b5781519161006283610387565b9261006f88519485610350565b8084528484019685828401011161034b57868561008c93016103a2565b803b156102f9578551635c60da1b60e01b80825292916001600160a01b0316908481600481855afa9081156102ee576000916102b9575b503b1561025c577fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b03191682179055865192817f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e600080a2825115801590610254575b610142575b875161023c90816104798239f35b6004848693819382525afa9182156102495760009261020f575b5085519360608501908111858210176101f9578652602784527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c83850152660819985a5b195960ca1b84870152516101e3946000918291845af4903d156101f0573d6101c781610387565b906101d488519283610350565b8152600081943d92013e6103c5565b5038808080808080610134565b606092506103c5565b634e487b7160e01b600052604160045260246000fd5b90918382813d8311610242575b6102268183610350565b8101031261023f575061023890610373565b903861015c565b80fd5b503d61021c565b86513d6000823e3d90fd5b50600061012f565b865162461bcd60e51b815260048101859052603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608490fd5b908582813d83116102e7575b6102cf8183610350565b8101031261023f57506102e190610373565b386100c3565b503d6102c5565b88513d6000823e3d90fd5b855162461bcd60e51b815260048101849052602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b6064820152608490fd5b600080fd5b601f909101601f19168101906001600160401b038211908210176101f957604052565b51906001600160a01b038216820361034b57565b6001600160401b0381116101f957601f01601f191660200190565b60005b8381106103b55750506000910152565b81810151838201526020016103a5565b9192901561042757508151156103d9575090565b3b156103e25790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561043a5750805190602001fd5b6044604051809262461bcd60e51b82526020600483015261046a81518092816024860152602086860191016103a2565b601f01601f19168101030190fdfe608080604052366100e65760208160048173ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d505416635c60da1b60e01b82525afa9081156100da57600091610069575b50610187565b6020903d82116100d2575b601f8201601f1916810167ffffffffffffffff8111828210176100a55761009f9350604052016101a6565b38610063565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b3d9150610074565b6040513d6000823e3d90fd5b6004602073ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50541660405192838092635c60da1b60e01b82525afa9081156100da576000916101495750610187565b60203d8111610180575b601f8101601f1916820167ffffffffffffffff8111838210176100a55761009f93506040528101906101da565b503d610153565b6000808092368280378136915af43d82803e156101a2573d90f35b3d90fd5b602090607f1901126101d55760805173ffffffffffffffffffffffffffffffffffffffff811681036101d55790565b600080fd5b908160209103126101d5575173ffffffffffffffffffffffffffffffffffffffff811681036101d5579056fea2646970667358221220d172cfa4b289befd3a7b68fddb915d7e5473fd0f8f66b7ff9e9fe50de02d1be164736f6c6343000812003360806040908082526106b580380380916100198285610350565b8339810190828183031261034b5761003081610373565b6020828101516001600160401b039391929184821161034b57019084601f8301121561034b5781519161006283610387565b9261006f88519485610350565b8084528484019685828401011161034b57868561008c93016103a2565b803b156102f9578551635c60da1b60e01b80825292916001600160a01b0316908481600481855afa9081156102ee576000916102b9575b503b1561025c577fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b03191682179055865192817f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e600080a2825115801590610254575b610142575b875161023c90816104798239f35b6004848693819382525afa9182156102495760009261020f575b5085519360608501908111858210176101f9578652602784527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c83850152660819985a5b195960ca1b84870152516101e3946000918291845af4903d156101f0573d6101c781610387565b906101d488519283610350565b8152600081943d92013e6103c5565b5038808080808080610134565b606092506103c5565b634e487b7160e01b600052604160045260246000fd5b90918382813d8311610242575b6102268183610350565b8101031261023f575061023890610373565b903861015c565b80fd5b503d61021c565b86513d6000823e3d90fd5b50600061012f565b865162461bcd60e51b815260048101859052603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608490fd5b908582813d83116102e7575b6102cf8183610350565b8101031261023f57506102e190610373565b386100c3565b503d6102c5565b88513d6000823e3d90fd5b855162461bcd60e51b815260048101849052602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b6064820152608490fd5b600080fd5b601f909101601f19168101906001600160401b038211908210176101f957604052565b51906001600160a01b038216820361034b57565b6001600160401b0381116101f957601f01601f191660200190565b60005b8381106103b55750506000910152565b81810151838201526020016103a5565b9192901561042757508151156103d9575090565b3b156103e25790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561043a5750805190602001fd5b6044604051809262461bcd60e51b82526020600483015261046a81518092816024860152602086860191016103a2565b601f01601f19168101030190fdfe608080604052366100e65760208160048173ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d505416635c60da1b60e01b82525afa9081156100da57600091610069575b50610187565b6020903d82116100d2575b601f8201601f1916810167ffffffffffffffff8111828210176100a55761009f9350604052016101a6565b38610063565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b3d9150610074565b6040513d6000823e3d90fd5b6004602073ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50541660405192838092635c60da1b60e01b82525afa9081156100da576000916101495750610187565b60203d8111610180575b601f8101601f1916820167ffffffffffffffff8111838210176100a55761009f93506040528101906101da565b503d610153565b6000808092368280378136915af43d82803e156101a2573d90f35b3d90fd5b602090607f1901126101d55760805173ffffffffffffffffffffffffffffffffffffffff811681036101d55790565b600080fd5b908160209103126101d5575173ffffffffffffffffffffffffffffffffffffffff811681036101d5579056fea2646970667358221220d172cfa4b289befd3a7b68fddb915d7e5473fd0f8f66b7ff9e9fe50de02d1be164736f6c63430008120033a264697066735822122044fd150f58184790169a0de69d24a1b06eb1ad549fcef9657793da5f03374acb64736f6c63430008120033
Deployed Bytecode
0x604060808152600490813610156200001657600080fd5b600091823560e01c80630230ed15146200105057806302b2ed7d1462000e245780630bbe70b91462000c425780633bd61ba81462000c18578063400b119e1462000b995780634538c1a21462000b6d57806346c96aac1462000b435780634bc2a6571462000ac45780635a2480d81462000a03578063715018a614620009a457806373217954146200097a5780638bd9eeb614620008b35780638da5cb5b1462000889578063b9565c7414620007f8578063bbe78b3814620007ad578063c83ade29146200076f578063d45d959314620006f0578063d8f67495146200062c578063e4890d3b1462000573578063ec458adb1462000535578063f2cd05741462000507578063f2fde38b14620004565763f8c8765e146200013657600080fd5b346200045257608036600319011262000452576200015362001122565b906200015e6200118f565b6044356001600160a01b03928382168092036200044e57606435938085168095036200044a5787549560ff8760081c1615968780986200043c575b801562000423575b15620003ba5760ff1981166001178a5582919088620003a8575b501693843b156200033f571690813b15620002d657823b156200026d57506001600160a01b03199283606654161760665582606854161760685581606554161760655560675416176067556200022360ff845460081c166200021d8162001247565b62001247565b6200022e33620011ff565b62000237575080f35b60207f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989161ff001984541684555160018152a180f35b608490602088519162461bcd60e51b8352820152602760248201527f696e697469616c697a653a206d77206d75737420626520612076616c6964206360448201527f6f6e7472616374000000000000000000000000000000000000000000000000006064820152fd5b608490602088519162461bcd60e51b8352820152603160248201527f696e697469616c697a653a205f6272696265426561636f6e206d75737420626560448201527f20612076616c696420636f6e74726163740000000000000000000000000000006064820152fd5b60848360208a519162461bcd60e51b8352820152603460248201527f696e697469616c697a653a205f7265776172646572426561636f6e206d75737460448201527f20626520612076616c696420636f6e74726163740000000000000000000000006064820152fd5b61ffff1916610101178a5538620001bb565b60848460208b519162461bcd60e51b8352820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152fd5b50303b158015620001a15750600160ff821614620001a1565b50600160ff82161062000199565b8780fd5b8680fd5b8280fd5b50346200045257602036600319011262000452576200047462001122565b916200047f620011a6565b6001600160a01b038316156200049e57836200049b84620011ff565b80f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152fd5b50503462000531578160031936011262000531576020906001600160a01b03606854169051908152f35b5080fd5b505034620005315760203660031901126200053157602091816001600160a01b0391826200056262001122565b168152606985522054169051908152f35b5034620004525762000585366200113e565b9590926001600160a01b03946020866065541691602489518094819363015f253560e71b83528b8816908301525afa92831562000621578093620005df575b505091620005d7939160209793620015aa565b169051908152f35b909192506020823d821162000618575b81620005fe6020938362001301565b81010312620006155750519080620005d7620005c4565b80fd5b3d9150620005ef565b8751903d90823e3d90fd5b8284346200061557806003193601126200061557908051918290606b549182855260208095018093606b84527fbd43cb8ece8cd1863bcd6082d65c5b0d25665b1ce17980f0da43c0ed545f98b490845b818110620006db57505050816200069591038262001301565b83519485948186019282875251809352850193925b828110620006ba57505050500390f35b83516001600160a01b031685528695509381019392810192600101620006aa565b8254845292880192600192830192016200067c565b50503462000531576020366003190112620005315760207fb19ac9fc755934d25cfd8812f8a5618131674ab42a6066a6c6a865ead9071ca8916001600160a01b036200073b62001122565b62000745620011a6565b169062000755823b151562001b79565b816001600160a01b0319606654161760665551908152a180f35b505034620005315760203660031901126200053157602091816001600160a01b0391826200079c62001122565b168152606a85522054169051908152f35b505034620005315760203660031901126200053157602090620007ef6001600160a01b03620007db62001122565b16600052606c602052604060002054151590565b90519015158152f35b5050346200053157602036600319011262000531577fcc3e3e12ea0f2694156ab3b7583e608291a16e8ad1c2451ac1fe7d4baace9d07906001600160a01b036200084162001122565b6200084b620011a6565b166200086e6200086882600052606c602052604060002054151590565b62001501565b620008798162001ce6565b508151908152836020820152a180f35b50503462000531578160031936011262000531576020906001600160a01b03603354169051908152f35b50503462000531578060031936011262000531577f37a098f2ac54298d7d2f2167e2c4217733ee6f1f050c56e842a0eb912864251890620008f362001122565b62000974620009016200118f565b926200090c620011a6565b6001600160a01b03808416808852606a6020526200093682848a2054169287168093141562001bc5565b8752606a602052818720906001600160a01b031982541617905551928392839060209093929360408301946001600160a01b03809216845216910152565b0390a180f35b50503462000531578160031936011262000531576020906001600160a01b03606654169051908152f35b83346200061557806003193601126200061557620009c1620011a6565b806001600160a01b036033546001600160a01b03198116603355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50503462000531578060031936011262000531577f79d402d5bdae48d5c5e135bb5d79217c6763dcfd2635f6a2bb5af36a562180199062000a4362001122565b6200097462000a516200118f565b9262000a5c620011a6565b6001600160a01b03808416808852606960205262000a8682848a2054169287168093141562001bc5565b87526069602052818720906001600160a01b031982541617905551928392839060209093929360408301946001600160a01b03809216845216910152565b50503462000531576020366003190112620005315760207fc6ff127433b785c51da9ae4088ee184c909b1a55b9afd82ae6c64224d3bc15d2916001600160a01b0362000b0f62001122565b62000b19620011a6565b169062000b29823b151562001b79565b816001600160a01b0319606754161760675551908152a180f35b50503462000531578160031936011262000531576020906001600160a01b03606754169051908152f35b50503462000531576020906001600160a01b03620005d762000b8f366200113e565b929190916200190a565b50503462000531576020366003190112620005315760207f2d1daa4d94a2a11c36dc42698e0f605a7fd463d1d2aceed2fd9616171a9044a9916001600160a01b0362000be462001122565b62000bee620011a6565b169062000bfe823b151562001b79565b816001600160a01b0319606854161760685551908152a180f35b50503462000531578160031936011262000531576020906001600160a01b03606554169051908152f35b509034620004525762000c55366200113e565b94916001600160a01b039691969586606554169786519263015f253560e71b8452888716868501526020998a85602481845afa94851562000dde57908b91879662000de8575b50906024918a519283809263ca6f309d60e01b8252898c8301525afa90811562000dde579162000ce18b62000ce995938197958f8b9262000daa575b5050161562001345565b8589620015aa565b16956065541692833b156200045257906044839283885196879485937f2f8759290000000000000000000000000000000000000000000000000000000085528401528a60248401525af190811562000d9f57509184917f776955300e1eeb6ea4fb35a0884fa45b7c71d09b62c24280c2f4d088674b2cfb9362000d8d575b5083516001600160a01b0391821681529116602082015280604081015b0390a151908152f35b62000d9890620012b9565b3862000d67565b8451903d90823e3d90fd5b62000dce9250803d1062000dd6575b62000dc5818362001301565b81019062001324565b388f62000cd7565b503d62000db9565b89513d88823e3d90fd5b8281939297503d831162000e1c575b62000e03818362001301565b8101031262000e185751938a90602462000c9b565b8580fd5b503d62000df7565b50919034620005315762000e38366200113e565b6001600160a01b039693969592918660675416928760e08a60248a518094819363636edb2160e11b83521698898c8301525afa90811562001046578987928892899162001003575b501662000f9a578962000e969116151562001469565b1562000f57579162000eab9188938a6200190a565b16946067541692833b156200045257906044839283875196879485937fb6da5b200000000000000000000000000000000000000000000000000000000085528401528960248401525af190811562000f4c57506020947f822c906e0424ff0ca967644b8f8431648e14afe4170fa2eeec92ae109301943192859262000d8d575083516001600160a01b03918216815291166020820152806040810162000d84565b8351903d90823e3d90fd5b606486602089519162461bcd60e51b8352820152601860248201527f627269626520636f6e74726163742069732070617573656400000000000000006044820152fd5b60848860208b519162461bcd60e51b8352820152602760248201527f627269626520636f6e747261637420616c72656164792065786973747320666f60448201527f72206761756765000000000000000000000000000000000000000000000000006064820152fd5b919350506200102d915060e03d81116200103e575b62001024818362001301565b810190620013d2565b955095935091505092913862000e80565b503d62001018565b88513d88823e3d90fd5b50346200045257602036600319011262000452576001600160a01b036200107662001122565b62001080620011a6565b16906200109a82600052606c602052604060002054151590565b620010df57509081620010ce7fcc3e3e12ea0f2694156ab3b7583e608291a16e8ad1c2451ac1fe7d4baace9d079362001c5f565b50815190815260016020820152a180f35b606490602084519162461bcd60e51b8352820152601360248201527f616c72656164792077686974656c6973746564000000000000000000000000006044820152fd5b600435906001600160a01b03821682036200113957565b600080fd5b608090600319011262001139576001600160a01b0360043581811681036200113957916024359160443590811681036200113957906064356bffffffffffffffffffffffff81168103620011395790565b602435906001600160a01b03821682036200113957565b6001600160a01b03603354163303620011bb57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b603354906001600160a01b0380911691826001600160a01b0319821617603355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b156200124f57565b608460405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152fd5b67ffffffffffffffff8111620012ce57604052565b634e487b7160e01b600052604160045260246000fd5b6020810190811067ffffffffffffffff821117620012ce57604052565b90601f8019910116810190811067ffffffffffffffff821117620012ce57604052565b908160209103126200113957516001600160a01b0381168103620011395790565b156200134d57565b608460405162461bcd60e51b815260206004820152602160248201527f726577617264657220636f6e747261637420616c7265616c647920657869737460448201527f73000000000000000000000000000000000000000000000000000000000000006064820152fd5b51906cffffffffffffffffffffffffff821682036200113957565b908160e09103126200113957620013e981620013b7565b91620013f860208301620013b7565b91604081015164ffffffffff8116810362001139579160608201516fffffffffffffffffffffffffffffffff811681036200113957916080810151801515810362001139579160a08201516001600160a01b03908181168103620011395760c0909301519081168103620011395790565b156200147157565b606460405162461bcd60e51b815260206004820152601460248201527f676175676520646f6573206e6f742065786973740000000000000000000000006044820152fd5b15620014bd57565b606460405162461bcd60e51b815260206004820152600f60248201527f4e6f7420617574687572697a65642e00000000000000000000000000000000006044820152fd5b156200150957565b606460405162461bcd60e51b815260206004820152601f60248201527f72657761726420746f6b656e206973206e6f742077686974656c6973746564006044820152fd5b906001600160a01b039093929316815260209260408483015280519081604084015260005b8281106200159557505060609293506000838284010152601f8019910116010190565b81810186015184820160600152850162001572565b919294939094606754956000966001600160a01b03809116803b6200188d575b5080606554166020604093602485518094819363ca6f309d60e01b835260048301525afa90811562001883576200160e9183918b9162001860575b50161562001345565b8085169788815260696020526200162c8284832054163314620014b5565b818416986200164c620008688b600052606c602052604060002054151590565b826066541684516200165e81620012e4565b8381528551916106b58084019084821067ffffffffffffffff8311176200184c5791849391620016949362001dde86396200154d565b039083f080156200183e578316998360655416908b3b1562001848579160c48492838e8d968a519788968795631cc6653f60e21b875230600488015260248701526044860152606485015260848401526bffffffffffffffffffffffff8c1660a48401525af180156200183e576200182c575b5090883b1562000531578251634c386bff60e11b81523360048201528281602481838e5af1801562001822579083916200180a575b505060335416883b15620005315782519063f2fde38b60e01b825260048201528181602481838d5af18015620018005790899594939291620017de575b5050516001600160a01b0394851681526020810195909552831660408501526bffffffffffffffffffffffff1660608401521660808201527f91d9c5d230809fb439d9c3efbcd0ec64cbf4505732e75068ea0818df77e13a80908060a081015b0390a1565b819293949550620017ef90620012b9565b620006155790818894939262001779565b83513d84823e3d90fd5b6200181590620012b9565b620005315781386200173c565b84513d85823e3d90fd5b6200183790620012b9565b3862001707565b84513d84823e3d90fd5b8380fd5b602487634e487b7160e01b81526041600452fd5b6200187c915060203d811162000dd65762000dc5818362001301565b3862001605565b83513d8b823e3d90fd5b60e06024916040519283809263636edb2160e11b8252868b1660048301525afa908115620018ff57620018ce9183918b91620018d5575b5016151562001469565b38620015ca565b620018f1915060e03d81116200103e5762001024818362001301565b5094505050505038620018c4565b6040513d8b823e3d90fd5b9091939260675494600060409081519063636edb2160e11b82526001600160a01b039160e08160248186808c169e8f6004840152165afa9081156200183e57620019619184918491620018d5575016151562001469565b888152606a6020526200197b8284832054163314620014b5565b818416986200199b620008688b600052606c602052604060002054151590565b82606854168451620019ad81620012e4565b8381528551916106b58084019084821067ffffffffffffffff8311176200184c5791849391620019e3936200249386396200154d565b039083f080156200183e578316998360675416908b3b1562001848579160c48492838e8d968a519788968795631cc6653f60e21b875230600488015260248701526044860152606485015260848401526bffffffffffffffffffffffff8c1660a48401525af180156200183e5762001b67575b5090883b1562000531578251634c386bff60e11b81523360048201528281602481838e5af18015620018225790839162001b4f575b505060335416883b15620005315782519063f2fde38b60e01b825260048201528181602481838d5af1801562001800579089959493929162001b2d575b5050516001600160a01b0394851681526020810195909552831660408501526bffffffffffffffffffffffff1660608401521660808201527f4d795085a40d5e3d6ea5309a4afb6dc4a8fdac8171f2d493d21caed3742cb097908060a08101620017d9565b81929394955062001b3e90620012b9565b620006155790818894939262001ac8565b62001b5a90620012b9565b6200053157813862001a8b565b62001b7290620012b9565b3862001a56565b1562001b8157565b606460405162461bcd60e51b815260206004820152600f60248201527f696e76616c6964206164647265737300000000000000000000000000000000006044820152fd5b1562001bcd57565b606460405162461bcd60e51b815260206004820152601760248201527f616c726561647920736574206173206465706c6f7965720000000000000000006044820152fd5b606b5481101562001c4957606b6000527fbd43cb8ece8cd1863bcd6082d65c5b0d25665b1ce17980f0da43c0ed545f98b40190600090565b634e487b7160e01b600052603260045260246000fd5b6000818152606c602052604081205462001ce157606b546801000000000000000081101562001ccd57908262001cb962001ca284600160409601606b5562001c11565b819391549060031b91821b91600019901b19161790565b9055606b54928152606c6020522055600190565b602482634e487b7160e01b81526041600452fd5b905090565b6000818152606c6020526040812054909190801562001dd8576000199080820181811162001dc457606b549083820191821162001db05780820362001d76575b505050606b54801562001d625781019062001d418262001c11565b909182549160031b1b19169055606b558152606c6020526040812055600190565b602484634e487b7160e01b81526031600452fd5b62001d9962001d8962001ca29362001c11565b90549060031b1c92839262001c11565b90558452606c602052604084205538808062001d26565b602486634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b50509056fe60806040908082526106b580380380916100198285610350565b8339810190828183031261034b5761003081610373565b6020828101516001600160401b039391929184821161034b57019084601f8301121561034b5781519161006283610387565b9261006f88519485610350565b8084528484019685828401011161034b57868561008c93016103a2565b803b156102f9578551635c60da1b60e01b80825292916001600160a01b0316908481600481855afa9081156102ee576000916102b9575b503b1561025c577fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b03191682179055865192817f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e600080a2825115801590610254575b610142575b875161023c90816104798239f35b6004848693819382525afa9182156102495760009261020f575b5085519360608501908111858210176101f9578652602784527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c83850152660819985a5b195960ca1b84870152516101e3946000918291845af4903d156101f0573d6101c781610387565b906101d488519283610350565b8152600081943d92013e6103c5565b5038808080808080610134565b606092506103c5565b634e487b7160e01b600052604160045260246000fd5b90918382813d8311610242575b6102268183610350565b8101031261023f575061023890610373565b903861015c565b80fd5b503d61021c565b86513d6000823e3d90fd5b50600061012f565b865162461bcd60e51b815260048101859052603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608490fd5b908582813d83116102e7575b6102cf8183610350565b8101031261023f57506102e190610373565b386100c3565b503d6102c5565b88513d6000823e3d90fd5b855162461bcd60e51b815260048101849052602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b6064820152608490fd5b600080fd5b601f909101601f19168101906001600160401b038211908210176101f957604052565b51906001600160a01b038216820361034b57565b6001600160401b0381116101f957601f01601f191660200190565b60005b8381106103b55750506000910152565b81810151838201526020016103a5565b9192901561042757508151156103d9575090565b3b156103e25790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561043a5750805190602001fd5b6044604051809262461bcd60e51b82526020600483015261046a81518092816024860152602086860191016103a2565b601f01601f19168101030190fdfe608080604052366100e65760208160048173ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d505416635c60da1b60e01b82525afa9081156100da57600091610069575b50610187565b6020903d82116100d2575b601f8201601f1916810167ffffffffffffffff8111828210176100a55761009f9350604052016101a6565b38610063565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b3d9150610074565b6040513d6000823e3d90fd5b6004602073ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50541660405192838092635c60da1b60e01b82525afa9081156100da576000916101495750610187565b60203d8111610180575b601f8101601f1916820167ffffffffffffffff8111838210176100a55761009f93506040528101906101da565b503d610153565b6000808092368280378136915af43d82803e156101a2573d90f35b3d90fd5b602090607f1901126101d55760805173ffffffffffffffffffffffffffffffffffffffff811681036101d55790565b600080fd5b908160209103126101d5575173ffffffffffffffffffffffffffffffffffffffff811681036101d5579056fea2646970667358221220d172cfa4b289befd3a7b68fddb915d7e5473fd0f8f66b7ff9e9fe50de02d1be164736f6c6343000812003360806040908082526106b580380380916100198285610350565b8339810190828183031261034b5761003081610373565b6020828101516001600160401b039391929184821161034b57019084601f8301121561034b5781519161006283610387565b9261006f88519485610350565b8084528484019685828401011161034b57868561008c93016103a2565b803b156102f9578551635c60da1b60e01b80825292916001600160a01b0316908481600481855afa9081156102ee576000916102b9575b503b1561025c577fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b03191682179055865192817f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e600080a2825115801590610254575b610142575b875161023c90816104798239f35b6004848693819382525afa9182156102495760009261020f575b5085519360608501908111858210176101f9578652602784527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c83850152660819985a5b195960ca1b84870152516101e3946000918291845af4903d156101f0573d6101c781610387565b906101d488519283610350565b8152600081943d92013e6103c5565b5038808080808080610134565b606092506103c5565b634e487b7160e01b600052604160045260246000fd5b90918382813d8311610242575b6102268183610350565b8101031261023f575061023890610373565b903861015c565b80fd5b503d61021c565b86513d6000823e3d90fd5b50600061012f565b865162461bcd60e51b815260048101859052603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608490fd5b908582813d83116102e7575b6102cf8183610350565b8101031261023f57506102e190610373565b386100c3565b503d6102c5565b88513d6000823e3d90fd5b855162461bcd60e51b815260048101849052602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b6064820152608490fd5b600080fd5b601f909101601f19168101906001600160401b038211908210176101f957604052565b51906001600160a01b038216820361034b57565b6001600160401b0381116101f957601f01601f191660200190565b60005b8381106103b55750506000910152565b81810151838201526020016103a5565b9192901561042757508151156103d9575090565b3b156103e25790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b82519091501561043a5750805190602001fd5b6044604051809262461bcd60e51b82526020600483015261046a81518092816024860152602086860191016103a2565b601f01601f19168101030190fdfe608080604052366100e65760208160048173ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d505416635c60da1b60e01b82525afa9081156100da57600091610069575b50610187565b6020903d82116100d2575b601f8201601f1916810167ffffffffffffffff8111828210176100a55761009f9350604052016101a6565b38610063565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b3d9150610074565b6040513d6000823e3d90fd5b6004602073ffffffffffffffffffffffffffffffffffffffff7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50541660405192838092635c60da1b60e01b82525afa9081156100da576000916101495750610187565b60203d8111610180575b601f8101601f1916820167ffffffffffffffff8111838210176100a55761009f93506040528101906101da565b503d610153565b6000808092368280378136915af43d82803e156101a2573d90f35b3d90fd5b602090607f1901126101d55760805173ffffffffffffffffffffffffffffffffffffffff811681036101d55790565b600080fd5b908160209103126101d5575173ffffffffffffffffffffffffffffffffffffffff811681036101d5579056fea2646970667358221220d172cfa4b289befd3a7b68fddb915d7e5473fd0f8f66b7ff9e9fe50de02d1be164736f6c63430008120033a264697066735822122044fd150f58184790169a0de69d24a1b06eb1ad549fcef9657793da5f03374acb64736f6c63430008120033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 27 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.