Overview
ETH Balance
ETH Value
$0.00Latest 1 from a total of 1 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Initialize | 20654749 | 210 days ago | IN | 0 ETH | 0 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IPair } from './interfaces/IPair.sol';
import { IBribe } from './interfaces/IBribe.sol';
import { IGauge } from './interfaces/IGauge.sol';
import {IRewarder} from './interfaces/IRewarder.sol';
import {IVersionable} from './interfaces/IVersionable.sol';
import { Math } from "./libraries/Math.sol";
import { Constants } from "./Constants.sol";
import { IVoterV5 } from './VoterV5/IVoterV5.sol';
import {IGaugeV2, IERC165} from './interfaces/IGaugeV2.sol';
import {IMultiTokenPool} from './interfaces/IMultiTokenPool.sol';
import {IGaugeFactoryV2_Base} from './factories/interfaces/IGaugeFactoryV2.sol';
import {CentralTokenPoolModule} from './modules/CentralTokenPoolModule.sol';
/**
* @title GaugeV2
* @dev
* - 2.1.0: Add depositTo function, Add rewardToken to Harvest event
* - 2.2.0: Pull internal_bribe and external_bribe from VoterV5
* - 2.3.0: BREAKING Change to IVoterV5.oToken() in updateRewardToken, VoterV5 must support oToken()
* - 2.4.0: Add MultiTokenPool integration with secure pool revocation
*/
contract GaugeV2 is CentralTokenPoolModule, ReentrancyGuardUpgradeable, Ownable2StepUpgradeable, IGaugeV2, IVersionable {
using SafeERC20 for IERC20;
string public constant override VERSION = "2.4.0";
/// -----------------------------------------------------------------------
/// Storage variables
/// -----------------------------------------------------------------------
bool public isForPair;
bool public emergency;
IERC20 public rewardToken;
IERC20 public stakeToken;
address public VE;
address public DISTRIBUTION;
address public gaugeRewarder;
uint256 public DURATION;
uint internal constant MAX_REWARD_TOKENS = 6;
address[] public rewards;
mapping(address => bool) public isReward;
mapping(address => uint) public rewardRate;
mapping(address => uint) public periodFinishToken;
mapping(address => uint) public lastUpdateTime;
mapping(address => uint) public rewardPerTokenStored;
mapping(address => mapping(address => uint)) public lastEarn;
mapping(address => mapping(address => uint)) public userRewardPerTokenStored;
mapping(address => mapping(address => uint)) public userRewardPerTokenPaid;
uint256 internal _totalSupply;
mapping(address => uint256) internal _balances;
mapping(address => uint) public balanceWithLock;
mapping(address => uint) public lockEnd;
/// @dev Central token pool address for cross-chain claims
address public centralTokenPool;
/// @dev Gap to provide storage for future variables
uint256[49] private __gap;
/// -----------------------------------------------------------------------
/// Events
/// -----------------------------------------------------------------------
event RewardAdded(uint256 reward);
event Deposit(address indexed user, uint256 amount);
event Withdraw(address indexed user, uint256 amount);
event Harvest(address indexed user, uint256 reward, address indexed rewardToken);
event ClaimFees(address indexed from, uint256 claimed0, uint256 claimed1);
event EmergencyActivated(address indexed gauge, uint256 timestamp);
event EmergencyDeactivated(address indexed gauge, uint256 timestamp);
event SetDistribution(address newDistribution);
event SetRewarder(address newRewarder);
event NotifyReward(address sender, address token, uint256 amount);
event SweepWithdrawToken(address indexed to, IERC20 indexed token, uint256 amount);
/// -----------------------------------------------------------------------
/// Custom Errors
/// -----------------------------------------------------------------------
error OnlyDistributor();
error IsEmergency(bool emergency);
error ZeroAddress();
error SameAddress();
error OnlyAllowed();
error InvalidAmount();
error NoBalances();
/// -----------------------------------------------------------------------
/// Modifiers
/// -----------------------------------------------------------------------
modifier updateReward(address account) {
_updateRewardForAllTokens(account);
_;
}
modifier onlyDistribution() {
if(msg.sender != DISTRIBUTION) revert OnlyDistributor();
_;
}
modifier isNotEmergency() {
if(emergency == true) revert IsEmergency(emergency);
_;
}
constructor() {}
function initialize(
address _rewardToken,
address _ve,
address _stakeToken,
address _distribution,
bool _isForPair
) public initializer {
__Ownable_init();
__ReentrancyGuard_init();
rewardToken = IERC20(_rewardToken); // main reward
VE = _ve; // vested
stakeToken = IERC20(_stakeToken); // underlying (LP)
DISTRIBUTION = _distribution; // distribution address (voter)
DURATION = Constants.EPOCH; // distribution time
isForPair = _isForPair; // pair boolean, if false no claim_fees
emergency = false;
isReward[_rewardToken] = true;
rewards.push(_rewardToken);
// Central token pool module initialization
address factory = msg.sender;
address _centralTokenPool = address(0);
if (_isContract(factory)) {
try IGaugeFactoryV2_Base(factory).centralTokenPool() returns (address pool) {
_centralTokenPool = pool;
} catch {}
_setCentralTokenPool(_centralTokenPool);
}
}
/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
ONLY OWNER
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */
///@notice set distribution address (should be voter)
function setDistribution(address _distribution) external onlyOwner {
if(_distribution == address(0)) revert ZeroAddress();
if(_distribution == DISTRIBUTION) revert SameAddress();
DISTRIBUTION = _distribution;
emit SetDistribution(DISTRIBUTION);
}
///@notice set gauge rewarder address
function setGaugeRewarder(address _gaugeRewarder) external onlyOwner {
if(_gaugeRewarder == gaugeRewarder) revert SameAddress();
gaugeRewarder = _gaugeRewarder;
emit SetRewarder(gaugeRewarder);
}
function activateEmergencyMode() external onlyOwner {
if(emergency == true) revert IsEmergency(emergency);
emergency = true;
emit EmergencyActivated(address(this), block.timestamp);
}
function stopEmergencyMode() external onlyOwner {
if(emergency == false) revert IsEmergency(emergency);
emergency = false;
emit EmergencyDeactivated(address(this), block.timestamp);
}
/// @notice Update rewardToken address to match with Voter contract
function updateRewardToken() external onlyOwner {
isReward[address(rewardToken)] = false;
address rewardAddress = _getVoterOToken();
if (rewardAddress == address(0)) {
rewardAddress = IVoterV5(DISTRIBUTION).base();
}
if (!isReward[rewardAddress]) {
isReward[rewardAddress] = true;
rewards.push(rewardAddress);
}
rewardToken = IERC20(rewardAddress);
}
/// @notice Owner can add reward tokens beyond limit
function addRewardToken(address _rewardToken) external onlyOwner {
if (!isReward[_rewardToken]) {
isReward[_rewardToken] = true;
rewards.push(_rewardToken);
} else {
revert("Already added");
}
}
function removeRewardToken(address _rewardToken) external onlyOwner {
require(isReward[_rewardToken], "Not added");
_updateRewardForAllTokens(address(this));
for (uint i = 0; i<rewards.length-1; i++){
if (rewards[i] == _rewardToken) {
rewards[i] = rewards[rewards.length-1];
rewards.pop();
break;
}
}
isReward[_rewardToken] = false;
}
/// @notice Owner can sweep tokens in case of emergency
function sweepTokens(IERC20[] memory tokens, uint256[] memory amounts, address to) public onlyOwner {
require(tokens.length == amounts.length, "Tokens and amounts length mismatch");
for (uint256 i = 0; i < tokens.length; i++) {
IERC20 token = tokens[i];
require(token != stakeToken, "Cannot sweep stake token");
uint256 amount = amounts[i];
uint256 balance = token.balanceOf(address(this));
require(balance >= amount, "Insufficient token balance");
token.transfer(to, amount);
emit SweepWithdrawToken(to, token, amount);
}
}
/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
VIEW FUNCTIONS
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */
///@notice total supply held
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
///@notice balance of a user
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
function availableBalance(address account) public view returns (uint) {
if (block.timestamp >= lockEnd[account]) return _balances[account];
return _balances[account] - balanceWithLock[account];
}
function lastTimeRewardApplicable(address rewardAddress) public view returns (uint256) {
return Math.min(block.timestamp, periodFinishToken[rewardAddress]);
}
function rewardPerToken(address rewardAddress) public view returns (uint256) {
if (_totalSupply == 0) {
return rewardPerTokenStored[rewardAddress];
} else {
return rewardPerTokenStored[rewardAddress] + (lastTimeRewardApplicable(rewardAddress) - lastUpdateTime[rewardAddress]) * rewardRate[rewardAddress] * 1e18 / _totalSupply;
}
}
///@notice see earned rewards for user
function earned(address account) external view returns (uint256) {
return earned(account, address(rewardToken));
}
///@notice see earned rewards for user
function earned(address account, address rewardAddress) public view returns (uint256) {
return userRewardPerTokenStored[rewardAddress][account] + _balances[account] * (rewardPerToken(rewardAddress) - userRewardPerTokenPaid[rewardAddress][account]) / 1e18;
}
///@notice get total reward for the duration
function rewardForDuration(address rewardAddress) public view returns (uint256) {
return rewardRate[rewardAddress] * DURATION;
}
function periodFinish(address rewardAddress) public view returns (uint256) {
return periodFinishToken[rewardAddress];
}
///@notice get the internal bribe address for this gauge. LP fees are sent here.
///@dev Using snake case for backward compatibility
function internal_bribe() public view returns (address) {
return IVoterV5(DISTRIBUTION).internal_bribes(address(this));
}
///@notice get the external bribe address for this gauge. Bribe fees are sent here.
///@dev Using snake case for backward compatibility
function external_bribe() public view returns (address) {
return IVoterV5(DISTRIBUTION).external_bribes(address(this));
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool supported) {
return interfaceId == type(IGaugeV2).interfaceId;
}
/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
USER INTERACTION
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */
///@notice deposit all stakeToken of msg.sender
function depositAll() external {
_deposit(stakeToken.balanceOf(msg.sender), msg.sender);
}
///@notice deposit amount stakeToken
function deposit(uint256 amount) external {
_deposit(amount, msg.sender);
}
///@notice deposit amount stakeToken to account
function depositTo(uint256 amount, address account) external {
_deposit(amount, account);
}
///@notice deposits a locked LP position. Generally called from oToken
function depositWithLock(address account, uint256 amount, uint256 _lockDuration) external {
require(msg.sender == account || msg.sender == address(rewardToken) || IVoterV5(DISTRIBUTION).isGaugeDepositor(msg.sender), "Not allowed to deposit with lock");
_deposit(amount, account);
if(block.timestamp >= lockEnd[account]) {
// if the current lock is expired release the tokens from that lock before locking again
delete lockEnd[account];
delete balanceWithLock[account];
}
balanceWithLock[account] += amount;
uint256 currentLockEnd = lockEnd[account];
uint256 newLockEnd = block.timestamp + _lockDuration ;
if (currentLockEnd > newLockEnd) {
// The lock end can only be extended
revert("The current lock end > new lock end");
}
lockEnd[account] = newLockEnd;
}
/// @notice Internal deposit function with all checks and pool integration
function _deposit(uint256 amount, address account) internal nonReentrant isNotEmergency updateReward(account) {
if(amount <= 0) revert InvalidAmount();
_balances[account] = _balances[account] + amount;
_totalSupply = _totalSupply + amount;
if (address(gaugeRewarder) != address(0)) {
IRewarder(gaugeRewarder).onReward(account, account, _balances[account]);
}
stakeToken.safeTransferFrom(msg.sender, address(this), amount);
// If central pool is enabled, deposit tokens to the pool for cross-chain access
if (_isCentralTokenPoolEnabled()) {
_depositToCentralTokenPool(stakeToken, amount);
}
emit Deposit(account, amount);
}
///@notice withdraw all token
function withdrawAll() external {
_withdraw(_balances[msg.sender]);
}
/// @notice Withdraw a specific amount of tokens from the gauge
function withdraw(uint256 amount) external {
_withdraw(amount);
}
/// @notice Internal withdraw function with all checks and pool integration
function _withdraw(uint256 amount) internal nonReentrant isNotEmergency updateReward(msg.sender) {
if(amount <= 0) revert InvalidAmount();
if(_balances[msg.sender] <= 0) revert NoBalances();
if(block.timestamp >= lockEnd[msg.sender]) {
// if the current lock is expired, release the tokens
delete lockEnd[msg.sender];
delete balanceWithLock[msg.sender];
}
uint256 totalBalance = _balances[msg.sender];
uint256 lockedAmount = balanceWithLock[msg.sender];
uint256 freeAmount = totalBalance - lockedAmount;
// Update lock related mappings when withdraw amount greater than free amount
if (amount > freeAmount) {
revert("Cannot withdraw more than free amount");
}
_totalSupply -= amount;
_balances[msg.sender] -= amount;
if (address(gaugeRewarder) != address(0)) {
IRewarder(gaugeRewarder).onReward(msg.sender, msg.sender, _balances[msg.sender]);
}
_safeTransferStakeToken(msg.sender, amount);
emit Withdraw(msg.sender, amount);
}
function emergencyWithdraw() external nonReentrant {
if(!emergency) revert IsEmergency(emergency);
if(_balances[msg.sender] <= 0) revert NoBalances();
uint256 _amount = _balances[msg.sender];
_totalSupply = _totalSupply - _amount;
_balances[msg.sender] = 0;
_updateRewardForAllTokens(address(0));
if (gaugeRewarder != address(0)) {
IRewarder(gaugeRewarder).onEmergencyWithdrawAmount(msg.sender, _amount);
}
_safeTransferStakeTokenEmergency(msg.sender, _amount);
emit Withdraw(msg.sender, _amount);
}
function emergencyWithdrawAmount(uint256 _amount) external nonReentrant {
if(!emergency) revert IsEmergency(emergency);
if(_balances[msg.sender] < _amount) revert NoBalances();
_totalSupply = _totalSupply - _amount;
_balances[msg.sender] -= _amount;
_updateRewardForAllTokens(address(0));
if (gaugeRewarder != address(0)) {
IRewarder(gaugeRewarder).onEmergencyWithdrawAmount(msg.sender, _amount);
}
_safeTransferStakeTokenEmergency(msg.sender, _amount);
emit Withdraw(msg.sender, _amount);
}
///@notice withdraw all stakeToken and harvest rewardToken
function withdrawAllAndHarvest() external {
_withdraw(_balances[msg.sender]);
getReward();
}
/// @notice User harvest function called from distribution (voter allows harvest on multiple gauges)
function getReward(address _user) external onlyDistribution {
address[] memory tokens = new address[](1);
tokens[0] = address(rewardToken);
return _getReward(_user, tokens);
}
/// @notice User harvest function
/// Enables backward compatibility and focuses on harvesting main reward tokern
function getReward() public {
address[] memory tokens = new address[](1);
tokens[0] = address(rewardToken);
return _getReward(msg.sender, tokens);
}
///@notice User harvest function called from distribution (voter allows harvest on multiple gauges)
function getReward(address _user, address[] memory tokens) external {
require(msg.sender == _user || msg.sender == DISTRIBUTION);
return _getReward(_user, tokens);
}
function _getReward(address _user, address[] memory tokens) internal nonReentrant updateReward(_user) {
uint length = tokens.length;
for (uint i = 0; i < length; i++) {
address rewardAddress = tokens[i];
uint256 reward = userRewardPerTokenStored[rewardAddress][_user];
if (reward > 0) {
userRewardPerTokenStored[rewardAddress][_user] = 0;
IERC20(rewardAddress).safeTransfer(_user, reward);
emit Harvest(_user, reward, rewardAddress);
}
}
if (gaugeRewarder != address(0)) {
IRewarder(gaugeRewarder).onReward(_user, _user, _balances[_user]);
}
}
function left(address token) external view returns (uint) {
if (block.timestamp >= periodFinishToken[token]) return 0;
uint _remaining = periodFinishToken[token] - block.timestamp;
return _remaining * rewardRate[token];
}
function _updateRewardForAllTokens(address account) internal {
uint256 length = rewards.length;
for (uint i; i < length; i++) {
address rewardAddress = rewards[i];
rewardPerTokenStored[rewardAddress] = rewardPerToken(rewardAddress);
lastUpdateTime[rewardAddress] = lastTimeRewardApplicable(rewardAddress);
if (account != address(0)) {
userRewardPerTokenStored[rewardAddress][account] = earned(account, rewardAddress);
userRewardPerTokenPaid[rewardAddress][account] = rewardPerTokenStored[rewardAddress];
}
}
}
/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
DISTRIBUTION
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */
/// @dev Receive rewards
function notifyRewardAmount(address rewardAddress, uint256 rewardAmount) external virtual nonReentrant isNotEmergency updateReward(address(0)) {
uint256 balanceBefore = IERC20(rewardAddress).balanceOf(address(this));
IERC20(rewardAddress).safeTransferFrom(msg.sender, address(this), rewardAmount);
uint256 balanceAfter = IERC20(rewardAddress).balanceOf(address(this));
rewardAmount = balanceAfter - balanceBefore;
_notifyRewardAmount(rewardAddress, rewardAmount);
}
/// @notice helper for updateRewardToken to be able to override
function _getVoterOToken() internal virtual view returns (address) {
return IVoterV5(DISTRIBUTION).oToken();
}
function _notifyRewardAmount(address rewardAddress, uint rewardAmount) internal {
require(rewardAddress != address(stakeToken), "Can't add stake token as reward");
require(rewardAmount > 0, "Reward amount needs to be higher than 0");
if (!isReward[rewardAddress]) {
require(IVoterV5(DISTRIBUTION).isWhitelisted(rewardAddress), "rewards tokens must be whitelisted");
if (rewardAddress != _getVoterOToken() && rewardAddress != IVoterV5(DISTRIBUTION).base())
require(rewards.length < MAX_REWARD_TOKENS, "too many rewards tokens");
}
if (block.timestamp >= periodFinishToken[rewardAddress]) {
rewardRate[rewardAddress] = rewardAmount / DURATION;
} else {
uint256 remaining = periodFinishToken[rewardAddress] - block.timestamp;
uint256 leftover = remaining * rewardRate[rewardAddress];
require(rewardAmount > leftover, "Cannot decrease reward rate");
/// @dev: This will spread the remaining rewards over the new period.
rewardRate[rewardAddress] = (rewardAmount + leftover) / DURATION;
}
// Ensure the provided reward amount is not more than the balance in the contract.
// This keeps the reward rate in the right range, preventing overflows due to
// very high values of rewardRate in the earned and rewardsPerToken functions;
// Reward + leftover must be less than 2^256 / 10^18 to avoid overflow.
uint256 balance = IERC20(rewardAddress).balanceOf(address(this));
require(rewardRate[rewardAddress] <= balance / DURATION, "Provided reward too high");
lastUpdateTime[rewardAddress] = block.timestamp;
periodFinishToken[rewardAddress] = block.timestamp + DURATION;
if (!isReward[rewardAddress]) {
isReward[rewardAddress] = true;
rewards.push(rewardAddress);
}
emit NotifyReward(msg.sender, rewardAddress, rewardAmount);
}
function claimFees() external nonReentrant returns (uint256 claimed0, uint256 claimed1) {
return _claimFees();
}
function _claimFees() internal virtual returns (uint256 claimed0, uint256 claimed1) {
if (!isForPair) {
return (0, 0);
}
address _token = address(stakeToken);
(claimed0, claimed1) = IPair(_token).claimFees();
if (claimed0 > 0 || claimed1 > 0) {
uint256 _fees0 = claimed0;
uint256 _fees1 = claimed1;
(address _token0, address _token1) = IPair(_token).tokens();
address internalBribe = internal_bribe();
if (_fees0 > 0) {
IERC20(_token0).approve(internalBribe, 0);
IERC20(_token0).approve(internalBribe, _fees0);
IBribe(internalBribe).notifyRewardAmount(_token0, _fees0);
}
if (_fees1 > 0) {
IERC20(_token1).approve(internalBribe, 0);
IERC20(_token1).approve(internalBribe, _fees1);
IBribe(internalBribe).notifyRewardAmount(_token1, _fees1);
}
emit ClaimFees(msg.sender, claimed0, claimed1);
}
}
/* -----------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
MULTITOKENPOOL MODULE IMPLEMENTATION
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------------------------------------------------------------------- */
/// @notice transfer stakeToken to account
/// @dev if central pool is enabled, withdraw tokens from the pool first
function _safeTransferStakeToken(address account, uint256 amount) internal {
if (_isCentralTokenPoolEnabled()) {
_withdrawFromCentralTokenPool(stakeToken, amount);
}
stakeToken.safeTransfer(account, amount);
}
/// @notice Emergency transfer stakeToken to account bypassing central pool failures
/// @dev Used in emergency mode - attempts central pool withdrawal but continues if it fails
function _safeTransferStakeTokenEmergency(address account, uint256 amount) internal {
if (_isCentralTokenPoolEnabled()) {
try this._withdrawFromCentralPoolSafe(stakeToken, amount) {
// Success - tokens withdrawn from central pool
} catch {
// Central pool withdrawal failed - continue with direct transfer
// This ensures users can always withdraw in emergency mode even if pool is broken
}
}
// Ensure we have sufficient tokens in the contract
uint256 contractBalance = stakeToken.balanceOf(address(this));
require(contractBalance >= amount, "Insufficient tokens for emergency withdrawal");
stakeToken.safeTransfer(account, amount);
}
/// @notice Safe wrapper for central pool withdrawal that can be called via try/catch
/// @dev External function to enable try/catch pattern in _safeTransferStakeTokenEmergency
function _withdrawFromCentralPoolSafe(IERC20 token, uint256 amount) external {
require(msg.sender == address(this), "Only self-call allowed");
_withdrawFromCentralTokenPool(token, amount);
}
/// @notice Implementation of virtual access function
/// @inheritdoc CentralTokenPoolModule
function getCentralTokenPool() public view override returns (address) {
return centralTokenPool;
}
/// @notice Implementation of virtual setter function
/// @dev ⚠️ WARNING: This function bypasses all validation checks!
/// - DO NOT call this function directly
/// - Use _setCentralTokenPool() instead for safe operations
/// - Only called internally by the validated _setCentralTokenPool()
/// - This is an implementation detail of CentralTokenPoolModule
/// @param newPool The new pool address (UNCHECKED - can be invalid!)
function _setCentralTokenPoolUnchecked(address newPool) internal override {
centralTokenPool = newPool;
}
/// @notice Public function that delegates to module
/// @dev Only callable by gauge owner/admin. This is a one-way operation - pool can only be re-enabled via upgrade
function revokeCentralTokenPool() external onlyOwner {
_revokeCentralTokenPool(stakeToken);
}
/// @notice Helper function to check if an address contains contract code
/// @dev Used during initialization to validate factory responses
function _isContract(address addr) private view returns (bool) {
uint256 size;
assembly {
size := extcodesize(addr)
}
return size > 0;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/**
* @title The interface for the Algebra Factory
* @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
* https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
*/
interface IAlgebraFactory {
/**
* @notice Emitted when the owner of the factory is changed
* @param newOwner The owner after the owner was changed
*/
event Owner(address indexed newOwner);
/**
* @notice Emitted when the vault address is changed
* @param newVaultAddress The vault address after the address was changed
*/
event VaultAddress(address indexed newVaultAddress);
/**
* @notice Emitted when a pool is created
* @param token0 The first token of the pool by address sort order
* @param token1 The second token of the pool by address sort order
* @param pool The address of the created pool
*/
event Pool(address indexed token0, address indexed token1, address pool);
/**
* @notice Emitted when the farming address is changed
* @param newFarmingAddress The farming address after the address was changed
*/
event FarmingAddress(address indexed newFarmingAddress);
event FeeConfiguration(
uint16 alpha1,
uint16 alpha2,
uint32 beta1,
uint32 beta2,
uint16 gamma1,
uint16 gamma2,
uint32 volumeBeta,
uint16 volumeGamma,
uint16 baseFee
);
/**
* @notice Returns the current owner of the factory
* @dev Can be changed by the current owner via setOwner
* @return The address of the factory owner
*/
function owner() external view returns (address);
/**
* @notice Returns the current poolDeployerAddress
* @return The address of the poolDeployer
*/
function poolDeployer() external view returns (address);
/**
* @dev Is retrieved from the pools to restrict calling
* certain functions not by a tokenomics contract
* @return The tokenomics contract address
*/
function farmingAddress() external view returns (address);
function vaultAddress() external view returns (address);
/**
* @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
* @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
* @param tokenA The contract address of either token0 or token1
* @param tokenB The contract address of the other token
* @return pool The pool address
*/
function poolByPair(address tokenA, address tokenB) external view returns (address pool);
/**
* @notice Creates a pool for the given two tokens and fee
* @param tokenA One of the two tokens in the desired pool
* @param tokenB The other of the two tokens in the desired pool
* @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
* from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
* are invalid.
* @return pool The address of the newly created pool
*/
function createPool(address tokenA, address tokenB) external returns (address pool);
/**
* @notice Updates the owner of the factory
* @dev Must be called by the current owner
* @param _owner The new owner of the factory
*/
function setOwner(address _owner) external;
/**
* @dev updates tokenomics address on the factory
* @param _farmingAddress The new tokenomics contract address
*/
function setFarmingAddress(address _farmingAddress) external;
/**
* @dev updates vault address on the factory
* @param _vaultAddress The new vault contract address
*/
function setVaultAddress(address _vaultAddress) external;
/**
* @notice Changes initial fee configuration for new pools
* @dev changes coefficients for sigmoids: α / (1 + e^( (β-x) / γ))
* alpha1 + alpha2 + baseFee (max possible fee) must be <= type(uint16).max
* gammas must be > 0
* @param alpha1 max value of the first sigmoid
* @param alpha2 max value of the second sigmoid
* @param beta1 shift along the x-axis for the first sigmoid
* @param beta2 shift along the x-axis for the second sigmoid
* @param gamma1 horizontal stretch factor for the first sigmoid
* @param gamma2 horizontal stretch factor for the second sigmoid
* @param volumeBeta shift along the x-axis for the outer volume-sigmoid
* @param volumeGamma horizontal stretch factor the outer volume-sigmoid
* @param baseFee minimum possible fee
*/
function setBaseFeeConfiguration(
uint16 alpha1,
uint16 alpha2,
uint32 beta1,
uint32 beta2,
uint16 gamma1,
uint16 gamma2,
uint32 volumeBeta,
uint16 volumeGamma,
uint16 baseFee
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.0;
import "./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.
*
* By default, the owner account will be the one that deploys the contract. 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 {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
function __Ownable2Step_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable2Step_init_unchained() internal onlyInitializing {
}
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
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 {
_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 {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
_transferOwnership(sender);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../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.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721Upgradeable.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol) pragma solidity ^0.8.0; import "../utils/introspection/IERC165.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface 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 v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
library Constants {
// FIXME: DUMMY
uint48 constant EPOCH = 4 hours;
// uint48 constant EPOCH = 1 weeks;
}/// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { PoolKey } from "./PoolKey.sol";
// import {IImmutableState} from "@uniswap/v4-periphery/src/interfaces/IImmutableState.sol";
interface IImmutableState {
/// @notice The Uniswap v4 PoolManager contract
function poolManager() external view returns (address /*IPoolManager*/);
}
/**
* @title IMultiPositionManager
* @author Gamma
* @notice This interface is used to interact with Gamma ALM strategies which use UniswapV4 pools as concentrated liquidity positions.
*/
interface IMultiPositionManager is IERC20, IImmutableState {
struct Position {
PoolKey poolKey;
int24 lowerTick;
int24 upperTick;
}
struct PositionData {
uint128 liquidity;
uint256 amount0;
uint256 amount1;
}
function getPositions() external view returns (
Position[] memory,
PositionData[] memory
);
function basePositionsLength() external view returns (uint256);
function token0() external view returns (IERC20);
function token1() external view returns (IERC20);
function getTotalAmounts() external view returns (
uint256 total0,
uint256 total1,
uint256 totalFee0,
uint256 totalFee1
);
function currentTicks() external view returns (int24[] memory);
function rebalance(
Position[] memory baseRanges,
uint128[] memory liquidities,
int24 limitWidth,
uint256[2][] memory inMin,
uint256[2][] memory outMin,
int24 aimTick,
uint24 tickOffset
) external;
function compound(
uint128[] memory liquidities,
uint256[2][] memory inMin,
int24 aimTick,
uint24 tickOffset
) external;
function claimFee() external;
function setWhitelist(address _whitelist) external;
function setFeeRecipient(address _feeRecipient) external;
function setFee(uint16 fee) external;
// function setTickOffset(uint24 offset) external;
function deposit(
uint256 deposit0Desired,
uint256 deposit1Desired,
address to,
address from
) external payable returns (uint256, uint256, uint256);
function zeroBurnAll() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "./PoolKey.sol";
type PoolId is bytes32;
/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
/// @notice Returns value equal to keccak256(abi.encode(poolKey))
function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
assembly ("memory-safe") {
// 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
poolId := keccak256(poolKey, 0xa0)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolIdLibrary} from "./PoolIdLibrary.sol";
// import {Currency} from "./Currency.sol";
// import {IHooks} from "../interfaces/IHooks.sol";
using PoolIdLibrary for PoolKey global;
/// @notice Returns the key for identifying a pool
struct PoolKey {
/// @notice The lower currency of the pool, sorted numerically
address currency0; // NOTE: Should be Currency
/// @notice The higher currency of the pool, sorted numerically
address currency1; // NOTE: Should be Currency
/// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
uint24 fee;
/// @notice Ticks that involve positions must be a multiple of tick spacing
int24 tickSpacing;
/// @notice The hooks of the pool
address hooks; // NOTE: Should be IHooks
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.13;
/// @dev Base interface for the GaugeFactoryV2
interface IGaugeFactoryV2_Base {
/// @notice Creates a new gauge with the given parameters.
/// @dev Bribes have been extracted and are now being pulled from the VoterV5. The params have been left for backwards compatibility for V2 gauges.
function createGaugeV2(
address _rewardToken,
address _ve,
address _token,
address _distribution,
/// @dev unused parameter for backwards compatibility
address /*_internal_bribe*/,
/// @dev unused parameter for backwards compatibility
address /*_external_bribe*/,
bool _isPair
) external returns (address);
function activateEmergencyMode(address[] memory _gauges) external;
function gauges() external view returns (address[] memory);
function last_gauge() external view returns (address);
function length() external view returns (uint256);
function permissionsRegistry() external view returns (address);
function setDistribution(address[] memory _gauges, address distro) external;
function setGaugeRewarder(address[] memory _gauges, address[] memory _rewarder) external;
function setPermissionsRegistry(address _registry) external;
function stopEmergencyMode(address[] memory _gauges) external;
/// -----------------------------------------------------------------------
/// MultiTokenPool Integration
/// -----------------------------------------------------------------------
/// @notice Gets the current central token pool address (can be address(0) to disable)
/// @dev CRITICAL: Even if this changes, users must always be able to withdraw their funds
function centralTokenPool() external view returns (address);
/// @notice Sets the central token pool address
/// @dev Can be set to address(0) to disable central pooling
/// CRITICAL: This change does NOT affect existing funds - users can always withdraw
function setCentralTokenPool(address _pool) external;
}
/// @dev This interface is used to manage gauges which use UniV2 like LP tokens found in this protocol.
interface IGaugeFactoryV2 is IGaugeFactoryV2_Base {
function initialize(address _permissionRegistry, address _gaugeBeacon, address _beaconFactoryAdmin) external;
}
/// @dev This interface is used to manage gauges which use GAMMA ALM fungible LP tokens for Concentrated Liquidity on Algebra.
interface IGaugeFactoryV2_Gamma is IGaugeFactoryV2_Base {
function initialize(
address _permissionsRegistry,
address _gammaFeeRecipient,
address _pairFactoryClassic,
address _feeVaultImplementation,
address _gaugeImplementation,
address _beaconFactoryAdmin,
address _wrappedNativeToken
) external;
function gammaFeeRecipient() external view returns (address);
function last_feeVault() external view returns (address);
function setGammaDefaultFeeRecipient(address _rec) external;
function setGaugeFeeVault(address[] memory _gauges, address _vault) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IBribe {
function deposit(uint amount, uint tokenId) external;
function withdraw(uint amount, uint tokenId) external;
function getRewardForOwner(uint tokenId, address[] memory tokens) external;
function getRewardForAddress(address _owner, address[] memory tokens) external;
function notifyRewardAmount(address token, uint amount) external;
function addReward(address) external;
function setVoter(address _Voter) external;
function setMinter(address _Voter) external;
function setOwner(address _Voter) external;
function emergencyRecoverERC20(address tokenAddress, uint256 tokenAmount) external;
function recoverERC20AndUpdateData(address tokenAddress, uint256 tokenAmount) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IBribeFactory {
function createInternalBribe(address[] memory) external returns (address);
function createExternalBribe(address[] memory) external returns (address);
function createBribe(address _owner,address _token0,address _token1, string memory _type) external returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IERC20 {
function totalSupply() external view returns (uint256);
function transfer(address recipient, uint amount) external returns (bool);
function decimals() external view returns (uint8);
function symbol() external view returns (string memory);
function balanceOf(address) external view returns (uint);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IGauge {
function notifyRewardAmount(address token, uint amount) external;
function getReward(address account, address[] memory tokens) external;
function getReward(address account) external;
function claimFees() external returns (uint claimed0, uint claimed1);
function rewardRate(address _pair) external view returns (uint);
function balanceOf(address _account) external view returns (uint);
function isForPair() external view returns (bool);
function totalSupply() external view returns (uint);
function earned(address token, address account) external view returns (uint);
function stakeToken() external view returns (address);
function setDistribution(address _distro) external;
function addRewardToken(address _rewardToken) external;
function removeRewardToken(address _rewardToken) external;
function updateRewardToken() external;
function activateEmergencyMode() external;
function stopEmergencyMode() external;
function setInternalBribe(address intbribe) external;
function setGaugeRewarder(address _gr) external;
function setFeeVault(address _feeVault) external;
function depositWithLock(address account, uint256 amount, uint256 _lockDuration) external;
function sweepTokens(address[] memory tokens, uint256[] memory amounts, address to) external;
function initialize(address _rewardToken,address _ve,address _stakeToken,address _distribution, address _internal_bribe, address _external_bribe, bool _isForPair) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IGaugeFactory {
function createGauge(address, address, address, address, bool, address[] memory) external returns (address);
function createGaugeV2(address _rewardToken,address _ve,address _token,address _distribution, address _internal_bribe, address _external_bribe, bool _isPair) external returns (address) ;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @title IGaugeV2
* @custom:version 2.1.0
* - 2.1.0 initialize function no longer takes _internal_bribe and _external_bribe params
*/
interface IGaugeV2 is IERC165 {
function deposit(uint256 amount) external;
function depositTo(uint256 amount, address account) external;
function withdrawAll() external;
function withdraw(uint256 amount) external;
function notifyRewardAmount(address token, uint amount) external;
function getReward(address account, address[] memory tokens) external;
function getReward(address account) external;
function claimFees() external returns (uint claimed0, uint claimed1);
function rewardRate(address _pair) external view returns (uint);
function balanceOf(address _account) external view returns (uint);
function isForPair() external view returns (bool);
function totalSupply() external view returns (uint);
function earned(address token, address account) external view returns (uint);
function stakeToken() external view returns (IERC20);
function setDistribution(address _distro) external;
function addRewardToken(address _rewardToken) external;
function removeRewardToken(address _rewardToken) external;
function updateRewardToken() external;
function activateEmergencyMode() external;
function stopEmergencyMode() external;
function setGaugeRewarder(address _gr) external;
function depositWithLock(address account, uint256 amount, uint256 _lockDuration) external;
function sweepTokens(IERC20[] memory tokens, uint256[] memory amounts, address to) external;
function initialize(address _rewardToken, address _ve, address _stakeToken, address _distribution, bool _isForPair) external;
/// -----------------------------------------------------------------------
/// MultiTokenPool Integration
/// -----------------------------------------------------------------------
/// @notice Gets the central pool address that was set during initialization
function centralTokenPool() external view returns (address);
/// @notice Revokes the central token pool by withdrawing all tokens and setting pool to address(0)
/// @dev Only callable by gauge owner/admin. This is a one-way operation - pool can only be re-enabled via upgrade
function revokeCentralTokenPool() external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IHypervisor {
function pool() external view returns(address);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IMinter {
function update_period() external returns (uint256);
function check() external view returns(bool);
function period() external view returns(uint256);
function active_period() external view returns(uint256);
function WEEK() external view returns(uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @title IMultiTokenPool
* @notice ⚠️ IMPORTANT: STANDARD ERC20 TOKENS ONLY
* @dev ❌ DO NOT USE WITH:
* - Fee-on-transfer tokens
* - Deflationary/inflationary tokens
* - Rebase tokens (AMPL, etc.)
* - Tokens with transfer hooks (ERC777)
* - Non-standard tokens that modify balances
*
* ✅ DESIGNED FOR: Standard ERC20 LP tokens from DEX pairs
*
* This pool allows anyone to deposit tokens but only the depositor can withdraw
* Address-based isolation ensures secure token storage across multiple users
* Designed for cross-chain deployment using CREATE2 for deterministic addresses
* Owner can sweep excess tokens for security
* Reusable across any protocol needing multi-token storage with user isolation
*/
interface IMultiTokenPool is IERC165 {
/// -----------------------------------------------------------------------
/// Events
/// -----------------------------------------------------------------------
/// @notice Emitted when tokens are deposited
event Deposit(address indexed token, address indexed depositor, uint256 amount);
/// @notice Emitted when tokens are withdrawn
event Withdraw(address indexed token, address indexed depositor, uint256 amount);
/// @notice Emitted when tokens are swept
event TokenSwept(address indexed token, address indexed owner, uint256 amount);
/// -----------------------------------------------------------------------
/// Errors
/// -----------------------------------------------------------------------
/// @notice Error thrown when invalid amount is provided
error InvalidAmount();
/// @notice Error thrown when insufficient balance
error InsufficientBalance();
/// @notice Error thrown when zero address is provided
error ZeroAddress();
/// @notice Error thrown when zero amount is provided
error ZeroAmount();
/// @notice Error thrown when non-standard token is detected
error NonStandardToken();
/// @notice Error thrown when no excess tokens available for sweep
error NoExcessTokens();
/// @notice Error thrown when fallback function is called
error FallbackNotAllowed();
/// -----------------------------------------------------------------------
/// Functions
/// -----------------------------------------------------------------------
/**
* @notice Deposit ERC20 tokens to the pool
* @param token The ERC20 token address
* @param amount The amount to deposit
*/
function deposit(address token, uint256 amount) external;
/**
* @notice Deposit ERC20 tokens to the pool on behalf of another address
* @param token The ERC20 token address
* @param amount The amount to deposit
* @param depositor The address that will be credited with the deposit
*/
function depositFor(address token, uint256 amount, address depositor) external;
/**
* @notice Withdraw ERC20 tokens from the pool
* @param token The ERC20 token address
* @param amount The amount to withdraw
*/
function withdraw(address token, uint256 amount) external;
/**
* @notice Withdraw all tokens of a specific type for the calling address only
* @param token The ERC20 token address
*/
function withdrawAll(address token) external;
/**
* @notice Get the balance of a specific token for a user
* @param token The token address
* @param user The user address
* @return The balance
*/
function balanceOf(address token, address user) external view returns (uint256);
/**
* @notice Get total deposited amount of a specific token
* @param token The token address
* @return The total amount
*/
function totalDeposited(address token) external view returns (uint256);
/**
* @notice Get the list of all tokens that have been deposited
* @return Array of token addresses
*/
function getDepositedTokens() external view returns (address[] memory);
/**
* @notice Get user deposit information for a specific token
* @param user The user address
* @param token The token address
* @return amount The deposited amount
* @return timestamp The deposit timestamp
*/
function getUserDeposit(address user, address token) external view returns (uint256 amount, uint256 timestamp);
/// -----------------------------------------------------------------------
/// Owner Functions
/// -----------------------------------------------------------------------
/**
* @notice Sweep excess tokens from the contract
* @dev Only owner can call this function and only excess tokens above total deposits can be swept
* @param token The token address to sweep
* @param to The address to send swept tokens to
*/
function sweepExcessTokens(address token, address to) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IPair {
function metadata() external view returns (uint dec0, uint dec1, uint r0, uint r1, bool st, address t0, address t1);
function claimFees() external returns (uint, uint);
function tokens() external view returns (address, address);
function token0() external view returns (address);
function token1() external view returns (address);
function fees() external view returns (address);
function transferFrom(address src, address dst, uint amount) external returns (bool);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function burn(address to) external returns (uint amount0, uint amount1);
function mint(address to) external returns (uint liquidity);
function getReserves() external view returns (uint _reserve0, uint _reserve1, uint _blockTimestampLast);
function getAmountOut(uint amountIn, address tokenIn) external view returns (uint);
function name() external view returns(string memory);
function symbol() external view returns(string memory);
function totalSupply() external view returns (uint);
function decimals() external view returns (uint8);
function claimable0(address _user) external view returns (uint);
function claimable1(address _user) external view returns (uint);
function isStable() external view returns(bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IPairFactory {
function allPairsLength() external view returns (uint);
function isPair(address pair) external view returns (bool);
function getFee(bool) external view returns (uint);
function allPairs(uint index) external view returns (address);
function feeManager() external view returns (address);
function pairCodeHash() external pure returns (bytes32);
function getPair(address tokenA, address token, bool stable) external view returns (address);
function createPair(address tokenA, address tokenB, bool stable) external returns (address pair);
function getInitializable() external view returns (address, address, bool);
function MAX_REFERRAL_FEE() external view returns(uint);
function dibs() external view returns(address);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IPairInfo {
function token0() external view returns(address);
function reserve0() external view returns(uint);
function decimals0() external view returns(uint);
function token1() external view returns(address);
function reserve1() external view returns(uint);
function decimals1() external view returns(uint);
function isPair(address _pair) external view returns(bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
interface IPermissionsRegistry {
function adminMultisig() external view returns (address);
function teamMultisig() external view returns (address);
function emergencyCouncil() external view returns (address);
/// @notice Check if an address has a bytes role
function hasRole(bytes memory role, address caller) external view returns (bool);
/// @notice Check if an address has a role
function hasRoleString(string memory role, address _user) external view returns(bool);
/// @notice Read roles and return array of role strings
function rolesToString() external view returns(string[] memory __roles);
/// @notice Read roles return an array of roles in bytes
function roles() external view returns(bytes[] memory);
/// @notice Read the number of roles
function rolesLength() external view returns(uint);
/// @notice Return addresses for a given role
function roleToAddresses(string memory role) external view returns(address[] memory _addresses);
/// @notice Return roles for a given address
function addressToRole(address _user) external view returns(string[] memory);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IRewarder {
function onReward(uint256 pid, address user, address recipient, uint256 lqdrAmount, uint256 newLpAmount) external;
function pendingTokens(uint256 pid, address user, uint256 lqdrAmount) external view returns (IERC20[] memory, uint256[] memory);
function onReward(address user, address recipient, uint256 userBalance) external;
function onEmergencyWithdrawAmount(address user, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IVersionable {
function VERSION() external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
library Math {
function max(uint a, uint b) internal pure returns (uint) {
return a >= b ? a : b;
}
function min(uint a, uint b) internal pure returns (uint) {
return a < b ? a : b;
}
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function cbrt(uint256 n) internal pure returns (uint256) { unchecked {
uint256 x = 0;
for (uint256 y = 1 << 255; y > 0; y >>= 3) {
x <<= 1;
uint256 z = 3 * x * (x + 1) + 1;
if (n / y >= z) {
n -= y * z;
x += 1;
}
}
return x;
}}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'Math: Sub-underflow');
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IUniswapV3Factory} from '@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol';
/// @title UniswapV3Helper
/// @notice Helper library for UniswapV3 pool validation and fee tier management
/// @dev Used to abstract UniswapV3-specific logic from gauge creation
library UniswapV3Helper {
/// @notice Standard UniswapV3 fee tiers (in basis points)
uint24 public constant FEE_LOW = 500; // 0.05%
uint24 public constant FEE_MEDIUM = 3000; // 0.30%
uint24 public constant FEE_HIGH = 10000; // 1.00%
/// @notice Validates that a pool exists in UniswapV3 factory for given tokens
/// @param _factory The UniswapV3Factory address
/// @param _tokenA Token A address
/// @param _tokenB Token B address
/// @param _expectedPool The expected pool address to validate
/// @return isValid True if the pool exists in the factory for any standard fee tier
function validatePoolExists(
address _factory,
address _tokenA,
address _tokenB,
address _expectedPool
) internal view returns (bool isValid) {
// Check if the pool matches any of the standard fee tiers
uint24[3] memory fees = [FEE_LOW, FEE_MEDIUM, FEE_HIGH];
for (uint256 i = 0; i < fees.length; i++) {
address factoryPool = IUniswapV3Factory(_factory).getPool(_tokenA, _tokenB, fees[i]);
if (_expectedPool == factoryPool && factoryPool != address(0)) {
return true;
}
}
return false;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IMultiTokenPool} from '../interfaces/IMultiTokenPool.sol';
/**
* @title CentralTokenPoolModule
* @notice Abstract module for MultiTokenPool integration
* @dev Provides reusable logic for integrating with central token pools
* Features:
* - Zero storage footprint (uses virtual functions)
* - Clean separation of concerns
* - Reusable across different gauge implementations
* - Secure pool revocation mechanism
*/
abstract contract CentralTokenPoolModule {
using SafeERC20 for IERC20;
/// -----------------------------------------------------------------------
/// Events
/// -----------------------------------------------------------------------
/// @notice Emitted when central token pool is revoked
event CentralTokenPoolRevoked(address indexed gauge, address indexed pool);
/// -----------------------------------------------------------------------
/// Errors
/// -----------------------------------------------------------------------
/// @notice MultiTokenPool errors
error PoolAlreadyRevoked();
error PoolNotEnabled();
error PoolDepositFailed();
error PoolWithdrawFailed();
error InvalidPoolInterface();
/// -----------------------------------------------------------------------
/// Virtual Access Functions
/// -----------------------------------------------------------------------
/// @notice Get the central token pool address - implemented by child contract
/// @dev Made public for external visibility as requested
function getCentralTokenPool() public view virtual returns (address);
/// @notice Set the central token pool address with validation
/// @param newPool The new pool address (can be address(0) to disable)
function _setCentralTokenPool(address newPool) internal virtual {
_validatePoolInterface(newPool);
_setCentralTokenPoolUnchecked(newPool);
}
/// @notice Set the central token pool address without validation
/// @dev ⚠️ INTERNAL IMPLEMENTATION ONLY - DO NOT CALL DIRECTLY!
/// This function is automatically called by _setCentralTokenPool() after validation.
/// Override this in child contract for actual storage update only.
/// Always use _setCentralTokenPool() for safe pool updates.
/// @param newPool The new pool address (bypasses all safety checks)
function _setCentralTokenPoolUnchecked(address newPool) internal virtual;
/// -----------------------------------------------------------------------
/// Modifiers
/// -----------------------------------------------------------------------
/// @notice Modifier to ensure pool is enabled before operations
modifier onlyWithEnabledPool() {
if (getCentralTokenPool() == address(0)) revert PoolNotEnabled();
_;
}
/// -----------------------------------------------------------------------
/// Module Logic
/// -----------------------------------------------------------------------
/// @notice Validate that a pool address supports the required interface
/// @param poolAddress The pool address to validate
/// @dev Extracted from GaugeV2 initialize function for reusability
function _validatePoolInterface(address poolAddress) internal view {
if (poolAddress != address(0)) {
// Use try-catch to handle cases where the address doesn't support supportsInterface
// This is especially important for test scenarios
try IMultiTokenPool(poolAddress).supportsInterface(type(IMultiTokenPool).interfaceId) returns (bool supported) {
if (!supported) {
revert InvalidPoolInterface();
}
} catch {
// If supportsInterface call fails, treat as invalid interface
// This handles test scenarios and malformed addresses gracefully
revert InvalidPoolInterface();
}
}
}
/// @notice Check if central pool routing is enabled
function _isCentralTokenPoolEnabled() internal view returns (bool) {
return getCentralTokenPool() != address(0);
}
/// @notice Deposit tokens to central pool with proper approval management
/// @param token The token to deposit
/// @param amount Amount to deposit
function _depositToCentralTokenPool(IERC20 token, uint256 amount) internal onlyWithEnabledPool {
address pool = getCentralTokenPool();
token.approve(pool, amount);
IMultiTokenPool(pool).deposit(address(token), amount);
token.approve(pool, 0);
}
/// @notice Withdraw tokens from central pool
/// @param token The token to withdraw
/// @param amount Amount to withdraw
function _withdrawFromCentralTokenPool(IERC20 token, uint256 amount) internal onlyWithEnabledPool {
address pool = getCentralTokenPool();
IMultiTokenPool(pool).withdraw(address(token), amount);
}
/// @notice Revokes the central token pool by withdrawing all tokens
/// @param token The token to withdraw all of
function _revokeCentralTokenPool(IERC20 token) internal onlyWithEnabledPool {
address pool = getCentralTokenPool();
IMultiTokenPool(pool).withdrawAll(address(token));
emit CentralTokenPoolRevoked(address(this), pool);
// Set pool to address(0) through virtual function
_setCentralTokenPoolUnchecked(address(0));
}
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.7.0;
interface IDynamicTwapOracle {
/**
* @notice Get the address of the pool
* @return The address of the pool
*/
function pool() external view returns (address);
/**
* @notice Get the address of the first token in the pool
* @return The address of the first token
*/
function token0() external view returns (address);
/**
* @notice Get the address of the second token in the pool
* @return The address of the second token
*/
function token1() external view returns (address);
/**
* @notice Estimate the output amount of a trade
* @param tokenIn The address of the input token
* @param amountIn The amount of the input token
* @param secondsAgo The number of seconds ago to start the TWAP
* @return amountOut The estimated output amount
*/
function estimateAmountOut(
address tokenIn,
uint128 amountIn,
uint32 secondsAgo
) external view returns (uint amountOut);
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.13;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
interface IOption is IAccessControl {
function paymentToken() external view returns (IERC20);
function getPaymentAmount(uint256 _amount, bytes calldata _data) external view returns (uint256);
function exercise(uint256 _amount, address sender, bytes calldata _data) external returns (uint256);
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.13;
interface IOptionFeeDistributor {
function distribute(address token, uint256 amount) external;
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.8.13;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {IDynamicTwapOracle} from "./DynamicTwapOracle/IDynamicTwapOracle.sol";
import {IOptionFeeDistributor} from "./IOptionFeeDistributor.sol";
import {IPair} from "../interfaces/IPair.sol";
import {IOption} from "./IOption.sol";
interface IOptionTokenV3 is IERC20, IAccessControl {
function ADMIN_ROLE() external view returns (bytes32);
function MINTER_ROLE() external view returns (bytes32);
function PAUSER_ROLE() external view returns (bytes32);
function paymentToken() external view returns (IERC20);
function UNDERLYING_TOKEN() external view returns (IERC20);
function voter() external view returns (address);
function mint(address _to, uint256 _amount) external;
function exercise(uint256 _amount, uint256 _maxPaymentAmount, address _recipient) external returns (uint256);
function exercise(uint256 _amount, uint256 _maxPaymentAmount, address _recipient, uint256 _deadline) external returns (uint256);
function exerciseVe(uint256 _amount, uint256 _maxPaymentAmount, address _recipient, uint256 _discount, uint256 _deadline) external returns (uint256, uint256);
function exerciseLp(uint256 _amount, uint256 _maxPaymentAmount, uint256 _maxLPAmount, address _recipient, uint256 _discount, uint256 _deadline) external returns (uint256, uint256);
function exerciseExternal(IOption _option, uint256 _amount, uint256 _deadline, bytes calldata _data) external returns (uint256);
function getVotingEscrow() external view returns (address votingEscrow);
function getLockDurationForVeDiscount(uint256 _discount) external view returns (uint256 duration);
function getSlopeInterceptForVeDiscount() external view returns (int256 slope, int256 intercept);
function togglePermissionedMint() external;
function toggleOption(address option, bool enabled) external;
function getDiscountedPrice(uint256 _amount) external view returns (uint256);
function getDiscountedPrice(uint256 _amount, uint256 _discount) external view returns (uint256);
function getLockDurationForLpDiscount(uint256 _amount) external view returns (uint256);
function getPaymentTokenAmountForExerciseLp(
uint256 _amount,
uint256 _discount
) external view returns (uint256, uint256);
function getSlopeInterceptForLpDiscount() external view returns (int256, int256);
function getTimeWeightedAveragePrice(uint256 _amount) external view returns (uint256);
function setTwapOracleAndPaymentToken(IDynamicTwapOracle _twapOracle, address _paymentToken) external;
function setPairAndPaymentToken(IPair _pair, address _paymentToken) external;
function setFeeDistributor(IOptionFeeDistributor _feeDistributor) external;
function setDiscount(uint256 _discount) external;
function setVeDiscount(uint256 _veDiscount) external;
function setMinLPDiscount(uint256 _lpMinDiscount) external;
function setMaxLPDiscount(uint256 _lpMaxDiscount) external;
function setLockDurationForMaxLpDiscount(uint256 _duration) external;
function setLockDurationForMinLpDiscount(uint256 _duration) external;
function setTwapSeconds(uint32 _twapSeconds) external;
function burn(uint256 _amount) external;
function updateGauge() external;
function setGauge(address _gauge) external;
function setRouter(address _router) external;
function unPause() external;
function pause() external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IBribe is IERC165 {
function deposit(uint amount, address account) external;
function withdraw(uint amount, address account) external;
function getRewardForOwner(uint tokenId, address[] memory tokens) external;
function getRewardForAddress(address _owner, address[] memory tokens) external;
function notifyRewardAmount(address token, uint amount) external;
function addRewardToken(address _rewardsToken) external;
function addRewardTokens(address[] memory _rewardsToken) external;
function setVoter(address _Voter) external;
function setMinter(address _Voter) external;
function setOwner(address _Voter) external;
function emergencyRecoverERC20(address tokenAddress, uint256 tokenAmount) external;
function recoverERC20AndUpdateData(address tokenAddress, uint256 tokenAmount) external;
}
interface IBribe_Init is IBribe {
function initialize(address _owner, address _voter, address _bribeFactory, string memory _type) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IVoterV5_ClaimHelper
* @notice Interface to claim rewards from LP gauges and bribes from VoterV5
*/
interface IVoterV5_ClaimHelper {
/// @notice claim LP gauge rewards
function claimRewards(address[] memory _gauges) external;
/// @notice claim LP gauge rewards for a given address
function claimRewardsFor(address[] memory _gauges, address _claimFor) external;
/// @notice claim specific reward tokens from LP gauges
function claimRewardTokens(address[] memory _gauges, address[][] memory _tokens) external;
/// @notice claim specific reward tokens from LP gauges for a given address
function claimRewardTokensFor(address[] memory _gauges, address[][] memory _tokens, address _claimFor) external;
/// @notice claim bribes rewards given a TokenID
function claimBribes(address[] memory _bribes, address[][] memory _tokens, uint256 _tokenId) external;
/// @notice claim fees rewards given a TokenID
function claimFees(address[] memory _fees, address[][] memory _tokens, uint256 _tokenId) external;
/// @notice claim bribes rewards given an address
function claimBribes(address[] memory _bribes, address[][] memory _tokens) external;
/// @notice claim fees rewards given an address
function claimFees(address[] memory _fees, address[][] memory _tokens) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
/// @title IVoterV5_GaugeLogic
interface IVoterV5_GaugeLogic is IERC165 {
function createGauge(
address _pool,
uint256 _gaugeType
) external returns (address _gauge, address _internal_bribe, address _external_bribe);
function isValidGaugeType(uint256 _gaugeType) external pure returns (bool);
function MAX_GAUGE_TYPE() external pure returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVoterV5_GaugeLogic} from "./VoterV5_GaugeLogic.sol";
import {IVoterV5_ClaimHelper} from "./IVoterV5_ClaimHelper.sol";
import {IBribe} from "./IBribe.sol";
import {IGauge} from "../interfaces/IGauge.sol";
import {IOptionTokenV3} from "../OptionToken/IOptionTokenV3.sol";
import {IMinter} from "../interfaces/IMinter.sol";
import {IPermissionsRegistry} from "../interfaces/IPermissionsRegistry.sol";
import {IVotingEscrowV2} from "./VotingEscrow/IVotingEscrowV2.sol";
/// @title IVoterV5_Logic
/// @notice Interface to manage the functionality of the VoterV5 contract
/// @custom:version 2.0.0
/// - Replace addFactory, removeFactory, replaceFactory with setFactory to support GaugeType enum
interface IVoterV5_Logic is IVoterV5_ClaimHelper {
// Initialization
function initialize(
address __ve,
address _pairFactory,
address _gaugeFactory,
address _bribes,
address _gaugeLogic,
string memory _protocolName
) external;
function _init(address[] memory _tokens, address _permissionsRegistry, address _minter, address _oToken) external;
// Role Management
function setVoteDelay(uint256 _delay) external;
function setMinter(address _minter) external;
function setOptionsToken(address _oToken) external;
function refreshApprovals(uint256 start, uint256 finish, address _oldOtoken) external;
function setGaugeDepositor(address _depositor, bool _enabled) external;
function setBribeFactory(address _bribeFactory) external;
function setPermissionsRegistry(address _permissionRegistry) external;
function setNewBribes(address _gauge, address _internal, address _external) external;
function setInternalBribeFor(address _gauge, address _internal) external;
function setExternalBribeFor(address _gauge, address _external) external;
function setFactory(uint256 _gaugeType, address _pairFactory, address _gaugeFactory) external;
// Governance
function updateWhitelistToken(address[] memory _tokens, bool _whitelist) external;
function updateWhitelistPool(address[] memory _pools, bool _whitelist) external;
function killGauge(address _gauge) external;
function reviveGauge(address _gauge) external;
// User Interaction
function reset() external;
function poke() external;
function vote(address[] calldata _poolVote, uint256[] calldata _weights) external;
// Gauge Management
function createGauges(
address[] memory _pool,
uint256[] memory _gaugeTypes
) external returns (address[] memory, address[] memory, address[] memory);
function createGauge(
address _pool,
uint256 _gaugeType
) external returns (address _gauge, address _internal_bribe, address _external_bribe);
// View Functions
function length() external view returns (uint256);
function poolVoteLength(address voter) external view returns (uint256);
function factories() external view returns (address[] memory);
function factoryLength() external view returns (uint256);
function gaugeFactories() external view returns (address[] memory);
function gaugeFactoriesLength() external view returns (uint256);
function weights(address _pool) external view returns (uint256);
function weightsAt(address _pool, uint256 _time) external view returns (uint256);
function totalWeight() external view returns (uint256);
function totalWeightAt(uint256 _time) external view returns (uint256);
function _epochTimestamp() external view returns (uint256);
function ve() external view returns (address);
// Distribution
function notifyRewardAmount(uint256 amount) external;
function distributeFees(address[] memory _gauges) external;
function distributeAll() external;
function distribute(uint256 start, uint256 finish) external;
function distribute(address[] memory _gauges) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVoterV5_GaugeLogic} from "./IVoterV5_GaugeLogic.sol";
/// @title IVoterV5_Storage
/// @notice Interface for accessing public and external variables of the VoterV5_Storage contract
interface IVoterV5_Storage {
/// @notice Returns the address of the ve token
function _ve() external view returns (address);
/// @notice Returns the address of the base token
function base() external view returns (address);
/// @notice Returns the address of the option token
function oToken() external view returns (address);
/// @notice Returns the address of the bribe factory
function bribefactory() external view returns (address);
/// @notice Returns the address of the minter
function minter() external view returns (address);
/// @notice Returns the address of the permission registry
function permissionRegistry() external view returns (address);
/// @notice Returns the address of a pool at a given index
/// @param index The index of the pool in the pools array
function pools(uint256 index) external view returns (address);
/// @notice Returns the global gauge index
function index() external view returns (uint256);
/// @notice Returns the delay between votes in seconds
function VOTE_DELAY() external view returns (uint256);
/// @notice Returns the maximum vote delay allowed
function MAX_VOTE_DELAY() external view returns (uint256);
/// @notice Returns the claimable amount for a given account
/// @param account The address of the account
function claimable(address account) external view returns (uint256);
/// @notice Returns the gauge address for a given pool
/// @param pool The address of the pool
function gauges(address pool) external view returns (address);
/// @notice Returns the last distribution timestamp for a given gauge
/// @param gauge The address of the gauge
function gaugesDistributionTimestamp(address gauge) external view returns (uint256);
/// @notice Returns the pool address for a given gauge
/// @param gauge The address of the gauge
function poolForGauge(address gauge) external view returns (address);
/// @notice Returns the internal bribe address for a given gauge
/// @param gauge The address of the gauge
function internal_bribes(address gauge) external view returns (address);
/// @notice Returns the external bribe address for a given gauge
/// @param gauge The address of the gauge
function external_bribes(address gauge) external view returns (address);
/// @notice Returns the votes for a given NFT and pool
/// @param nft The address of the NFT
/// @param pool The address of the pool
function votes(address nft, address pool) external view returns (uint256);
/// @notice Returns the pool address at a given index for a given NFT
/// @param nft The address of the NFT
/// @param index The index of the pool in the poolVote array
function poolVote(address nft, uint256 index) external view returns (address);
/// @notice Returns the timestamp of the last vote for a given NFT
/// @param nft The address of the NFT
function lastVoted(address nft) external view returns (uint256);
/// @notice Returns whether a given address is a gauge
/// @param gauge The address of the gauge
function isGauge(address gauge) external view returns (bool);
/// @notice Returns whether a given token is whitelisted
/// @param token The address of the token
function isWhitelisted(address token) external view returns (bool);
/// @notice Returns whether a given pool is whitelisted
/// @param token The address of the pool token
function isWhitelistedPool(address token) external view returns (bool);
/// @notice Returns whether a given gauge is alive
/// @param gauge The address of the gauge
function isAlive(address gauge) external view returns (bool);
/// @notice Returns the factory status of a given address
/// @param factory The address of the factory
function isFactory(address factory) external view returns (uint8);
/// @notice Returns whether a given address is a gauge factory
/// @param gaugeFactory The address of the gauge factory
/// @dev in 5.4.1, this returns a uint8 instead of a bool
/// This allows the same gauge factory to be used across multiple gauge types.
/// Storage-safe: bool and uint8 both occupy 1 byte, existing true/false values
/// become 1/0 counters seamlessly during upgrades.
function isGaugeFactory(address gaugeFactory) external view returns (uint8);
/// @notice Returns whether a given address is a gauge depositor
/// @param gaugeFactory The address of the gauge factory
function isGaugeDepositor(address gaugeFactory) external view returns (bool);
/// @notice Returns the address of the gauge logic contract
function gaugeLogic() external view returns (IVoterV5_GaugeLogic);
/// @notice Returns the epoch timestamp when a given gauge was killed
/// @param gauge The address of the gauge
function gaugeKilledEpoch(address gauge) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVoterV5_Logic} from "../VoterV5/IVoterV5_Logic.sol";
import {IVoterV5_Storage} from "../VoterV5/IVoterV5_Storage.sol";
/// @title IVoterV5
/// @dev This interface is a composition of the IVoterV5_Logic and IVoterV5_Storage interfaces.
/// By composing these two interfaces, any contract that integrates IVoterV5 gains access to both the logic operations
/// and storage getters defined in IVoterV5_Logic and IVoterV5_Storage respectively. This design also
/// circumvents the need for the VoterV5_GaugeLogic to be abstract, as it separates the concerns of
/// logic handling and state management into distinct interfaces.
interface IVoterV5 is IVoterV5_Logic, IVoterV5_Storage {}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVoterV5_GaugeLogic, IERC165} from "./IVoterV5_GaugeLogic.sol";
import {IERC20} from "../interfaces/IERC20.sol";
import {IAlgebraFactory} from "@cryptoalgebra/v1-core/contracts/interfaces/IAlgebraFactory.sol";
import {IBribeFactory} from "../interfaces/IBribeFactory.sol";
import {IGaugeFactory} from "../interfaces/IGaugeFactory.sol";
import {IPermissionsRegistry} from "../interfaces/IPermissionsRegistry.sol";
import {IHypervisor} from "../interfaces/IHypervisor.sol";
import {IMultiPositionManager} from "../dex/uniswap-v4/IMultiPositionManager.sol";
import {IPairFactory} from "../interfaces/IPairFactory.sol";
import {IPairInfo} from "../interfaces/IPairInfo.sol";
import {VoterV5_Storage} from "./VoterV5_Storage.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {UniswapV3Helper} from "../libraries/UniswapV3Helper.sol";
/**
* @notice Table showing GaugeType configurations
* ┌──────────────────────┬──────────────────────────┬────────────────────────┐
* │ GaugeType │ DEX Factory │ Gauge Factory │
* ├──────────────────────┼──────────────────────────┼────────────────────────┤
* │ PAIR_CLASSIC │ PairFactoryUpgradable │ GaugeFactoryV2 │
* │ ALM_ALGEBRA_V1 │ AlgebraFactory │ GaugeFactoryV2_CL │
* │ ALM_ICHI_UNISWAP_V3 │ UniswapV3Factory │ GaugeFactoryV2_CL │
* │ ALM_GAMMA_UNISWAP_V4 │ UniswapV4PoolManager │ GaugeFactoryV2_CL │
* └──────────────────────┴──────────────────────────┴────────────────────────┘
*/
/// @notice Enum representing different gauge types
/// @dev Make sure to use the correct gaugeType or gauge creation will fail
enum GaugeType {
PAIR_CLASSIC, // 0: Classic Stable/Volatile pair
ALM_ALGEBRA_V1, // 1: Ichi/Gamma concentrated liquidity for Algebra
ALM_ICHI_UNISWAP_V3, // 2: Ichi concentrated liquidity for UniswapV3
ALM_GAMMA_UNISWAP_V4 // 3: Gamma concentrated liquidity for UniswapV4
}
/// @title VoterV5_GaugeLogic
/// @notice This contract contains the logic for creating gauges in the VoterV5 system. It is used to save contract
/// size in VoterV5 by separating out expensive logic.
/// @dev This contract MUST be called from VoterV5 through delegatecall().
contract VoterV5_GaugeLogic is IVoterV5_GaugeLogic, VoterV5_Storage, ERC165 {
/**
* @notice changelog
* - 1.1.0: Add Support for UniswapV3 and UniswapV4 Gauges
*/
string public constant VERSION_GAUGE_LOGIC = "1.1.0";
/// @notice Maximum valid gauge type enum value
uint256 public constant MAX_GAUGE_TYPE = uint256(type(GaugeType).max);
/// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IVoterV5_GaugeLogic).interfaceId || super.supportsInterface(interfaceId);
}
/// @notice Validate if gauge type is within enum bounds (pure function)
function isValidGaugeType(uint256 _gaugeType) public pure returns (bool) {
return _gaugeType <= MAX_GAUGE_TYPE;
}
struct _CreateGauge_LocalVars {
address tokenA;
address tokenB;
address rewardToken;
address dexFactory;
address gaugeFactory;
address internal_bribe;
address external_bribe;
bool isPair;
}
/// @notice create a gauge
/// @param _pool LP address, which varies based on gauge type:
/// - For PAIR_CLASSIC: The actual pair contract address (similar to UniswapV2 pairs)
/// - For ALM strategies (GAMMA): The strategy contract address that manages the position
/// @param _gaugeType enum GaugeType, the type of gauge to create. The associated factory (_factories[_gaugeType])
/// represents different things based on type:
/// - For PAIR_CLASSIC: Deploy a Gauge for Solidly Classic Pairs
/// - For ALM_GAMMA_ALGEBRA: Deploy a Gauge for Gamma + Algebra ALM strategies
/// - For ALM_GAMMA_UNISWAP_V3: Deploy a Gauge for Gamma + UniswapV3 ALM strategies
/// - For ALM_GAMMA_UNISWAP_V4: Deploy a Gauge for Gamma + UniswapV4 ALM strategies
function createGauge(
address _pool,
uint256 _gaugeType
) external override returns (address _gauge, address _internal_bribe, address _external_bribe) {
// Enhanced validation
require(_gaugeType <= MAX_GAUGE_TYPE, "Invalid gauge type enum");
require(_gaugeType < _factories.length, "Gauge type not configured");
require(gauges[_pool] == address(0), "!exists");
require(_pool.code.length > 0, "!contract");
_CreateGauge_LocalVars memory vars;
vars.dexFactory = _factories[_gaugeType];
vars.gaugeFactory = _gaugeFactories[_gaugeType];
require(vars.dexFactory != address(0), "dex factory not set");
require(vars.gaugeFactory != address(0), "gauge factory not set");
(vars.tokenA) = IPairInfo(_pool).token0();
(vars.tokenB) = IPairInfo(_pool).token1();
if (_gaugeType == uint256(GaugeType.PAIR_CLASSIC)) {
/**
* @dev Classic Stable/Volatile pair
*/
vars.isPair = IPairFactory(vars.dexFactory).isPair(_pool);
} else if (_gaugeType == uint256(GaugeType.ALM_ALGEBRA_V1)) {
/**
* @dev ICHI/GAMMA + Algebra ALM strategy
*/
address _pool_factory = IAlgebraFactory(vars.dexFactory).poolByPair(vars.tokenA, vars.tokenB);
address _pool_hyper = IHypervisor(_pool).pool();
require(_pool_hyper == _pool_factory, "wrong tokens");
vars.isPair = true;
} else if (_gaugeType == uint256(GaugeType.ALM_ICHI_UNISWAP_V3)) {
/**
* @dev ICHI + Uniswap V3 ALM strategy
*/
address _pool_hyper = IHypervisor(_pool).pool();
bool isValidPool = UniswapV3Helper.validatePoolExists(vars.dexFactory, vars.tokenA, vars.tokenB, _pool_hyper);
require(isValidPool, "wrong tokens");
vars.isPair = true;
} else if (_gaugeType == uint256(GaugeType.ALM_GAMMA_UNISWAP_V4)) {
/**
* @dev GAMMA + Uniswap V4 ALM strategy
*/
address _poolManager = IMultiPositionManager(_pool).poolManager();
require(_poolManager == vars.dexFactory, "!poolManager");
/// @dev IMultiPositionManager supports token0() and token1()
// vars.tokenA = address(IMultiPositionManager(_pool).token0());
// vars.tokenB = address(IMultiPositionManager(_pool).token1());
vars.isPair = true;
}
/// @dev Gov can create for any pool, even non-lynex pairs
if (!IPermissionsRegistry(permissionRegistry).hasRole("GOVERNANCE", msg.sender)) {
require(vars.isPair, "!_pool");
if(_gaugeType != uint256(GaugeType.PAIR_CLASSIC)) {
/// @dev Assume this is an ALM strategy
require(isWhitelistedPool[_pool], "Only whitelisted strategies");
}
if(_gaugeType != uint256(GaugeType.ALM_GAMMA_UNISWAP_V4)) {
/// @dev UniswapV4 supports native tokens at address(0)
require(isWhitelisted[vars.tokenA], "!whitelistedA");
require(vars.tokenA != address(0), "!pair.tokenA");
}
require(isWhitelisted[vars.tokenB], "!whitelistedB");
require(vars.tokenB != address(0), "!pair.tokenB");
}
/// -----------------------------------------------------------------------
/// Setup Bribes
/// -----------------------------------------------------------------------
// create internal and external bribe
address _owner = IPermissionsRegistry(permissionRegistry).teamMultisig();
string memory _type = string.concat(protocolName, " LP Fees: ", IERC20(_pool).symbol());
vars.internal_bribe = IBribeFactory(bribefactory).createBribe(_owner, vars.tokenA, vars.tokenB, _type);
_type = string.concat(protocolName, " Bribes: ", IERC20(_pool).symbol());
vars.external_bribe = IBribeFactory(bribefactory).createBribe(_owner, vars.tokenA, vars.tokenB, _type);
/// -----------------------------------------------------------------------
/// Setup Gauge
/// -----------------------------------------------------------------------
vars.rewardToken = oToken != address(0) ? oToken : base;
_gauge = IGaugeFactory(vars.gaugeFactory).createGaugeV2(
vars.rewardToken,
_ve,
_pool,
address(this), // distribution address
vars.internal_bribe,
vars.external_bribe,
vars.isPair
);
// approve spending for protocol token, this is set back to zero if gauge is killed
IERC20(vars.rewardToken).approve(_gauge, type(uint256).max);
/// -----------------------------------------------------------------------
/// Save Gauge Data
/// -----------------------------------------------------------------------
internal_bribes[_gauge] = vars.internal_bribe;
external_bribes[_gauge] = vars.external_bribe;
gauges[_pool] = _gauge;
poolForGauge[_gauge] = _pool;
isGauge[_gauge] = true;
isAlive[_gauge] = true;
pools.push(_pool);
// update supplyIndex (gaugeRewardsPerVoteWeight) gauge => index (globalRewardsPerVoteWeight)
supplyIndex[_gauge] = index; // new gauges are set to the default global state
return (_gauge, vars.internal_bribe, vars.external_bribe);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVoterV5_Storage} from "./IVoterV5_Storage.sol";
import {IVoterV5_GaugeLogic} from "./IVoterV5_GaugeLogic.sol";
import {IVersionable} from "../interfaces/IVersionable.sol";
/// @title VoterV5_Storage
/// @notice This contract contains the storage variables for VoterV5.
/// @dev This contract is used to ensure both VoterV5 and VoterV5_GaugeLogic have access to the same storage variables
/// in the correct slots. They MUST both extend this.
/// - The storage layout for all version 5.x contracts MUST remain compatible for upgradeability.
contract VoterV5_Storage is IVoterV5_Storage, IVersionable {
/// @notice The current version of the contract
/// - 5.2.0: Add "protocolName", refactor to "oToken"
/// - 5.2.1: Change from require to revert CustomErrors
/// - 5.3.1: Add claim helper functions in VoterV5
/// - 5.4.0: GaugeType improvement, use setFactory to configure factories with GaugeType
/// - 5.4.1: Change isGaugeFactory mapping from bool to uint8 for reference counting.
/// This allows the same gauge factory to be used across multiple gauge types.
/// Storage-safe: bool and uint8 both occupy 1 byte, existing true/false values
/// become 1/0 counters seamlessly during upgrades.
string public constant override VERSION = "5.4.1";
bool internal initflag;
address public _ve; // ve token that governs these contracts
address[] internal _factories; // Array with all the pair factories
address public base; // underlying protocol token
address public oToken; // option protocol token
address[] internal _gaugeFactories; // array with all the gauge factories
address public bribefactory; // bribe factory (internal and external)
address public minter; // minter mints protocol tokens each epoch
address public permissionRegistry; // registry to check accesses
address[] public pools; // all pools viable for incentives
uint256 public index; // (globalRewardsPerVoteWeight) gauge index
uint256 internal DURATION; // rewards are released over 1 epoch
uint256 public VOTE_DELAY; // delay between votes in seconds
uint256 public MAX_VOTE_DELAY; // Max vote delay allowed
mapping(address => uint256) internal supplyIndex; /// (gaugeRewardsPerVoteWeight) gauge => index
mapping(address => uint256) public claimable; /// @dev deprecated, but leaving for upgradeability
mapping(address => address) public gauges; // pool => gauge
mapping(address => uint256) public gaugesDistributionTimestamp; // gauge => last Distribution Time
mapping(address => address) public poolForGauge; // gauge => pool
mapping(address => address) public internal_bribes; // gauge => internal bribe (only fees)
mapping(address => address) public external_bribes; // gauge => external bribe (real bribes)
mapping(address => mapping(address => uint256)) public votes; // nft => pool => votes
mapping(address => address[]) public poolVote; // nft => pools
mapping(uint256 => mapping(address => uint256)) internal weightsPerEpoch; // timestamp => pool => weights
mapping(uint256 => uint256) internal totalWeightsPerEpoch; // timestamp => total weights
mapping(address => uint256) public lastVoted; // nft => timestamp of last vote
mapping(address => bool) public isGauge; // gauge => boolean [is a gauge?]
mapping(address => bool) public isWhitelisted; // token => boolean [is an allowed token?]
mapping(address => bool) public isWhitelistedPool; // token => boolean [is an allowed token?]
mapping(address => bool) public isAlive; // gauge => boolean [is the gauge alive?]
mapping(address => uint8) public isFactory; // factory => boolean [the pair factory exists?]
mapping(address => uint8) public isGaugeFactory; // g.factory=> usage count [how many gauge types use this factory]
mapping(address => bool) public isGaugeDepositor; // g.factory=> boolean [the gauge factory exists?]
IVoterV5_GaugeLogic public gaugeLogic; // gauge logic contract
/**
* @dev May 2024: The state variables below this have been added in VoterV5 and the gap variable reduced accordingly.
*/
mapping(address => uint256) public gaugeKilledEpoch; // gauge => timestamp [epoch when gauge was killed]
string public protocolName; // name of the protocol for gauge creation
// Reserved space for future state variables
uint256[48] private __gap;
}// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
/**
* @title Non-Fungible Vesting Token Standard.
* @notice A non-fungible token standard used to vest ERC-20 tokens over a vesting release curve
* scheduled using timestamps.
* @dev Because this standard relies on timestamps for the vesting schedule, it's important to keep track of the
* tokens claimed per Vesting NFT so that a user cannot withdraw more tokens than allotted for a specific Vesting NFT.
* @custom:interface-id 0xbd3a202b
*/
interface IERC5725Upgradeable is IERC721Upgradeable {
/**
* This event is emitted when the payout is claimed through the claim function.
* @param tokenId the NFT tokenId of the assets being claimed.
* @param recipient The address which is receiving the payout.
* @param claimAmount The amount of tokens being claimed.
*/
event PayoutClaimed(uint256 indexed tokenId, address indexed recipient, uint256 claimAmount);
/**
* This event is emitted when an `owner` sets an address to manage token claims for all tokens.
* @param owner The address setting a manager to manage all tokens.
* @param spender The address being permitted to manage all tokens.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
event ClaimApprovalForAll(address indexed owner, address indexed spender, bool approved);
/**
* This event is emitted when an `owner` sets an address to manage token claims for a `tokenId`.
* @param owner The `owner` of `tokenId`.
* @param spender The address being permitted to manage a tokenId.
* @param tokenId The unique identifier of the token being managed.
* @param approved A boolean indicating whether the spender is approved to claim for `tokenId`.
*/
event ClaimApproval(address indexed owner, address indexed spender, uint256 indexed tokenId, bool approved);
/**
* @notice Claim the pending payout for the NFT.
* @dev MUST grant the claimablePayout value at the time of claim being called to `msg.sender`.
* MUST revert if not called by the token owner or approved users.
* MUST emit PayoutClaimed.
* SHOULD revert if there is nothing to claim.
* @param tokenId The NFT token id.
*/
function claim(uint256 tokenId) external;
/**
* @notice Number of tokens for the NFT which have been claimed at the current timestamp.
* @param tokenId The NFT token id.
* @return payout The total amount of payout tokens claimed for this NFT.
*/
function claimedPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Number of tokens for the NFT which can be claimed at the current timestamp.
* @dev It is RECOMMENDED that this is calculated as the `vestedPayout()` subtracted from `payoutClaimed()`.
* @param tokenId The NFT token id.
* @return payout The amount of unlocked payout tokens for the NFT which have not yet been claimed.
*/
function claimablePayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Total amount of tokens which have been vested at the current timestamp.
* This number also includes vested tokens which have been claimed.
* @dev It is RECOMMENDED that this function calls `vestedPayoutAtTime`
* with `block.timestamp` as the `timestamp` parameter.
* @param tokenId The NFT token id.
* @return payout Total amount of tokens which have been vested at the current timestamp.
*/
function vestedPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice Total amount of vested tokens at the provided timestamp.
* This number also includes vested tokens which have been claimed.
* @dev `timestamp` MAY be both in the future and in the past.
* Zero MUST be returned if the timestamp is before the token was minted.
* @param tokenId The NFT token id.
* @param timestamp The timestamp to check on, can be both in the past and the future.
* @return payout Total amount of tokens which have been vested at the provided timestamp.
*/
function vestedPayoutAtTime(uint256 tokenId, uint256 timestamp) external view returns (uint256 payout);
/**
* @notice Number of tokens for an NFT which are currently vesting.
* @dev The sum of vestedPayout and vestingPayout SHOULD always be the total payout.
* @param tokenId The NFT token id.
* @return payout The number of tokens for the NFT which are vesting until a future date.
*/
function vestingPayout(uint256 tokenId) external view returns (uint256 payout);
/**
* @notice The start and end timestamps for the vesting of the provided NFT.
* MUST return the timestamp where no further increase in vestedPayout occurs for `vestingEnd`.
* @param tokenId The NFT token id.
* @return vestingStart The beginning of the vesting as a unix timestamp.
* @return vestingEnd The ending of the vesting as a unix timestamp.
*/
function vestingPeriod(uint256 tokenId) external view returns (uint256 vestingStart, uint256 vestingEnd);
/**
* @notice Token which is used to pay out the vesting claims.
* @param tokenId The NFT token id.
* @return token The token which is used to pay out the vesting claims.
*/
function payoutToken(uint256 tokenId) external view returns (address token);
/**
* @notice Sets a global `operator` with permission to manage all tokens owned by the current `msg.sender`.
* @param operator The address to let manage all tokens.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
function setClaimApprovalForAll(address operator, bool approved) external;
/**
* @notice Sets a tokenId `operator` with permission to manage a single `tokenId` owned by the `msg.sender`.
* @param operator The address to let manage a single `tokenId`.
* @param tokenId the `tokenId` to be managed.
* @param approved A boolean indicating whether the spender is approved to claim for all tokens.
*/
function setClaimApproval(address operator, bool approved, uint256 tokenId) external;
/**
* @notice Returns true if `owner` has set `operator` to manage all `tokenId`s.
* @param owner The owner allowing `operator` to manage all `tokenId`s.
* @param operator The address who is given permission to spend tokens on behalf of the `owner`.
*/
function isClaimApprovedForAll(address owner, address operator) external view returns (bool isClaimApproved);
/**
* @notice Returns the operating address for a `tokenId`.
* If `tokenId` is not managed, then returns the zero address.
* @param tokenId The NFT `tokenId` to query for a `tokenId` manager.
*/
function getClaimApproved(uint256 tokenId) external view returns (address operator);
}
interface IERC5725_ExtendedApproval is IERC5725Upgradeable {
/**
* @notice Returns true if `operator` is allowed to transfer the `tokenId` NFT.
* @param operator The address to check if it is approved for the transfer
* @param tokenId The token id to check if the operator is approved for
*/
function isApprovedOrOwner(address operator, uint tokenId) external view returns (bool);
/**
* @notice Returns true if `operator` is allowed to claim for the provided tokenId
* @param operator The address to check if it is approved for the claim or owner of the token
* @param tokenId The token id to check if the operator is approved for
*/
function isApprovedClaimOrOwner(address operator, uint256 tokenId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (governance/utils/IVotes.sol)
pragma solidity ^0.8.0;
/**
* @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.
*
* _Available since v4.5._
*/
interface IVotes {
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/**
* @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
/**
* @dev Returns the current amount of votes that `account` has.
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*/
function getPastVotes(address account, uint256 timepoint) external view returns (uint256);
/**
* @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is
* configured to use block numbers, this will return the value at the end of the corresponding block.
*
* NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.
* Votes that have not been delegated are still part of total supply, even though they would not participate in a
* vote.
*/
function getPastTotalSupply(uint256 timepoint) external view returns (uint256);
/**
* @dev Returns the delegate that `account` has chosen.
*/
function delegates(address account) external view returns (address);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(address delegatee) external;
/**
* @notice Removed from the interface to avoid signature conflicts.
* @dev Delegates votes from signer to `delegatee`.
*/
// function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {IVotes} from "./interfaces/IVotes.sol";
import {Checkpoints} from "./libraries/Checkpoints.sol";
import {IERC5725_ExtendedApproval} from "./erc5725/IERC5725Upgradeable.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import {IERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/IERC721EnumerableUpgradeable.sol";
import {IVersionable} from "../../interfaces/IVersionable.sol";
/**
* @title Voting Escrow V2 Interface for Upgrades
*/
interface IVotingEscrowV2 is IVotes, IERC5725_ExtendedApproval, IERC721EnumerableUpgradeable, IVersionable {
struct LockDetails {
uint256 amount; /// @dev amount of tokens locked
uint256 startTime; /// @dev when locking started
uint256 endTime; /// @dev when locking ends
bool isPermanent; /// @dev if its a permanent lock
}
/// -----------------------------------------------------------------------
/// Events
/// -----------------------------------------------------------------------
event SupplyUpdated(uint256 oldSupply, uint256 newSupply);
/// @notice Lock events
event LockCreated(uint256 indexed tokenId, address indexed to, uint256 value, uint256 unlockTime, bool isPermanent);
event LockUpdated(uint256 indexed tokenId, uint256 value, uint256 unlockTime, bool isPermanent);
event LockMerged(
uint256 indexed fromTokenId,
uint256 indexed toTokenId,
uint256 totalValue,
uint256 unlockTime,
bool isPermanent
);
event LockSplit(uint256[] splitWeights, uint256 indexed _tokenId);
event LockDurationExtended(uint256 indexed tokenId, uint256 newUnlockTime, bool isPermanent);
event LockAmountIncreased(uint256 indexed tokenId, uint256 value);
event UnlockPermanent(uint256 indexed tokenId, address indexed sender, uint256 unlockTime);
/// @notice Delegate events
event LockDelegateChanged(
uint256 indexed tokenId,
address indexed delegator,
address fromDelegate,
address indexed toDelegate
);
/// -----------------------------------------------------------------------
/// Errors
/// -----------------------------------------------------------------------
error AlreadyVoted();
error InvalidNonce();
error InvalidDelegatee();
error InvalidSignature();
error InvalidSignatureS();
error InvalidWeights();
error LockDurationNotInFuture();
error LockDurationTooLong();
error LockExpired();
error LockNotExpired();
error LockHoldsValue();
error LockModifiedDelay();
error NotPermanentLock();
error PermanentLock();
error PermanentLockMismatch();
error SameNFT();
error SignatureExpired();
error ZeroAmount();
error NotLockOwner();
function supply() external view returns (uint);
function token() external view returns (IERC20Upgradeable);
function totalNftsMinted() external view returns (uint256);
function balanceOfNFT(uint256 _tokenId) external view returns (uint256);
function balanceOfNFTAt(uint256 _tokenId, uint256 _timestamp) external view returns (uint256);
function delegates(uint256 tokenId, uint48 timestamp) external view returns (address);
function lockDetails(uint256 tokenId) external view returns (LockDetails calldata);
function getPastEscrowPoint(
uint256 _tokenId,
uint256 _timePoint
) external view returns (Checkpoints.Point memory, uint48);
function getFirstEscrowPoint(uint256 _tokenId) external view returns (Checkpoints.Point memory, uint48);
function checkpoint() external;
function increaseAmount(uint256 _tokenId, uint256 _value) external;
function createLockFor(
uint256 _value,
uint256 _lockDuration,
address _to,
bool _permanent
) external returns (uint256);
function createDelegatedLockFor(
uint256 _value,
uint256 _lockDuration,
address _to,
address _delegatee,
bool _permanent
) external returns (uint256);
function split(uint256[] memory _weights, uint256 _tokenId) external;
function merge(uint256 _from, uint256 _to) external;
function burn(uint256 _tokenId) external;
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// This file was derived from OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/Checkpoints.sol)
pragma solidity 0.8.13;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
/**
* @dev This library defines the `Trace*` struct, for checkpointing values as they change at different points in
* time, and later looking up past values by block number. See {Votes} as an example.
*
* To create a history of checkpoints define a variable type `Checkpoints.Trace*` in your contract, and store a new
* checkpoint for the current transaction block using the {push} function.
*/
library Checkpoints {
struct Trace {
Checkpoint[] _checkpoints;
}
/**
* @dev Struct to keep track of the voting power over time.
*/
struct Point {
/// @dev The voting power at a specific time
/// - MUST never be negative.
int128 bias;
/// @dev The rate at which the voting power decreases over time.
int128 slope;
/// @dev The value of tokens which do not decrease over time, representing permanent voting power
/// - MUST never be negative.
int128 permanent;
}
struct Checkpoint {
uint48 _key;
Point _value;
}
/**
* @dev A value was attempted to be inserted on a past checkpoint.
*/
error CheckpointUnorderedInsertions();
/**
* @dev Pushes a (`key`, `value`) pair into a Trace so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the
* library.
*/
function push(Trace storage self, uint48 key, Point memory value) internal returns (Point memory, Point memory) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace storage self, uint48 key) internal view returns (Point memory) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? blankPoint() : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(
Trace storage self,
uint48 key
) internal view returns (bool exists, uint48 _key, Point memory _value) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
exists = pos != 0;
_value = exists ? _unsafeAccess(self._checkpoints, pos - 1)._value : blankPoint();
_key = exists ? _unsafeAccess(self._checkpoints, pos - 1)._key : 0;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(
Trace storage self,
uint48 key
) internal view returns (bool exists, uint48 _key, Point memory _value) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
exists = pos != 0;
_value = exists ? _unsafeAccess(self._checkpoints, pos - 1)._value : blankPoint();
_key = exists ? _unsafeAccess(self._checkpoints, pos - 1)._key : 0;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace storage self) internal view returns (Point memory) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? blankPoint() : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(
Trace storage self
) internal view returns (bool exists, uint48 _key, Point memory _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, blankPoint());
} else {
Checkpoint memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function firstCheckpoint(
Trace storage self
) internal view returns (bool exists, uint48 _key, Point memory _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, blankPoint());
} else {
Checkpoint memory ckpt = _unsafeAccess(self._checkpoints, 0);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace storage self, uint48 pos) internal view returns (Checkpoint memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(
Checkpoint[] storage self,
uint48 key,
Point memory value
) private returns (Point memory, Point memory) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertions();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint({_key: key, _value: value}));
return (blankPoint(), value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(Checkpoint[] storage self, uint256 pos) private view returns (Checkpoint storage result) {
return self[pos];
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _realUnsafeAccess(
Checkpoint[] storage self,
uint256 pos
) private pure returns (Checkpoint storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
function blankPoint() internal pure returns (Point memory) {
return Point({bias: 0, slope: 0, permanent: 0});
}
struct TraceAddress {
CheckpointAddress[] _checkpoints;
}
struct CheckpointAddress {
uint48 _key;
address _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a TraceAddress so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the
* library.
*/
function push(TraceAddress storage self, uint48 key, address value) internal returns (address, address) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(TraceAddress storage self, uint48 key) internal view returns (address) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? address(0) : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(TraceAddress storage self, uint48 key) internal view returns (address) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? address(0) : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(TraceAddress storage self, uint48 key) internal view returns (address) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? address(0) : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(TraceAddress storage self) internal view returns (address) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? address(0) : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(
TraceAddress storage self
) internal view returns (bool exists, uint48 _key, address _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, address(0));
} else {
CheckpointAddress memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(TraceAddress storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(TraceAddress storage self, uint48 pos) internal view returns (CheckpointAddress memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(CheckpointAddress[] storage self, uint48 key, address value) private returns (address, address) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
CheckpointAddress memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertions();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(CheckpointAddress({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(CheckpointAddress({_key: key, _value: value}));
return (address(0), value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
CheckpointAddress[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
CheckpointAddress[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
CheckpointAddress[] storage self,
uint256 pos
) private pure returns (CheckpointAddress storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidPoolInterface","type":"error"},{"inputs":[{"internalType":"bool","name":"emergency","type":"bool"}],"name":"IsEmergency","type":"error"},{"inputs":[],"name":"NoBalances","type":"error"},{"inputs":[],"name":"OnlyAllowed","type":"error"},{"inputs":[],"name":"OnlyDistributor","type":"error"},{"inputs":[],"name":"PoolAlreadyRevoked","type":"error"},{"inputs":[],"name":"PoolDepositFailed","type":"error"},{"inputs":[],"name":"PoolNotEnabled","type":"error"},{"inputs":[],"name":"PoolWithdrawFailed","type":"error"},{"inputs":[],"name":"SameAddress","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"gauge","type":"address"},{"indexed":true,"internalType":"address","name":"pool","type":"address"}],"name":"CentralTokenPoolRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"claimed0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"claimed1","type":"uint256"}],"name":"ClaimFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"gauge","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"EmergencyActivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"gauge","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"EmergencyDeactivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":true,"internalType":"address","name":"rewardToken","type":"address"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"NotifyReward","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":"reward","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newDistribution","type":"address"}],"name":"SetDistribution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newRewarder","type":"address"}],"name":"SetRewarder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SweepWithdrawToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DISTRIBUTION","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_withdrawFromCentralPoolSafe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"activateEmergencyMode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"availableBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceWithLock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"centralTokenPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimFees","outputs":[{"internalType":"uint256","name":"claimed0","type":"uint256"},{"internalType":"uint256","name":"claimed1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"account","type":"address"}],"name":"depositTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"_lockDuration","type":"uint256"}],"name":"depositWithLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"rewardAddress","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergency","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"emergencyWithdrawAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"external_bribe","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gaugeRewarder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCentralTokenPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"},{"internalType":"address","name":"_ve","type":"address"},{"internalType":"address","name":"_stakeToken","type":"address"},{"internalType":"address","name":"_distribution","type":"address"},{"internalType":"bool","name":"_isForPair","type":"bool"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"internal_bribe","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isForPair","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isReward","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"lastEarn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardAddress","type":"address"}],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"left","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lockEnd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardAddress","type":"address"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"name":"notifyRewardAmount","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":[{"internalType":"address","name":"rewardAddress","type":"address"}],"name":"periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"periodFinishToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardToken","type":"address"}],"name":"removeRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokeCentralTokenPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardAddress","type":"address"}],"name":"rewardForDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"rewardAddress","type":"address"}],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewards","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_distribution","type":"address"}],"name":"setDistribution","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gaugeRewarder","type":"address"}],"name":"setGaugeRewarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakeToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stopEmergencyMode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"supported","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address","name":"to","type":"address"}],"name":"sweepTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAllAndHarvest","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b506143a7806100206000396000f3fe608060405234801561001057600080fd5b50600436106103da5760003560e01c80638150c86b1161020a578063c6c8f6b611610125578063e30c3978116100b8578063f301af4211610087578063f301af42146108cc578063f7c618c1146108df578063f97d2114146108f8578063fc5b5fda1461090b578063ffa1ad741461091e57600080fd5b8063e30c397814610888578063e574821314610899578063f1229777146108a6578063f2fde38b146108b957600080fd5b8063d294f093116100f4578063d294f09314610832578063da09d19d1461084f578063db2e21bc14610878578063de5f62681461088057600080fd5b8063c6c8f6b6146107f2578063c863657d14610805578063caa6fea414610818578063d00960101461082a57600080fd5b8063a0821be31161019d578063b4d8f1a61161016c578063b4d8f1a6146107a6578063b66503cf146107b9578063b6b55f25146107cc578063c00007b0146107df57600080fd5b8063a0821be31461074d578063a495e5b514610760578063b1534ecd1461078b578063b3aa527d1461079357600080fd5b80638da5cb5b116101d95780638da5cb5b146106e95780639843bafa146106fa57806399bcc0521461071a5780639ce43f901461072d57600080fd5b80638150c86b146106b5578063853828b6146106bd578063863e2442146106c557806386f9c23c146106d857600080fd5b80633d509c97116102fa57806370a082311161028d578063770f85711161025c578063770f85711461067f57806379ba5097146106875780637c91e4eb1461068f5780637f699015146106a257600080fd5b806370a082311461062857806370aff70f14610651578063715018a61461066457806376a0adf21461066c57600080fd5b80636265ff48116102c95780636265ff48146105cf578063638634ee146105e25780636e9852f2146105f55780637035ab98146105fd57600080fd5b80633d509c971461057e57806340e1950f146105915780634d5ce0381461059957806351ed6a30146105bc57600080fd5b8063211dc32d116103725780632e1a7d4d116103415780632e1a7d4d1461052557806331279d3d146105385780633ca068b61461054b5780633d18b9121461057657600080fd5b8063211dc32d146104b2578063221ca18c146104c557806323792279146104e55780632ce9aead1461050557600080fd5b806318160ddd116103ae57806318160ddd146104795780631be05289146104815780631c03e6cc1461048a5780631f933c2d1461049f57600080fd5b80628cc262146103df57806301ffc9a71461040557806303fbf83a1461043957806307723bf514610459575b600080fd5b6103f26103ed366004613ce8565b61094f565b6040519081526020015b60405180910390f35b610429610413366004613d05565b6001600160e01b03191663126be74f60e01b1490565b60405190151581526020016103fc565b610441610976565b6040516001600160a01b0390911681526020016103fc565b6103f2610467366004613ce8565b60d26020526000908152604090205481565b60d8546103f2565b6103f260ce5481565b61049d610498366004613ce8565b6109e9565b005b61049d6104ad366004613d2f565b610aa5565b6103f26104c0366004613d64565b610cab565b6103f26104d3366004613ce8565b60d16020526000908152604090205481565b6103f26104f3366004613ce8565b60db6020526000908152604090205481565b6103f2610513366004613ce8565b60d36020526000908152604090205481565b61049d610533366004613d9d565b610d54565b61049d610546366004613e21565b610d5d565b6103f2610559366004613d64565b60d660209081526000928352604080842090915290825290205481565b61049d610d95565b61049d61058c366004613ce8565b610e0a565b61049d610fa5565b6104296105a7366004613ce8565b60d06020526000908152604090205460ff1681565b60ca54610441906001600160a01b031681565b60dc54610441906001600160a01b031681565b6103f26105f0366004613ce8565b610fc4565b61049d610fe8565b6103f261060b366004613d64565b60d760209081526000928352604080842090915290825290205481565b6103f2610636366004613ce8565b6001600160a01b0316600090815260d9602052604090205490565b61049d61065f366004613ed5565b611009565b61049d611013565b6103f261067a366004613ce8565b611025565b61044161104c565b61049d61107d565b60cc54610441906001600160a01b031681565b61049d6106b0366004613ce8565b6110f4565b61049d6111a7565b61049d611307565b60cd54610441906001600160a01b031681565b60dc546001600160a01b0316610441565b6065546001600160a01b0316610441565b6103f2610708366004613ce8565b60da6020526000908152604090205481565b6103f2610728366004613ce8565b611320565b6103f261073b366004613ce8565b60d46020526000908152604090205481565b6103f261075b366004613ce8565b611391565b6103f261076e366004613d64565b60d560209081526000928352604080842090915290825290205481565b61049d6113fb565b61049d6107a1366004613f60565b611482565b61049d6107b4366004614032565b61172c565b61049d6107c7366004614032565b61177e565b61049d6107da366004613d9d565b6118de565b61049d6107ed366004613ce8565b6118e8565b61049d610800366004613d9d565b611988565b60cb54610441906001600160a01b031681565b60c95461042990610100900460ff1681565b61049d611af5565b61083a611b7c565b604080519283526020830191909152016103fc565b6103f261085d366004613ce8565b6001600160a01b0316600090815260d2602052604090205490565b61049d611ba0565b61049d611d07565b6097546001600160a01b0316610441565b60c9546104299060ff1681565b6103f26108b4366004613ce8565b611d7b565b61049d6108c7366004613ce8565b611e2c565b6104416108da366004613d9d565b611e9d565b60c954610441906201000090046001600160a01b031681565b61049d610906366004613ce8565b611ec7565b61049d61091936600461406c565b611f4c565b610942604051806040016040528060058152602001640322e342e360dc1b81525081565b6040516103fc9190614109565b60006109708260c960029054906101000a90046001600160a01b0316610cab565b92915050565b60cc5460405163ae21c4cb60e01b81523060048201526000916001600160a01b03169063ae21c4cb906024015b602060405180830381865afa1580156109c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e4919061413c565b905090565b6109f1612191565b6001600160a01b038116600090815260d0602052604090205460ff16610a65576001600160a01b0316600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b0319169091179055565b60405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b60448201526064015b60405180910390fd5b50565b336001600160a01b0384161480610acc575060c9546201000090046001600160a01b031633145b80610b3e575060cc54604051630f2312ab60e41b81523360048201526001600160a01b039091169063f2312ab090602401602060405180830381865afa158015610b1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3e9190614159565b610b8a5760405162461bcd60e51b815260206004820181905260248201527f4e6f7420616c6c6f77656420746f206465706f7369742077697468206c6f636b6044820152606401610a99565b610b9482846121eb565b6001600160a01b038316600090815260db60205260409020544210610bda576001600160a01b038316600090815260db6020908152604080832083905560da9091528120555b6001600160a01b038316600090815260da602052604081208054849290610c0290849061418c565b90915550506001600160a01b038316600090815260db602052604081205490610c2b834261418c565b905080821115610c895760405162461bcd60e51b815260206004820152602360248201527f5468652063757272656e74206c6f636b20656e64203e206e6577206c6f636b20604482015262195b9960ea1b6064820152608401610a99565b6001600160a01b03909416600090815260db6020526040902093909355505050565b6001600160a01b03808216600090815260d760209081526040808320938616835292905290812054670de0b6b3a764000090610ce684611d7b565b610cf091906141a4565b6001600160a01b038516600090815260d96020526040902054610d1391906141bb565b610d1d91906141da565b6001600160a01b03808416600090815260d66020908152604080832093881683529290522054610d4d919061418c565b9392505050565b610aa2816123bb565b336001600160a01b0383161480610d7e575060cc546001600160a01b031633145b610d8757600080fd5b610d918282612621565b5050565b6040805160018082528183019092526000916020808301908036833701905050905060c960029054906101000a90046001600160a01b031681600081518110610de057610de06141fc565b60200260200101906001600160a01b031690816001600160a01b031681525050610aa23382612621565b610e12612191565b6001600160a01b038116600090815260d0602052604090205460ff16610e665760405162461bcd60e51b8152602060048201526009602482015268139bdd08185919195960ba1b6044820152606401610a99565b610e6f306127bf565b60005b60cf54610e81906001906141a4565b811015610f8357816001600160a01b031660cf8281548110610ea557610ea56141fc565b6000918252602090912001546001600160a01b031603610f715760cf8054610ecf906001906141a4565b81548110610edf57610edf6141fc565b60009182526020909120015460cf80546001600160a01b039092169183908110610f0b57610f0b6141fc565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060cf805480610f4a57610f4a614212565b600082815260209020810160001990810180546001600160a01b0319169055019055610f83565b80610f7b81614228565b915050610e72565b506001600160a01b0316600090815260d060205260409020805460ff19169055565b610fad612191565b60ca54610fc2906001600160a01b03166128b5565b565b6001600160a01b038116600090815260d260205260408120546109709042906129a3565b33600090815260d96020526040902054611001906123bb565b610fc2610d95565b610d9182826121eb565b61101b612191565b610fc260006129b9565b60ce546001600160a01b038216600090815260d160205260408120549091610970916141bb565b60cc54604051637572079360e11b81523060048201526000916001600160a01b03169063eae40f26906024016109a3565b60975433906001600160a01b031681146110eb5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610a99565b610aa2816129b9565b6110fc612191565b6001600160a01b0381166111235760405163d92e233d60e01b815260040160405180910390fd5b60cc546001600160a01b03908116908216036111525760405163367558c360e01b815260040160405180910390fd5b60cc80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff085c57737528946971c505b4c9d6f7ca7ab5925b0cee78d8cb75797f36f3628906020015b60405180910390a150565b6111af612191565b60c9546201000090046001600160a01b0316600090815260d060205260408120805460ff191690556111df6129d2565b90506001600160a01b0381166112695760cc60009054906101000a90046001600160a01b03166001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611242573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611266919061413c565b90505b6001600160a01b038116600090815260d0602052604090205460ff166112dd576001600160a01b038116600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b03191690911790555b60c980546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b33600090815260d96020526040902054610fc2906123bb565b6001600160a01b038116600090815260d26020526040812054421061134757506000919050565b6001600160a01b038216600090815260d2602052604081205461136b9042906141a4565b6001600160a01b038416600090815260d16020526040902054909150610d4d90826141bb565b6001600160a01b038116600090815260db602052604081205442106113cc57506001600160a01b0316600090815260d9602052604090205490565b6001600160a01b038216600090815260da602090815260408083205460d99092529091205461097091906141a4565b611403612191565b60c954610100900460ff16151560000361143f5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60c9805461ff001916905560405142815230907fa30763a9bc0d8e121a6e721624965cae68010ece74128b4ae5b01b8dc22c00f8906020015b60405180910390a2565b61148a612191565b81518351146114e65760405162461bcd60e51b815260206004820152602260248201527f546f6b656e7320616e6420616d6f756e7473206c656e677468206d69736d61746044820152610c6d60f31b6064820152608401610a99565b60005b8351811015611726576000848281518110611506576115066141fc565b602090810291909101015160ca549091506001600160a01b03908116908216036115725760405162461bcd60e51b815260206004820152601860248201527f43616e6e6f74207377656570207374616b6520746f6b656e00000000000000006044820152606401610a99565b6000848381518110611586576115866141fc565b60209081029190910101516040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff9190614241565b9050818110156116515760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e2062616c616e63650000000000006044820152606401610a99565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb9061167f908890869060040161425a565b6020604051808303816000875af115801561169e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116c29190614159565b50826001600160a01b0316856001600160a01b03167f5bf76ef0db3550a96f76d3c13dfa002b5e1df9e4c4d65dce31f074c670b8b6488460405161170891815260200190565b60405180910390a3505050808061171e90614228565b9150506114e9565b50505050565b3330146117745760405162461bcd60e51b815260206004820152601660248201527513db9b1e481cd95b198b58d85b1b08185b1b1bddd95960521b6044820152606401610a99565b610d918282612a1c565b611786612ad3565b60c954610100900460ff1615156001036117c25760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60006117cd816127bf565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015611814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118389190614241565b905061184f6001600160a01b038516333086612b2c565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015611896573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ba9190614241565b90506118c682826141a4565b93506118d28585612b84565b505050610d9160018055565b610aa281336121eb565b60cc546001600160a01b0316331461191357604051631b8f6df360e01b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905060c960029054906101000a90046001600160a01b03168160008151811061195e5761195e6141fc565b60200260200101906001600160a01b031690816001600160a01b031681525050610d918282612621565b611990612ad3565b60c954610100900460ff166119c75760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33600090815260d960205260409020548111156119f757604051633fa92e1560e01b815260040160405180910390fd5b8060d854611a0591906141a4565b60d85533600090815260d9602052604081208054839290611a279084906141a4565b90915550611a37905060006127bf565b60cd546001600160a01b031615611aad5760cd54604051632bada09360e01b81526001600160a01b0390911690632bada09390611a7a903390859060040161425a565b600060405180830381600087803b158015611a9457600080fd5b505af1158015611aa8573d6000803e3d6000fd5b505050505b611ab73382613119565b60405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a2610aa260018055565b611afd612191565b60c954610100900460ff161515600103611b395760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60c9805461ff00191661010017905560405130907f774b57c3410c76d04ea4d51b0c15a9bac99b0e70f28fd88b53d702b5427fd318906114789042815260200190565b600080611b87612ad3565b611b8f61326e565b91509150611b9c60018055565b9091565b611ba8612ad3565b60c954610100900460ff16611bdf5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33600090815260d96020526040902054611c0c57604051633fa92e1560e01b815260040160405180910390fd5b33600090815260d9602052604090205460d854611c2a9082906141a4565b60d85533600090815260d960205260408120819055611c48906127bf565b60cd546001600160a01b031615611cbe5760cd54604051632bada09360e01b81526001600160a01b0390911690632bada09390611c8b903390859060040161425a565b600060405180830381600087803b158015611ca557600080fd5b505af1158015611cb9573d6000803e3d6000fd5b505050505b611cc83382613119565b60405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250610fc260018055565b60ca546040516370a0823160e01b8152336004820152610fc2916001600160a01b0316906370a0823190602401602060405180830381865afa158015611d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d759190614241565b336121eb565b600060d854600003611da357506001600160a01b0316600090815260d4602052604090205490565b60d8546001600160a01b038316600090815260d1602090815260408083205460d390925290912054611dd485610fc4565b611dde91906141a4565b611de891906141bb565b611dfa90670de0b6b3a76400006141bb565b611e0491906141da565b6001600160a01b038316600090815260d46020526040902054610970919061418c565b919050565b611e34612191565b609780546001600160a01b0383166001600160a01b03199091168117909155611e656065546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60cf8181548110611ead57600080fd5b6000918252602090912001546001600160a01b0316905081565b611ecf612191565b60cd546001600160a01b0390811690821603611efe5760405163367558c360e01b815260040160405180910390fd5b60cd80546001600160a01b0319166001600160a01b0383169081179091556040519081527fcf0aff36caea97f7ad632b334936cb196014c193ac1a790b578f12a70d9836db9060200161119c565b600054610100900460ff1615808015611f6c5750600054600160ff909116105b80611f865750303b158015611f86575060005460ff166001145b611fe95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a99565b6000805460ff19166001179055801561200c576000805461ff0019166101001790555b612014613667565b61201c613696565b60c9805460cb80546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560cc8054821688841617905561384060ce5561ff01600160b01b031990921662010000918a1691820260ff19908116919091178615151761ff001916909355600081815260d0602052604081208054909416600190811790945560cf80549485018155815260008051602061435283398151915290930180549092161790553390813b1561214157816001600160a01b0316636265ff486040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612130575060408051601f3d908101601f1916820190925261212d9181019061413c565b60015b156121385790505b612141816136c5565b50508015612189576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6065546001600160a01b03163314610fc25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a99565b6121f3612ad3565b60c954610100900460ff16151560010361222f5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b80612239816127bf565b6000831161225a5760405163162908e360e11b815260040160405180910390fd5b6001600160a01b038216600090815260d9602052604090205461227e90849061418c565b6001600160a01b038316600090815260d9602052604090205560d8546122a590849061418c565b60d85560cd546001600160a01b0316156123335760cd546001600160a01b03838116600090815260d960205260409081902054905163711f31c160e11b8152919092169163e23e638291612300918691829190600401614273565b600060405180830381600087803b15801561231a57600080fd5b505af115801561232e573d6000803e3d6000fd5b505050505b60ca5461234b906001600160a01b0316333086612b2c565b6123536136d7565b1561236e5760ca5461236e906001600160a01b0316846136fc565b816001600160a01b03167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c846040516123a991815260200190565b60405180910390a250610d9160018055565b6123c3612ad3565b60c954610100900460ff1615156001036123ff5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33612409816127bf565b6000821161242a5760405163162908e360e11b815260040160405180910390fd5b33600090815260d9602052604090205461245757604051633fa92e1560e01b815260040160405180910390fd5b33600090815260db6020526040902054421061248b5733600090815260db6020908152604080832083905560da9091528120555b33600090815260d9602090815260408083205460da90925282205490916124b282846141a4565b9050808511156125125760405162461bcd60e51b815260206004820152602560248201527f43616e6e6f74207769746864726177206d6f7265207468616e206672656520616044820152641b5bdd5b9d60da1b6064820152608401610a99565b8460d8600082825461252491906141a4565b909155505033600090815260d96020526040812080548792906125489084906141a4565b909155505060cd546001600160a01b0316156125d55760cd5433600081815260d960205260409081902054905163711f31c160e11b81526001600160a01b039093169263e23e6382926125a2929091829190600401614273565b600060405180830381600087803b1580156125bc57600080fd5b505af11580156125d0573d6000803e3d6000fd5b505050505b6125df3386613892565b60405185815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250505050610aa260018055565b612629612ad3565b81612633816127bf565b815160005b81811015612728576000848281518110612654576126546141fc565b6020908102919091018101516001600160a01b03808216600090815260d684526040808220928b16825291909352909120549091508015612713576001600160a01b03808316600081815260d660209081526040808320948c168352939052918220919091556126c59088836138c8565b816001600160a01b0316876001600160a01b03167f49e6aa9a971bb7d18b2ede509ae7267a8861aae4e7c444a27af1d3037d7391178360405161270a91815260200190565b60405180910390a35b5050808061272090614228565b915050612638565b5060cd546001600160a01b0316156127b45760cd546001600160a01b03858116600090815260d960205260409081902054905163711f31c160e11b8152919092169163e23e638291612781918891829190600401614273565b600060405180830381600087803b15801561279b57600080fd5b505af11580156127af573d6000803e3d6000fd5b505050505b5050610d9160018055565b60cf5460005b818110156128b057600060cf82815481106127e2576127e26141fc565b6000918252602090912001546001600160a01b0316905061280281611d7b565b6001600160a01b038216600090815260d4602052604090205561282481610fc4565b6001600160a01b03808316600090815260d3602052604090209190915584161561289d576128528482610cab565b6001600160a01b03808316600081815260d660209081526040808320948a168084529482528083209590955591815260d482528381205460d783528482209382529290915291909120555b50806128a881614228565b9150506127c5565b505050565b60006128c960dc546001600160a01b031690565b6001600160a01b0316036128f057604051638b4b22cf60e01b815260040160405180910390fd5b600061290460dc546001600160a01b031690565b604051630fa09e6360e41b81526001600160a01b0384811660048301529192509082169063fa09e63090602401600060405180830381600087803b15801561294b57600080fd5b505af115801561295f573d6000803e3d6000fd5b50506040516001600160a01b03841692503091507f7082576d53aad702e1fb3e8965824fce40f7825ef06672a679d69210edadbb3490600090a3610d9160006138e7565b60008183106129b25781610d4d565b5090919050565b609780546001600160a01b0319169055610aa281613909565b60cc5460408051630d19556b60e11b815290516000926001600160a01b031691631a32aad69160048083019260209291908290030181865afa1580156109c0573d6000803e3d6000fd5b6000612a3060dc546001600160a01b031690565b6001600160a01b031603612a5757604051638b4b22cf60e01b815260040160405180910390fd5b6000612a6b60dc546001600160a01b031690565b60405163f3fef3a360e01b81529091506001600160a01b0382169063f3fef3a390612a9c908690869060040161425a565b600060405180830381600087803b158015612ab657600080fd5b505af1158015612aca573d6000803e3d6000fd5b50505050505050565b600260015403612b255760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a99565b6002600155565b611726846323b872dd60e01b858585604051602401612b4d93929190614273565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261395b565b60ca546001600160a01b0390811690831603612be25760405162461bcd60e51b815260206004820152601f60248201527f43616e277420616464207374616b6520746f6b656e20617320726577617264006044820152606401610a99565b60008111612c425760405162461bcd60e51b815260206004820152602760248201527f52657761726420616d6f756e74206e6565647320746f206265206869676865726044820152660207468616e20360cc1b6064820152608401610a99565b6001600160a01b038216600090815260d0602052604090205460ff16612e2f5760cc54604051633af32abf60e01b81526001600160a01b03848116600483015290911690633af32abf90602401602060405180830381865afa158015612cac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cd09190614159565b612d275760405162461bcd60e51b815260206004820152602260248201527f7265776172647320746f6b656e73206d7573742062652077686974656c697374604482015261195960f21b6064820152608401610a99565b612d2f6129d2565b6001600160a01b0316826001600160a01b031614158015612dd8575060cc60009054906101000a90046001600160a01b03166001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dc2919061413c565b6001600160a01b0316826001600160a01b031614155b15612e2f5760cf54600611612e2f5760405162461bcd60e51b815260206004820152601760248201527f746f6f206d616e79207265776172647320746f6b656e730000000000000000006044820152606401610a99565b6001600160a01b038216600090815260d260205260409020544210612e795760ce54612e5b90826141da565b6001600160a01b038316600090815260d16020526040902055612f48565b6001600160a01b038216600090815260d26020526040812054612e9d9042906141a4565b6001600160a01b038416600090815260d1602052604081205491925090612ec490836141bb565b9050808311612f155760405162461bcd60e51b815260206004820152601b60248201527f43616e6e6f7420646563726561736520726577617264207261746500000000006044820152606401610a99565b60ce54612f22828561418c565b612f2c91906141da565b6001600160a01b038516600090815260d1602052604090205550505b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612f8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb39190614241565b905060ce5481612fc391906141da565b6001600160a01b038416600090815260d16020526040902054111561302a5760405162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152606401610a99565b6001600160a01b038316600090815260d360205260409020429081905560ce546130539161418c565b6001600160a01b038416600090815260d2602090815260408083209390935560d09052205460ff166130d3576001600160a01b038316600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b03191690911790555b7ff70d5c697de7ea828df48e5c4573cb2194c659f1901f70110c52b066dcf5082633848460405161310693929190614273565b60405180910390a1505050565b60018055565b6131216136d7565b156131835760ca54604051635a6c78d360e11b8152309163b4d8f1a691613156916001600160a01b031690859060040161425a565b600060405180830381600087803b15801561317057600080fd5b505af1925050508015613181575060015b505b60ca546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156131cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f09190614241565b9050818110156132575760405162461bcd60e51b815260206004820152602c60248201527f496e73756666696369656e7420746f6b656e7320666f7220656d657267656e6360448201526b1e481dda5d1a191c985dd85b60a21b6064820152608401610a99565b60ca546128b0906001600160a01b031684846138c8565b60c954600090819060ff166132865750600091829150565b60ca546040805163d294f09360e01b815281516001600160a01b0390931692839263d294f093926004808201939182900301816000875af11580156132cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132f39190614297565b9093509150821515806133065750600082115b156136625760008390506000839050600080846001600160a01b0316639d63848a6040518163ffffffff1660e01b81526004016040805180830381865afa158015613355573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061337991906142bb565b91509150600061338761104c565b905084156134d55760405163095ea7b360e01b81526001600160a01b0384169063095ea7b3906133be90849060009060040161425a565b6020604051808303816000875af11580156133dd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134019190614159565b5060405163095ea7b360e01b81526001600160a01b0384169063095ea7b390613430908490899060040161425a565b6020604051808303816000875af115801561344f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134739190614159565b5060405163b66503cf60e01b81526001600160a01b0382169063b66503cf906134a2908690899060040161425a565b600060405180830381600087803b1580156134bc57600080fd5b505af11580156134d0573d6000803e3d6000fd5b505050505b83156136215760405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061350a90849060009060040161425a565b6020604051808303816000875af1158015613529573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354d9190614159565b5060405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061357c908490889060040161425a565b6020604051808303816000875af115801561359b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135bf9190614159565b5060405163b66503cf60e01b81526001600160a01b0382169063b66503cf906135ee908590889060040161425a565b600060405180830381600087803b15801561360857600080fd5b505af115801561361c573d6000803e3d6000fd5b505050505b604080518981526020810189905233917fbc567d6cbad26368064baa0ab5a757be46aae4d70f707f9203d9d9b6c8ccbfa3910160405180910390a250505050505b509091565b600054610100900460ff1661368e5760405162461bcd60e51b8152600401610a99906142ea565b610fc2613a30565b600054610100900460ff166136bd5760405162461bcd60e51b8152600401610a99906142ea565b610fc2613a60565b6136ce81613a87565b610aa2816138e7565b6000806136ec60dc546001600160a01b031690565b6001600160a01b03161415905090565b600061371060dc546001600160a01b031690565b6001600160a01b03160361373757604051638b4b22cf60e01b815260040160405180910390fd5b600061374b60dc546001600160a01b031690565b60405163095ea7b360e01b81529091506001600160a01b0384169063095ea7b39061377c908490869060040161425a565b6020604051808303816000875af115801561379b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137bf9190614159565b506040516311f9fbc960e21b81526001600160a01b038216906347e7ef24906137ee908690869060040161425a565b600060405180830381600087803b15801561380857600080fd5b505af115801561381c573d6000803e3d6000fd5b505060405163095ea7b360e01b81526001600160a01b038616925063095ea7b3915061384f90849060009060040161425a565b6020604051808303816000875af115801561386e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117269190614159565b61389a6136d7565b156138b55760ca546138b5906001600160a01b031682612a1c565b60ca54610d91906001600160a01b031683835b6128b08363a9059cbb60e01b8484604051602401612b4d92919061425a565b60dc80546001600160a01b0319166001600160a01b0392909216919091179055565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006139b0826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613b389092919063ffffffff16565b90508051600014806139d15750808060200190518101906139d19190614159565b6128b05760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a99565b600054610100900460ff16613a575760405162461bcd60e51b8152600401610a99906142ea565b610fc2336129b9565b600054610100900460ff166131135760405162461bcd60e51b8152600401610a99906142ea565b6001600160a01b03811615610aa2576040516301ffc9a760e01b8152631f03f58760e01b60048201526001600160a01b038216906301ffc9a790602401602060405180830381865afa925050508015613afd575060408051601f3d908101601f19168201909252613afa91810190614159565b60015b613b1a57604051634ea147d560e01b815260040160405180910390fd5b80610d9157604051634ea147d560e01b815260040160405180910390fd5b6060613b478484600085613b4f565b949350505050565b606082471015613bb05760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a99565b600080866001600160a01b03168587604051613bcc9190614335565b60006040518083038185875af1925050503d8060008114613c09576040519150601f19603f3d011682016040523d82523d6000602084013e613c0e565b606091505b5091509150613c1f87838387613c2a565b979650505050505050565b60608315613c99578251600003613c92576001600160a01b0385163b613c925760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a99565b5081613b47565b613b478383815115613cae5781518083602001fd5b8060405162461bcd60e51b8152600401610a999190614109565b6001600160a01b0381168114610aa257600080fd5b8035611e2781613cc8565b600060208284031215613cfa57600080fd5b8135610d4d81613cc8565b600060208284031215613d1757600080fd5b81356001600160e01b031981168114610d4d57600080fd5b600080600060608486031215613d4457600080fd5b8335613d4f81613cc8565b95602085013595506040909401359392505050565b60008060408385031215613d7757600080fd5b8235613d8281613cc8565b91506020830135613d9281613cc8565b809150509250929050565b600060208284031215613daf57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715613df557613df5613db6565b604052919050565b600067ffffffffffffffff821115613e1757613e17613db6565b5060051b60200190565b60008060408385031215613e3457600080fd5b8235613e3f81613cc8565b915060208381013567ffffffffffffffff811115613e5c57600080fd5b8401601f81018613613e6d57600080fd5b8035613e80613e7b82613dfd565b613dcc565b81815260059190911b82018301908381019088831115613e9f57600080fd5b928401925b82841015613ec6578335613eb781613cc8565b82529284019290840190613ea4565b80955050505050509250929050565b60008060408385031215613ee857600080fd5b823591506020830135613d9281613cc8565b600082601f830112613f0b57600080fd5b81356020613f1b613e7b83613dfd565b82815260059290921b84018101918181019086841115613f3a57600080fd5b8286015b84811015613f555780358352918301918301613f3e565b509695505050505050565b600080600060608486031215613f7557600080fd5b833567ffffffffffffffff80821115613f8d57600080fd5b818601915086601f830112613fa157600080fd5b81356020613fb1613e7b83613dfd565b82815260059290921b8401810191818101908a841115613fd057600080fd5b948201945b83861015613ff7578535613fe881613cc8565b82529482019490820190613fd5565b9750508701359250508082111561400d57600080fd5b5061401a86828701613efa565b92505061402960408501613cdd565b90509250925092565b6000806040838503121561404557600080fd5b823561405081613cc8565b946020939093013593505050565b8015158114610aa257600080fd5b600080600080600060a0868803121561408457600080fd5b853561408f81613cc8565b9450602086013561409f81613cc8565b935060408601356140af81613cc8565b925060608601356140bf81613cc8565b915060808601356140cf8161405e565b809150509295509295909350565b60005b838110156140f85781810151838201526020016140e0565b838111156117265750506000910152565b60208152600082518060208401526141288160408501602087016140dd565b601f01601f19169190910160400192915050565b60006020828403121561414e57600080fd5b8151610d4d81613cc8565b60006020828403121561416b57600080fd5b8151610d4d8161405e565b634e487b7160e01b600052601160045260246000fd5b6000821982111561419f5761419f614176565b500190565b6000828210156141b6576141b6614176565b500390565b60008160001904831182151516156141d5576141d5614176565b500290565b6000826141f757634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b60006001820161423a5761423a614176565b5060010190565b60006020828403121561425357600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b600080604083850312156142aa57600080fd5b505080516020909101519092909150565b600080604083850312156142ce57600080fd5b82516142d981613cc8565b6020840151909250613d9281613cc8565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082516143478184602087016140dd565b919091019291505056feacb8d954e2cfef495862221e91bd7523613cf8808827cb33edfe4904cc51bf29a264697066735822122031979f746357194b7f871d6f213539d588a34cd08ef82fe2b3c5bd086ef3554464736f6c634300080d0033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103da5760003560e01c80638150c86b1161020a578063c6c8f6b611610125578063e30c3978116100b8578063f301af4211610087578063f301af42146108cc578063f7c618c1146108df578063f97d2114146108f8578063fc5b5fda1461090b578063ffa1ad741461091e57600080fd5b8063e30c397814610888578063e574821314610899578063f1229777146108a6578063f2fde38b146108b957600080fd5b8063d294f093116100f4578063d294f09314610832578063da09d19d1461084f578063db2e21bc14610878578063de5f62681461088057600080fd5b8063c6c8f6b6146107f2578063c863657d14610805578063caa6fea414610818578063d00960101461082a57600080fd5b8063a0821be31161019d578063b4d8f1a61161016c578063b4d8f1a6146107a6578063b66503cf146107b9578063b6b55f25146107cc578063c00007b0146107df57600080fd5b8063a0821be31461074d578063a495e5b514610760578063b1534ecd1461078b578063b3aa527d1461079357600080fd5b80638da5cb5b116101d95780638da5cb5b146106e95780639843bafa146106fa57806399bcc0521461071a5780639ce43f901461072d57600080fd5b80638150c86b146106b5578063853828b6146106bd578063863e2442146106c557806386f9c23c146106d857600080fd5b80633d509c97116102fa57806370a082311161028d578063770f85711161025c578063770f85711461067f57806379ba5097146106875780637c91e4eb1461068f5780637f699015146106a257600080fd5b806370a082311461062857806370aff70f14610651578063715018a61461066457806376a0adf21461066c57600080fd5b80636265ff48116102c95780636265ff48146105cf578063638634ee146105e25780636e9852f2146105f55780637035ab98146105fd57600080fd5b80633d509c971461057e57806340e1950f146105915780634d5ce0381461059957806351ed6a30146105bc57600080fd5b8063211dc32d116103725780632e1a7d4d116103415780632e1a7d4d1461052557806331279d3d146105385780633ca068b61461054b5780633d18b9121461057657600080fd5b8063211dc32d146104b2578063221ca18c146104c557806323792279146104e55780632ce9aead1461050557600080fd5b806318160ddd116103ae57806318160ddd146104795780631be05289146104815780631c03e6cc1461048a5780631f933c2d1461049f57600080fd5b80628cc262146103df57806301ffc9a71461040557806303fbf83a1461043957806307723bf514610459575b600080fd5b6103f26103ed366004613ce8565b61094f565b6040519081526020015b60405180910390f35b610429610413366004613d05565b6001600160e01b03191663126be74f60e01b1490565b60405190151581526020016103fc565b610441610976565b6040516001600160a01b0390911681526020016103fc565b6103f2610467366004613ce8565b60d26020526000908152604090205481565b60d8546103f2565b6103f260ce5481565b61049d610498366004613ce8565b6109e9565b005b61049d6104ad366004613d2f565b610aa5565b6103f26104c0366004613d64565b610cab565b6103f26104d3366004613ce8565b60d16020526000908152604090205481565b6103f26104f3366004613ce8565b60db6020526000908152604090205481565b6103f2610513366004613ce8565b60d36020526000908152604090205481565b61049d610533366004613d9d565b610d54565b61049d610546366004613e21565b610d5d565b6103f2610559366004613d64565b60d660209081526000928352604080842090915290825290205481565b61049d610d95565b61049d61058c366004613ce8565b610e0a565b61049d610fa5565b6104296105a7366004613ce8565b60d06020526000908152604090205460ff1681565b60ca54610441906001600160a01b031681565b60dc54610441906001600160a01b031681565b6103f26105f0366004613ce8565b610fc4565b61049d610fe8565b6103f261060b366004613d64565b60d760209081526000928352604080842090915290825290205481565b6103f2610636366004613ce8565b6001600160a01b0316600090815260d9602052604090205490565b61049d61065f366004613ed5565b611009565b61049d611013565b6103f261067a366004613ce8565b611025565b61044161104c565b61049d61107d565b60cc54610441906001600160a01b031681565b61049d6106b0366004613ce8565b6110f4565b61049d6111a7565b61049d611307565b60cd54610441906001600160a01b031681565b60dc546001600160a01b0316610441565b6065546001600160a01b0316610441565b6103f2610708366004613ce8565b60da6020526000908152604090205481565b6103f2610728366004613ce8565b611320565b6103f261073b366004613ce8565b60d46020526000908152604090205481565b6103f261075b366004613ce8565b611391565b6103f261076e366004613d64565b60d560209081526000928352604080842090915290825290205481565b61049d6113fb565b61049d6107a1366004613f60565b611482565b61049d6107b4366004614032565b61172c565b61049d6107c7366004614032565b61177e565b61049d6107da366004613d9d565b6118de565b61049d6107ed366004613ce8565b6118e8565b61049d610800366004613d9d565b611988565b60cb54610441906001600160a01b031681565b60c95461042990610100900460ff1681565b61049d611af5565b61083a611b7c565b604080519283526020830191909152016103fc565b6103f261085d366004613ce8565b6001600160a01b0316600090815260d2602052604090205490565b61049d611ba0565b61049d611d07565b6097546001600160a01b0316610441565b60c9546104299060ff1681565b6103f26108b4366004613ce8565b611d7b565b61049d6108c7366004613ce8565b611e2c565b6104416108da366004613d9d565b611e9d565b60c954610441906201000090046001600160a01b031681565b61049d610906366004613ce8565b611ec7565b61049d61091936600461406c565b611f4c565b610942604051806040016040528060058152602001640322e342e360dc1b81525081565b6040516103fc9190614109565b60006109708260c960029054906101000a90046001600160a01b0316610cab565b92915050565b60cc5460405163ae21c4cb60e01b81523060048201526000916001600160a01b03169063ae21c4cb906024015b602060405180830381865afa1580156109c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e4919061413c565b905090565b6109f1612191565b6001600160a01b038116600090815260d0602052604090205460ff16610a65576001600160a01b0316600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b0319169091179055565b60405162461bcd60e51b815260206004820152600d60248201526c105b1c9958591e481859191959609a1b60448201526064015b60405180910390fd5b50565b336001600160a01b0384161480610acc575060c9546201000090046001600160a01b031633145b80610b3e575060cc54604051630f2312ab60e41b81523360048201526001600160a01b039091169063f2312ab090602401602060405180830381865afa158015610b1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3e9190614159565b610b8a5760405162461bcd60e51b815260206004820181905260248201527f4e6f7420616c6c6f77656420746f206465706f7369742077697468206c6f636b6044820152606401610a99565b610b9482846121eb565b6001600160a01b038316600090815260db60205260409020544210610bda576001600160a01b038316600090815260db6020908152604080832083905560da9091528120555b6001600160a01b038316600090815260da602052604081208054849290610c0290849061418c565b90915550506001600160a01b038316600090815260db602052604081205490610c2b834261418c565b905080821115610c895760405162461bcd60e51b815260206004820152602360248201527f5468652063757272656e74206c6f636b20656e64203e206e6577206c6f636b20604482015262195b9960ea1b6064820152608401610a99565b6001600160a01b03909416600090815260db6020526040902093909355505050565b6001600160a01b03808216600090815260d760209081526040808320938616835292905290812054670de0b6b3a764000090610ce684611d7b565b610cf091906141a4565b6001600160a01b038516600090815260d96020526040902054610d1391906141bb565b610d1d91906141da565b6001600160a01b03808416600090815260d66020908152604080832093881683529290522054610d4d919061418c565b9392505050565b610aa2816123bb565b336001600160a01b0383161480610d7e575060cc546001600160a01b031633145b610d8757600080fd5b610d918282612621565b5050565b6040805160018082528183019092526000916020808301908036833701905050905060c960029054906101000a90046001600160a01b031681600081518110610de057610de06141fc565b60200260200101906001600160a01b031690816001600160a01b031681525050610aa23382612621565b610e12612191565b6001600160a01b038116600090815260d0602052604090205460ff16610e665760405162461bcd60e51b8152602060048201526009602482015268139bdd08185919195960ba1b6044820152606401610a99565b610e6f306127bf565b60005b60cf54610e81906001906141a4565b811015610f8357816001600160a01b031660cf8281548110610ea557610ea56141fc565b6000918252602090912001546001600160a01b031603610f715760cf8054610ecf906001906141a4565b81548110610edf57610edf6141fc565b60009182526020909120015460cf80546001600160a01b039092169183908110610f0b57610f0b6141fc565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060cf805480610f4a57610f4a614212565b600082815260209020810160001990810180546001600160a01b0319169055019055610f83565b80610f7b81614228565b915050610e72565b506001600160a01b0316600090815260d060205260409020805460ff19169055565b610fad612191565b60ca54610fc2906001600160a01b03166128b5565b565b6001600160a01b038116600090815260d260205260408120546109709042906129a3565b33600090815260d96020526040902054611001906123bb565b610fc2610d95565b610d9182826121eb565b61101b612191565b610fc260006129b9565b60ce546001600160a01b038216600090815260d160205260408120549091610970916141bb565b60cc54604051637572079360e11b81523060048201526000916001600160a01b03169063eae40f26906024016109a3565b60975433906001600160a01b031681146110eb5760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610a99565b610aa2816129b9565b6110fc612191565b6001600160a01b0381166111235760405163d92e233d60e01b815260040160405180910390fd5b60cc546001600160a01b03908116908216036111525760405163367558c360e01b815260040160405180910390fd5b60cc80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff085c57737528946971c505b4c9d6f7ca7ab5925b0cee78d8cb75797f36f3628906020015b60405180910390a150565b6111af612191565b60c9546201000090046001600160a01b0316600090815260d060205260408120805460ff191690556111df6129d2565b90506001600160a01b0381166112695760cc60009054906101000a90046001600160a01b03166001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611242573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611266919061413c565b90505b6001600160a01b038116600090815260d0602052604090205460ff166112dd576001600160a01b038116600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b03191690911790555b60c980546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b33600090815260d96020526040902054610fc2906123bb565b6001600160a01b038116600090815260d26020526040812054421061134757506000919050565b6001600160a01b038216600090815260d2602052604081205461136b9042906141a4565b6001600160a01b038416600090815260d16020526040902054909150610d4d90826141bb565b6001600160a01b038116600090815260db602052604081205442106113cc57506001600160a01b0316600090815260d9602052604090205490565b6001600160a01b038216600090815260da602090815260408083205460d99092529091205461097091906141a4565b611403612191565b60c954610100900460ff16151560000361143f5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60c9805461ff001916905560405142815230907fa30763a9bc0d8e121a6e721624965cae68010ece74128b4ae5b01b8dc22c00f8906020015b60405180910390a2565b61148a612191565b81518351146114e65760405162461bcd60e51b815260206004820152602260248201527f546f6b656e7320616e6420616d6f756e7473206c656e677468206d69736d61746044820152610c6d60f31b6064820152608401610a99565b60005b8351811015611726576000848281518110611506576115066141fc565b602090810291909101015160ca549091506001600160a01b03908116908216036115725760405162461bcd60e51b815260206004820152601860248201527f43616e6e6f74207377656570207374616b6520746f6b656e00000000000000006044820152606401610a99565b6000848381518110611586576115866141fc565b60209081029190910101516040516370a0823160e01b81523060048201529091506000906001600160a01b038416906370a0823190602401602060405180830381865afa1580156115db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115ff9190614241565b9050818110156116515760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e2062616c616e63650000000000006044820152606401610a99565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb9061167f908890869060040161425a565b6020604051808303816000875af115801561169e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116c29190614159565b50826001600160a01b0316856001600160a01b03167f5bf76ef0db3550a96f76d3c13dfa002b5e1df9e4c4d65dce31f074c670b8b6488460405161170891815260200190565b60405180910390a3505050808061171e90614228565b9150506114e9565b50505050565b3330146117745760405162461bcd60e51b815260206004820152601660248201527513db9b1e481cd95b198b58d85b1b08185b1b1bddd95960521b6044820152606401610a99565b610d918282612a1c565b611786612ad3565b60c954610100900460ff1615156001036117c25760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60006117cd816127bf565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015611814573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118389190614241565b905061184f6001600160a01b038516333086612b2c565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015611896573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ba9190614241565b90506118c682826141a4565b93506118d28585612b84565b505050610d9160018055565b610aa281336121eb565b60cc546001600160a01b0316331461191357604051631b8f6df360e01b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905060c960029054906101000a90046001600160a01b03168160008151811061195e5761195e6141fc565b60200260200101906001600160a01b031690816001600160a01b031681525050610d918282612621565b611990612ad3565b60c954610100900460ff166119c75760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33600090815260d960205260409020548111156119f757604051633fa92e1560e01b815260040160405180910390fd5b8060d854611a0591906141a4565b60d85533600090815260d9602052604081208054839290611a279084906141a4565b90915550611a37905060006127bf565b60cd546001600160a01b031615611aad5760cd54604051632bada09360e01b81526001600160a01b0390911690632bada09390611a7a903390859060040161425a565b600060405180830381600087803b158015611a9457600080fd5b505af1158015611aa8573d6000803e3d6000fd5b505050505b611ab73382613119565b60405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a2610aa260018055565b611afd612191565b60c954610100900460ff161515600103611b395760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b60c9805461ff00191661010017905560405130907f774b57c3410c76d04ea4d51b0c15a9bac99b0e70f28fd88b53d702b5427fd318906114789042815260200190565b600080611b87612ad3565b611b8f61326e565b91509150611b9c60018055565b9091565b611ba8612ad3565b60c954610100900460ff16611bdf5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33600090815260d96020526040902054611c0c57604051633fa92e1560e01b815260040160405180910390fd5b33600090815260d9602052604090205460d854611c2a9082906141a4565b60d85533600090815260d960205260408120819055611c48906127bf565b60cd546001600160a01b031615611cbe5760cd54604051632bada09360e01b81526001600160a01b0390911690632bada09390611c8b903390859060040161425a565b600060405180830381600087803b158015611ca557600080fd5b505af1158015611cb9573d6000803e3d6000fd5b505050505b611cc83382613119565b60405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250610fc260018055565b60ca546040516370a0823160e01b8152336004820152610fc2916001600160a01b0316906370a0823190602401602060405180830381865afa158015611d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d759190614241565b336121eb565b600060d854600003611da357506001600160a01b0316600090815260d4602052604090205490565b60d8546001600160a01b038316600090815260d1602090815260408083205460d390925290912054611dd485610fc4565b611dde91906141a4565b611de891906141bb565b611dfa90670de0b6b3a76400006141bb565b611e0491906141da565b6001600160a01b038316600090815260d46020526040902054610970919061418c565b919050565b611e34612191565b609780546001600160a01b0383166001600160a01b03199091168117909155611e656065546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60cf8181548110611ead57600080fd5b6000918252602090912001546001600160a01b0316905081565b611ecf612191565b60cd546001600160a01b0390811690821603611efe5760405163367558c360e01b815260040160405180910390fd5b60cd80546001600160a01b0319166001600160a01b0383169081179091556040519081527fcf0aff36caea97f7ad632b334936cb196014c193ac1a790b578f12a70d9836db9060200161119c565b600054610100900460ff1615808015611f6c5750600054600160ff909116105b80611f865750303b158015611f86575060005460ff166001145b611fe95760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610a99565b6000805460ff19166001179055801561200c576000805461ff0019166101001790555b612014613667565b61201c613696565b60c9805460cb80546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560cc8054821688841617905561384060ce5561ff01600160b01b031990921662010000918a1691820260ff19908116919091178615151761ff001916909355600081815260d0602052604081208054909416600190811790945560cf80549485018155815260008051602061435283398151915290930180549092161790553390813b1561214157816001600160a01b0316636265ff486040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612130575060408051601f3d908101601f1916820190925261212d9181019061413c565b60015b156121385790505b612141816136c5565b50508015612189576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6065546001600160a01b03163314610fc25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a99565b6121f3612ad3565b60c954610100900460ff16151560010361222f5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b80612239816127bf565b6000831161225a5760405163162908e360e11b815260040160405180910390fd5b6001600160a01b038216600090815260d9602052604090205461227e90849061418c565b6001600160a01b038316600090815260d9602052604090205560d8546122a590849061418c565b60d85560cd546001600160a01b0316156123335760cd546001600160a01b03838116600090815260d960205260409081902054905163711f31c160e11b8152919092169163e23e638291612300918691829190600401614273565b600060405180830381600087803b15801561231a57600080fd5b505af115801561232e573d6000803e3d6000fd5b505050505b60ca5461234b906001600160a01b0316333086612b2c565b6123536136d7565b1561236e5760ca5461236e906001600160a01b0316846136fc565b816001600160a01b03167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c846040516123a991815260200190565b60405180910390a250610d9160018055565b6123c3612ad3565b60c954610100900460ff1615156001036123ff5760c954604051630825023760e11b815261010090910460ff1615156004820152602401610a99565b33612409816127bf565b6000821161242a5760405163162908e360e11b815260040160405180910390fd5b33600090815260d9602052604090205461245757604051633fa92e1560e01b815260040160405180910390fd5b33600090815260db6020526040902054421061248b5733600090815260db6020908152604080832083905560da9091528120555b33600090815260d9602090815260408083205460da90925282205490916124b282846141a4565b9050808511156125125760405162461bcd60e51b815260206004820152602560248201527f43616e6e6f74207769746864726177206d6f7265207468616e206672656520616044820152641b5bdd5b9d60da1b6064820152608401610a99565b8460d8600082825461252491906141a4565b909155505033600090815260d96020526040812080548792906125489084906141a4565b909155505060cd546001600160a01b0316156125d55760cd5433600081815260d960205260409081902054905163711f31c160e11b81526001600160a01b039093169263e23e6382926125a2929091829190600401614273565b600060405180830381600087803b1580156125bc57600080fd5b505af11580156125d0573d6000803e3d6000fd5b505050505b6125df3386613892565b60405185815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649060200160405180910390a250505050610aa260018055565b612629612ad3565b81612633816127bf565b815160005b81811015612728576000848281518110612654576126546141fc565b6020908102919091018101516001600160a01b03808216600090815260d684526040808220928b16825291909352909120549091508015612713576001600160a01b03808316600081815260d660209081526040808320948c168352939052918220919091556126c59088836138c8565b816001600160a01b0316876001600160a01b03167f49e6aa9a971bb7d18b2ede509ae7267a8861aae4e7c444a27af1d3037d7391178360405161270a91815260200190565b60405180910390a35b5050808061272090614228565b915050612638565b5060cd546001600160a01b0316156127b45760cd546001600160a01b03858116600090815260d960205260409081902054905163711f31c160e11b8152919092169163e23e638291612781918891829190600401614273565b600060405180830381600087803b15801561279b57600080fd5b505af11580156127af573d6000803e3d6000fd5b505050505b5050610d9160018055565b60cf5460005b818110156128b057600060cf82815481106127e2576127e26141fc565b6000918252602090912001546001600160a01b0316905061280281611d7b565b6001600160a01b038216600090815260d4602052604090205561282481610fc4565b6001600160a01b03808316600090815260d3602052604090209190915584161561289d576128528482610cab565b6001600160a01b03808316600081815260d660209081526040808320948a168084529482528083209590955591815260d482528381205460d783528482209382529290915291909120555b50806128a881614228565b9150506127c5565b505050565b60006128c960dc546001600160a01b031690565b6001600160a01b0316036128f057604051638b4b22cf60e01b815260040160405180910390fd5b600061290460dc546001600160a01b031690565b604051630fa09e6360e41b81526001600160a01b0384811660048301529192509082169063fa09e63090602401600060405180830381600087803b15801561294b57600080fd5b505af115801561295f573d6000803e3d6000fd5b50506040516001600160a01b03841692503091507f7082576d53aad702e1fb3e8965824fce40f7825ef06672a679d69210edadbb3490600090a3610d9160006138e7565b60008183106129b25781610d4d565b5090919050565b609780546001600160a01b0319169055610aa281613909565b60cc5460408051630d19556b60e11b815290516000926001600160a01b031691631a32aad69160048083019260209291908290030181865afa1580156109c0573d6000803e3d6000fd5b6000612a3060dc546001600160a01b031690565b6001600160a01b031603612a5757604051638b4b22cf60e01b815260040160405180910390fd5b6000612a6b60dc546001600160a01b031690565b60405163f3fef3a360e01b81529091506001600160a01b0382169063f3fef3a390612a9c908690869060040161425a565b600060405180830381600087803b158015612ab657600080fd5b505af1158015612aca573d6000803e3d6000fd5b50505050505050565b600260015403612b255760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a99565b6002600155565b611726846323b872dd60e01b858585604051602401612b4d93929190614273565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261395b565b60ca546001600160a01b0390811690831603612be25760405162461bcd60e51b815260206004820152601f60248201527f43616e277420616464207374616b6520746f6b656e20617320726577617264006044820152606401610a99565b60008111612c425760405162461bcd60e51b815260206004820152602760248201527f52657761726420616d6f756e74206e6565647320746f206265206869676865726044820152660207468616e20360cc1b6064820152608401610a99565b6001600160a01b038216600090815260d0602052604090205460ff16612e2f5760cc54604051633af32abf60e01b81526001600160a01b03848116600483015290911690633af32abf90602401602060405180830381865afa158015612cac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cd09190614159565b612d275760405162461bcd60e51b815260206004820152602260248201527f7265776172647320746f6b656e73206d7573742062652077686974656c697374604482015261195960f21b6064820152608401610a99565b612d2f6129d2565b6001600160a01b0316826001600160a01b031614158015612dd8575060cc60009054906101000a90046001600160a01b03166001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d9e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dc2919061413c565b6001600160a01b0316826001600160a01b031614155b15612e2f5760cf54600611612e2f5760405162461bcd60e51b815260206004820152601760248201527f746f6f206d616e79207265776172647320746f6b656e730000000000000000006044820152606401610a99565b6001600160a01b038216600090815260d260205260409020544210612e795760ce54612e5b90826141da565b6001600160a01b038316600090815260d16020526040902055612f48565b6001600160a01b038216600090815260d26020526040812054612e9d9042906141a4565b6001600160a01b038416600090815260d1602052604081205491925090612ec490836141bb565b9050808311612f155760405162461bcd60e51b815260206004820152601b60248201527f43616e6e6f7420646563726561736520726577617264207261746500000000006044820152606401610a99565b60ce54612f22828561418c565b612f2c91906141da565b6001600160a01b038516600090815260d1602052604090205550505b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612f8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fb39190614241565b905060ce5481612fc391906141da565b6001600160a01b038416600090815260d16020526040902054111561302a5760405162461bcd60e51b815260206004820152601860248201527f50726f76696465642072657761726420746f6f206869676800000000000000006044820152606401610a99565b6001600160a01b038316600090815260d360205260409020429081905560ce546130539161418c565b6001600160a01b038416600090815260d2602090815260408083209390935560d09052205460ff166130d3576001600160a01b038316600081815260d060205260408120805460ff1916600190811790915560cf805491820181559091526000805160206143528339815191520180546001600160a01b03191690911790555b7ff70d5c697de7ea828df48e5c4573cb2194c659f1901f70110c52b066dcf5082633848460405161310693929190614273565b60405180910390a1505050565b60018055565b6131216136d7565b156131835760ca54604051635a6c78d360e11b8152309163b4d8f1a691613156916001600160a01b031690859060040161425a565b600060405180830381600087803b15801561317057600080fd5b505af1925050508015613181575060015b505b60ca546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa1580156131cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f09190614241565b9050818110156132575760405162461bcd60e51b815260206004820152602c60248201527f496e73756666696369656e7420746f6b656e7320666f7220656d657267656e6360448201526b1e481dda5d1a191c985dd85b60a21b6064820152608401610a99565b60ca546128b0906001600160a01b031684846138c8565b60c954600090819060ff166132865750600091829150565b60ca546040805163d294f09360e01b815281516001600160a01b0390931692839263d294f093926004808201939182900301816000875af11580156132cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132f39190614297565b9093509150821515806133065750600082115b156136625760008390506000839050600080846001600160a01b0316639d63848a6040518163ffffffff1660e01b81526004016040805180830381865afa158015613355573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061337991906142bb565b91509150600061338761104c565b905084156134d55760405163095ea7b360e01b81526001600160a01b0384169063095ea7b3906133be90849060009060040161425a565b6020604051808303816000875af11580156133dd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134019190614159565b5060405163095ea7b360e01b81526001600160a01b0384169063095ea7b390613430908490899060040161425a565b6020604051808303816000875af115801561344f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134739190614159565b5060405163b66503cf60e01b81526001600160a01b0382169063b66503cf906134a2908690899060040161425a565b600060405180830381600087803b1580156134bc57600080fd5b505af11580156134d0573d6000803e3d6000fd5b505050505b83156136215760405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061350a90849060009060040161425a565b6020604051808303816000875af1158015613529573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354d9190614159565b5060405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061357c908490889060040161425a565b6020604051808303816000875af115801561359b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135bf9190614159565b5060405163b66503cf60e01b81526001600160a01b0382169063b66503cf906135ee908590889060040161425a565b600060405180830381600087803b15801561360857600080fd5b505af115801561361c573d6000803e3d6000fd5b505050505b604080518981526020810189905233917fbc567d6cbad26368064baa0ab5a757be46aae4d70f707f9203d9d9b6c8ccbfa3910160405180910390a250505050505b509091565b600054610100900460ff1661368e5760405162461bcd60e51b8152600401610a99906142ea565b610fc2613a30565b600054610100900460ff166136bd5760405162461bcd60e51b8152600401610a99906142ea565b610fc2613a60565b6136ce81613a87565b610aa2816138e7565b6000806136ec60dc546001600160a01b031690565b6001600160a01b03161415905090565b600061371060dc546001600160a01b031690565b6001600160a01b03160361373757604051638b4b22cf60e01b815260040160405180910390fd5b600061374b60dc546001600160a01b031690565b60405163095ea7b360e01b81529091506001600160a01b0384169063095ea7b39061377c908490869060040161425a565b6020604051808303816000875af115801561379b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137bf9190614159565b506040516311f9fbc960e21b81526001600160a01b038216906347e7ef24906137ee908690869060040161425a565b600060405180830381600087803b15801561380857600080fd5b505af115801561381c573d6000803e3d6000fd5b505060405163095ea7b360e01b81526001600160a01b038616925063095ea7b3915061384f90849060009060040161425a565b6020604051808303816000875af115801561386e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117269190614159565b61389a6136d7565b156138b55760ca546138b5906001600160a01b031682612a1c565b60ca54610d91906001600160a01b031683835b6128b08363a9059cbb60e01b8484604051602401612b4d92919061425a565b60dc80546001600160a01b0319166001600160a01b0392909216919091179055565b606580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006139b0826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613b389092919063ffffffff16565b90508051600014806139d15750808060200190518101906139d19190614159565b6128b05760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a99565b600054610100900460ff16613a575760405162461bcd60e51b8152600401610a99906142ea565b610fc2336129b9565b600054610100900460ff166131135760405162461bcd60e51b8152600401610a99906142ea565b6001600160a01b03811615610aa2576040516301ffc9a760e01b8152631f03f58760e01b60048201526001600160a01b038216906301ffc9a790602401602060405180830381865afa925050508015613afd575060408051601f3d908101601f19168201909252613afa91810190614159565b60015b613b1a57604051634ea147d560e01b815260040160405180910390fd5b80610d9157604051634ea147d560e01b815260040160405180910390fd5b6060613b478484600085613b4f565b949350505050565b606082471015613bb05760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a99565b600080866001600160a01b03168587604051613bcc9190614335565b60006040518083038185875af1925050503d8060008114613c09576040519150601f19603f3d011682016040523d82523d6000602084013e613c0e565b606091505b5091509150613c1f87838387613c2a565b979650505050505050565b60608315613c99578251600003613c92576001600160a01b0385163b613c925760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a99565b5081613b47565b613b478383815115613cae5781518083602001fd5b8060405162461bcd60e51b8152600401610a999190614109565b6001600160a01b0381168114610aa257600080fd5b8035611e2781613cc8565b600060208284031215613cfa57600080fd5b8135610d4d81613cc8565b600060208284031215613d1757600080fd5b81356001600160e01b031981168114610d4d57600080fd5b600080600060608486031215613d4457600080fd5b8335613d4f81613cc8565b95602085013595506040909401359392505050565b60008060408385031215613d7757600080fd5b8235613d8281613cc8565b91506020830135613d9281613cc8565b809150509250929050565b600060208284031215613daf57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715613df557613df5613db6565b604052919050565b600067ffffffffffffffff821115613e1757613e17613db6565b5060051b60200190565b60008060408385031215613e3457600080fd5b8235613e3f81613cc8565b915060208381013567ffffffffffffffff811115613e5c57600080fd5b8401601f81018613613e6d57600080fd5b8035613e80613e7b82613dfd565b613dcc565b81815260059190911b82018301908381019088831115613e9f57600080fd5b928401925b82841015613ec6578335613eb781613cc8565b82529284019290840190613ea4565b80955050505050509250929050565b60008060408385031215613ee857600080fd5b823591506020830135613d9281613cc8565b600082601f830112613f0b57600080fd5b81356020613f1b613e7b83613dfd565b82815260059290921b84018101918181019086841115613f3a57600080fd5b8286015b84811015613f555780358352918301918301613f3e565b509695505050505050565b600080600060608486031215613f7557600080fd5b833567ffffffffffffffff80821115613f8d57600080fd5b818601915086601f830112613fa157600080fd5b81356020613fb1613e7b83613dfd565b82815260059290921b8401810191818101908a841115613fd057600080fd5b948201945b83861015613ff7578535613fe881613cc8565b82529482019490820190613fd5565b9750508701359250508082111561400d57600080fd5b5061401a86828701613efa565b92505061402960408501613cdd565b90509250925092565b6000806040838503121561404557600080fd5b823561405081613cc8565b946020939093013593505050565b8015158114610aa257600080fd5b600080600080600060a0868803121561408457600080fd5b853561408f81613cc8565b9450602086013561409f81613cc8565b935060408601356140af81613cc8565b925060608601356140bf81613cc8565b915060808601356140cf8161405e565b809150509295509295909350565b60005b838110156140f85781810151838201526020016140e0565b838111156117265750506000910152565b60208152600082518060208401526141288160408501602087016140dd565b601f01601f19169190910160400192915050565b60006020828403121561414e57600080fd5b8151610d4d81613cc8565b60006020828403121561416b57600080fd5b8151610d4d8161405e565b634e487b7160e01b600052601160045260246000fd5b6000821982111561419f5761419f614176565b500190565b6000828210156141b6576141b6614176565b500390565b60008160001904831182151516156141d5576141d5614176565b500290565b6000826141f757634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b60006001820161423a5761423a614176565b5060010190565b60006020828403121561425357600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b600080604083850312156142aa57600080fd5b505080516020909101519092909150565b600080604083850312156142ce57600080fd5b82516142d981613cc8565b6020840151909250613d9281613cc8565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600082516143478184602087016140dd565b919091019291505056feacb8d954e2cfef495862221e91bd7523613cf8808827cb33edfe4904cc51bf29a264697066735822122031979f746357194b7f871d6f213539d588a34cd08ef82fe2b3c5bd086ef3554464736f6c634300080d0033
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.