文件 1 的 23:AbstractStaking.sol
pragma solidity 0.8.6;
import "./interfaces/INil.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
abstract contract AbstractStaking is AccessControl, ReentrancyGuard {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN");
bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN");
event Staked(address account, uint256 amount, uint256 balance, uint256 rewards, uint256 votes);
event Unstaked(address account, uint256 amount, uint256 balance, uint256 rewards, uint256 votes);
event Rewarded(address account, uint256 rewards);
event VotesSpent(address account, uint256 votesSpent, uint256 totalVotesStored);
event VotesSpenderSet(address spender);
event MinStakingPeriodSet(uint256 minStakingPeriod);
mapping(address => uint256) public balancePerAccount;
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public userVotesPerTokenPaid;
mapping(address => uint256) public rewardsByAccount;
mapping(address => uint256) public votesByAccount;
mapping(address => uint256) public stakingTimeByAccount;
address public voteSpender;
bool public emergencyShutdown;
uint256 public lastRewardsRateUpdate;
uint256 public lastVotesUpdate;
uint256 public rewardRatePerSecond;
uint256 public votesRatePerSecond;
uint256 public rewardPerTokenStored;
uint256 public votesPerTokenStored;
uint256 public totalVotesStored;
uint256 public minStakingPeriod;
uint256 public totalBalance;
INil public immutable nil;
constructor(
INil nil_,
address dao,
uint256 rewardRatePerSecond_,
uint256 votesRatePerSecond_
) {
require(address(nil_) != address(0), "AbstractStaking:ILLEGAL_ADDRESS");
nil = nil_;
rewardRatePerSecond = rewardRatePerSecond_;
votesRatePerSecond = votesRatePerSecond_;
lastRewardsRateUpdate = block.timestamp;
lastVotesUpdate = block.timestamp;
minStakingPeriod = 0;
_setupRole(GUARDIAN_ROLE, dao);
_setupRole(ADMIN_ROLE, dao);
_setupRole(GUARDIAN_ROLE, msg.sender);
_setupRole(ADMIN_ROLE, msg.sender);
_setRoleAdmin(GUARDIAN_ROLE, ADMIN_ROLE);
_setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
}
modifier onlyGuardian() {
require(hasRole(GUARDIAN_ROLE, msg.sender), "AbstractStaking:ACCESS_DENIED");
_;
}
modifier onlyAdmin() {
require(hasRole(ADMIN_ROLE, msg.sender), "AbstractStaking:ACCESS_DENIED");
_;
}
function updateRewards(uint256 newRate) external onlyAdmin {
require(newRate != rewardRatePerSecond, "AbstractStaking:RATE_NOT_CHANGED");
rewardPerTokenStored = rewardPerToken();
lastRewardsRateUpdate = block.timestamp;
rewardRatePerSecond = newRate;
}
function updateVotes(uint256 newRate) external onlyAdmin {
require(newRate != votesRatePerSecond, "AbstractStaking:RATE_NOT_CHANGED");
totalVotesStored = totalVotes();
votesPerTokenStored = votesPerToken();
lastVotesUpdate = block.timestamp;
votesRatePerSecond = newRate;
}
function rewardPerToken() public view returns (uint256) {
uint256 delta = block.timestamp - lastRewardsRateUpdate;
uint256 accruedRewards = delta * rewardRatePerSecond;
return (rewardPerTokenStored + accruedRewards);
}
function votesPerToken() public view returns (uint256) {
uint256 delta = block.timestamp - lastVotesUpdate;
uint256 accruedVotes = delta * votesRatePerSecond;
return (votesPerTokenStored + accruedVotes);
}
function calculateCurrentRewards(address account) public view returns (uint256, uint256) {
uint256 currentRewardPerToken = rewardPerToken();
uint256 newlyAccruedRewardsPerToken = (currentRewardPerToken - userRewardPerTokenPaid[account]);
uint256 currentRewards = rewardsByAccount[account] +
((balancePerAccount[account] * newlyAccruedRewardsPerToken) / 1e18);
return (currentRewards, currentRewardPerToken);
}
function calculateCurrentVotes(address account) public view returns (uint256, uint256) {
uint256 currentVotesPerToken = votesPerToken();
uint256 newlyAccruedVotesPerToken = (currentVotesPerToken - userVotesPerTokenPaid[account]);
uint256 currentVotes = votesByAccount[account] +
((balancePerAccount[account] * newlyAccruedVotesPerToken) / 1e18);
return (currentVotes, currentVotesPerToken);
}
function _accrueRewards(address account) internal returns (uint256) {
(uint256 currentRewards, uint256 currentRewardPerToken) = calculateCurrentRewards(account);
rewardsByAccount[account] = currentRewards;
userRewardPerTokenPaid[account] = currentRewardPerToken;
return currentRewards;
}
function _accrueVotes(address account) internal returns (uint256) {
(uint256 currentVotes, uint256 currentVotesPerToken) = calculateCurrentVotes(account);
votesByAccount[account] = currentVotes;
userVotesPerTokenPaid[account] = currentVotesPerToken;
uint256 newlyAccruedVotesPerToken = (currentVotesPerToken - votesPerTokenStored);
totalVotesStored = totalVotesStored + ((totalBalance * newlyAccruedVotesPerToken) / 1e18);
lastVotesUpdate = block.timestamp;
votesPerTokenStored = currentVotesPerToken;
return currentVotes;
}
function _stake(address account, uint256 amount) internal {
require(!emergencyShutdown, "AbstractStaking:SHUTDOWN");
uint256 rewards = _accrueRewards(account);
uint256 votes = _accrueVotes(account);
uint256 balance = balancePerAccount[account];
balancePerAccount[account] = balance + amount;
totalBalance += amount;
stakingTimeByAccount[account] = block.timestamp;
emit Staked(account, amount, balance, rewards, votes);
}
function _unstake(address account, uint256 amount) internal {
if (emergencyShutdown) return;
require(
block.timestamp - stakingTimeByAccount[account] > minStakingPeriod,
"AbstractStaking:MIN_STAKING_REQUIRED"
);
uint256 rewards = _accrueRewards(account);
uint256 votes = _accrueVotes(account);
uint256 balance = balancePerAccount[account];
balancePerAccount[account] = balance - amount;
totalBalance -= amount;
emit Unstaked(account, amount, balance, rewards, votes);
}
function claim(address account) external nonReentrant {
require(!emergencyShutdown, "AbstractStaking:SHUTDOWN");
(uint256 currentRewards, uint256 currentRewardPerToken) = calculateCurrentRewards(account);
require(currentRewards > 0, "AbstractStaking:ZERO_REWARDS");
rewardsByAccount[account] = 0;
userRewardPerTokenPaid[account] = currentRewardPerToken;
nil.mint(account, currentRewards);
emit Rewarded(account, currentRewards);
}
function claimableOf(address account) external view returns (uint256) {
(uint256 currentRewards, ) = calculateCurrentRewards(account);
return currentRewards;
}
function spendVotes(address account, uint256 amount) external nonReentrant {
require(!emergencyShutdown, "AbstractStaking:SHUTDOWN");
require(voteSpender == msg.sender, "AbstractStaking:ACCESS_DENIED");
(uint256 currentVotes, uint256 currentVotesPerToken) = calculateCurrentVotes(account);
votesByAccount[account] = currentVotes - amount;
userVotesPerTokenPaid[account] = currentVotesPerToken;
uint256 newlyAccruedVotesPerToken = (currentVotesPerToken - votesPerTokenStored);
totalVotesStored = (totalVotesStored + ((totalBalance * newlyAccruedVotesPerToken) / 1e18)) - amount;
lastVotesUpdate = block.timestamp;
votesPerTokenStored = currentVotesPerToken;
emit VotesSpent(account, amount, totalVotesStored);
}
function totalVotes() public view returns (uint256) {
return (totalVotesStored + ((totalBalance * (votesPerToken() - votesPerTokenStored)) / 1e18));
}
function setVoteSpender(address voteSpender_) external onlyAdmin {
voteSpender = voteSpender_;
emit VotesSpenderSet(voteSpender_);
}
function setMinStakingPeriod(uint256 minStakingPeriod_) external onlyAdmin {
require(minStakingPeriod_ < 14 days, "AbstractStaking:ILLEGAL_MIN_STAKING_PERIOD");
minStakingPeriod = minStakingPeriod_;
emit MinStakingPeriodSet(minStakingPeriod_);
}
function setEmergencyShutdown(bool emergencyShutdown_) external onlyGuardian {
emergencyShutdown = emergencyShutdown_;
}
}
文件 2 的 23:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) private {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 3 的 23:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 4 的 23:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 5 的 23:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 6 的 23:ERC721.sol
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
string private _name;
string private _symbol;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: owner query for nonexistent token");
return owner;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
function _baseURI() internal view virtual returns (string memory) {
return "";
}
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not owner nor approved for all"
);
_approve(to, tokenId);
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");
_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
function _safeTransfer(
address from,
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
}
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
}
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
}
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}
文件 7 的 23:ERC721Enumerable.sol
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
mapping(uint256 => uint256) private _ownedTokensIndex;
uint256[] private _allTokens;
mapping(uint256 => uint256) private _allTokensIndex;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId;
_ownedTokensIndex[lastTokenId] = tokenIndex;
}
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId;
_allTokensIndex[lastTokenId] = tokenIndex;
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
文件 8 的 23:ERC721Holder.sol
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
contract ERC721Holder is IERC721Receiver {
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
文件 9 的 23:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 10 的 23:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 11 的 23:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 12 的 23:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 13 的 23:IERC721Enumerable.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 14 的 23:IERC721Metadata.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Metadata is IERC721 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
}
文件 15 的 23:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 16 的 23:IN.sol
pragma solidity 0.8.6;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
interface IN is IERC721Enumerable, IERC721Metadata {
function getFirst(uint256 tokenId) external view returns (uint256);
function getSecond(uint256 tokenId) external view returns (uint256);
function getThird(uint256 tokenId) external view returns (uint256);
function getFourth(uint256 tokenId) external view returns (uint256);
function getFifth(uint256 tokenId) external view returns (uint256);
function getSixth(uint256 tokenId) external view returns (uint256);
function getSeventh(uint256 tokenId) external view returns (uint256);
function getEight(uint256 tokenId) external view returns (uint256);
}
文件 17 的 23:INOwnerResolver.sol
pragma solidity 0.8.6;
interface INOwnerResolver {
function ownerOf(uint256 nid) external view returns (address);
function balanceOf(address account) external view returns (uint256);
function nOwned(address owner) external view returns (uint256[] memory);
}
文件 18 的 23:INil.sol
pragma solidity 0.8.6;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface INil is IERC20 {
function MAX_SUPPLY() external returns (uint256);
function mint(address to, uint256 amount) external;
}
文件 19 的 23:NilProtocolUtils.sol
pragma solidity 0.8.6;
library NilProtocolUtils {
bytes internal constant TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function base64encode(bytes memory data) external pure returns (string memory) {
uint256 len = data.length;
if (len == 0) return "";
uint256 encodedLen = 4 * ((len + 2) / 3);
bytes memory result = new bytes(encodedLen + 32);
bytes memory table = TABLE;
assembly {
let tablePtr := add(table, 1)
let resultPtr := add(result, 32)
for {
let i := 0
} lt(i, len) {
} {
i := add(i, 3)
let input := and(mload(add(data, i)), 0xffffff)
let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF))
out := shl(8, out)
out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF))
out := shl(224, out)
mstore(resultPtr, out)
resultPtr := add(resultPtr, 4)
}
switch mod(len, 3)
case 1 {
mstore(sub(resultPtr, 2), shl(240, 0x3d3d))
}
case 2 {
mstore(sub(resultPtr, 1), shl(248, 0x3d))
}
mstore(result, encodedLen)
}
return string(result);
}
function stringify(uint256 value) external pure returns (string memory) {
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
}
文件 20 的 23:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 21 的 23:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
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");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 22 的 23:StakedN.sol
pragma solidity 0.8.6;
import "./AbstractStaking.sol";
import "./interfaces/IN.sol";
import "./interfaces/INil.sol";
import "./interfaces/INOwnerResolver.sol";
import "./libraries/NilProtocolUtils.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract StakedN is AbstractStaking, ERC721Holder, INOwnerResolver, ERC721Enumerable {
using Strings for uint256;
uint256 public constant N_UNIT = 1e18;
uint256 public constant N_SUPPLY = 8888;
uint256 public constant INVERSE_N_SHARE_OF_NIL = 4;
uint256 public constant VOTE_DENOMINATOR = 1;
IN public immutable n;
constructor(
INil nil_,
IN n_,
address dao,
uint256 rewardRatePerSecond,
uint256 votesRatePerSecond
) AbstractStaking(nil_, dao, rewardRatePerSecond, votesRatePerSecond) ERC721("Staked n", "STN") {
require(address(n_) != address(0), "StakedN:ILLEGAL_ADDRESS");
n = n_;
}
function stake(uint256[] calldata nIds) external nonReentrant {
for (uint256 i = 0; i < nIds.length; i++) {
n.safeTransferFrom(msg.sender, address(this), nIds[i]);
_mint(msg.sender, nIds[i]);
}
_stake(msg.sender, nIds.length * N_UNIT);
}
function unstake(uint256[] calldata nIds) external nonReentrant {
_unstake(msg.sender, nIds.length * N_UNIT);
for (uint256 i = 0; i < nIds.length; i++) {
require(ownerOf(nIds[i]) == msg.sender, "StakedN:WRONG_OWNER");
_burn(nIds[i]);
n.safeTransferFrom(address(this), msg.sender, nIds[i]);
}
}
function nOwned(address owner) external view override returns (uint256[] memory nids) {
uint256 balance = balanceOf(owner);
nids = new uint256[](balance);
for (uint256 i = 0; i < balance; i++) {
nids[i] = tokenOfOwnerByIndex(owner, i);
}
}
function ownerOf(uint256 nid) public view override(INOwnerResolver, ERC721) returns (address) {
return super.ownerOf(nid);
}
function balanceOf(address account) public view override(INOwnerResolver, ERC721) returns (uint256) {
return super.balanceOf(account);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 id
) internal virtual override {
require(from == address(0) || to == address(0), "StakedN:TRANSFER_DENIED");
super._beforeTokenTransfer(from, to, id);
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721Enumerable, AccessControl)
returns (bool)
{
return ERC721Enumerable.supportsInterface(interfaceId) || AccessControl.supportsInterface(interfaceId);
}
function getFirst(uint256 tokenId) public view returns (uint256) {
return n.getFirst(tokenId);
}
function getSecond(uint256 tokenId) public view returns (uint256) {
return n.getSecond(tokenId);
}
function getThird(uint256 tokenId) public view returns (uint256) {
return n.getThird(tokenId);
}
function getFourth(uint256 tokenId) public view returns (uint256) {
return n.getFourth(tokenId);
}
function getFifth(uint256 tokenId) public view returns (uint256) {
return n.getFifth(tokenId);
}
function getSixth(uint256 tokenId) public view returns (uint256) {
return n.getSixth(tokenId);
}
function getSeventh(uint256 tokenId) public view returns (uint256) {
return n.getSeventh(tokenId);
}
function getEight(uint256 tokenId) public view returns (uint256) {
return n.getEight(tokenId);
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
string[17] memory parts;
parts[
0
] = '<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>c1{stroke:#231f20;stroke-miterlimit:10;}c2{fill:#fff;}</style><rect class="cls-1" x="0.5" y="0.5" width="350" height="350"></rect><rect class="cls-2" x="182.734" y="129.922" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -45.581875, 186.4375)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="182.734" y="182.734" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -82.925415, 201.906036)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="235.545" y="182.734" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -67.456871, 239.248123)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="182.734" y="235.547" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -120.267502, 217.373123)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="129.924" y="129.922" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -61.050415, 149.093964)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="129.924" y="77.112" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -23.706875, 133.626877)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="77.112" y="129.922" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -76.517502, 111.751877)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="209.14" y="103.516" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -19.175833, 197.375)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="235.545" y="77.112" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, 7.22875, 208.3125)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="261.95" y="50.706" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, 33.634792, 219.25)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="50.706" y="261.949" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -177.609161, 131.75)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="77.112" y="235.547" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -151.20459, 142.6875)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="103.517" y="209.14" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -124.798538, 153.625)" style="fill: rgb(51, 51, 51);"></rect><rect class="cls-2" x="129.924" y="182.734" width="37.344" height="37.344" transform="matrix(0.707108, -0.707106, 0.707107, 0.707107, -98.392502, 164.5625)" style="fill: rgb(51, 51, 51);"></rect><text style="fill: rgb(255, 255, 255); font-family: serif, sans-serif; font-size: 6px; white-space: pre;" x="254.873" y="294.774" transform="matrix(1.166667, 0, 0, 1.166667, -0.083333, -0.083333)">';
parts[1] = NilProtocolUtils.stringify(n.getFirst(tokenId));
parts[2] = " ";
parts[3] = NilProtocolUtils.stringify(n.getSecond(tokenId));
parts[4] = " ";
parts[5] = NilProtocolUtils.stringify(n.getThird(tokenId));
parts[6] = " ";
parts[7] = NilProtocolUtils.stringify(n.getFourth(tokenId));
parts[8] = " ";
parts[9] = NilProtocolUtils.stringify(n.getFifth(tokenId));
parts[10] = " ";
parts[11] = NilProtocolUtils.stringify(n.getSixth(tokenId));
parts[12] = " ";
parts[13] = NilProtocolUtils.stringify(n.getSeventh(tokenId));
parts[14] = " ";
parts[15] = NilProtocolUtils.stringify(n.getEight(tokenId));
parts[16] = "</text></svg>";
string memory output = string(
abi.encodePacked(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8])
);
output = string(
abi.encodePacked(
output,
parts[9],
parts[10],
parts[11],
parts[12],
parts[13],
parts[14],
parts[15],
parts[16]
)
);
string memory json = NilProtocolUtils.base64encode(
bytes(
string(
abi.encodePacked(
'{"name": "sN #',
NilProtocolUtils.stringify(tokenId),
'", "description": "Staked N is just staked numbers.", "image": "data:image/svg+xml;base64,',
NilProtocolUtils.base64encode(bytes(output)),
'"}'
)
)
)
);
output = string(abi.encodePacked("data:application/json;base64,", json));
return output;
}
}
文件 23 的 23:Strings.sol
pragma solidity ^0.8.0;
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
function toString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
{
"compilationTarget": {
"contracts/StakedN.sol": "StakedN"
},
"evmVersion": "berlin",
"libraries": {
"contracts/libraries/NilProtocolUtils.sol:NilProtocolUtils": "0x61fae53d161095e9b75306837ff06c7b778f6504"
},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"contract INil","name":"nil_","type":"address"},{"internalType":"contract IN","name":"n_","type":"address"},{"internalType":"address","name":"dao","type":"address"},{"internalType":"uint256","name":"rewardRatePerSecond","type":"uint256"},{"internalType":"uint256","name":"votesRatePerSecond","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minStakingPeriod","type":"uint256"}],"name":"MinStakingPeriodSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"}],"name":"Rewarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"balance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"votes","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"balance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"votes","type":"uint256"}],"name":"Unstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"spender","type":"address"}],"name":"VotesSpenderSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"votesSpent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalVotesStored","type":"uint256"}],"name":"VotesSpent","type":"event"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GUARDIAN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"INVERSE_N_SHARE_OF_NIL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"N_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"N_UNIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VOTE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","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":"balancePerAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"calculateCurrentRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"calculateCurrentVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"claimableOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getEight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFifth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFirst","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFourth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSeventh","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSixth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getThird","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastRewardsRateUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastVotesUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minStakingPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"n","outputs":[{"internalType":"contract IN","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nOwned","outputs":[{"internalType":"uint256[]","name":"nids","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nil","outputs":[{"internalType":"contract INil","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nid","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardRatePerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardsByAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"emergencyShutdown_","type":"bool"}],"name":"setEmergencyShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minStakingPeriod_","type":"uint256"}],"name":"setMinStakingPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"voteSpender_","type":"address"}],"name":"setVoteSpender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"spendVotes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nIds","type":"uint256[]"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakingTimeByAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalVotesStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"nIds","type":"uint256[]"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRate","type":"uint256"}],"name":"updateRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRate","type":"uint256"}],"name":"updateVotes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userVotesPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"voteSpender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"votesByAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votesPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votesPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votesRatePerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]