Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DelegationLogicLibrary
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
import {IVotingEscrow} from "../interfaces/IVotingEscrow.sol";
import {SafeCastLibrary} from "./SafeCastLibrary.sol";
library DelegationLogicLibrary {
using SafeCastLibrary for int128;
/// @notice Used by `_mint`, `_transferFrom`, `_burn` and `delegate`
/// to update delegator voting checkpoints.
/// Automatically dedelegates, then updates checkpoint.
/// @dev This function depends on `_locked` and must be called prior to token state changes.
/// If you wish to dedelegate only, use `_delegate(tokenId, 0)` instead.
/// @param _locked State of all locked balances
/// @param _numCheckpoints State of all user checkpoint counts
/// @param _checkpoints State of all user checkpoints
/// @param _delegates State of all user delegatees
/// @param _delegator The delegator to update checkpoints for
/// @param _delegatee The new delegatee for the delegator. Cannot be equal to `_delegator` (use 0 instead).
/// @param _owner The new (or current) owner for the delegator
function checkpointDelegator(
mapping(uint256 => IVotingEscrow.LockedBalance) storage _locked,
mapping(uint256 => uint48) storage _numCheckpoints,
mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage _checkpoints,
mapping(uint256 => uint256) storage _delegates,
uint256 _delegator,
uint256 _delegatee,
address _owner
) external {
uint256 delegatedBalance = _locked[_delegator].amount.toUint256();
uint48 numCheckpoint = _numCheckpoints[_delegator];
IVotingEscrow.Checkpoint storage cpOld = numCheckpoint > 0
? _checkpoints[_delegator][numCheckpoint - 1]
: _checkpoints[_delegator][0];
// Dedelegate from delegatee if delegated
checkpointDelegatee(_numCheckpoints, _checkpoints, cpOld.delegatee, delegatedBalance, false);
IVotingEscrow.Checkpoint storage cp = _checkpoints[_delegator][numCheckpoint];
cp.fromTimestamp = block.timestamp;
cp.delegatedBalance = cpOld.delegatedBalance;
cp.delegatee = _delegatee;
cp.owner = _owner;
if (_isCheckpointInNewBlock(_numCheckpoints, _checkpoints, _delegator)) {
_numCheckpoints[_delegator]++;
} else {
_checkpoints[_delegator][numCheckpoint - 1] = cp;
delete _checkpoints[_delegator][numCheckpoint];
}
_delegates[_delegator] = _delegatee;
}
/// @notice Update delegatee's `delegatedBalance` by `balance`.
/// Only updates if delegating to a new delegatee.
/// @dev If used with `balance` == `_locked[_tokenId].amount`, then this is the same as
/// delegating or dedelegating from `_tokenId`
/// If used with `balance` < `_locked[_tokenId].amount`, then this is used to adjust
/// `delegatedBalance` when a user's balance is modified (e.g. `increaseAmount`, `merge` etc).
/// If `delegatee` is 0 (i.e. user is not delegating), then do nothing.
/// @param _numCheckpoints State of all user checkpoint counts
/// @param _checkpoints State of all user checkpoints
/// @param _delegatee The delegatee's tokenId
/// @param balance_ The delta in balance change
/// @param _increase True if balance is increasing, false if decreasing
function checkpointDelegatee(
mapping(uint256 => uint48) storage _numCheckpoints,
mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage _checkpoints,
uint256 _delegatee,
uint256 balance_,
bool _increase
) public {
if (_delegatee == 0) return;
uint48 numCheckpoint = _numCheckpoints[_delegatee];
IVotingEscrow.Checkpoint storage cpOld = numCheckpoint > 0
? _checkpoints[_delegatee][numCheckpoint - 1]
: _checkpoints[_delegatee][0];
IVotingEscrow.Checkpoint storage cp = _checkpoints[_delegatee][numCheckpoint];
cp.fromTimestamp = block.timestamp;
cp.owner = cpOld.owner;
// do not expect balance_ > cpOld.delegatedBalance when decrementing but just in case
cp.delegatedBalance = _increase
? cpOld.delegatedBalance + balance_
: (balance_ < cpOld.delegatedBalance ? cpOld.delegatedBalance - balance_ : 0);
cp.delegatee = cpOld.delegatee;
if (_isCheckpointInNewBlock(_numCheckpoints, _checkpoints, _delegatee)) {
_numCheckpoints[_delegatee]++;
} else {
_checkpoints[_delegatee][numCheckpoint - 1] = cp;
delete _checkpoints[_delegatee][numCheckpoint];
}
}
function _isCheckpointInNewBlock(
mapping(uint256 => uint48) storage _numCheckpoints,
mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage _checkpoints,
uint256 _tokenId
) internal view returns (bool) {
uint48 _nCheckPoints = _numCheckpoints[_tokenId];
if (_nCheckPoints > 0 && _checkpoints[_tokenId][_nCheckPoints - 1].fromTimestamp == block.timestamp) {
return false;
} else {
return true;
}
}
/// @notice Binary search to get the voting checkpoint for a token id at or prior to a given timestamp.
/// @dev If a checkpoint does not exist prior to the timestamp, this will return 0.
/// @param _numCheckpoints State of all user checkpoint counts
/// @param _checkpoints State of all user checkpoints
/// @param _tokenId .
/// @param _timestamp .
/// @return The index of the checkpoint.
function getPastVotesIndex(
mapping(uint256 => uint48) storage _numCheckpoints,
mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage _checkpoints,
uint256 _tokenId,
uint256 _timestamp
) internal view returns (uint48) {
uint48 nCheckpoints = _numCheckpoints[_tokenId];
if (nCheckpoints == 0) return 0;
// First check most recent balance
if (_checkpoints[_tokenId][nCheckpoints - 1].fromTimestamp <= _timestamp) return (nCheckpoints - 1);
// Next check implicit zero balance
if (_checkpoints[_tokenId][0].fromTimestamp > _timestamp) return 0;
uint48 lower = 0;
uint48 upper = nCheckpoints - 1;
while (upper > lower) {
uint48 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
IVotingEscrow.Checkpoint storage cp = _checkpoints[_tokenId][center];
if (cp.fromTimestamp == _timestamp) {
return center;
} else if (cp.fromTimestamp < _timestamp) {
lower = center;
} else {
upper = center - 1;
}
}
return lower;
}
/// @notice Retrieves historical voting balance for a token id at a given timestamp.
/// @dev If a checkpoint does not exist prior to the timestamp, this will return 0.
/// The user must also own the token at the time in order to receive a voting balance.
/// @param _numCheckpoints State of all user checkpoint counts
/// @param _checkpoints State of all user checkpoints
/// @param _account .
/// @param _tokenId .
/// @param _timestamp .
/// @return Total voting balance including delegations at a given timestamp.
function getPastVotes(
mapping(uint256 => uint48) storage _numCheckpoints,
mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage _checkpoints,
address _account,
uint256 _tokenId,
uint256 _timestamp
) external view returns (uint256) {
uint48 _checkIndex = getPastVotesIndex(_numCheckpoints, _checkpoints, _tokenId, _timestamp);
IVotingEscrow.Checkpoint memory lastCheckpoint = _checkpoints[_tokenId][_checkIndex];
// If no point exists prior to the given timestamp, return 0
if (lastCheckpoint.fromTimestamp > _timestamp) return 0;
// Check ownership
if (_account != lastCheckpoint.owner) return 0;
uint256 votes = lastCheckpoint.delegatedBalance;
return
lastCheckpoint.delegatee == 0
? votes + IVotingEscrow(address(this)).balanceOfNFTAt(_tokenId, _timestamp)
: votes;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
/// Modified IVotes interface for tokenId based voting
interface IVotes {
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, uint256 indexed fromDelegate, uint256 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 amount of votes that `tokenId` had at a specific moment in the past.
* If the account passed in is not the owner, returns 0.
*/
function getPastVotes(address account, uint256 tokenId, 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 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 `tokenId` has chosen. Can never be equal to the delegator's `tokenId`.
* Returns 0 if not delegated.
*/
function delegates(uint256 tokenId) external view returns (uint256);
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(uint256 delegator, uint256 delegatee) external;
/**
* @dev Delegates votes from `delegator` to `delegatee`. Signer must own `delegator`.
*/
function delegateBySig(
uint256 delegator,
uint256 delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC165, IERC721, IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import {IERC6372} from "@openzeppelin/contracts/interfaces/IERC6372.sol";
import {IERC4906} from "@openzeppelin/contracts/interfaces/IERC4906.sol";
import {IVotes} from "../governance/IVotes.sol";
interface IVotingEscrow is IVotes, IERC4906, IERC6372, IERC721Metadata {
struct LockedBalance {
int128 amount;
uint256 end;
bool isPermanent;
}
struct UserPoint {
int128 bias;
int128 slope; // # -dweight / dt
uint256 ts;
uint256 blk; // block
uint256 permanent;
}
struct GlobalPoint {
int128 bias;
int128 slope; // # -dweight / dt
uint256 ts;
uint256 blk; // block
uint256 permanentLockBalance;
}
/// @notice A checkpoint for recorded delegated voting weights at a certain timestamp
struct Checkpoint {
uint256 fromTimestamp;
address owner;
uint256 delegatedBalance;
uint256 delegatee;
}
enum DepositType {
DEPOSIT_FOR_TYPE,
CREATE_LOCK_TYPE,
INCREASE_LOCK_AMOUNT,
INCREASE_UNLOCK_TIME
}
/// @dev Different types of veNFTs:
/// NORMAL - typical veNFT
/// LOCKED - veNFT which is locked into a MANAGED veNFT
/// MANAGED - veNFT which can accept the deposit of NORMAL veNFTs
enum EscrowType {
NORMAL,
LOCKED,
MANAGED
}
error AlreadyVoted();
error AmountTooBig();
error ERC721ReceiverRejectedTokens();
error ERC721TransferToNonERC721ReceiverImplementer();
error InvalidNonce();
error InvalidSignature();
error InvalidSignatureS();
error InvalidManagedNFTId();
error LockDurationNotInFuture();
error LockDurationTooLong();
error LockExpired();
error LockNotExpired();
error NoLockFound();
error NonExistentToken();
error NotApprovedOrOwner();
error NotDistributor();
error NotEmergencyCouncilOrGovernor();
error NotGovernor();
error NotGovernorOrManager();
error NotManagedNFT();
error NotManagedOrNormalNFT();
error NotLockedNFT();
error NotNormalNFT();
error NotPermanentLock();
error NotOwner();
error NotTeam();
error NotVoter();
error OwnershipChange();
error PermanentLock();
error SameAddress();
error SameNFT();
error SameState();
error SplitNoOwner();
error SplitNotAllowed();
error SignatureExpired();
error TooManyTokenIDs();
error ZeroAddress();
error ZeroAmount();
error ZeroBalance();
event Deposit(
address indexed provider,
uint256 indexed tokenId,
DepositType indexed depositType,
uint256 value,
uint256 locktime,
uint256 ts
);
event Withdraw(address indexed provider, uint256 indexed tokenId, uint256 value, uint256 ts);
event LockPermanent(address indexed _owner, uint256 indexed _tokenId, uint256 amount, uint256 _ts);
event UnlockPermanent(address indexed _owner, uint256 indexed _tokenId, uint256 amount, uint256 _ts);
event Supply(uint256 prevSupply, uint256 supply);
event Merge(
address indexed _sender,
uint256 indexed _from,
uint256 indexed _to,
uint256 _amountFrom,
uint256 _amountTo,
uint256 _amountFinal,
uint256 _locktime,
uint256 _ts
);
event Split(
uint256 indexed _from,
uint256 indexed _tokenId1,
uint256 indexed _tokenId2,
address _sender,
uint256 _splitAmount1,
uint256 _splitAmount2,
uint256 _locktime,
uint256 _ts
);
event CreateManaged(
address indexed _to,
uint256 indexed _mTokenId,
address indexed _from,
address _lockedManagedReward,
address _freeManagedReward
);
event DepositManaged(
address indexed _owner,
uint256 indexed _tokenId,
uint256 indexed _mTokenId,
uint256 _weight,
uint256 _ts
);
event WithdrawManaged(
address indexed _owner,
uint256 indexed _tokenId,
uint256 indexed _mTokenId,
uint256 _weight,
uint256 _ts
);
event SetAllowedManager(address indexed _allowedManager);
// State variables
/// @notice Address of Meta-tx Forwarder
function forwarder() external view returns (address);
/// @notice Address of FactoryRegistry.sol
function factoryRegistry() external view returns (address);
/// @notice Address of token (NEP) used to create a veNFT
function token() external view returns (address);
/// @notice Address of RewardsDistributor.sol
function distributor() external view returns (address);
/// @notice Address of Voter.sol
function voter() external view returns (address);
/// @notice Address of Protocol Team multisig
function team() external view returns (address);
/// @notice Address of art proxy used for on-chain art generation
function artProxy() external view returns (address);
/// @dev address which can create managed NFTs
function allowedManager() external view returns (address);
/// @dev Current count of token
function tokenId() external view returns (uint256);
/*///////////////////////////////////////////////////////////////
MANAGED NFT STORAGE
//////////////////////////////////////////////////////////////*/
/// @dev Mapping of token id to escrow type
/// Takes advantage of the fact default value is EscrowType.NORMAL
function escrowType(uint256 tokenId) external view returns (EscrowType);
/// @dev Mapping of token id to managed id
function idToManaged(uint256 tokenId) external view returns (uint256 managedTokenId);
/// @dev Mapping of user token id to managed token id to weight of token id
function weights(uint256 tokenId, uint256 managedTokenId) external view returns (uint256 weight);
/// @dev Mapping of managed id to deactivated state
function deactivated(uint256 tokenId) external view returns (bool inactive);
/// @dev Mapping from managed nft id to locked managed rewards
/// `token` denominated rewards (rebases/rewards) stored in locked managed rewards contract
/// to prevent co-mingling of assets
function managedToLocked(uint256 tokenId) external view returns (address);
/// @dev Mapping from managed nft id to free managed rewards contract
/// these rewards can be freely withdrawn by users
function managedToFree(uint256 tokenId) external view returns (address);
/*///////////////////////////////////////////////////////////////
MANAGED NFT LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice Create managed NFT (a permanent lock) for use within ecosystem.
/// @dev Throws if address already owns a managed NFT.
/// @return _mTokenId managed token id.
function createManagedLockFor(address _to) external returns (uint256 _mTokenId);
/// @notice Delegates balance to managed nft
/// Note that NFTs deposited into a managed NFT will be re-locked
/// to the maximum lock time on withdrawal.
/// Permanent locks that are deposited will automatically unlock.
/// @dev Managed nft will remain max-locked as long as there is at least one
/// deposit or withdrawal per week.
/// Throws if deposit nft is managed.
/// Throws if recipient nft is not managed.
/// Throws if deposit nft is already locked.
/// Throws if not called by voter.
/// @param _tokenId tokenId of NFT being deposited
/// @param _mTokenId tokenId of managed NFT that will receive the deposit
function depositManaged(uint256 _tokenId, uint256 _mTokenId) external;
/// @notice Retrieves locked rewards and withdraws balance from managed nft.
/// Note that the NFT withdrawn is re-locked to the maximum lock time.
/// @dev Throws if NFT not locked.
/// Throws if not called by voter.
/// @param _tokenId tokenId of NFT being deposited.
function withdrawManaged(uint256 _tokenId) external;
/// @notice Permit one address to call createManagedLockFor() that is not Voter.governor()
function setAllowedManager(address _allowedManager) external;
/// @notice Set Managed NFT state. Inactive NFTs cannot be deposited into.
/// @param _mTokenId managed nft state to set
/// @param _state true => inactive, false => active
function setManagedState(uint256 _mTokenId, bool _state) external;
/*///////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function version() external view returns (string memory);
function decimals() external view returns (uint8);
function setTeam(address _team) external;
function setArtProxy(address _proxy) external;
/// @inheritdoc IERC721Metadata
function tokenURI(uint256 tokenId) external view returns (string memory);
/*//////////////////////////////////////////////////////////////
ERC721 BALANCE/OWNER STORAGE
//////////////////////////////////////////////////////////////*/
/// @dev Mapping from owner address to mapping of index to tokenId
function ownerToNFTokenIdList(address _owner, uint256 _index) external view returns (uint256 _tokenId);
/// @inheritdoc IERC721
function ownerOf(uint256 tokenId) external view returns (address owner);
/// @inheritdoc IERC721
function balanceOf(address owner) external view returns (uint256 balance);
/*//////////////////////////////////////////////////////////////
ERC721 APPROVAL STORAGE
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IERC721
function getApproved(uint256 _tokenId) external view returns (address operator);
/// @inheritdoc IERC721
function isApprovedForAll(address owner, address operator) external view returns (bool);
/// @notice Check whether spender is owner or an approved user for a given veNFT
/// @param _spender .
/// @param _tokenId .
function isApprovedOrOwner(address _spender, uint256 _tokenId) external returns (bool);
/*//////////////////////////////////////////////////////////////
ERC721 LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IERC721
function approve(address to, uint256 tokenId) external;
/// @inheritdoc IERC721
function setApprovalForAll(address operator, bool approved) external;
/// @inheritdoc IERC721
function transferFrom(address from, address to, uint256 tokenId) external;
/// @inheritdoc IERC721
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/// @inheritdoc IERC721
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/*//////////////////////////////////////////////////////////////
ERC165 LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IERC165
function supportsInterface(bytes4 _interfaceID) external view returns (bool);
/*//////////////////////////////////////////////////////////////
ESCROW STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice Total count of epochs witnessed since contract creation
function epoch() external view returns (uint256);
/// @notice Total amount of token() deposited
function supply() external view returns (uint256);
/// @notice Aggregate permanent locked balances
function permanentLockBalance() external view returns (uint256);
function userPointEpoch(uint256 _tokenId) external view returns (uint256 _epoch);
/// @notice time -> signed slope change
function slopeChanges(uint256 _timestamp) external view returns (int128);
/// @notice account -> can split
function canSplit(address _account) external view returns (bool);
/// @notice Global point history at a given index
function pointHistory(uint256 _loc) external view returns (GlobalPoint memory);
/// @notice Get the LockedBalance (amount, end) of a _tokenId
/// @param _tokenId .
/// @return LockedBalance of _tokenId
function locked(uint256 _tokenId) external view returns (LockedBalance memory);
/// @notice User -> UserPoint[userEpoch]
function userPointHistory(uint256 _tokenId, uint256 _loc) external view returns (UserPoint memory);
/*//////////////////////////////////////////////////////////////
ESCROW LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice Record global data to checkpoint
function checkpoint() external;
/// @notice Deposit `_value` tokens for `_tokenId` and add to the lock
/// @dev Anyone (even a smart contract) can deposit for someone else, but
/// cannot extend their locktime and deposit for a brand new user
/// @param _tokenId lock NFT
/// @param _value Amount to add to user's lock
function depositFor(uint256 _tokenId, uint256 _value) external;
/// @notice Deposit `_value` tokens for `msg.sender` and lock for `_lockDuration`
/// @param _value Amount to deposit
/// @param _lockDuration Number of seconds to lock tokens for (rounded down to nearest week)
/// @return TokenId of created veNFT
function createLock(uint256 _value, uint256 _lockDuration) external returns (uint256);
/// @notice Deposit `_value` tokens for `_to` and lock for `_lockDuration`
/// @param _value Amount to deposit
/// @param _lockDuration Number of seconds to lock tokens for (rounded down to nearest week)
/// @param _to Address to deposit
/// @return TokenId of created veNFT
function createLockFor(uint256 _value, uint256 _lockDuration, address _to) external returns (uint256);
/// @notice Deposit `_value` additional tokens for `_tokenId` without modifying the unlock time
/// @param _value Amount of tokens to deposit and add to the lock
function increaseAmount(uint256 _tokenId, uint256 _value) external;
/// @notice Extend the unlock time for `_tokenId`
/// Cannot extend lock time of permanent locks
/// @param _lockDuration New number of seconds until tokens unlock
function increaseUnlockTime(uint256 _tokenId, uint256 _lockDuration) external;
/// @notice Withdraw all tokens for `_tokenId`
/// @dev Only possible if the lock is both expired and not permanent
/// This will burn the veNFT. Any rebases or rewards that are unclaimed
/// will no longer be claimable. Claim all rebases and rewards prior to calling this.
function withdraw(uint256 _tokenId) external;
/// @notice Merges `_from` into `_to`.
/// @dev Cannot merge `_from` locks that are permanent or have already voted this epoch.
/// Cannot merge `_to` locks that have already expired.
/// This will burn the veNFT. Any rebases or rewards that are unclaimed
/// will no longer be claimable. Claim all rebases and rewards prior to calling this.
/// @param _from VeNFT to merge from.
/// @param _to VeNFT to merge into.
function merge(uint256 _from, uint256 _to) external;
/// @notice Splits veNFT into two new veNFTS - one with oldLocked.amount - `_amount`, and the second with `_amount`
/// @dev This burns the tokenId of the target veNFT
/// Callable by approved or owner
/// If this is called by approved, approved will not have permissions to manipulate the newly created veNFTs
/// Returns the two new split veNFTs to owner
/// If `from` is permanent, will automatically dedelegate.
/// This will burn the veNFT. Any rebases or rewards that are unclaimed
/// will no longer be claimable. Claim all rebases and rewards prior to calling this.
/// @param _from VeNFT to split.
/// @param _amount Amount to split from veNFT.
/// @return _tokenId1 Return tokenId of veNFT with oldLocked.amount - `_amount`.
/// @return _tokenId2 Return tokenId of veNFT with `_amount`.
function split(uint256 _from, uint256 _amount) external returns (uint256 _tokenId1, uint256 _tokenId2);
/// @notice Toggle split for a specific address.
/// @dev Toggle split for address(0) to enable or disable for all.
/// @param _account Address to toggle split permissions
/// @param _bool True to allow, false to disallow
function toggleSplit(address _account, bool _bool) external;
/// @notice Permanently lock a veNFT. Voting power will be equal to
/// `LockedBalance.amount` with no decay. Required to delegate.
/// @dev Only callable by unlocked normal veNFTs.
/// @param _tokenId tokenId to lock.
function lockPermanent(uint256 _tokenId) external;
/// @notice Unlock a permanently locked veNFT. Voting power will decay.
/// Will automatically dedelegate if delegated.
/// @dev Only callable by permanently locked veNFTs.
/// Cannot unlock if already voted this epoch.
/// @param _tokenId tokenId to unlock.
function unlockPermanent(uint256 _tokenId) external;
/*///////////////////////////////////////////////////////////////
GAUGE VOTING STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice Get the voting power for _tokenId at the current timestamp
/// @dev Returns 0 if called in the same block as a transfer.
/// @param _tokenId .
/// @return Voting power
function balanceOfNFT(uint256 _tokenId) external view returns (uint256);
/// @notice Get the voting power for _tokenId at a given timestamp
/// @param _tokenId .
/// @param _t Timestamp to query voting power
/// @return Voting power
function balanceOfNFTAt(uint256 _tokenId, uint256 _t) external view returns (uint256);
/// @notice Calculate total voting power at current timestamp
/// @return Total voting power at current timestamp
function totalSupply() external view returns (uint256);
/// @notice Calculate total voting power at a given timestamp
/// @param _t Timestamp to query total voting power
/// @return Total voting power at given timestamp
function totalSupplyAt(uint256 _t) external view returns (uint256);
/*///////////////////////////////////////////////////////////////
GAUGE VOTING LOGIC
//////////////////////////////////////////////////////////////*/
/// @notice See if a queried _tokenId has actively voted
/// @param _tokenId .
/// @return True if voted, else false
function voted(uint256 _tokenId) external view returns (bool);
/// @notice Set the global state voter and distributor
/// @dev This is only called once, at setup
function setVoterAndDistributor(address _voter, address _distributor) external;
/// @notice Set `voted` for _tokenId to true or false
/// @dev Only callable by voter
/// @param _tokenId .
/// @param _voted .
function voting(uint256 _tokenId, bool _voted) external;
/*///////////////////////////////////////////////////////////////
DAO VOTING STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice The number of checkpoints for each tokenId
function numCheckpoints(uint256 tokenId) external view returns (uint48);
/// @notice A record of states for signing / validating signatures
function nonces(address account) external view returns (uint256);
/// @inheritdoc IVotes
function delegates(uint256 delegator) external view returns (uint256);
/// @notice A record of delegated token checkpoints for each account, by index
/// @param tokenId .
/// @param index .
/// @return Checkpoint
function checkpoints(uint256 tokenId, uint48 index) external view returns (Checkpoint memory);
/// @inheritdoc IVotes
function getPastVotes(address account, uint256 tokenId, uint256 timestamp) external view returns (uint256);
/// @inheritdoc IVotes
function getPastTotalSupply(uint256 timestamp) external view returns (uint256);
/*///////////////////////////////////////////////////////////////
DAO VOTING LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IVotes
function delegate(uint256 delegator, uint256 delegatee) external;
/// @inheritdoc IVotes
function delegateBySig(
uint256 delegator,
uint256 delegatee,
uint256 nonce,
uint256 expiry,
uint8 v,
bytes32 r,
bytes32 s
) external;
/*//////////////////////////////////////////////////////////////
ERC6372 LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IERC6372
function clock() external view returns (uint48);
/// @inheritdoc IERC6372
function CLOCK_MODE() external view returns (string memory);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;
/// @title SafeCast Library
/// @notice Safely convert unsigned and signed integers without overflow / underflow
library SafeCastLibrary {
error SafeCastOverflow();
error SafeCastUnderflow();
/// @dev Safely convert uint256 to int128
function toInt128(uint256 value) internal pure returns (int128) {
if (value > uint128(type(int128).max)) revert SafeCastOverflow();
return int128(uint128(value));
}
/// @dev Safely convert int128 to uint256
function toUint256(int128 value) internal pure returns (uint256) {
if (value < 0) revert SafeCastUnderflow();
return uint256(int256(value));
}
}// 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
pragma solidity ^0.8.0;
import "./IERC165.sol";
import "./IERC721.sol";
/// @title EIP-721 Metadata Update Extension
interface IERC4906 is IERC165, IERC721 {
/// @dev This event emits when the metadata of a token is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFT.
event MetadataUpdate(uint256 _tokenId);
/// @dev This event emits when the metadata of a range of tokens is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFTs.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (interfaces/IERC6372.sol)
pragma solidity ^0.8.0;
interface IERC6372 {
/**
* @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
*/
function clock() external view returns (uint48);
/**
* @dev Description of the clock
*/
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() external view returns (string memory);
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol) pragma solidity ^0.8.0; import "../token/ERC721/IERC721.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @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 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);
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"remappings": [
"@opengsn/=lib/gsn/packages/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@uniswap/v3-core/=lib/v3-core/",
"ds-test/=lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"gsn/=lib/gsn/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solady/=lib/solady/src/",
"utils/=test/utils/"
],
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract Creation Code
610a8961003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061004b5760003560e01c8063656a7ea614610050578063690f66bf14610075578063ebe3337214610097575b600080fd5b61006361005e366004610885565b6100b7565b60405190815260200160405180910390f35b81801561008157600080fd5b506100956100903660046108cc565b6101f0565b005b8180156100a357600080fd5b506100956100b2366004610928565b61045d565b6000806100c687878686610677565b60008581526020888152604080832065ffffffffffff851684528252918290208251608081018452815480825260018301546001600160a01b03169382019390935260028201549381019390935260030154606083015291925090841015610133576000925050506101e7565b80602001516001600160a01b0316866001600160a01b03161461015b576000925050506101e7565b604081015160608201511561017057806101e1565b604051637028a55d60e11b81526004810187905260248101869052309063e0514aba90604401602060405180830381865afa1580156101b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d7919061097a565b6101e190826109a9565b93505050505b95945050505050565b60008381526020889052604081205461020b90600f0b6107ca565b60008581526020899052604081205491925065ffffffffffff9091169081610249576000868152602089815260408083208380529091529020610282565b6000868152602089905260408120906102636001856109c2565b65ffffffffffff1665ffffffffffff1681526020019081526020016000205b90506102968989836003015486600061045d565b60008681526020898152604080832065ffffffffffff86168452909152902042815560028281015490820155600381018690556001810180546001600160a01b0319166001600160a01b0387161790556102f18a8a896107f6565b1561034057600087815260208b905260408120805465ffffffffffff1691610318836109e8565b91906101000a81548165ffffffffffff021916908365ffffffffffff16021790555050610443565b600087815260208a905260408120829161035b6001876109c2565b65ffffffffffff1665ffffffffffff168152602001908152602001600020600082015481600001556001820160009054906101000a90046001600160a01b03168160010160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550600282015481600201556003820154816003015590505088600088815260200190815260200160002060008465ffffffffffff1665ffffffffffff1681526020019081526020016000206000808201600090556001820160006101000a8154906001600160a01b0302191690556002820160009055600382016000905550505b505050600093845250506020929092526040902055505050565b82156106705760008381526020869052604081205465ffffffffffff16908161049c5760008581526020878152604080832083805290915290206104d5565b6000858152602087905260408120906104b66001856109c2565b65ffffffffffff1665ffffffffffff1681526020019081526020016000205b60008681526020888152604080832065ffffffffffff87168452909152902042815560018083015490820180546001600160a01b0319166001600160a01b039092169190911790559091508361054c578160020154851061053757600061055c565b8482600201546105479190610a0d565b61055c565b84826002015461055c91906109a9565b6002820155600380830154908201556105768888886107f6565b156105c5576000868152602089905260408120805465ffffffffffff169161059d836109e8565b91906101000a81548165ffffffffffff021916908365ffffffffffff1602179055505061066c565b600086815260208890526040812082916105e06001876109c2565b65ffffffffffff9081168252602080830193909352604091820160009081208554815560018087015481830180546001600160a01b039092166001600160a01b031992831617905560028089015481850155600398890154938901939093558d84528e8752858420948b1684529390955292812081815593840180549092169091559082018190559101555b5050505b5050505050565b60008281526020859052604081205465ffffffffffff1680820361069f5760009150506107c2565b600084815260208690526040812084916106ba6001856109c2565b65ffffffffffff168152602081019190915260400160002054116106eb576106e36001826109c2565b9150506107c2565b6000848152602086815260408083208380529091529020548310156107145760009150506107c2565b6000806107226001846109c2565b90505b8165ffffffffffff168165ffffffffffff1611156107bd576000600261074b84846109c2565b6107559190610a20565b61075f90836109c2565b600088815260208a8152604080832065ffffffffffff851684529091529020805491925090879003610797575093506107c292505050565b80548711156107a8578193506107b6565b6107b36001836109c2565b92505b5050610725565b509150505b949350505050565b60008082600f0b12156107ef5760405162406f5d60e21b815260040160405180910390fd5b50600f0b90565b60008181526020849052604081205465ffffffffffff16801580159061084d5750600083815260208590526040812042916108326001856109c2565b65ffffffffffff168152602081019190915260400160002054145b1561085c576000915050610862565b60019150505b9392505050565b80356001600160a01b038116811461088057600080fd5b919050565b600080600080600060a0868803121561089d57600080fd5b85359450602086013593506108b460408701610869565b94979396509394606081013594506080013592915050565b600080600080600080600060e0888a0312156108e757600080fd5b873596506020880135955060408801359450606088013593506080880135925060a0880135915061091a60c08901610869565b905092959891949750929550565b600080600080600060a0868803121561094057600080fd5b853594506020860135935060408601359250606086013591506080860135801515811461096c57600080fd5b809150509295509295909350565b60006020828403121561098c57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156109bc576109bc610993565b92915050565b65ffffffffffff8281168282160390808211156109e1576109e1610993565b5092915050565b600065ffffffffffff808316818103610a0357610a03610993565b6001019392505050565b818103818111156109bc576109bc610993565b600065ffffffffffff80841680610a4757634e487b7160e01b600052601260045260246000fd5b9216919091049291505056fea2646970667358221220829b53da859e96bb70aab52d6bcf1ff77241bcd7952ca642196459403d1feea264736f6c63430008130033
Deployed Bytecode
0x7327db543f03481f97c79cf9ae866c9c2286cf7fdb301460806040526004361061004b5760003560e01c8063656a7ea614610050578063690f66bf14610075578063ebe3337214610097575b600080fd5b61006361005e366004610885565b6100b7565b60405190815260200160405180910390f35b81801561008157600080fd5b506100956100903660046108cc565b6101f0565b005b8180156100a357600080fd5b506100956100b2366004610928565b61045d565b6000806100c687878686610677565b60008581526020888152604080832065ffffffffffff851684528252918290208251608081018452815480825260018301546001600160a01b03169382019390935260028201549381019390935260030154606083015291925090841015610133576000925050506101e7565b80602001516001600160a01b0316866001600160a01b03161461015b576000925050506101e7565b604081015160608201511561017057806101e1565b604051637028a55d60e11b81526004810187905260248101869052309063e0514aba90604401602060405180830381865afa1580156101b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d7919061097a565b6101e190826109a9565b93505050505b95945050505050565b60008381526020889052604081205461020b90600f0b6107ca565b60008581526020899052604081205491925065ffffffffffff9091169081610249576000868152602089815260408083208380529091529020610282565b6000868152602089905260408120906102636001856109c2565b65ffffffffffff1665ffffffffffff1681526020019081526020016000205b90506102968989836003015486600061045d565b60008681526020898152604080832065ffffffffffff86168452909152902042815560028281015490820155600381018690556001810180546001600160a01b0319166001600160a01b0387161790556102f18a8a896107f6565b1561034057600087815260208b905260408120805465ffffffffffff1691610318836109e8565b91906101000a81548165ffffffffffff021916908365ffffffffffff16021790555050610443565b600087815260208a905260408120829161035b6001876109c2565b65ffffffffffff1665ffffffffffff168152602001908152602001600020600082015481600001556001820160009054906101000a90046001600160a01b03168160010160006101000a8154816001600160a01b0302191690836001600160a01b03160217905550600282015481600201556003820154816003015590505088600088815260200190815260200160002060008465ffffffffffff1665ffffffffffff1681526020019081526020016000206000808201600090556001820160006101000a8154906001600160a01b0302191690556002820160009055600382016000905550505b505050600093845250506020929092526040902055505050565b82156106705760008381526020869052604081205465ffffffffffff16908161049c5760008581526020878152604080832083805290915290206104d5565b6000858152602087905260408120906104b66001856109c2565b65ffffffffffff1665ffffffffffff1681526020019081526020016000205b60008681526020888152604080832065ffffffffffff87168452909152902042815560018083015490820180546001600160a01b0319166001600160a01b039092169190911790559091508361054c578160020154851061053757600061055c565b8482600201546105479190610a0d565b61055c565b84826002015461055c91906109a9565b6002820155600380830154908201556105768888886107f6565b156105c5576000868152602089905260408120805465ffffffffffff169161059d836109e8565b91906101000a81548165ffffffffffff021916908365ffffffffffff1602179055505061066c565b600086815260208890526040812082916105e06001876109c2565b65ffffffffffff9081168252602080830193909352604091820160009081208554815560018087015481830180546001600160a01b039092166001600160a01b031992831617905560028089015481850155600398890154938901939093558d84528e8752858420948b1684529390955292812081815593840180549092169091559082018190559101555b5050505b5050505050565b60008281526020859052604081205465ffffffffffff1680820361069f5760009150506107c2565b600084815260208690526040812084916106ba6001856109c2565b65ffffffffffff168152602081019190915260400160002054116106eb576106e36001826109c2565b9150506107c2565b6000848152602086815260408083208380529091529020548310156107145760009150506107c2565b6000806107226001846109c2565b90505b8165ffffffffffff168165ffffffffffff1611156107bd576000600261074b84846109c2565b6107559190610a20565b61075f90836109c2565b600088815260208a8152604080832065ffffffffffff851684529091529020805491925090879003610797575093506107c292505050565b80548711156107a8578193506107b6565b6107b36001836109c2565b92505b5050610725565b509150505b949350505050565b60008082600f0b12156107ef5760405162406f5d60e21b815260040160405180910390fd5b50600f0b90565b60008181526020849052604081205465ffffffffffff16801580159061084d5750600083815260208590526040812042916108326001856109c2565b65ffffffffffff168152602081019190915260400160002054145b1561085c576000915050610862565b60019150505b9392505050565b80356001600160a01b038116811461088057600080fd5b919050565b600080600080600060a0868803121561089d57600080fd5b85359450602086013593506108b460408701610869565b94979396509394606081013594506080013592915050565b600080600080600080600060e0888a0312156108e757600080fd5b873596506020880135955060408801359450606088013593506080880135925060a0880135915061091a60c08901610869565b905092959891949750929550565b600080600080600060a0868803121561094057600080fd5b853594506020860135935060408601359250606086013591506080860135801515811461096c57600080fd5b809150509295509295909350565b60006020828403121561098c57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156109bc576109bc610993565b92915050565b65ffffffffffff8281168282160390808211156109e1576109e1610993565b5092915050565b600065ffffffffffff808316818103610a0357610a03610993565b6001019392505050565b818103818111156109bc576109bc610993565b600065ffffffffffff80841680610a4757634e487b7160e01b600052601260045260246000fd5b9216919091049291505056fea2646970667358221220829b53da859e96bb70aab52d6bcf1ff77241bcd7952ca642196459403d1feea264736f6c63430008130033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.