Source Code
Overview
MNT Balance
MNT Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
VeMoe
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 600 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {FixedPointMathLib} from "@solmate/src/utils/FixedPointMathLib.sol";
import {Math} from "./libraries/Math.sol";
import {Rewarder} from "./libraries/Rewarder.sol";
import {Amounts} from "./libraries/Amounts.sol";
import {Constants} from "./libraries/Constants.sol";
import {IVeMoeRewarder} from "./interfaces/IVeMoeRewarder.sol";
import {IMoeStaking} from "./interfaces/IMoeStaking.sol";
import {IMasterChef} from "./interfaces/IMasterChef.sol";
import {IVeMoe} from "./interfaces/IVeMoe.sol";
import {IRewarderFactory} from "./interfaces/IRewarderFactory.sol";
/**
* @title VeMoe Contract
* @dev The VeMoe Contract allows users to vote on pool weights in the MasterChef contract.
* Protocols can create bribe contracts to incentivize users to vote on their pools.
*/
contract VeMoe is Ownable2StepUpgradeable, IVeMoe {
using Math for uint256;
using Rewarder for Rewarder.Parameter;
using Amounts for Amounts.Parameter;
using EnumerableSet for EnumerableSet.UintSet;
IMoeStaking private immutable _moeStaking;
IMasterChef private immutable _masterChef;
IRewarderFactory private immutable _rewarderFactory;
uint256 private immutable _maxVeMoePerMoe;
uint256 private _topPidsTotalVotes;
EnumerableSet.UintSet private _topPids;
uint256 private _veMoePerSecondPerMoe;
Rewarder.Parameter private _veRewarder;
// pid to Vote
Amounts.Parameter private _votes;
mapping(address => User) private _users;
mapping(IVeMoeRewarder => mapping(uint256 => uint256)) private _bribesTotalVotes;
uint256 private _alpha;
uint256 private _topPidsTotalWeights;
mapping(uint256 => uint256) private _weights;
/**
* @dev Constructor for VeMoe contract.
* @param moeStaking The MOE Staking contract.
* @param masterChef The MasterChef contract.
* @param rewarderFactory The Rewarder Factory contract.
* @param maxVeMoePerMoe The maximum veMOE per MOE.
*/
constructor(
IMoeStaking moeStaking,
IMasterChef masterChef,
IRewarderFactory rewarderFactory,
uint256 maxVeMoePerMoe
) {
if (maxVeMoePerMoe > Constants.MAX_VE_MOE_PER_MOE) revert VeMoe__InvalidMaxVeMoePerMoe();
_disableInitializers();
_moeStaking = moeStaking;
_masterChef = masterChef;
_rewarderFactory = rewarderFactory;
_maxVeMoePerMoe = maxVeMoePerMoe;
}
/**
* @dev Initializes the contract.
* @param initialOwner The initial owner of the contract.
*/
function initialize(address initialOwner) external reinitializer(2) {
__Ownable_init(initialOwner);
_setAlpha(Constants.PRECISION);
}
/**
* @dev Returns the MOE Staking contract.
* @return The MOE Staking contract.
*/
function getMoeStaking() external view override returns (IMoeStaking) {
return _moeStaking;
}
/**
* @dev Returns the MasterChef contract.
* @return The MasterChef contract.
*/
function getMasterChef() external view override returns (IMasterChef) {
return _masterChef;
}
/**
* @dev Returns the Rewarder Factory contract.
* @return The Rewarder Factory contract.
*/
function getRewarderFactory() external view override returns (IRewarderFactory) {
return _rewarderFactory;
}
/**
* @dev Returns the maximum veMOE per MOE.
* @return The maximum veMOE per MOE.
*/
function getMaxVeMoePerMoe() external view override returns (uint256) {
return _maxVeMoePerMoe;
}
/**
* @dev Returns the total veMOE of the specified account.
* @param account The address of the account.
* @return veMoe The total veMOE of the account.
*/
function balanceOf(address account) external view override returns (uint256 veMoe) {
User storage user = _users[account];
uint256 balance = _moeStaking.getDeposit(account);
uint256 totalVested = _veRewarder.getTotalRewards(_veMoePerSecondPerMoe, Constants.PRECISION);
uint256 userVested = _veRewarder.getPendingReward(account, balance, Constants.PRECISION, totalVested);
(veMoe,) = _getVeMoe(user, balance, balance, userVested);
}
/**
* @dev Returns the veMoePerSecondPerMoe
* @return The veMoePerSecondPerMoe
*/
function getVeMoePerSecondPerMoe() external view override returns (uint256) {
return _veMoePerSecondPerMoe;
}
/**
* @dev Returns the total votes of a pool.
* @param pid The pool ID.
* @return The total votes of the pool.
*/
function getVotes(uint256 pid) external view override returns (uint256) {
return _votes.getAmountOf(pid);
}
/**
* @dev Returns the total votes of all pools.
* @return The total votes of all pools.
*/
function getTotalVotes() external view override returns (uint256) {
return _votes.getTotalAmount();
}
/**
* @dev Returns the weight of a pool.
* @param pid The pool ID.
* @return The weight of the pool.
*/
function getWeight(uint256 pid) external view override returns (uint256) {
return _weights[pid];
}
/**
* @dev Returns the total weight of all pools.
* @return The total weight of all pools.
*/
function getTotalWeight() external view override returns (uint256) {
return _topPidsTotalWeights;
}
/**
* @dev Returns the alpha value, used to calculate the weight of a pool (weight = min(votes, votes^alpha)).
* @return The alpha value.
*/
function getAlpha() external view override returns (uint256) {
return _alpha;
}
/**
* @dev Returns the total votes of a pool for a bribe contract.
* @param bribe The bribe contract.
* @param pid The pool ID.
* @return The total votes of the pool for the bribe contract.
*/
function getBribesTotalVotes(IVeMoeRewarder bribe, uint256 pid) external view override returns (uint256) {
return _bribesTotalVotes[bribe][pid];
}
/**
* @dev Returns the bribes contract of a pool for an account.
* Will return address(0) if the account has not set a bribes contract for the pool.
* @param account The address of the account.
* @param pid The pool ID.
* @return The bribes contract of the pool for the account.
*/
function getBribesOf(address account, uint256 pid) external view override returns (IVeMoeRewarder) {
return _users[account].bribes[pid];
}
/**
* @dev Returns the votes of an account for a pool.
* @param account The address of the account.
* @param pid The pool ID.
* @return The votes of the account for the pool.
*/
function getVotesOf(address account, uint256 pid) external view override returns (uint256) {
return _users[account].votes.getAmountOf(pid);
}
/**
* @dev Returns the total votes of an account for all pools.
* @param account The address of the account.
* @return The total votes of the account for all pools.
*/
function getTotalVotesOf(address account) external view override returns (uint256) {
return _users[account].votes.getTotalAmount();
}
/**
* @dev Returns the top pool IDs.
* @return The top pool IDs.
*/
function getTopPoolIds() external view override returns (uint256[] memory) {
return _topPids.values();
}
/**
* @dev Returns whether a pool ID is in the top pool IDs.
* @param pid The pool ID.
* @return Whether the pool ID is in the top pool IDs.
*/
function isInTopPoolIds(uint256 pid) external view override returns (bool) {
return _topPids.contains(pid);
}
/**
* @dev Returns the total votes of the top pool IDs.
* @return The total votes of the top pool IDs.
*/
function getTopPidsTotalVotes() external view override returns (uint256) {
return _topPidsTotalVotes;
}
/**
* @dev Returns the pending rewards for an account for each pool in the pids list.
* @param account The address of the account.
* @param pids The list of pool IDs.
* @return tokens The list of tokens.
* @return pendingRewards The list of pending rewards.
*/
function getPendingRewards(address account, uint256[] calldata pids)
external
view
override
returns (IERC20[] memory tokens, uint256[] memory pendingRewards)
{
uint256 length = pids.length;
tokens = new IERC20[](length);
pendingRewards = new uint256[](length);
User storage user = _users[account];
for (uint256 i; i < length; ++i) {
uint256 pid = pids[i];
IVeMoeRewarder bribe = user.bribes[pid];
if (address(bribe) != address(0)) {
uint256 userVotes = user.votes.getAmountOf(pid);
uint256 totalVotes = _bribesTotalVotes[bribe][pid];
(tokens[i], pendingRewards[i]) = bribe.getPendingReward(account, userVotes, totalVotes);
}
}
}
/**
* @dev Claims the pending rewards in bribe contracts for each pool in the pids list.
* @param pids The list of pool IDs.
*/
function claim(uint256[] calldata pids) external override {
User storage user = _users[msg.sender];
for (uint256 i; i < pids.length; ++i) {
uint256 pid = pids[i];
IVeMoeRewarder bribe = _users[msg.sender].bribes[pid];
if (address(bribe) != address(0)) {
uint256 userVotes = user.votes.getAmountOf(pid);
uint256 totalVotes = _bribesTotalVotes[bribe][pid];
uint256 rewards = bribe.onModify(msg.sender, pid, userVotes, userVotes, totalVotes);
bribe.claim(msg.sender, rewards);
}
}
}
/**
* @dev Votes for the pools in the pids list.
* Will update the top pool IDs in the MasterChef contract.
* @param pids The list of pool IDs.
* @param deltaAmounts The list of delta amounts.
*/
function vote(uint256[] calldata pids, int256[] calldata deltaAmounts) external override {
uint256 length = pids.length;
if (length != deltaAmounts.length) revert VeMoe__InvalidLength();
uint256 numberOfFarm = _masterChef.getNumberOfFarms();
_masterChef.updateAll(_topPids.values());
User storage user = _users[msg.sender];
{
uint256 balance = _moeStaking.getDeposit(msg.sender);
_claim(msg.sender, balance, balance);
}
uint256 userTotalVeMoe = user.veMoe;
uint256 topPidsTotalVotes = _topPidsTotalVotes;
uint256 topPidsTotalWeights = _topPidsTotalWeights;
BribeReward[] memory bribes = new BribeReward[](length);
uint256 poolVotes;
uint256 alpha = _alpha;
for (uint256 i; i < length; ++i) {
uint256 pid = pids[i];
if (pid >= numberOfFarm) revert VeMoe__InvalidPid(pid);
(bribes[i], poolVotes) = _vote(user, pid, deltaAmounts[i], userTotalVeMoe);
if (_topPids.contains(pid)) {
uint256 oldWeight = _weights[pid];
uint256 newWeight = _calculateWeight(poolVotes, alpha);
_weights[pid] = newWeight;
topPidsTotalVotes = topPidsTotalVotes.addDelta(deltaAmounts[i]);
topPidsTotalWeights = topPidsTotalWeights - oldWeight + newWeight;
}
}
_topPidsTotalVotes = topPidsTotalVotes;
_topPidsTotalWeights = topPidsTotalWeights;
for (uint256 i; i < length; ++i) {
uint256 rewardAmount = bribes[i].rewardAmount;
if (rewardAmount > 0) bribes[i].bribe.claim(msg.sender, rewardAmount);
}
emit Vote(msg.sender, pids, deltaAmounts);
}
/**
* @dev Sets the bribes contract for each pool in the pids list.
* @param pids The list of pool IDs.
* @param bribes The list of bribes contracts.
*/
function setBribes(uint256[] calldata pids, IVeMoeRewarder[] calldata bribes) external override {
if (pids.length != bribes.length) revert VeMoe__InvalidLength();
User storage user = _users[msg.sender];
for (uint256 i; i < pids.length; ++i) {
uint256 pid = pids[i];
IVeMoeRewarder newBribe = bribes[i];
IVeMoeRewarder oldBribe = user.bribes[pid];
if (oldBribe == newBribe) continue;
if (
address(newBribe) != address(0)
&& _rewarderFactory.getRewarderType(newBribe) != IRewarderFactory.RewarderType.VeMoeRewarder
) {
revert VeMoe__InvalidBribeAddress();
}
uint256 userVotes = user.votes.getAmountOf(pid);
user.bribes[pid] = newBribe;
uint256 oldBribesTotalVotes;
uint256 newBribesTotalVotes;
if (address(oldBribe) != address(0)) {
oldBribesTotalVotes = _bribesTotalVotes[oldBribe][pid];
_bribesTotalVotes[oldBribe][pid] = oldBribesTotalVotes - userVotes;
}
if (address(newBribe) != address(0)) {
newBribesTotalVotes = _bribesTotalVotes[newBribe][pid];
_bribesTotalVotes[newBribe][pid] = newBribesTotalVotes + userVotes;
}
// Done after updating _bribesTotalVotes to avoid reentrancy attack on total votes
uint256 newBribesRewards = (address(newBribe) != address(0))
? newBribe.onModify(msg.sender, pid, 0, userVotes, newBribesTotalVotes)
: uint256(0);
uint256 oldBribesRewards = (address(oldBribe) != address(0))
? oldBribe.onModify(msg.sender, pid, userVotes, 0, oldBribesTotalVotes)
: uint256(0);
// Done after updating bribes to avoid reentrancy attack on rewards
if (newBribesRewards > 0) newBribe.claim(msg.sender, newBribesRewards); // Should never be reached, but kept for consistency
if (oldBribesRewards > 0) oldBribe.claim(msg.sender, oldBribesRewards);
}
emit BribesSet(msg.sender, pids, bribes);
}
/**
* @dev Emergency function to unset the bribes contract for each pool in the pids list, forfeiting the rewards.
* @param pids The list of pool IDs.
*/
function emergencyUnsetBribes(uint256[] calldata pids) external override {
User storage user = _users[msg.sender];
for (uint256 i; i < pids.length; ++i) {
uint256 pid = pids[i];
IVeMoeRewarder bribe = user.bribes[pid];
if (address(bribe) == address(0)) revert VeMoe__NoBribeForPid(pid);
uint256 userVotes = user.votes.getAmountOf(pid);
_bribesTotalVotes[bribe][pid] -= userVotes;
delete user.bribes[pid];
}
emit BribesSet(msg.sender, pids, new IVeMoeRewarder[](pids.length));
}
/**
* @dev Called by the caller contract to update the veMOE of an account.
* @param account The account to update.
* @param oldBalance The old balance of the account.
* @param newBalance The new balance of the account.
*/
function onModify(address account, uint256 oldBalance, uint256 newBalance, uint256, uint256) external override {
if (msg.sender != address(_moeStaking)) revert VeMoe__InvalidCaller();
_claim(account, oldBalance, newBalance);
}
/**
* @dev Sets the top pool IDs.
* @param pids The list of pool IDs.
*/
function setTopPoolIds(uint256[] calldata pids) external override onlyOwner {
uint256 length = pids.length;
if (length > Constants.MAX_NUMBER_OF_FARMS) revert VeMoe__TooManyPoolIds();
_masterChef.updateAll(pids);
uint256[] memory oldIds = _topPids.values();
if (oldIds.length > 0) {
_masterChef.updateAll(oldIds);
for (uint256 i = oldIds.length; i > 0;) {
uint256 pid = oldIds[--i];
_topPids.remove(pid);
_weights[pid] = 0;
}
}
for (uint256 i; i < length; ++i) {
uint256 pid = pids[i];
if (!_topPids.add(pid)) revert VeMoe__DuplicatePoolId(pid);
if (_masterChef.getStaticPoolShare(pid) > 0) revert VeMoe__StaticPool(pid);
}
_updateWeights(pids, _alpha);
emit TopPoolIdsSet(pids);
}
/**
* @dev Sets the alpha value, used to calculate the weight of a pool (weight = min(votes, votes^alpha)).
* @param alpha The alpha value.
*/
function setAlpha(uint256 alpha) external override onlyOwner {
_setAlpha(alpha);
}
/**
* @dev Sets the veMOE per second.
* @param veMoePerSecondPerMoe The veMOE per second.
*/
function setVeMoePerSecondPerMoe(uint256 veMoePerSecondPerMoe) external override onlyOwner {
_veRewarder.updateAccDebtPerShare(
Constants.PRECISION, _veRewarder.getTotalRewards(_veMoePerSecondPerMoe, Constants.PRECISION)
);
_veMoePerSecondPerMoe = veMoePerSecondPerMoe;
emit VeMoePerSecondPerMoeSet(veMoePerSecondPerMoe);
}
/**
* @dev Blocks the renouncing of ownership.
*/
function renounceOwnership() public pure override {
revert VeMoe__CannotRenounceOwnership();
}
/**
* @dev Returns the weight from a number of votes.
* @param poolVotes The number of votes of a pool.
* @param alpha The alpha value.
* @return weight The weight.
*/
function _calculateWeight(uint256 poolVotes, uint256 alpha) private pure returns (uint256 weight) {
if (poolVotes <= Constants.PRECISION || alpha == Constants.PRECISION) return poolVotes;
int256 sweight = FixedPointMathLib.powWad(Math.toInt256(poolVotes), int256(alpha));
if (sweight < 0) return 0;
weight = uint256(sweight) > poolVotes ? poolVotes : uint256(sweight);
}
/**
* @dev Claims the pending veMOE of an account.
* @param account The account to claim veMOE for.
* @param oldBalance The old balance of the account.
* @param newBalance The new balance of the account.
*/
function _claim(address account, uint256 oldBalance, uint256 newBalance) private {
User storage user = _users[account];
uint256 totalVested = _veRewarder.getTotalRewards(_veMoePerSecondPerMoe, Constants.PRECISION);
uint256 userVested = _veRewarder.update(account, oldBalance, newBalance, Constants.PRECISION, totalVested);
(uint256 newVeMoe, int256 deltaVeMoe) = _getVeMoe(user, oldBalance, newBalance, userVested);
user.veMoe = newVeMoe;
emit Claim(account, deltaVeMoe);
}
/**
* @dev Updates the weights of the pools in the pids list.
* @param pids The list of pool IDs.
* @param alpha The alpha value.
*/
function _updateWeights(uint256[] memory pids, uint256 alpha) private {
uint256 totalVotes;
uint256 totalWeights;
uint256 length = pids.length;
for (uint256 i; i < length; ++i) {
uint256 pid = pids[i];
uint256 votes = _votes.getAmountOf(pid);
uint256 weight = _calculateWeight(votes, alpha);
_weights[pid] = weight;
totalVotes += votes;
totalWeights += weight;
}
_topPidsTotalVotes = totalVotes;
_topPidsTotalWeights = totalWeights;
}
/**
* @dev Sets the alpha value and updates the weights of the pools in the top pool IDs.
* @param alpha The alpha value.
*/
function _setAlpha(uint256 alpha) private {
if (alpha == 0 || alpha > Constants.PRECISION) revert VeMoe__InvalidAlpha();
_alpha = alpha;
_updateWeights(_topPids.values(), alpha);
emit AlphaSet(alpha);
}
/**
* @dev Votes for a pool.
* @param user The storage pointer to the user.
* @param pid The pool ID.
* @param deltaAmount The delta amount to vote.
* @param userTotalVeMoe The total veMOE of the user.
* @return bribeReward The pending bribe reward.
* @return newPoolVotes The total votes of the pool.
*/
function _vote(User storage user, uint256 pid, int256 deltaAmount, uint256 userTotalVeMoe)
private
returns (BribeReward memory bribeReward, uint256 newPoolVotes)
{
(uint256 userOldVotes, uint256 userNewVotes,, uint256 userNewTotalVotes) = user.votes.update(pid, deltaAmount);
if (userNewTotalVotes > userTotalVeMoe) revert VeMoe__InsufficientVeMoe(userTotalVeMoe, userNewTotalVotes);
(, newPoolVotes,,) = _votes.update(pid, deltaAmount);
IVeMoeRewarder bribe = user.bribes[pid];
if (address(bribe) != address(0)) {
uint256 totalVotes = _bribesTotalVotes[bribe][pid];
_bribesTotalVotes[bribe][pid] = totalVotes.addDelta(deltaAmount);
bribeReward = BribeReward({
bribe: bribe,
rewardAmount: bribe.onModify(msg.sender, pid, userOldVotes, userNewVotes, totalVotes)
});
}
}
/**
* @dev Returns the veMOE of an account.
* @param user The user to check.
* @param oldBalance The old balance of the account.
* @param newBalance The new balance of the account.
* @param userVested The vested veMOE of the account.
* @return newVeMoe The new veMOE of the account.
* @return deltaVeMoe The delta veMOE of the account.
*/
function _getVeMoe(User storage user, uint256 oldBalance, uint256 newBalance, uint256 userVested)
private
view
returns (uint256 newVeMoe, int256 deltaVeMoe)
{
uint256 oldVeMoe = user.veMoe;
if (newBalance >= oldBalance) {
newVeMoe = oldVeMoe + userVested;
uint256 maxVeMoe = oldBalance * _maxVeMoePerMoe / Constants.PRECISION;
newVeMoe = newVeMoe > maxVeMoe ? maxVeMoe : newVeMoe;
} else {
if (user.votes.getTotalAmount() > 0) revert VeMoe__CannotUnstakeWithVotes();
newVeMoe = 0;
}
unchecked {
deltaVeMoe = newVeMoe.toInt256() - oldVeMoe.toInt256();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {OwnableUpgradeable} from "./OwnableUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable2Step
struct Ownable2StepStorage {
address _pendingOwner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable2Step")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant Ownable2StepStorageLocation = 0x237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c00;
function _getOwnable2StepStorage() private pure returns (Ownable2StepStorage storage $) {
assembly {
$.slot := Ownable2StepStorageLocation
}
}
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
function __Ownable2Step_init() internal onlyInitializing {
}
function __Ownable2Step_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
return $._pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
$._pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
Ownable2StepStorage storage $ = _getOwnable2StepStorage();
delete $._pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. 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 {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @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) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @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 {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @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 Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 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 in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._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 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._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() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @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 {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface 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].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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 An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @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.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @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);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) 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 FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @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 is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @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._positions[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 cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 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 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[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._positions[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
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
function powWad(int256 x, int256 y) internal pure returns (int256) {
// Equivalent to x to the power of y because x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)
return expWad((lnWad(x) * y) / int256(WAD)); // Using ln(x) means x must be greater than 0.
}
function expWad(int256 x) internal pure returns (int256 r) {
unchecked {
// When the result is < 0.5 we return zero. This happens when
// x <= floor(log(0.5e18) * 1e18) ~ -42e18
if (x <= -42139678854452767551) return 0;
// When the result is > (2**255 - 1) / 1e18 we can not represent it as an
// int. This happens when x >= floor(log((2**255 - 1) / 1e18) * 1e18) ~ 135.
if (x >= 135305999368893231589) revert("EXP_OVERFLOW");
// x is now in the range (-42, 136) * 1e18. Convert to (-42, 136) * 2**96
// for more intermediate precision and a binary basis. This base conversion
// is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
x = (x << 78) / 5**18;
// Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
// of two such that exp(x) = exp(x') * 2**k, where k is an integer.
// Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
int256 k = ((x << 96) / 54916777467707473351141471128 + 2**95) >> 96;
x = x - k * 54916777467707473351141471128;
// k is in the range [-61, 195].
// Evaluate using a (6, 7)-term rational approximation.
// p is made monic, we'll multiply by a scale factor later.
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
// We leave p in 2**192 basis so we don't need to scale it back up for the division.
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial won't have zeros in the domain as all its roots are complex.
// No scaling is necessary because p is already 2**96 too large.
r := sdiv(p, q)
}
// r should be in the range (0.09, 0.25) * 2**96.
// We now need to multiply r by:
// * the scale factor s = ~6.031367120.
// * the 2**k factor from the range reduction.
// * the 1e18 / 2**96 factor for base conversion.
// We do this all at once, with an intermediate result in 2**213
// basis, so the final right shift is always by a positive amount.
r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k));
}
}
function lnWad(int256 x) internal pure returns (int256 r) {
unchecked {
require(x > 0, "UNDEFINED");
// We want to convert x from 10**18 fixed point to 2**96 fixed point.
// We do this by multiplying by 2**96 / 10**18. But since
// ln(x * C) = ln(x) + ln(C), we can simply do nothing here
// and add ln(2**96 / 10**18) at the end.
// Reduce range of x to (1, 2) * 2**96
// ln(2^k * x) = k * ln(2) + ln(x)
int256 k = int256(log2(uint256(x))) - 96;
x <<= uint256(159 - k);
x = int256(uint256(x) >> 159);
// Evaluate using a (8, 8)-term rational approximation.
// p is made monic, we will multiply by a scale factor later.
int256 p = x + 3273285459638523848632254066296;
p = ((p * x) >> 96) + 24828157081833163892658089445524;
p = ((p * x) >> 96) + 43456485725739037958740375743393;
p = ((p * x) >> 96) - 11111509109440967052023855526967;
p = ((p * x) >> 96) - 45023709667254063763336534515857;
p = ((p * x) >> 96) - 14706773417378608786704636184526;
p = p * x - (795164235651350426258249787498 << 96);
// We leave p in 2**192 basis so we don't need to scale it back up for the division.
// q is monic by convention.
int256 q = x + 5573035233440673466300451813936;
q = ((q * x) >> 96) + 71694874799317883764090561454958;
q = ((q * x) >> 96) + 283447036172924575727196451306956;
q = ((q * x) >> 96) + 401686690394027663651624208769553;
q = ((q * x) >> 96) + 204048457590392012362485061816622;
q = ((q * x) >> 96) + 31853899698501571402653359427138;
q = ((q * x) >> 96) + 909429971244387300277376558375;
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial is known not to have zeros in the domain.
// No scaling required because p is already 2**96 too large.
r := sdiv(p, q)
}
// r is in the range (0, 0.125) * 2**96
// Finalization, we need to:
// * multiply by the scale factor s = 5.549…
// * add ln(2**96 / 10**18)
// * add k * ln(2)
// * multiply by 10**18 / 2**96 = 5**18 >> 78
// mul s * 5e18 * 2**96, base is now 5**18 * 2**192
r *= 1677202110996718588342820967067443963516166;
// add ln(2) * k * 5e18 * 2**192
r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;
// add ln(2**96 / 10**18) * 5e18 * 2**192
r += 600920179829731861736702779321621459595472258049074101567377883020018308;
// base conversion: mul 2**18 / 2**192
r >>= 174;
}
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
assembly {
// Store x * y in z for now.
z := mul(x, y)
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
revert(0, 0)
}
// Divide z by the denominator.
z := div(z, denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
assembly {
// Store x * y in z for now.
z := mul(x, y)
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) {
revert(0, 0)
}
// First, divide z - 1 by the denominator and add 1.
// We allow z - 1 to underflow if z is 0, because we multiply the
// end result by 0 if z is zero, ensuring we return 0 if z is zero.
z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
assembly {
let y := x // We start y at x, which will help us make our initial estimate.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
y := shr(128, y)
z := shl(64, z)
}
if iszero(lt(y, 0x1000000000000000000)) {
y := shr(64, y)
z := shl(32, z)
}
if iszero(lt(y, 0x10000000000)) {
y := shr(32, y)
z := shl(16, z)
}
if iszero(lt(y, 0x1000000)) {
y := shr(16, y)
z := shl(8, z)
}
// Goal was to get z*z*y within a small factor of x. More iterations could
// get y in a tighter range. Currently, we will have y in [256, 256*2^16).
// We ensured y >= 256 so that the relative difference between y and y+1 is small.
// That's not possible if x < 256 but we can just verify those cases exhaustively.
// Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256.
// Correctness can be checked exhaustively for x < 256, so we assume y >= 256.
// Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps.
// For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range
// (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256.
// Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate
// sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18.
// There is no overflow risk here since y < 2^136 after the first branch above.
z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If x+1 is a perfect square, the Babylonian method cycles between
// floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
// Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
// If you don't care whether the floor or ceil square root is returned, you can remove this statement.
z := sub(z, lt(div(x, z), z))
}
}
function log2(uint256 x) internal pure returns (uint256 r) {
require(x > 0, "UNDEFINED");
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
r := or(r, shl(2, lt(0xf, shr(r, x))))
r := or(r, shl(1, lt(0x3, shr(r, x))))
r := or(r, lt(0x1, shr(r, x)))
}
}
function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
// z will equal 0 if y is 0, unlike in Solidity where it will revert.
z := mod(x, y)
}
}
function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
// z will equal 0 if y is 0, unlike in Solidity where it will revert.
z := div(x, y)
}
}
/// @dev Will return 0 instead of reverting if y is zero.
function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
// Add 1 to x * y if x % y > 0.
z := add(gt(mod(x, y), 0), div(x, y))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IBaseRewarder {
error BaseRewarder__NativeTransferFailed();
error BaseRewarder__InvalidCaller();
error BaseRewarder__Stopped();
error BaseRewarder__AlreadyStopped();
error BaseRewarder__NotNativeRewarder();
error BaseRewarder__ZeroAmount();
error BaseRewarder__ZeroReward();
error BaseRewarder__InvalidDuration();
error BaseRewarder__InvalidPid(uint256 pid);
error BaseRewarder__InvalidStartTimestamp(uint256 startTimestamp);
error BaseRewarder__CannotRenounceOwnership();
event Claim(address indexed account, IERC20 indexed token, uint256 reward);
event RewardParameterUpdated(uint256 rewardPerSecond, uint256 startTimestamp, uint256 endTimestamp);
event Stopped();
event Swept(IERC20 indexed token, address indexed account, uint256 amount);
function getToken() external view returns (IERC20);
function getCaller() external view returns (address);
function getPid() external view returns (uint256);
function getRewarderParameter()
external
view
returns (IERC20 token, uint256 rewardPerSecond, uint256 lastUpdateTimestamp, uint256 endTimestamp);
function getRemainingReward() external view returns (uint256);
function getPendingReward(address account, uint256 balance, uint256 totalSupply)
external
view
returns (IERC20 token, uint256 pendingReward);
function isStopped() external view returns (bool);
function initialize(address initialOwner) external;
function setRewardPerSecond(uint256 maxRewardPerSecond, uint256 expectedDuration)
external
returns (uint256 rewardPerSecond);
function setRewarderParameters(uint256 maxRewardPerSecond, uint256 startTimestamp, uint256 expectedDuration)
external
returns (uint256 rewardPerSecond);
function stop() external;
function sweep(IERC20 token, address account) external;
function onModify(address account, uint256 pid, uint256 oldBalance, uint256 newBalance, uint256 totalSupply)
external
returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IMasterChefRewarder} from "./IMasterChefRewarder.sol";
import {IMoe} from "./IMoe.sol";
import {IVeMoe} from "./IVeMoe.sol";
import {Rewarder} from "../libraries/Rewarder.sol";
import {Amounts} from "../libraries/Amounts.sol";
import {IRewarderFactory} from "./IRewarderFactory.sol";
interface IMasterChef {
error MasterChef__InvalidShares();
error MasterChef__InvalidMoePerSecond();
error MasterChef__ZeroAddress();
error MasterChef__NotMasterchefRewarder();
error MasterChef__CannotRenounceOwnership();
error MasterChef__MintFailed();
error MasterChef__TopPool(uint256 pid);
error MasterChef__TooManyStaticPools();
error MasterChef__StaticPoolSharesOverflow();
error MasterChef__InvalidPoolId(uint256 pid);
struct Farm {
Amounts.Parameter amounts;
Rewarder.Parameter rewarder;
IERC20 token;
IMasterChefRewarder extraRewarder;
}
event PositionModified(uint256 indexed pid, address indexed account, int256 deltaAmount, uint256 moeReward);
event MoePerSecondSet(uint256 moePerSecond);
event FarmAdded(uint256 indexed pid, IERC20 indexed token);
event ExtraRewarderSet(uint256 indexed pid, IMasterChefRewarder extraRewarder);
event TreasurySet(address indexed treasury);
event StaticPoolShareSet(uint256 indexed pid, uint256 share);
event StaticShareSet(uint256 share);
function add(IERC20 token, IMasterChefRewarder extraRewarder) external;
function claim(uint256[] memory pids) external;
function deposit(uint256 pid, uint256 amount) external;
function emergencyWithdraw(uint256 pid) external;
function getDeposit(uint256 pid, address account) external view returns (uint256);
function getLastUpdateTimestamp(uint256 pid) external view returns (uint256);
function getPendingRewards(address account, uint256[] memory pids)
external
view
returns (uint256[] memory moeRewards, IERC20[] memory extraTokens, uint256[] memory extraRewards);
function getExtraRewarder(uint256 pid) external view returns (IMasterChefRewarder);
function getMoe() external view returns (IMoe);
function getMoePerSecond() external view returns (uint256);
function getMoePerSecondForPid(uint256 pid) external view returns (uint256);
function getNumberOfFarms() external view returns (uint256);
function getToken(uint256 pid) external view returns (IERC20);
function getTotalDeposit(uint256 pid) external view returns (uint256);
function getTreasury() external view returns (address);
function getTreasuryShare() external view returns (uint256);
function getStaticShare() external view returns (uint256);
function getTotalStaticPoolShares() external view returns (uint256);
function getStaticPoolShare(uint256 pid) external view returns (uint256);
function getStaticPoolIds() external view returns (uint256[] memory);
function isStaticPool(uint256 pid) external view returns (bool);
function getRewarderFactory() external view returns (IRewarderFactory);
function getLBHooksManager() external view returns (address);
function getVeMoe() external view returns (IVeMoe);
function setExtraRewarder(uint256 pid, IMasterChefRewarder extraRewarder) external;
function setMoePerSecond(uint96 moePerSecond) external;
function setTreasury(address treasury) external;
function setStaticPoolShare(uint256 pid, uint128 share) external;
function setStaticShare(uint128 share) external;
function updateAll(uint256[] calldata pids) external;
function withdraw(uint256 pid, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IBaseRewarder} from "./IBaseRewarder.sol";
interface IMasterChefRewarder is IBaseRewarder {
error MasterChefRewarder__AlreadyLinked();
error MasterChefRewarder__NotLinked();
error MasterChefRewarder__UseUnlink();
enum Status {
Unlinked,
Linked,
Stopped
}
function link(uint256 pid) external;
function unlink(uint256 pid) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IMoe is IERC20 {
error Moe__NotMinter(address account);
error Moe__InvalidInitialSupply();
error Moe__InvalidMaxSupply();
function getMinter() external view returns (address);
function getMaxSupply() external view returns (uint256);
function mint(address account, uint256 amount) external returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IMoe} from "./IMoe.sol";
import {IVeMoe} from "./IVeMoe.sol";
import {IStableMoe} from "./IStableMoe.sol";
interface IMoeStaking {
event PositionModified(address indexed account, int256 deltaAmount);
function getMoe() external view returns (IMoe);
function getVeMoe() external view returns (IVeMoe);
function getSMoe() external view returns (IStableMoe);
function getDeposit(address account) external view returns (uint256);
function getTotalDeposit() external view returns (uint256);
function stake(uint256 amount) external;
function unstake(uint256 amount) external;
function claim() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IBaseRewarder} from "../interfaces/IBaseRewarder.sol";
interface IRewarderFactory {
error RewarderFactory__ZeroAddress();
error RewarderFactory__InvalidRewarderType();
error RewarderFactory__InvalidPid();
enum RewarderType {
InvalidRewarder,
MasterChefRewarder,
VeMoeRewarder,
JoeStakingRewarder
}
event RewarderCreated(
RewarderType indexed rewarderType, IERC20 indexed token, uint256 indexed pid, IBaseRewarder rewarder
);
event RewarderImplementationSet(RewarderType indexed rewarderType, IBaseRewarder indexed implementation);
function getRewarderImplementation(RewarderType rewarderType) external view returns (IBaseRewarder);
function getRewarderCount(RewarderType rewarderType) external view returns (uint256);
function getRewarderAt(RewarderType rewarderType, uint256 index) external view returns (IBaseRewarder);
function getRewarderType(IBaseRewarder rewarder) external view returns (RewarderType);
function setRewarderImplementation(RewarderType rewarderType, IBaseRewarder implementation) external;
function createRewarder(RewarderType rewarderType, IERC20 token, uint256 pid) external returns (IBaseRewarder);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Rewarder} from "../libraries/Rewarder.sol";
import {IMoeStaking} from "../interfaces/IMoeStaking.sol";
interface IStableMoe {
error StableMoe__UnauthorizedCaller();
error StableMoe__RewardAlreadyAdded(IERC20 reward);
error StableMoe__RewardAlreadyRemoved(IERC20 reward);
error StableMoe__ActiveReward(IERC20 reward);
error StableMoe__NativeTransferFailed();
error StableMoe__TooManyActiveRewards();
error StableMoe__CannotRenounceOwnership();
struct Reward {
Rewarder.Parameter rewarder;
uint256 reserve;
}
event Claim(address indexed account, IERC20 indexed token, uint256 amount);
event AddReward(IERC20 indexed reward);
event RemoveReward(IERC20 indexed reward);
event Sweep(IERC20 indexed token, address indexed account);
function getMoeStaking() external view returns (IMoeStaking);
function getNumberOfRewards() external view returns (uint256);
function getRewardToken(uint256 id) external view returns (address);
function getRewardTokens() external view returns (address[] memory);
function getPendingRewards(address account)
external
view
returns (IERC20[] memory tokens, uint256[] memory rewards);
function claim() external;
function onModify(
address account,
uint256 oldBalance,
uint256 newBalance,
uint256 oldTotalSupply,
uint256 newTotalSupply
) external;
function addReward(IERC20 reward) external;
function removeReward(IERC20 reward) external;
function sweep(IERC20 token, address account) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IVeMoeRewarder} from "./IVeMoeRewarder.sol";
import {IMoeStaking} from "./IMoeStaking.sol";
import {IMasterChef} from "./IMasterChef.sol";
import {Amounts} from "../libraries/Amounts.sol";
import {Rewarder} from "../libraries/Rewarder.sol";
import {IRewarderFactory} from "./IRewarderFactory.sol";
interface IVeMoe {
error VeMoe__InvalidLength();
error VeMoe__InsufficientVeMoe(uint256 totalVeMoe, uint256 requiredVeMoe);
error VeMoe__InvalidCaller();
error VeMoe__InvalidBribeAddress();
error VeMoe__InvalidPid(uint256 pid);
error VeMoe__InvalidWeight();
error VeMoe__InvalidAlpha();
error VeMoe__CannotUnstakeWithVotes();
error VeMoe__NoBribeForPid(uint256 pid);
error VeMoe__TooManyPoolIds();
error VeMoe__DuplicatePoolId(uint256 pid);
error VeMoe__StaticPool(uint256 pid);
error VeMoe__CannotRenounceOwnership();
error VeMoe__InvalidMaxVeMoePerMoe();
struct User {
uint256 veMoe;
Amounts.Parameter votes;
mapping(uint256 => IVeMoeRewarder) bribes;
}
struct Reward {
Rewarder.Parameter rewarder;
IERC20 token;
uint256 reserve;
}
struct BribeReward {
IVeMoeRewarder bribe;
uint256 rewardAmount;
}
event BribesSet(address indexed account, uint256[] pids, IVeMoeRewarder[] bribes);
event Claim(address indexed account, int256 deltaVeMoe);
event TopPoolIdsSet(uint256[] topPoolIds);
event Vote(address account, uint256[] pids, int256[] deltaVeAmounts);
event VeMoePerSecondPerMoeSet(uint256 veMoePerSecondPerMoe);
event AlphaSet(uint256 alpha);
function balanceOf(address account) external view returns (uint256 veMoe);
function claim(uint256[] memory pids) external;
function emergencyUnsetBribes(uint256[] memory pids) external;
function getBribesOf(address account, uint256 pid) external view returns (IVeMoeRewarder);
function getBribesTotalVotes(IVeMoeRewarder bribe, uint256 pid) external view returns (uint256);
function getMasterChef() external view returns (IMasterChef);
function getMaxVeMoePerMoe() external view returns (uint256);
function getMoeStaking() external view returns (IMoeStaking);
function getPendingRewards(address account, uint256[] calldata pids)
external
view
returns (IERC20[] memory tokens, uint256[] memory pendingRewards);
function getTopPidsTotalVotes() external view returns (uint256);
function getTopPoolIds() external view returns (uint256[] memory);
function getTotalVotes() external view returns (uint256);
function getTotalWeight() external view returns (uint256);
function getTotalVotesOf(address account) external view returns (uint256);
function getVeMoePerSecondPerMoe() external view returns (uint256);
function getVotes(uint256 pid) external view returns (uint256);
function getWeight(uint256 pid) external view returns (uint256);
function getVotesOf(address account, uint256 pid) external view returns (uint256);
function getAlpha() external view returns (uint256);
function getRewarderFactory() external view returns (IRewarderFactory);
function isInTopPoolIds(uint256 pid) external view returns (bool);
function onModify(address account, uint256 oldBalance, uint256 newBalance, uint256 oldTotalSupply, uint256)
external;
function setBribes(uint256[] memory pids, IVeMoeRewarder[] memory bribes) external;
function setTopPoolIds(uint256[] memory pids) external;
function setAlpha(uint256 alpha) external;
function setVeMoePerSecondPerMoe(uint256 veMoePerSecondPerMoe) external;
function vote(uint256[] memory pids, int256[] memory deltaAmounts) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IBaseRewarder} from "./IBaseRewarder.sol";
interface IVeMoeRewarder is IBaseRewarder {
function claim(address account, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Math} from "./Math.sol";
/**
* @title Amounts Library
* @dev A library that defines various functions for manipulating amounts of a key and a total.
* The key can be bytes32, address, or uint256.
*/
library Amounts {
using Math for uint256;
struct Parameter {
uint256 totalAmount;
mapping(bytes32 => uint256) amounts;
}
/**
* @dev Returns the amount of a key.
* @param amounts The storage pointer to the amounts.
* @param key The key of the amount.
* @return The amount of the key.
*/
function getAmountOf(Parameter storage amounts, bytes32 key) internal view returns (uint256) {
return amounts.amounts[key];
}
/**
* @dev Returns the amount of an address.
* @param amounts The storage pointer to the amounts.
* @param account The address of the amount.
* @return The amount of the address.
*/
function getAmountOf(Parameter storage amounts, address account) internal view returns (uint256) {
return getAmountOf(amounts, bytes32(uint256(uint160(account))));
}
/**
* @dev Returns the amount of an id.
* @param amounts The storage pointer to the amounts.
* @param id The id of the amount.
* @return The amount of the id.
*/
function getAmountOf(Parameter storage amounts, uint256 id) internal view returns (uint256) {
return getAmountOf(amounts, bytes32(id));
}
/**
* @dev Returns the total amount.
* @param amounts The storage pointer to the amounts.
* @return The total amount.
*/
function getTotalAmount(Parameter storage amounts) internal view returns (uint256) {
return amounts.totalAmount;
}
/**
* @dev Updates the amount of a key. The delta is added to the key amount and the total amount.
* @param amounts The storage pointer to the amounts.
* @param key The key of the amount.
* @param deltaAmount The delta amount to update.
* @return oldAmount The old amount of the key.
* @return newAmount The new amount of the key.
* @return oldTotalAmount The old total amount.
* @return newTotalAmount The new total amount.
*/
function update(Parameter storage amounts, bytes32 key, int256 deltaAmount)
internal
returns (uint256 oldAmount, uint256 newAmount, uint256 oldTotalAmount, uint256 newTotalAmount)
{
oldAmount = amounts.amounts[key];
oldTotalAmount = amounts.totalAmount;
if (deltaAmount == 0) {
newAmount = oldAmount;
newTotalAmount = oldTotalAmount;
} else {
newAmount = oldAmount.addDelta(deltaAmount);
newTotalAmount = oldTotalAmount.addDelta(deltaAmount);
amounts.amounts[key] = newAmount;
amounts.totalAmount = newTotalAmount;
}
}
/**
* @dev Updates the amount of an address. The delta is added to the address amount and the total amount.
* @param amounts The storage pointer to the amounts.
* @param account The address of the amount.
* @param deltaAmount The delta amount to update.
* @return oldAmount The old amount of the key.
* @return newAmount The new amount of the key.
* @return oldTotalAmount The old total amount.
* @return newTotalAmount The new total amount.
*/
function update(Parameter storage amounts, address account, int256 deltaAmount)
internal
returns (uint256 oldAmount, uint256 newAmount, uint256 oldTotalAmount, uint256 newTotalAmount)
{
return update(amounts, bytes32(uint256(uint160(account))), deltaAmount);
}
/**
* @dev Updates the amount of an id. The delta is added to the id amount and the total amount.
* @param amounts The storage pointer to the amounts.
* @param id The id of the amount.
* @param deltaAmount The delta amount to update.
* @return oldAmount The old amount of the key.
* @return newAmount The new amount of the key.
* @return oldTotalAmount The old total amount.
* @return newTotalAmount The new total amount.
*/
function update(Parameter storage amounts, uint256 id, int256 deltaAmount)
internal
returns (uint256 oldAmount, uint256 newAmount, uint256 oldTotalAmount, uint256 newTotalAmount)
{
return update(amounts, bytes32(id), deltaAmount);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title Constants Library
* @dev A library that defines various constants used throughout the codebase.
*/
library Constants {
uint256 internal constant ACC_PRECISION_BITS = 64;
uint256 internal constant PRECISION = 1e18;
uint8 internal constant NEW_ACC_PRECISION_BITS = 128;
uint256 internal constant MAX_NUMBER_OF_FARMS = 32;
uint256 internal constant MAX_NUMBER_OF_REWARDS = 32;
uint256 internal constant MAX_SUPPLY = 1_000_000_000e18;
uint256 internal constant MAX_VE_MOE_PER_MOE = 100_000e18;
uint256 internal constant MAX_STATIC_SHARES = 1e32;
uint256 internal constant MAX_MOE_PER_SECOND = 10e18;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title Math
* @dev Library for mathematical operations with overflow and underflow checks.
*/
library Math {
error Math__UnderOverflow();
uint256 internal constant MAX_INT256 = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
/**
* @dev Adds a signed integer to an unsigned integer with overflow check.
* The result must be greater than or equal to 0 and less than or equal to MAX_INT256.
* @param x Unsigned integer to add to.
* @param delta Signed integer to add.
* @return y The result of the addition.
*/
function addDelta(uint256 x, int256 delta) internal pure returns (uint256 y) {
uint256 success;
assembly {
y := add(x, delta)
success := iszero(or(gt(x, MAX_INT256), gt(y, MAX_INT256)))
}
if (success == 0) revert Math__UnderOverflow();
}
/**
* @dev Safely converts an unsigned integer to a signed integer.
* @param x Unsigned integer to convert.
* @return y Signed integer result.
*/
function toInt256(uint256 x) internal pure returns (int256 y) {
if (x > MAX_INT256) revert Math__UnderOverflow();
return int256(x);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Amounts} from "./Amounts.sol";
import {Constants} from "./Constants.sol";
/**
* @title Rewarder Library
* @dev A library that defines various functions for calculating rewards.
* It takes care about the reward debt and the accumulated debt per share.
* The version 2 should be used as it offers more precision and avoid potential rounding errors.
*/
library Rewarder {
using Amounts for Amounts.Parameter;
struct Parameter {
uint256 lastUpdateTimestamp;
uint256 accDebtPerShare;
mapping(address => uint256) debt;
}
/**
* @dev Returns the debt associated with an amount.
* @param accDebtPerShare The accumulated debt per share.
* @param deposit The amount.
* @return The debt associated with the amount.
*/
function getDebt(uint256 accDebtPerShare, uint256 deposit) internal pure returns (uint256) {
return (deposit * accDebtPerShare) >> Constants.ACC_PRECISION_BITS;
}
/**
* @dev Returns the debt per share associated with a total deposit and total rewards.
* @param totalDeposit The total deposit.
* @param totalRewards The total rewards.
* @return The debt per share associated with the total deposit and total rewards.
*/
function getDebtPerShare(uint256 totalDeposit, uint256 totalRewards) internal pure returns (uint256) {
return totalDeposit == 0 ? 0 : (totalRewards << Constants.ACC_PRECISION_BITS) / totalDeposit;
}
/**
* @dev Returns the total rewards to emit.
* If the end timestamp is in the past, the rewards are calculated up to the end timestamp.
* If the last update timestamp is in the future, it will return 0.
* @param rewarder The storage pointer to the rewarder.
* @param rewardPerSecond The reward per second.
* @param endTimestamp The end timestamp.
* @param totalSupply The total supply.
* @return The total rewards.
*/
function getTotalRewards(
Parameter storage rewarder,
uint256 rewardPerSecond,
uint256 endTimestamp,
uint256 totalSupply
) internal view returns (uint256) {
if (totalSupply == 0) return 0;
uint256 lastUpdateTimestamp = rewarder.lastUpdateTimestamp;
uint256 timestamp = block.timestamp > endTimestamp ? endTimestamp : block.timestamp;
return timestamp > lastUpdateTimestamp ? (timestamp - lastUpdateTimestamp) * rewardPerSecond : 0;
}
/**
* @dev Returns the total rewards to emit.
* @param rewarder The storage pointer to the rewarder.
* @param rewardPerSecond The reward per second.
* @param totalSupply The total supply.
* @return The total rewards.
*/
function getTotalRewards(Parameter storage rewarder, uint256 rewardPerSecond, uint256 totalSupply)
internal
view
returns (uint256)
{
return getTotalRewards(rewarder, rewardPerSecond, block.timestamp, totalSupply);
}
/**
* @dev Returns the pending reward of an account.
* @param rewarder The storage pointer to the rewarder.
* @param amounts The storage pointer to the amounts.
* @param account The address of the account.
* @param totalRewards The total rewards.
* @return The pending reward of the account.
*/
function getPendingReward(
Parameter storage rewarder,
Amounts.Parameter storage amounts,
address account,
uint256 totalRewards
) internal view returns (uint256) {
return getPendingReward(rewarder, account, amounts.getAmountOf(account), amounts.getTotalAmount(), totalRewards);
}
/**
* @dev Returns the pending reward of an account.
* If the balance of the account is 0, it will always return 0.
* @param rewarder The storage pointer to the rewarder.
* @param account The address of the account.
* @param balance The balance of the account.
* @param totalSupply The total supply.
* @param totalRewards The total rewards.
* @return The pending reward of the account.
*/
function getPendingReward(
Parameter storage rewarder,
address account,
uint256 balance,
uint256 totalSupply,
uint256 totalRewards
) internal view returns (uint256) {
uint256 accDebtPerShare = rewarder.accDebtPerShare + getDebtPerShare(totalSupply, totalRewards);
return balance == 0 ? 0 : getDebt(accDebtPerShare, balance) - rewarder.debt[account];
}
/**
* @dev Updates the rewarder.
* If the balance of the account is 0, it will always return 0.
* @param rewarder The storage pointer to the rewarder.
* @param account The address of the account.
* @param oldBalance The old balance of the account.
* @param newBalance The new balance of the account.
* @param totalSupply The total supply.
* @param totalRewards The total rewards.
* @return rewards The rewards of the account.
*/
function update(
Parameter storage rewarder,
address account,
uint256 oldBalance,
uint256 newBalance,
uint256 totalSupply,
uint256 totalRewards
) internal returns (uint256 rewards) {
uint256 accDebtPerShare = updateAccDebtPerShare(rewarder, totalSupply, totalRewards);
rewards = oldBalance == 0 ? 0 : getDebt(accDebtPerShare, oldBalance) - rewarder.debt[account];
rewarder.debt[account] = getDebt(accDebtPerShare, newBalance);
}
/**
* @dev Updates the accumulated debt per share.
* If the last update timestamp is in the future, it will not update the last update timestamp.
* @param rewarder The storage pointer to the rewarder.
* @param totalSupply The total supply.
* @param totalRewards The total rewards.
* @return The accumulated debt per share.
*/
function updateAccDebtPerShare(Parameter storage rewarder, uint256 totalSupply, uint256 totalRewards)
internal
returns (uint256)
{
uint256 debtPerShare = getDebtPerShare(totalSupply, totalRewards);
if (block.timestamp > rewarder.lastUpdateTimestamp) rewarder.lastUpdateTimestamp = block.timestamp;
return debtPerShare == 0 ? rewarder.accDebtPerShare : rewarder.accDebtPerShare += debtPerShare;
}
}{
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"enabled": true,
"runs": 600
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": [
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@tj-dexv2/=lib/dexv2/",
"@solmate/=lib/solmate/",
"dexv2/=lib/dexv2/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/src/"
],
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IMoeStaking","name":"moeStaking","type":"address"},{"internalType":"contract IMasterChef","name":"masterChef","type":"address"},{"internalType":"contract IRewarderFactory","name":"rewarderFactory","type":"address"},{"internalType":"uint256","name":"maxVeMoePerMoe","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"Math__UnderOverflow","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"VeMoe__CannotRenounceOwnership","type":"error"},{"inputs":[],"name":"VeMoe__CannotUnstakeWithVotes","type":"error"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"VeMoe__DuplicatePoolId","type":"error"},{"inputs":[{"internalType":"uint256","name":"totalVeMoe","type":"uint256"},{"internalType":"uint256","name":"requiredVeMoe","type":"uint256"}],"name":"VeMoe__InsufficientVeMoe","type":"error"},{"inputs":[],"name":"VeMoe__InvalidAlpha","type":"error"},{"inputs":[],"name":"VeMoe__InvalidBribeAddress","type":"error"},{"inputs":[],"name":"VeMoe__InvalidCaller","type":"error"},{"inputs":[],"name":"VeMoe__InvalidLength","type":"error"},{"inputs":[],"name":"VeMoe__InvalidMaxVeMoePerMoe","type":"error"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"VeMoe__InvalidPid","type":"error"},{"inputs":[],"name":"VeMoe__InvalidWeight","type":"error"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"VeMoe__NoBribeForPid","type":"error"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"VeMoe__StaticPool","type":"error"},{"inputs":[],"name":"VeMoe__TooManyPoolIds","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"alpha","type":"uint256"}],"name":"AlphaSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"pids","type":"uint256[]"},{"indexed":false,"internalType":"contract IVeMoeRewarder[]","name":"bribes","type":"address[]"}],"name":"BribesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"int256","name":"deltaVeMoe","type":"int256"}],"name":"Claim","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","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":"uint256[]","name":"topPoolIds","type":"uint256[]"}],"name":"TopPoolIdsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"veMoePerSecondPerMoe","type":"uint256"}],"name":"VeMoePerSecondPerMoeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"pids","type":"uint256[]"},{"indexed":false,"internalType":"int256[]","name":"deltaVeAmounts","type":"int256[]"}],"name":"Vote","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"veMoe","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"}],"name":"emergencyUnsetBribes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAlpha","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"getBribesOf","outputs":[{"internalType":"contract IVeMoeRewarder","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IVeMoeRewarder","name":"bribe","type":"address"},{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"getBribesTotalVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMasterChef","outputs":[{"internalType":"contract IMasterChef","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxVeMoePerMoe","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMoeStaking","outputs":[{"internalType":"contract IMoeStaking","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256[]","name":"pids","type":"uint256[]"}],"name":"getPendingRewards","outputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"pendingRewards","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewarderFactory","outputs":[{"internalType":"contract IRewarderFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTopPidsTotalVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTopPoolIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getTotalVotesOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVeMoePerSecondPerMoe","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"getVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"getVotesOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"getWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"pid","type":"uint256"}],"name":"isInTopPoolIds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"oldBalance","type":"uint256"},{"internalType":"uint256","name":"newBalance","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"onModify","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"alpha","type":"uint256"}],"name":"setAlpha","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"},{"internalType":"contract IVeMoeRewarder[]","name":"bribes","type":"address[]"}],"name":"setBribes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"}],"name":"setTopPoolIds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"veMoePerSecondPerMoe","type":"uint256"}],"name":"setVeMoePerSecondPerMoe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"pids","type":"uint256[]"},{"internalType":"int256[]","name":"deltaAmounts","type":"int256[]"}],"name":"vote","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
61010060405234801562000011575f80fd5b50604051620031f7380380620031f7833981016040819052620000349162000155565b69152d02c7e14af68000008111156200005f5760405162dc8dd360e41b815260040160405180910390fd5b620000696200008c565b6001600160a01b0393841660805291831660a05290911660c05260e052620001ac565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff1615620000dd5760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146200013d5780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b6001600160a01b03811681146200013d575f80fd5b5f805f806080858703121562000169575f80fd5b8451620001768162000140565b6020860151909450620001898162000140565b60408601519093506200019c8162000140565b6060959095015193969295505050565b60805160a05160c05160e051612fd1620002265f395f81816103a8015261200501525f818161030c01526114d901525f8181610414015281816106d80152818161075a01528181610b6b01528181610bfb0152610d2b01525f81816103600152818161080901528181611234015261135b0152612fd15ff3fe608060405234801561000f575f80fd5b5060043610610201575f3560e01c8063870b50fd11610123578063c4d66de8116100b8578063e30c397811610088578063f2fde38b1161006e578063f2fde38b146104cf578063f4988a3d146104e2578063ff981099146104ea575f80fd5b8063e30c397814610492578063e720e4831461049a575f80fd5b8063c4d66de814610438578063d851fdfd1461044b578063e1e4d4191461046a578063e21e41461461047f575f80fd5b80638da5cb5b116100f35780638da5cb5b146103ef5780639a0e7d66146103f7578063af2a73f5146103ff578063b564496314610412575f80fd5b8063870b50fd1461038c5780638761e7fb1461039f578063888ed79e146103a6578063889e6072146103cc575f80fd5b8063518ab0d01161019957806370a082311161016957806370a0823114610343578063715018a61461035657806372f148b81461035e57806379ba509714610384575f80fd5b8063518ab0d0146102d6578063566aff6a146102e95780635c4323ab1461030a5780636ba4c13814610330575f80fd5b80631befbe36116101d45780631befbe36146102575780632f4f7fbb146102a857806347eaa2b4146102bb5780634f913d34146102ce575f80fd5b806306aba0e11461020557806307532f561461021c57806308ada2ed1461022f5780630c17d42c14610244575b5f80fd5b600c545b6040519081526020015b60405180910390f35b61020961022a3660046129e8565b6104fd565b61024261023d366004612a5a565b61052a565b005b610242610252366004612a99565b6106a0565b6102906102653660046129e8565b6001600160a01b039182165f9081526009602090815260408083209383526003909301905220541690565b6040516001600160a01b039091168152602001610213565b6102426102b6366004612ab0565b6106b4565b6102426102c9366004612a5a565b610b29565b600354610209565b6102096102e4366004612b17565b610e4e565b6102fc6102f7366004612b32565b610e6e565b604051610213929190612bbc565b7f0000000000000000000000000000000000000000000000000000000000000000610290565b61024261033e366004612a5a565b61106e565b610209610351366004612b17565b6111ff565b6102426112f2565b7f0000000000000000000000000000000000000000000000000000000000000000610290565b61024261130b565b61024261039a366004612c1b565b611350565b5f54610209565b7f0000000000000000000000000000000000000000000000000000000000000000610209565b6103df6103da366004612a99565b6113ab565b6040519015158152602001610213565b6102906113b7565b6102096113eb565b61024261040d366004612ab0565b6113fa565b7f0000000000000000000000000000000000000000000000000000000000000000610290565b610242610446366004612b17565b6118ce565b610209610459366004612a99565b5f908152600d602052604090205490565b6104726119ce565b6040516102139190612c5b565b61024261048d366004612a99565b6119da565b610290611a54565b6102096104a83660046129e8565b6001600160a01b03919091165f908152600a60209081526040808320938352929052205490565b6102426104dd366004612b17565b611a7c565b600b54610209565b6102096104f8366004612a99565b611b01565b6001600160a01b0382165f9081526009602052604081206105219060010183611b09565b90505b92915050565b335f908152600960205260408120905b8281101561061c575f84848381811061055557610555612c6d565b602090810292909201355f81815260038701909352604090922054919250506001600160a01b0316806105a35760405163bd959ca760e01b8152600481018390526024015b60405180910390fd5b5f6105b16001860184611b09565b6001600160a01b0383165f908152600a602090815260408083208784529091528120805492935083929091906105e8908490612c95565b9091555050505f91825250600383016020526040902080546001600160a01b031916905561061581612ca8565b905061053a565b50337f3fc3eae11c26578aac7a474672c345ee287e2859e213535ebc95ee1cc903798184848067ffffffffffffffff81111561065a5761065a612cc0565b604051908082528060200260200182016040528015610683578160200160208202803683370190505b5060405161069393929190612d1d565b60405180910390a2505050565b6106a8611b1e565b6106b181611b52565b50565b828181146106d5576040516371af99ab60e11b815260040160405180910390fd5b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c7a617836040518163ffffffff1660e01b8152600401602060405180830381865afa158015610732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107569190612d7d565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166304093c5b6107916001611bcc565b6040518263ffffffff1660e01b81526004016107ad9190612c5b565b5f604051808303815f87803b1580156107c4575f80fd5b505af11580156107d6573d5f803e3d5ffd5b5050335f818152600960205260408082209051637092a7dd60e11b81526004810193909352935091506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e1254fba90602401602060405180830381865afa15801561084e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108729190612d7d565b905061087f338283611bdf565b5080545f8054600c5490918667ffffffffffffffff8111156108a3576108a3612cc0565b6040519080825280602002602001820160405280156108e757816020015b604080518082019091525f80825260208201528152602001906001900390816108c15790505b50600b549091505f90815b89811015610a12575f8e8e8381811061090d5761090d612c6d565b90506020020135905089811061093957604051630e491bd960e01b81526004810182905260240161059a565b61095d89828f8f8681811061095057610950612c6d565b905060200201358b611c8b565b86848151811061096f5761096f612c6d565b6020908102919091010191909152935061098a600182611e02565b15610a01575f818152600d6020526040812054906109a88686611e19565b5f848152600d6020526040902081905590506109e58f8f868181106109cf576109cf612c6d565b905060200201358a611e8190919063ffffffff16565b9850806109f2838a612c95565b6109fc9190612d94565b975050505b50610a0b81612ca8565b90506108f2565b505f858155600c8590555b89811015610ada575f848281518110610a3857610a38612c6d565b60200260200101516020015190505f811115610ac957848281518110610a6057610a60612c6d565b602090810291909101015151604051635569f64b60e11b8152336004820152602481018390526001600160a01b039091169063aad3ec96906044015f604051808303815f87803b158015610ab2575f80fd5b505af1158015610ac4573d5f803e3d5ffd5b505050505b50610ad381612ca8565b9050610a1d565b507f3fcfd6369a124d94ed3356cce74c59840354822057e95889c108c6119ab7f49c338e8e8e8e604051610b12959493929190612da7565b60405180910390a150505050505050505050505050565b610b31611b1e565b806020811115610b54576040516384c066d960e01b815260040160405180910390fd5b6040516304093c5b60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906304093c5b90610ba29086908690600401612e05565b5f604051808303815f87803b158015610bb9575f80fd5b505af1158015610bcb573d5f803e3d5ffd5b505050505f610bda6001611bcc565b805190915015610cb9576040516304093c5b60e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906304093c5b90610c30908490600401612c5b565b5f604051808303815f87803b158015610c47575f80fd5b505af1158015610c59573d5f803e3d5ffd5b505082519150505b8015610cb7575f82610c7283612e18565b92508281518110610c8557610c85612c6d565b60200260200101519050610ca3816001611ebc90919063ffffffff16565b505f908152600d6020526040812055610c61565b505b5f5b82811015610dcf575f858583818110610cd657610cd6612c6d565b905060200201359050610cf3816001611ec790919063ffffffff16565b610d1357604051637e716dfd60e11b81526004810182905260240161059a565b6040516337f3c1c360e21b8152600481018290525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063dfcf070c90602401602060405180830381865afa158015610d78573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d9c9190612d7d565b1115610dbe57604051630208729f60e21b81526004810182905260240161059a565b50610dc881612ca8565b9050610cbb565b50610e0f8484808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525050600b549150611ed29050565b7f6a1be1056a891d625c5573d1a185d3f9d5e06e223f7570493778debf491c03738484604051610e40929190612e05565b60405180910390a150505050565b6001600160a01b0381165f90815260096020526040812060010154610524565b606080828067ffffffffffffffff811115610e8b57610e8b612cc0565b604051908082528060200260200182016040528015610eb4578160200160208202803683370190505b5092508067ffffffffffffffff811115610ed057610ed0612cc0565b604051908082528060200260200182016040528015610ef9578160200160208202803683370190505b506001600160a01b0387165f9081526009602052604081209193505b82811015611063575f878783818110610f3057610f30612c6d565b602090810292909201355f81815260038701909352604090922054919250506001600160a01b03168015611050575f610f6c6001860184611b09565b6001600160a01b038381165f818152600a602090815260408083208984529091529081902054905163c718325160e01b8152928f16600484015260248301849052604483018190529293509063c7183251906064016040805180830381865afa158015610fdb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fff9190612e2d565b8a878151811061101157611011612c6d565b602002602001018a888151811061102a5761102a612c6d565b6020026020010182815250826001600160a01b03166001600160a01b0316815250505050505b50508061105c90612ca8565b9050610f15565b505050935093915050565b335f908152600960205260408120905b828110156111f9575f84848381811061109957611099612c6d565b335f9081526009602090815260408083209382029590950135808352600390930190529290922054919250506001600160a01b031680156111e6575f6110e26001860184611b09565b6001600160a01b0383165f818152600a6020908152604080832088845290915280822054905163870b50fd60e01b8152336004820152602481018890526044810185905260648101859052608481018290529394509290919063870b50fd9060a4016020604051808303815f875af1158015611160573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111849190612d7d565b604051635569f64b60e11b8152336004820152602481018290529091506001600160a01b0385169063aad3ec96906044015f604051808303815f87803b1580156111cc575f80fd5b505af11580156111de573d5f803e3d5ffd5b505050505050505b5050806111f290612ca8565b905061107e565b50505050565b6001600160a01b038181165f818152600960205260408082209051637092a7dd60e11b815260048101939093529092909183917f0000000000000000000000000000000000000000000000000000000000000000169063e1254fba90602401602060405180830381865afa158015611279573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061129d9190612d7d565b90505f6112c0600354670de0b6b3a76400006004611f6d9092919063ffffffff16565b90505f6112d960048785670de0b6b3a764000086611f7a565b90506112e784848584611fdd565b509695505050505050565b604051636e5d2feb60e01b815260040160405180910390fd5b3380611315611a54565b6001600160a01b0316146113475760405163118cdaa760e01b81526001600160a01b038216600482015260240161059a565b6106b18161209b565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113995760405163f74fc43360e01b815260040160405180910390fd5b6113a4858585611bdf565b5050505050565b5f610524600183611e02565b5f807f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005b546001600160a01b031692915050565b5f6113f560075490565b905090565b82811461141a576040516371af99ab60e11b815260040160405180910390fd5b335f908152600960205260408120905b8481101561187f575f86868381811061144557611445612c6d565b9050602002013590505f85858481811061146157611461612c6d565b90506020020160208101906114769190612b17565b5f8381526003860160205260409020549091506001600160a01b0390811690821681036114a55750505061186f565b6001600160a01b0382161580159061155657506002604051634f4ee65b60e11b81526001600160a01b0384811660048301527f00000000000000000000000000000000000000000000000000000000000000001690639e9dccb690602401602060405180830381865afa15801561151e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115429190612e6d565b600381111561155357611553612e59565b14155b156115745760405163f070a1f760e01b815260040160405180910390fd5b5f6115826001870185611b09565b5f858152600388016020526040812080546001600160a01b0319166001600160a01b038781169190911790915591925090819084161561160f576001600160a01b0384165f908152600a6020908152604080832089845290915290205491506115eb8383612c95565b6001600160a01b0385165f908152600a602090815260408083208a84529091529020555b6001600160a01b0385161561167057506001600160a01b0384165f908152600a6020908152604080832088845290915290205461164c8382612d94565b6001600160a01b0386165f908152600a602090815260408083208a84529091529020555b5f6001600160a01b038616611685575f611707565b60405163870b50fd60e01b8152336004820152602481018890525f604482015260648101859052608481018390526001600160a01b0387169063870b50fd9060a4016020604051808303815f875af11580156116e3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117079190612d7d565b90505f6001600160a01b03861661171e575f6117a0565b60405163870b50fd60e01b815233600482015260248101899052604481018690525f6064820152608481018590526001600160a01b0387169063870b50fd9060a4016020604051808303815f875af115801561177c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117a09190612d7d565b9050811561180457604051635569f64b60e11b8152336004820152602481018390526001600160a01b0388169063aad3ec96906044015f604051808303815f87803b1580156117ed575f80fd5b505af11580156117ff573d5f803e3d5ffd5b505050505b801561186657604051635569f64b60e11b8152336004820152602481018290526001600160a01b0387169063aad3ec96906044015f604051808303815f87803b15801561184f575f80fd5b505af1158015611861573d5f803e3d5ffd5b505050505b50505050505050505b61187881612ca8565b905061142a565b50336001600160a01b03167f3fc3eae11c26578aac7a474672c345ee287e2859e213535ebc95ee1cc9037981868686866040516118bf9493929190612e8b565b60405180910390a25050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0080546002919068010000000000000000900460ff168061191d5750805467ffffffffffffffff808416911610155b1561193b5760405163f92ee8a960e01b815260040160405180910390fd5b805468ffffffffffffffffff191667ffffffffffffffff8316176801000000000000000017815561196b836120d7565b61197c670de0b6b3a7640000611b52565b805468ff00000000000000001916815560405167ffffffffffffffff831681527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a1505050565b60606113f56001611bcc565b6119e2611b1e565b611a17670de0b6b3a7640000611a0e600354670de0b6b3a76400006004611f6d9092919063ffffffff16565b600491906120e8565b5060038190556040518181527fa642a95837e5219f0719446e8dbc21c5ba557241cb65cd2ff3d411adb45bb94b906020015b60405180910390a150565b5f807f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c006113db565b611a84611b1e565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b0319166001600160a01b0383169081178255611ac86113b7565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b5f6105246007835b5f818152600183016020526040812054610521565b33611b276113b7565b6001600160a01b031614611b505760405163118cdaa760e01b815233600482015260240161059a565b565b801580611b665750670de0b6b3a764000081115b15611b845760405163337b1d4b60e11b815260040160405180910390fd5b600b819055611b9c611b966001611bcc565b82611ed2565b6040518181527f16954ed2b53a00c4f9cd4d5025ad8f7ac7d88c60b07eac34a1baacff8f2877b590602001611a49565b60605f611bd883612137565b9392505050565b6001600160a01b0383165f908152600960205260408120600354909190611c1190600490670de0b6b3a7640000611f6d565b90505f611c2b6004878787670de0b6b3a764000087612190565b90505f80611c3b85888886611fdd565b81875560405181815291935091506001600160a01b038916907fc1de1e7006f734e05946fe01d9535dbcb496877ff6f378def8c705b65540cbe69060200160405180910390a25050505050505050565b604080518082019091525f80825260208201525f808080611cb060018a018989612210565b9350509250925085811115611ce25760405163066c0de360e41b8152600481018790526024810182905260440161059a565b611cee60078989612210565b50505f8a815260038c0160205260409020549095506001600160a01b031690508015611df5576001600160a01b0381165f908152600a602090815260408083208c8452909152902054611d41818a611e81565b6001600160a01b0383165f818152600a602090815260408083208f84528252918290209390935580518082018252828152905163870b50fd60e01b8152336004820152602481018e905260448101899052606481018890526084810185905290928301919063870b50fd9060a4016020604051808303815f875af1158015611dcb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611def9190612d7d565b90529650505b5050505094509492505050565b5f8181526001830160205260408120541515610521565b5f670de0b6b3a764000083111580611e385750670de0b6b3a764000082145b15611e44575081610524565b5f611e57611e5185612231565b8461225e565b90505f811215611e6a575f915050610524565b838111611e775780611e79565b835b949350505050565b8181016001600160ff1b0380841190821117155f819003611eb5576040516308a942bb60e11b815260040160405180910390fd5b5092915050565b5f610521838361228e565b5f6105218383612371565b81515f908190815b81811015611f5f575f868281518110611ef557611ef5612c6d565b602002602001015190505f611f14826007611b0990919063ffffffff16565b90505f611f218289611e19565b5f848152600d602052604090208190559050611f3d8288612d94565b9650611f498187612d94565b955050505080611f5890612ca8565b9050611eda565b50505f91909155600c555050565b5f611e79848442856123bd565b5f80611f868484612402565b8760010154611f959190612d94565b90508415611fd0576001600160a01b0386165f908152600288016020526040902054611fc18287612424565b611fcb9190612c95565b611fd2565b5f5b979650505050505050565b83545f90819085851061204d57611ff48482612d94565b92505f670de0b6b3a764000061202a7f000000000000000000000000000000000000000000000000000000000000000089612eee565b6120349190612f19565b90508084116120435783612045565b805b93505061207c565b5f612059886001015490565b11156120785760405163fe73bb2560e01b815260040160405180910390fd5b5f92505b61208581612231565b61208e84612231565b0391505094509492505050565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b03191681556120d38261243a565b5050565b6120df6124aa565b6106b1816124f8565b5f806120f48484612402565b8554909150421115612104574285555b80156121285780856001015f82825461211d9190612d94565b92505081905561212e565b84600101545b95945050505050565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561218457602002820191905f5260205f20905b815481526020019060010190808311612170575b50505050509050919050565b5f8061219d8885856120e8565b905085156121d8576001600160a01b0387165f9081526002890160205260409020546121c98288612424565b6121d39190612c95565b6121da565b5f5b91506121e68186612424565b6001600160a01b039097165f90815260029098016020525060409096209490945550929392505050565b5f80808061221f878787612529565b93509350935093505b93509350935093565b5f6001600160ff1b0382111561225a576040516308a942bb60e11b815260040160405180910390fd5b5090565b5f610521670de0b6b3a76400008361227586612586565b61227f9190612f2c565b6122899190612f5b565b612765565b5f8181526001830160205260408120548015612368575f6122b0600183612c95565b85549091505f906122c390600190612c95565b9050808214612322575f865f0182815481106122e1576122e1612c6d565b905f5260205f200154905080875f01848154811061230157612301612c6d565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061233357612333612f87565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610524565b5f915050610524565b5f8181526001830160205260408120546123b657508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610524565b505f610524565b5f815f036123cc57505f611e79565b84545f4285106123dc57426123de565b845b90508181116123ed575f611fd2565b856123f88383612c95565b611fd29190612eee565b5f821561241c5761241783604084901b612f19565b610521565b505f92915050565b5f60406124318484612eee565b901c9392505050565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005468010000000000000000900460ff16611b5057604051631afcd79f60e31b815260040160405180910390fd5b6125006124aa565b6001600160a01b03811661134757604051631e4fbdf760e01b81525f600482015260240161059a565b5f828152600184016020526040812054845490919081848103612550575082915080612228565b61255a8486611e81565b92506125668286611e81565b5f8781526001890160205260409020849055808855905093509350935093565b5f8082136125c25760405162461bcd60e51b815260206004820152600960248201526815539111519253915160ba1b604482015260640161059a565b5f60606125ce8461292d565b03609f8181039490941b90931c6c465772b2bbbb5f824b15207a3081018102606090811d6d0388eaa27412d5aca026815d636e018202811d6d0df99ac502031bf953eff472fdcc018202811d6d13cdffb29d51d99322bdff5f2211018202811d6d0a0f742023def783a307a986912e018202811d6d01920d8043ca89b5239253284e42018202811d6c0b7a86d7375468fac667a0a527016c29508e458543d8aa4df2abee7883018302821d6d0139601a2efabe717e604cbb4894018302821d6d02247f7a7b6594320649aa03aba1018302821d6c8c3f38e95a6b1ff2ab1c3b343619018302821d6d02384773bdf1ac5676facced60901901830290911d6cb9a025d814b29c212b8b1a07cd19019091027ffffffffffffffff5f6af8f7b3396644f18e157960000000000000000000000000105711340daa0d5f769dba1915cef59f0815a5506027d0267a36c0c95b3975ab3ee5b203a7614a3f75373f047d803ae7b6687f2b393909302929092017d57115e47018c7177eebf7cd370a3356a1b7863008a5ae8028c72b88642840160ae1d92915050565b5f680248ce36a70cb26b3e19821361277e57505f919050565b680755bf798b4a1bf1e582126127d65760405162461bcd60e51b815260206004820152600c60248201527f4558505f4f564552464c4f570000000000000000000000000000000000000000604482015260640161059a565b6503782dace9d9604e83901b0591505f60606bb17217f7d1cf79abc9e3b39884821b056b80000000000000000000000001901d6bb17217f7d1cf79abc9e3b39881029093036c240c330e9fb2d9cbaf0fd5aafb1981018102606090811d6d0277594991cfc85f6e2461837cd9018202811d6d1a521255e34f6a5061b25ef1c9c319018202811d6db1bbb201f443cf962f1a1d3db4a5018202811d6e02c72388d9f74f51a9331fed693f1419018202811d6e05180bb14799ab47a8a8cb2a527d57016d02d16720577bd19bf614176fe9ea6c10fe68e7fd37d0007b713f765084018402831d9081019084016d01d3967ed30fc4f89c02bab5708119010290911d6e0587f503bb6ea29d25fcb7401964500190910279d835ebba824c98fb31b83b2ca45c000000000000000000000000010574029d9dc38563c32e5c2f6dc192ee70ef65f9978af30260c3939093039290921c92915050565b5f8082116129695760405162461bcd60e51b815260206004820152600960248201526815539111519253915160ba1b604482015260640161059a565b5060016fffffffffffffffffffffffffffffffff821160071b82811c67ffffffffffffffff1060061b1782811c63ffffffff1060051b1782811c61ffff1060041b1782811c60ff10600390811b90911783811c600f1060021b1783811c909110821b1791821c111790565b6001600160a01b03811681146106b1575f80fd5b5f80604083850312156129f9575f80fd5b8235612a04816129d4565b946020939093013593505050565b5f8083601f840112612a22575f80fd5b50813567ffffffffffffffff811115612a39575f80fd5b6020830191508360208260051b8501011115612a53575f80fd5b9250929050565b5f8060208385031215612a6b575f80fd5b823567ffffffffffffffff811115612a81575f80fd5b612a8d85828601612a12565b90969095509350505050565b5f60208284031215612aa9575f80fd5b5035919050565b5f805f8060408587031215612ac3575f80fd5b843567ffffffffffffffff80821115612ada575f80fd5b612ae688838901612a12565b90965094506020870135915080821115612afe575f80fd5b50612b0b87828801612a12565b95989497509550505050565b5f60208284031215612b27575f80fd5b8135611bd8816129d4565b5f805f60408486031215612b44575f80fd5b8335612b4f816129d4565b9250602084013567ffffffffffffffff811115612b6a575f80fd5b612b7686828701612a12565b9497909650939450505050565b5f8151808452602080850194508084015f5b83811015612bb157815187529582019590820190600101612b95565b509495945050505050565b604080825283519082018190525f906020906060840190828701845b82811015612bfd5781516001600160a01b031684529284019290840190600101612bd8565b50505083810382850152612c118186612b83565b9695505050505050565b5f805f805f60a08688031215612c2f575f80fd5b8535612c3a816129d4565b97602087013597506040870135966060810135965060800135945092505050565b602081525f6105216020830184612b83565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561052457610524612c81565b5f60018201612cb957612cb9612c81565b5060010190565b634e487b7160e01b5f52604160045260245ffd5b8183525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115612d04575f80fd5b8260051b80836020870137939093016020019392505050565b604081525f612d30604083018587612cd4565b8281036020848101919091528451808352858201928201905f5b81811015612d6f5784516001600160a01b031683529383019391830191600101612d4a565b509098975050505050505050565b5f60208284031215612d8d575f80fd5b5051919050565b8082018082111561052457610524612c81565b6001600160a01b03861681525f6020606081840152612dca606084018789612cd4565b8381036040850152848152859082015f5b86811015612df757823582529183019190830190600101612ddb565b509998505050505050505050565b602081525f611e79602083018486612cd4565b5f81612e2657612e26612c81565b505f190190565b5f8060408385031215612e3e575f80fd5b8251612e49816129d4565b6020939093015192949293505050565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215612e7d575f80fd5b815160048110611bd8575f80fd5b604081525f612e9e604083018688612cd4565b828103602084810191909152848252859181015f5b86811015612ee1578335612ec6816129d4565b6001600160a01b031682529282019290820190600101612eb3565b5098975050505050505050565b808202811582820484141761052457610524612c81565b634e487b7160e01b5f52601260045260245ffd5b5f82612f2757612f27612f05565b500490565b8082025f8212600160ff1b84141615612f4757612f47612c81565b818105831482151761052457610524612c81565b5f82612f6957612f69612f05565b600160ff1b82145f1984141615612f8257612f82612c81565b500590565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220f1c443c9d775bf74671267ad9c2362fb9fde77ab187d6d04b0123751e900455364736f6c63430008140033000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b5000000000000000000000000e283db759720982094de7fc6edc49d3adf84894300000000000000000000000000000000000000000000003635c9adc5dea00000
Deployed Bytecode
0x608060405234801561000f575f80fd5b5060043610610201575f3560e01c8063870b50fd11610123578063c4d66de8116100b8578063e30c397811610088578063f2fde38b1161006e578063f2fde38b146104cf578063f4988a3d146104e2578063ff981099146104ea575f80fd5b8063e30c397814610492578063e720e4831461049a575f80fd5b8063c4d66de814610438578063d851fdfd1461044b578063e1e4d4191461046a578063e21e41461461047f575f80fd5b80638da5cb5b116100f35780638da5cb5b146103ef5780639a0e7d66146103f7578063af2a73f5146103ff578063b564496314610412575f80fd5b8063870b50fd1461038c5780638761e7fb1461039f578063888ed79e146103a6578063889e6072146103cc575f80fd5b8063518ab0d01161019957806370a082311161016957806370a0823114610343578063715018a61461035657806372f148b81461035e57806379ba509714610384575f80fd5b8063518ab0d0146102d6578063566aff6a146102e95780635c4323ab1461030a5780636ba4c13814610330575f80fd5b80631befbe36116101d45780631befbe36146102575780632f4f7fbb146102a857806347eaa2b4146102bb5780634f913d34146102ce575f80fd5b806306aba0e11461020557806307532f561461021c57806308ada2ed1461022f5780630c17d42c14610244575b5f80fd5b600c545b6040519081526020015b60405180910390f35b61020961022a3660046129e8565b6104fd565b61024261023d366004612a5a565b61052a565b005b610242610252366004612a99565b6106a0565b6102906102653660046129e8565b6001600160a01b039182165f9081526009602090815260408083209383526003909301905220541690565b6040516001600160a01b039091168152602001610213565b6102426102b6366004612ab0565b6106b4565b6102426102c9366004612a5a565b610b29565b600354610209565b6102096102e4366004612b17565b610e4e565b6102fc6102f7366004612b32565b610e6e565b604051610213929190612bbc565b7f000000000000000000000000e283db759720982094de7fc6edc49d3adf848943610290565b61024261033e366004612a5a565b61106e565b610209610351366004612b17565b6111ff565b6102426112f2565b7f000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116610290565b61024261130b565b61024261039a366004612c1b565b611350565b5f54610209565b7f00000000000000000000000000000000000000000000003635c9adc5dea00000610209565b6103df6103da366004612a99565b6113ab565b6040519015158152602001610213565b6102906113b7565b6102096113eb565b61024261040d366004612ab0565b6113fa565b7f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b5610290565b610242610446366004612b17565b6118ce565b610209610459366004612a99565b5f908152600d602052604090205490565b6104726119ce565b6040516102139190612c5b565b61024261048d366004612a99565b6119da565b610290611a54565b6102096104a83660046129e8565b6001600160a01b03919091165f908152600a60209081526040808320938352929052205490565b6102426104dd366004612b17565b611a7c565b600b54610209565b6102096104f8366004612a99565b611b01565b6001600160a01b0382165f9081526009602052604081206105219060010183611b09565b90505b92915050565b335f908152600960205260408120905b8281101561061c575f84848381811061055557610555612c6d565b602090810292909201355f81815260038701909352604090922054919250506001600160a01b0316806105a35760405163bd959ca760e01b8152600481018390526024015b60405180910390fd5b5f6105b16001860184611b09565b6001600160a01b0383165f908152600a602090815260408083208784529091528120805492935083929091906105e8908490612c95565b9091555050505f91825250600383016020526040902080546001600160a01b031916905561061581612ca8565b905061053a565b50337f3fc3eae11c26578aac7a474672c345ee287e2859e213535ebc95ee1cc903798184848067ffffffffffffffff81111561065a5761065a612cc0565b604051908082528060200260200182016040528015610683578160200160208202803683370190505b5060405161069393929190612d1d565b60405180910390a2505050565b6106a8611b1e565b6106b181611b52565b50565b828181146106d5576040516371af99ab60e11b815260040160405180910390fd5b5f7f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b56001600160a01b031663c7a617836040518163ffffffff1660e01b8152600401602060405180830381865afa158015610732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107569190612d7d565b90507f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b56001600160a01b03166304093c5b6107916001611bcc565b6040518263ffffffff1660e01b81526004016107ad9190612c5b565b5f604051808303815f87803b1580156107c4575f80fd5b505af11580156107d6573d5f803e3d5ffd5b5050335f818152600960205260408082209051637092a7dd60e11b81526004810193909352935091506001600160a01b037f000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116169063e1254fba90602401602060405180830381865afa15801561084e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108729190612d7d565b905061087f338283611bdf565b5080545f8054600c5490918667ffffffffffffffff8111156108a3576108a3612cc0565b6040519080825280602002602001820160405280156108e757816020015b604080518082019091525f80825260208201528152602001906001900390816108c15790505b50600b549091505f90815b89811015610a12575f8e8e8381811061090d5761090d612c6d565b90506020020135905089811061093957604051630e491bd960e01b81526004810182905260240161059a565b61095d89828f8f8681811061095057610950612c6d565b905060200201358b611c8b565b86848151811061096f5761096f612c6d565b6020908102919091010191909152935061098a600182611e02565b15610a01575f818152600d6020526040812054906109a88686611e19565b5f848152600d6020526040902081905590506109e58f8f868181106109cf576109cf612c6d565b905060200201358a611e8190919063ffffffff16565b9850806109f2838a612c95565b6109fc9190612d94565b975050505b50610a0b81612ca8565b90506108f2565b505f858155600c8590555b89811015610ada575f848281518110610a3857610a38612c6d565b60200260200101516020015190505f811115610ac957848281518110610a6057610a60612c6d565b602090810291909101015151604051635569f64b60e11b8152336004820152602481018390526001600160a01b039091169063aad3ec96906044015f604051808303815f87803b158015610ab2575f80fd5b505af1158015610ac4573d5f803e3d5ffd5b505050505b50610ad381612ca8565b9050610a1d565b507f3fcfd6369a124d94ed3356cce74c59840354822057e95889c108c6119ab7f49c338e8e8e8e604051610b12959493929190612da7565b60405180910390a150505050505050505050505050565b610b31611b1e565b806020811115610b54576040516384c066d960e01b815260040160405180910390fd5b6040516304093c5b60e01b81526001600160a01b037f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b516906304093c5b90610ba29086908690600401612e05565b5f604051808303815f87803b158015610bb9575f80fd5b505af1158015610bcb573d5f803e3d5ffd5b505050505f610bda6001611bcc565b805190915015610cb9576040516304093c5b60e01b81526001600160a01b037f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b516906304093c5b90610c30908490600401612c5b565b5f604051808303815f87803b158015610c47575f80fd5b505af1158015610c59573d5f803e3d5ffd5b505082519150505b8015610cb7575f82610c7283612e18565b92508281518110610c8557610c85612c6d565b60200260200101519050610ca3816001611ebc90919063ffffffff16565b505f908152600d6020526040812055610c61565b505b5f5b82811015610dcf575f858583818110610cd657610cd6612c6d565b905060200201359050610cf3816001611ec790919063ffffffff16565b610d1357604051637e716dfd60e11b81526004810182905260240161059a565b6040516337f3c1c360e21b8152600481018290525f907f000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b56001600160a01b03169063dfcf070c90602401602060405180830381865afa158015610d78573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d9c9190612d7d565b1115610dbe57604051630208729f60e21b81526004810182905260240161059a565b50610dc881612ca8565b9050610cbb565b50610e0f8484808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525050600b549150611ed29050565b7f6a1be1056a891d625c5573d1a185d3f9d5e06e223f7570493778debf491c03738484604051610e40929190612e05565b60405180910390a150505050565b6001600160a01b0381165f90815260096020526040812060010154610524565b606080828067ffffffffffffffff811115610e8b57610e8b612cc0565b604051908082528060200260200182016040528015610eb4578160200160208202803683370190505b5092508067ffffffffffffffff811115610ed057610ed0612cc0565b604051908082528060200260200182016040528015610ef9578160200160208202803683370190505b506001600160a01b0387165f9081526009602052604081209193505b82811015611063575f878783818110610f3057610f30612c6d565b602090810292909201355f81815260038701909352604090922054919250506001600160a01b03168015611050575f610f6c6001860184611b09565b6001600160a01b038381165f818152600a602090815260408083208984529091529081902054905163c718325160e01b8152928f16600484015260248301849052604483018190529293509063c7183251906064016040805180830381865afa158015610fdb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fff9190612e2d565b8a878151811061101157611011612c6d565b602002602001018a888151811061102a5761102a612c6d565b6020026020010182815250826001600160a01b03166001600160a01b0316815250505050505b50508061105c90612ca8565b9050610f15565b505050935093915050565b335f908152600960205260408120905b828110156111f9575f84848381811061109957611099612c6d565b335f9081526009602090815260408083209382029590950135808352600390930190529290922054919250506001600160a01b031680156111e6575f6110e26001860184611b09565b6001600160a01b0383165f818152600a6020908152604080832088845290915280822054905163870b50fd60e01b8152336004820152602481018890526044810185905260648101859052608481018290529394509290919063870b50fd9060a4016020604051808303815f875af1158015611160573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111849190612d7d565b604051635569f64b60e11b8152336004820152602481018290529091506001600160a01b0385169063aad3ec96906044015f604051808303815f87803b1580156111cc575f80fd5b505af11580156111de573d5f803e3d5ffd5b505050505050505b5050806111f290612ca8565b905061107e565b50505050565b6001600160a01b038181165f818152600960205260408082209051637092a7dd60e11b815260048101939093529092909183917f000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116169063e1254fba90602401602060405180830381865afa158015611279573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061129d9190612d7d565b90505f6112c0600354670de0b6b3a76400006004611f6d9092919063ffffffff16565b90505f6112d960048785670de0b6b3a764000086611f7a565b90506112e784848584611fdd565b509695505050505050565b604051636e5d2feb60e01b815260040160405180910390fd5b3380611315611a54565b6001600160a01b0316146113475760405163118cdaa760e01b81526001600160a01b038216600482015260240161059a565b6106b18161209b565b336001600160a01b037f000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e11616146113995760405163f74fc43360e01b815260040160405180910390fd5b6113a4858585611bdf565b5050505050565b5f610524600183611e02565b5f807f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c1993005b546001600160a01b031692915050565b5f6113f560075490565b905090565b82811461141a576040516371af99ab60e11b815260040160405180910390fd5b335f908152600960205260408120905b8481101561187f575f86868381811061144557611445612c6d565b9050602002013590505f85858481811061146157611461612c6d565b90506020020160208101906114769190612b17565b5f8381526003860160205260409020549091506001600160a01b0390811690821681036114a55750505061186f565b6001600160a01b0382161580159061155657506002604051634f4ee65b60e11b81526001600160a01b0384811660048301527f000000000000000000000000e283db759720982094de7fc6edc49d3adf8489431690639e9dccb690602401602060405180830381865afa15801561151e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115429190612e6d565b600381111561155357611553612e59565b14155b156115745760405163f070a1f760e01b815260040160405180910390fd5b5f6115826001870185611b09565b5f858152600388016020526040812080546001600160a01b0319166001600160a01b038781169190911790915591925090819084161561160f576001600160a01b0384165f908152600a6020908152604080832089845290915290205491506115eb8383612c95565b6001600160a01b0385165f908152600a602090815260408083208a84529091529020555b6001600160a01b0385161561167057506001600160a01b0384165f908152600a6020908152604080832088845290915290205461164c8382612d94565b6001600160a01b0386165f908152600a602090815260408083208a84529091529020555b5f6001600160a01b038616611685575f611707565b60405163870b50fd60e01b8152336004820152602481018890525f604482015260648101859052608481018390526001600160a01b0387169063870b50fd9060a4016020604051808303815f875af11580156116e3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117079190612d7d565b90505f6001600160a01b03861661171e575f6117a0565b60405163870b50fd60e01b815233600482015260248101899052604481018690525f6064820152608481018590526001600160a01b0387169063870b50fd9060a4016020604051808303815f875af115801561177c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117a09190612d7d565b9050811561180457604051635569f64b60e11b8152336004820152602481018390526001600160a01b0388169063aad3ec96906044015f604051808303815f87803b1580156117ed575f80fd5b505af11580156117ff573d5f803e3d5ffd5b505050505b801561186657604051635569f64b60e11b8152336004820152602481018290526001600160a01b0387169063aad3ec96906044015f604051808303815f87803b15801561184f575f80fd5b505af1158015611861573d5f803e3d5ffd5b505050505b50505050505050505b61187881612ca8565b905061142a565b50336001600160a01b03167f3fc3eae11c26578aac7a474672c345ee287e2859e213535ebc95ee1cc9037981868686866040516118bf9493929190612e8b565b60405180910390a25050505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0080546002919068010000000000000000900460ff168061191d5750805467ffffffffffffffff808416911610155b1561193b5760405163f92ee8a960e01b815260040160405180910390fd5b805468ffffffffffffffffff191667ffffffffffffffff8316176801000000000000000017815561196b836120d7565b61197c670de0b6b3a7640000611b52565b805468ff00000000000000001916815560405167ffffffffffffffff831681527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a1505050565b60606113f56001611bcc565b6119e2611b1e565b611a17670de0b6b3a7640000611a0e600354670de0b6b3a76400006004611f6d9092919063ffffffff16565b600491906120e8565b5060038190556040518181527fa642a95837e5219f0719446e8dbc21c5ba557241cb65cd2ff3d411adb45bb94b906020015b60405180910390a150565b5f807f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c006113db565b611a84611b1e565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b0319166001600160a01b0383169081178255611ac86113b7565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a35050565b5f6105246007835b5f818152600183016020526040812054610521565b33611b276113b7565b6001600160a01b031614611b505760405163118cdaa760e01b815233600482015260240161059a565b565b801580611b665750670de0b6b3a764000081115b15611b845760405163337b1d4b60e11b815260040160405180910390fd5b600b819055611b9c611b966001611bcc565b82611ed2565b6040518181527f16954ed2b53a00c4f9cd4d5025ad8f7ac7d88c60b07eac34a1baacff8f2877b590602001611a49565b60605f611bd883612137565b9392505050565b6001600160a01b0383165f908152600960205260408120600354909190611c1190600490670de0b6b3a7640000611f6d565b90505f611c2b6004878787670de0b6b3a764000087612190565b90505f80611c3b85888886611fdd565b81875560405181815291935091506001600160a01b038916907fc1de1e7006f734e05946fe01d9535dbcb496877ff6f378def8c705b65540cbe69060200160405180910390a25050505050505050565b604080518082019091525f80825260208201525f808080611cb060018a018989612210565b9350509250925085811115611ce25760405163066c0de360e41b8152600481018790526024810182905260440161059a565b611cee60078989612210565b50505f8a815260038c0160205260409020549095506001600160a01b031690508015611df5576001600160a01b0381165f908152600a602090815260408083208c8452909152902054611d41818a611e81565b6001600160a01b0383165f818152600a602090815260408083208f84528252918290209390935580518082018252828152905163870b50fd60e01b8152336004820152602481018e905260448101899052606481018890526084810185905290928301919063870b50fd9060a4016020604051808303815f875af1158015611dcb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611def9190612d7d565b90529650505b5050505094509492505050565b5f8181526001830160205260408120541515610521565b5f670de0b6b3a764000083111580611e385750670de0b6b3a764000082145b15611e44575081610524565b5f611e57611e5185612231565b8461225e565b90505f811215611e6a575f915050610524565b838111611e775780611e79565b835b949350505050565b8181016001600160ff1b0380841190821117155f819003611eb5576040516308a942bb60e11b815260040160405180910390fd5b5092915050565b5f610521838361228e565b5f6105218383612371565b81515f908190815b81811015611f5f575f868281518110611ef557611ef5612c6d565b602002602001015190505f611f14826007611b0990919063ffffffff16565b90505f611f218289611e19565b5f848152600d602052604090208190559050611f3d8288612d94565b9650611f498187612d94565b955050505080611f5890612ca8565b9050611eda565b50505f91909155600c555050565b5f611e79848442856123bd565b5f80611f868484612402565b8760010154611f959190612d94565b90508415611fd0576001600160a01b0386165f908152600288016020526040902054611fc18287612424565b611fcb9190612c95565b611fd2565b5f5b979650505050505050565b83545f90819085851061204d57611ff48482612d94565b92505f670de0b6b3a764000061202a7f00000000000000000000000000000000000000000000003635c9adc5dea0000089612eee565b6120349190612f19565b90508084116120435783612045565b805b93505061207c565b5f612059886001015490565b11156120785760405163fe73bb2560e01b815260040160405180910390fd5b5f92505b61208581612231565b61208e84612231565b0391505094509492505050565b7f237e158222e3e6968b72b9db0d8043aacf074ad9f650f0d1606b4d82ee432c0080546001600160a01b03191681556120d38261243a565b5050565b6120df6124aa565b6106b1816124f8565b5f806120f48484612402565b8554909150421115612104574285555b80156121285780856001015f82825461211d9190612d94565b92505081905561212e565b84600101545b95945050505050565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561218457602002820191905f5260205f20905b815481526020019060010190808311612170575b50505050509050919050565b5f8061219d8885856120e8565b905085156121d8576001600160a01b0387165f9081526002890160205260409020546121c98288612424565b6121d39190612c95565b6121da565b5f5b91506121e68186612424565b6001600160a01b039097165f90815260029098016020525060409096209490945550929392505050565b5f80808061221f878787612529565b93509350935093505b93509350935093565b5f6001600160ff1b0382111561225a576040516308a942bb60e11b815260040160405180910390fd5b5090565b5f610521670de0b6b3a76400008361227586612586565b61227f9190612f2c565b6122899190612f5b565b612765565b5f8181526001830160205260408120548015612368575f6122b0600183612c95565b85549091505f906122c390600190612c95565b9050808214612322575f865f0182815481106122e1576122e1612c6d565b905f5260205f200154905080875f01848154811061230157612301612c6d565b5f918252602080832090910192909255918252600188019052604090208390555b855486908061233357612333612f87565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f905560019350505050610524565b5f915050610524565b5f8181526001830160205260408120546123b657508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610524565b505f610524565b5f815f036123cc57505f611e79565b84545f4285106123dc57426123de565b845b90508181116123ed575f611fd2565b856123f88383612c95565b611fd29190612eee565b5f821561241c5761241783604084901b612f19565b610521565b505f92915050565b5f60406124318484612eee565b901c9392505050565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005468010000000000000000900460ff16611b5057604051631afcd79f60e31b815260040160405180910390fd5b6125006124aa565b6001600160a01b03811661134757604051631e4fbdf760e01b81525f600482015260240161059a565b5f828152600184016020526040812054845490919081848103612550575082915080612228565b61255a8486611e81565b92506125668286611e81565b5f8781526001890160205260409020849055808855905093509350935093565b5f8082136125c25760405162461bcd60e51b815260206004820152600960248201526815539111519253915160ba1b604482015260640161059a565b5f60606125ce8461292d565b03609f8181039490941b90931c6c465772b2bbbb5f824b15207a3081018102606090811d6d0388eaa27412d5aca026815d636e018202811d6d0df99ac502031bf953eff472fdcc018202811d6d13cdffb29d51d99322bdff5f2211018202811d6d0a0f742023def783a307a986912e018202811d6d01920d8043ca89b5239253284e42018202811d6c0b7a86d7375468fac667a0a527016c29508e458543d8aa4df2abee7883018302821d6d0139601a2efabe717e604cbb4894018302821d6d02247f7a7b6594320649aa03aba1018302821d6c8c3f38e95a6b1ff2ab1c3b343619018302821d6d02384773bdf1ac5676facced60901901830290911d6cb9a025d814b29c212b8b1a07cd19019091027ffffffffffffffff5f6af8f7b3396644f18e157960000000000000000000000000105711340daa0d5f769dba1915cef59f0815a5506027d0267a36c0c95b3975ab3ee5b203a7614a3f75373f047d803ae7b6687f2b393909302929092017d57115e47018c7177eebf7cd370a3356a1b7863008a5ae8028c72b88642840160ae1d92915050565b5f680248ce36a70cb26b3e19821361277e57505f919050565b680755bf798b4a1bf1e582126127d65760405162461bcd60e51b815260206004820152600c60248201527f4558505f4f564552464c4f570000000000000000000000000000000000000000604482015260640161059a565b6503782dace9d9604e83901b0591505f60606bb17217f7d1cf79abc9e3b39884821b056b80000000000000000000000001901d6bb17217f7d1cf79abc9e3b39881029093036c240c330e9fb2d9cbaf0fd5aafb1981018102606090811d6d0277594991cfc85f6e2461837cd9018202811d6d1a521255e34f6a5061b25ef1c9c319018202811d6db1bbb201f443cf962f1a1d3db4a5018202811d6e02c72388d9f74f51a9331fed693f1419018202811d6e05180bb14799ab47a8a8cb2a527d57016d02d16720577bd19bf614176fe9ea6c10fe68e7fd37d0007b713f765084018402831d9081019084016d01d3967ed30fc4f89c02bab5708119010290911d6e0587f503bb6ea29d25fcb7401964500190910279d835ebba824c98fb31b83b2ca45c000000000000000000000000010574029d9dc38563c32e5c2f6dc192ee70ef65f9978af30260c3939093039290921c92915050565b5f8082116129695760405162461bcd60e51b815260206004820152600960248201526815539111519253915160ba1b604482015260640161059a565b5060016fffffffffffffffffffffffffffffffff821160071b82811c67ffffffffffffffff1060061b1782811c63ffffffff1060051b1782811c61ffff1060041b1782811c60ff10600390811b90911783811c600f1060021b1783811c909110821b1791821c111790565b6001600160a01b03811681146106b1575f80fd5b5f80604083850312156129f9575f80fd5b8235612a04816129d4565b946020939093013593505050565b5f8083601f840112612a22575f80fd5b50813567ffffffffffffffff811115612a39575f80fd5b6020830191508360208260051b8501011115612a53575f80fd5b9250929050565b5f8060208385031215612a6b575f80fd5b823567ffffffffffffffff811115612a81575f80fd5b612a8d85828601612a12565b90969095509350505050565b5f60208284031215612aa9575f80fd5b5035919050565b5f805f8060408587031215612ac3575f80fd5b843567ffffffffffffffff80821115612ada575f80fd5b612ae688838901612a12565b90965094506020870135915080821115612afe575f80fd5b50612b0b87828801612a12565b95989497509550505050565b5f60208284031215612b27575f80fd5b8135611bd8816129d4565b5f805f60408486031215612b44575f80fd5b8335612b4f816129d4565b9250602084013567ffffffffffffffff811115612b6a575f80fd5b612b7686828701612a12565b9497909650939450505050565b5f8151808452602080850194508084015f5b83811015612bb157815187529582019590820190600101612b95565b509495945050505050565b604080825283519082018190525f906020906060840190828701845b82811015612bfd5781516001600160a01b031684529284019290840190600101612bd8565b50505083810382850152612c118186612b83565b9695505050505050565b5f805f805f60a08688031215612c2f575f80fd5b8535612c3a816129d4565b97602087013597506040870135966060810135965060800135945092505050565b602081525f6105216020830184612b83565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561052457610524612c81565b5f60018201612cb957612cb9612c81565b5060010190565b634e487b7160e01b5f52604160045260245ffd5b8183525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115612d04575f80fd5b8260051b80836020870137939093016020019392505050565b604081525f612d30604083018587612cd4565b8281036020848101919091528451808352858201928201905f5b81811015612d6f5784516001600160a01b031683529383019391830191600101612d4a565b509098975050505050505050565b5f60208284031215612d8d575f80fd5b5051919050565b8082018082111561052457610524612c81565b6001600160a01b03861681525f6020606081840152612dca606084018789612cd4565b8381036040850152848152859082015f5b86811015612df757823582529183019190830190600101612ddb565b509998505050505050505050565b602081525f611e79602083018486612cd4565b5f81612e2657612e26612c81565b505f190190565b5f8060408385031215612e3e575f80fd5b8251612e49816129d4565b6020939093015192949293505050565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215612e7d575f80fd5b815160048110611bd8575f80fd5b604081525f612e9e604083018688612cd4565b828103602084810191909152848252859181015f5b86811015612ee1578335612ec6816129d4565b6001600160a01b031682529282019290820190600101612eb3565b5098975050505050505050565b808202811582820484141761052457610524612c81565b634e487b7160e01b5f52601260045260245ffd5b5f82612f2757612f27612f05565b500490565b8082025f8212600160ff1b84141615612f4757612f47612c81565b818105831482151761052457610524612c81565b5f82612f6957612f69612f05565b600160ff1b82145f1984141615612f8257612f82612c81565b500590565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220f1c443c9d775bf74671267ad9c2362fb9fde77ab187d6d04b0123751e900455364736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b5000000000000000000000000e283db759720982094de7fc6edc49d3adf84894300000000000000000000000000000000000000000000003635c9adc5dea00000
-----Decoded View---------------
Arg [0] : moeStaking (address): 0xb3938E6ee233E7847a5F17bb843E9bD0Aa07e116
Arg [1] : masterChef (address): 0xA756f7D419e1A5cbd656A438443011a7dE1955b5
Arg [2] : rewarderFactory (address): 0xE283Db759720982094de7Fc6Edc49D3adf848943
Arg [3] : maxVeMoePerMoe (uint256): 1000000000000000000000
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000b3938e6ee233e7847a5f17bb843e9bd0aa07e116
Arg [1] : 000000000000000000000000a756f7d419e1a5cbd656a438443011a7de1955b5
Arg [2] : 000000000000000000000000e283db759720982094de7fc6edc49d3adf848943
Arg [3] : 00000000000000000000000000000000000000000000003635c9adc5dea00000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MNT
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.