Source Code
More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 23 from a total of 23 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Unstake Nft | 2319899 | 1166 days ago | IN | 0 GLMR | 0.01922281 | ||||
| Unstake Nft | 2319897 | 1166 days ago | IN | 0 GLMR | 0.02080953 | ||||
| Stake Nft | 2319889 | 1166 days ago | IN | 0 GLMR | 0.03355953 | ||||
| Stake Nft | 2319888 | 1166 days ago | IN | 0 GLMR | 0.00423789 | ||||
| Stake Nft | 2319886 | 1166 days ago | IN | 0 GLMR | 0.035935 | ||||
| Unstake Nft | 2319410 | 1166 days ago | IN | 0 GLMR | 0.0239091 | ||||
| Unstake Nft | 2319391 | 1166 days ago | IN | 0 GLMR | 0.01996884 | ||||
| Stake Nft | 2319378 | 1166 days ago | IN | 0 GLMR | 0.03355953 | ||||
| Batch Claim Ince... | 2318948 | 1166 days ago | IN | 0 GLMR | 0.0380464 | ||||
| Batch Unstake Nf... | 2318930 | 1166 days ago | IN | 0 GLMR | 0.02222835 | ||||
| Unstake Nft | 2318506 | 1166 days ago | IN | 0 GLMR | 0.0265131 | ||||
| Unstake Nft | 2318505 | 1166 days ago | IN | 0 GLMR | 0.02398578 | ||||
| Batch Claim Ince... | 2317874 | 1166 days ago | IN | 0 GLMR | 0.04737175 | ||||
| Stake Nft | 2317727 | 1166 days ago | IN | 0 GLMR | 0.0344764 | ||||
| Stake Nft | 2317499 | 1166 days ago | IN | 0 GLMR | 0.02680767 | ||||
| Stake Nft | 2317498 | 1166 days ago | IN | 0 GLMR | 0.02743463 | ||||
| Unstake Nft | 2317288 | 1166 days ago | IN | 0 GLMR | 0.01327924 | ||||
| Unstake Nft | 2317287 | 1166 days ago | IN | 0 GLMR | 0.02144898 | ||||
| Batch Claim Ince... | 2317247 | 1166 days ago | IN | 0 GLMR | 0.04784034 | ||||
| Stake Nft | 2316620 | 1166 days ago | IN | 0 GLMR | 0.02743463 | ||||
| Stake Nft | 2316616 | 1166 days ago | IN | 0 GLMR | 0.02896953 | ||||
| Stake Nft | 2316364 | 1166 days ago | IN | 0 GLMR | 0.03084737 | ||||
| Set Nft Battle A... | 2312222 | 1167 days ago | IN | 0 GLMR | 0.0047318 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Loading...
Loading
Contract Name:
NftStakingPosition
Compiler Version
v0.8.13+commit.abaa5c0e
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import "ERC721.sol";
import "Ownable.sol";
import "IERC20.sol";
import "ListingList.sol";
import "NftBattleArena.sol";
/// @title NftStakingPosition
/// @notice Contract to stake/unstake NFTs
contract NftStakingPosition is ERC721, Ownable
{
struct Nft
{
address token;
uint256 id;
}
event NftBattleArenaSet(address nftBattleArena);
// Records NFT contracts available for staking.
NftBattleArena public nftBattleArena;
ListingList public listingList;
IERC20 public zoo;
mapping (uint256 => Nft) public positions;
constructor(string memory _name, string memory _symbol, address _listingList, address _zoo) ERC721(_name, _symbol) Ownable()
{
listingList = ListingList(_listingList);
zoo = IERC20(_zoo);
}
function setNftBattleArena(address payable _nftBattleArena) external onlyOwner
{
require(address(nftBattleArena) == address(0));
nftBattleArena = NftBattleArena(_nftBattleArena);
emit NftBattleArenaSet(_nftBattleArena);
}
function stakeNft(address token, uint256 id) external
{
require(listingList.eligibleCollections(token), "NFT collection is not allowed");
IERC721(token).transferFrom(msg.sender, address(this), id); // Sends NFT token to this contract.
uint256 index = nftBattleArena.createStakerPosition(msg.sender, token);
_safeMint(msg.sender, index);
positions[index] = Nft(token, id);
}
function unstakeNft(uint256 stakingPositionId) external
{
require(ownerOf(stakingPositionId) == msg.sender, "Not the owner of NFT");
nftBattleArena.removeStakerPosition(stakingPositionId, msg.sender);
Nft storage nft = positions[stakingPositionId];
IERC721(nft.token).transferFrom(address(this), msg.sender, nft.id); // Transfers token back to owner.
}
function claimRewardFromStaking(uint256 stakingPositionId, address beneficiary) external
{
require(ownerOf(stakingPositionId) == msg.sender, "Not the owner of NFT");
nftBattleArena.claimRewardFromStaking(stakingPositionId, msg.sender, beneficiary);
}
/// Claims rewards from multiple staking positions
/// @param stakingPositionIds array of staking positions indexes
/// @param beneficiary address to transfer reward to
function batchClaimRewardsFromStaking(uint256[] calldata stakingPositionIds, address beneficiary) external
{
for (uint256 i = 0; i < stakingPositionIds.length; i++)
{
require(msg.sender == ownerOf(stakingPositionIds[i]), "Not the owner of NFT");
nftBattleArena.claimRewardFromStaking(stakingPositionIds[i], msg.sender, beneficiary);
}
}
function batchUnstakeNft(uint256[] calldata stakingPositionIds) external
{
for (uint256 i = 0; i < stakingPositionIds.length; i++)
{
require(msg.sender == ownerOf(stakingPositionIds[i]), "Not the owner of NFT");
nftBattleArena.removeStakerPosition(stakingPositionIds[i], msg.sender);
Nft storage nft = positions[stakingPositionIds[i]];
IERC721(nft.token).transferFrom(address(this), msg.sender, nft.id); // Transfers token back to owner.
}
}
function claimIncentiveStakerReward(uint256 stakingPositionId, address beneficiary) external returns (uint256)
{
require(ownerOf(stakingPositionId) == msg.sender, "Not the owner!"); // Requires to be owner of position.
uint256 reward = nftBattleArena.calculateIncentiveRewardForStaker(stakingPositionId);
zoo.transfer(beneficiary, reward);
return reward;
}
function batchClaimIncentiveStakerReward(uint256[] calldata stakingPositionIds, address beneficiary) external returns (uint256 reward)
{
for (uint256 i = 0; i < stakingPositionIds.length; i++)
{
require(ownerOf(stakingPositionIds[i]) == msg.sender, "Not the owner!"); // Requires to be owner of position.
reward += nftBattleArena.calculateIncentiveRewardForStaker(stakingPositionIds[i]);
}
zoo.transfer(beneficiary, reward);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "IERC721.sol";
import "IERC721Receiver.sol";
import "IERC721Metadata.sol";
import "Address.sol";
import "Context.sol";
import "Strings.sol";
import "ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: balance query for the zero address");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
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;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
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())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overriden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
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);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
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);
}
/**
* @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.
*
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
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");
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
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));
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
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"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
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);
_afterTokenTransfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId);
// Clear approvals from the previous owner
_approve(address(0), tokenId);
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits a {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param _data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
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;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* 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 Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @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 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);
/**
* @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;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// 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.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
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);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
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);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import "Ownable.sol";
import "IERC20.sol";
import "ERC721.sol";
/// @title ListingList
/// @notice Contract for recording nft contracts eligible for Zoo Dao Battles.
contract ListingList is Ownable, ERC721
{
struct CollectionRecord
{
uint256 decayRate;
uint256 rateOfIncrease;
uint256 weightAtTheStart;
}
struct VePositionInfo
{
uint256 expirationDate;
uint256 zooLocked;
address collection;
uint256 decayRate;
}
IERC20 public zoo; // Zoo collection interface.
/// @notice Event records address of allowed nft contract.
event NewContractAllowed(address indexed collection, address royalteRecipient);
event ContractDisallowed(address indexed collection, address royalteRecipient);
event RoyalteRecipientChanged(address indexed collection, address recipient);
event VotedForCollection(address indexed collection, address indexed voter, uint256 amount);
event ZooUnlocked(address indexed voter,address indexed collection, uint256 amount);
mapping (address => uint256) public lastUpdatedEpochsForCollection;
// Nft contract => allowed or not.
mapping (address => bool) public eligibleCollections;
// Nft contract => address recipient.
mapping (address => address) public royalteRecipient;
// collection => epoch number => Record
mapping (address => mapping (uint256 => CollectionRecord)) public collectionRecords;
mapping (uint256 => VePositionInfo) public vePositions;
mapping (address => uint256[]) public tokenOfOwnerByIndex;
uint256 public epochDuration;
uint256 public startDate;
uint256 public minTimelock;
uint256 public maxTimelock;
uint256 public vePositionIndex = 1;
uint256 public endEpochOfIncentiveRewards;
constructor(address _zoo, uint256 _duration, uint256 _minTimelock, uint256 _maxTimelock, uint256 _incentiveRewardsDuration) ERC721("veZoo", "VEZOO")
{
require(_minTimelock <= _duration, "Duration should be more than minTimeLock");
zoo = IERC20(_zoo);
startDate = block.timestamp;
epochDuration = _duration;
minTimelock = _minTimelock;
maxTimelock = _maxTimelock;
endEpochOfIncentiveRewards = _incentiveRewardsDuration / _duration + 1;
}
function getEpochNumber(uint256 timestamp) public view returns (uint256)
{
return (timestamp - startDate) / epochDuration + 1;// epoch numbers must start from 1
}
function getVectorForEpoch(address collection, uint256 epochIndex) public view returns (uint256)
{
require(lastUpdatedEpochsForCollection[collection] >= epochIndex, "Epoch record was not updated");
return computeVectorForEpoch(collection, epochIndex);
}
// address(0) for total (collection sum)
/// @notice Function to get ve-model pool weight for nft collection.
function poolWeight(address collection, uint256 epochIndex) public view returns(uint256 weight)
{
require(lastUpdatedEpochsForCollection[collection] >= epochIndex, "Epoch and colletion records were not updated");
return collectionRecords[collection][epochIndex].weightAtTheStart;
}
function updateCurrentEpochAndReturnPoolWeight(address collection) public returns (uint256 weight)
{
uint256 epochNumber = getEpochNumber(block.timestamp);
uint256 i = lastUpdatedEpochsForCollection[collection];
weight = poolWeight(collection, i);
while (i < epochNumber)
{
CollectionRecord storage collectionRecord = collectionRecords[collection][i + 1];
CollectionRecord storage collectionRecordOfPreviousEpoch = collectionRecords[collection][i];
uint256 decreasingOfWeight = computeVectorForEpoch(collection, i) * epochDuration;
if (collectionRecordOfPreviousEpoch.weightAtTheStart + collectionRecord.weightAtTheStart >= decreasingOfWeight)
collectionRecord.weightAtTheStart = collectionRecord.weightAtTheStart + collectionRecordOfPreviousEpoch.weightAtTheStart - decreasingOfWeight;
else
collectionRecord.weightAtTheStart = 0;
collectionRecord.decayRate += collectionRecordOfPreviousEpoch.decayRate;
collectionRecord.rateOfIncrease += collectionRecordOfPreviousEpoch.rateOfIncrease;
i++;
weight = collectionRecord.weightAtTheStart;
}
lastUpdatedEpochsForCollection[collection] = epochNumber;
}
/* ========== Eligible projects and royalte managemenet ===========*/
/// @notice Function to allow new NFT contract into eligible projects.
/// @param collection - address of new Nft contract.
function allowNewContractForStaking(address collection, address _royalteRecipient) external onlyOwner
{
eligibleCollections[collection] = true; // Boolean for contract to be allowed for staking.
royalteRecipient[collection] = _royalteRecipient; // Recipient for % of reward from that nft collection.
lastUpdatedEpochsForCollection[collection] = getEpochNumber(block.timestamp);
emit NewContractAllowed(collection, _royalteRecipient); // Emits event that new contract are allowed.
}
/// @notice Function to allow multiplie contracts into eligible projects.
function batchAllowNewContract(address[] calldata tokens, address[] calldata royalteRecipients) external onlyOwner
{
for (uint256 i = 0; i < tokens.length; i++)
{
eligibleCollections[tokens[i]] = true;
royalteRecipient[tokens[i]] = royalteRecipients[i]; // Recipient for % of reward from that nft collection.
emit NewContractAllowed(tokens[i], royalteRecipients[i]); // Emits event that new contract are allowed.
}
}
/// @notice Function to disallow contract from eligible projects and change royalte recipient for already staked nft.
function disallowContractFromStaking(address collection, address recipient) external onlyOwner
{
eligibleCollections[collection] = false;
royalteRecipient[collection] = recipient; // Recipient for % of reward from that nft collection.
emit ContractDisallowed(collection, recipient); // Emits event that new contract are allowed.
}
/// @notice Function to set or change royalte recipient without removing from eligible projects.
function setRoyalteRecipient(address collection, address recipient) external onlyOwner
{
royalteRecipient[collection] = recipient;
emit RoyalteRecipientChanged(collection, recipient);
}
/* ========== Ve-Model voting part ===========*/
function voteForNftCollection(address collection, uint256 amount, uint256 lockTime) public
{
require(eligibleCollections[collection], "NFT collection is not allowed");
require(lockTime <= maxTimelock && lockTime >= minTimelock, "incorrect lockTime");
zoo.transferFrom(msg.sender, address(this), amount);
addRecordForNewPosition(collection, amount, lockTime, msg.sender, vePositionIndex);
tokenOfOwnerByIndex[msg.sender].push(vePositionIndex);
_mint(msg.sender, vePositionIndex++);
}
function unlockZoo(uint256 positionId) external
{
require(ownerOf(positionId) == msg.sender);
VePositionInfo storage vePosition = vePositions[positionId];
uint256 currentEpoch = getEpochNumber(block.timestamp);
require(block.timestamp >= vePosition.expirationDate, "time lock doesn't expire");
zoo.transfer(msg.sender, vePosition.zooLocked);
_burn(positionId);
emit ZooUnlocked(msg.sender, vePosition.collection, vePosition.zooLocked);
}
function prolongate(uint256 positionId, uint256 lockTime) external
{
require(lockTime <= maxTimelock && lockTime >= minTimelock, "incorrect lockTime");
require(ownerOf(positionId) == msg.sender);
VePositionInfo storage vePosition = vePositions[positionId];
uint256 currentEpoch = getEpochNumber(block.timestamp);
uint256 expirationEpoch = getEpochNumber(vePosition.expirationDate);
address collection = vePosition.collection;
uint256 decayRate = vePosition.decayRate;
updateCurrentEpochAndReturnPoolWeight(collection);
updateCurrentEpochAndReturnPoolWeight(address(0));
if (vePosition.expirationDate > block.timestamp) // If position has not expired yet. We need to liquidate it and recreate.
{
collectionRecords[collection][expirationEpoch].rateOfIncrease -= decayRate;
collectionRecords[collection][currentEpoch + 1].rateOfIncrease += decayRate; // todo: may be not at current but at current + 1 epoch?
}
addRecordForNewPosition(collection, vePosition.zooLocked, lockTime, msg.sender, positionId);
}
function addRecordForNewPosition(address collection, uint256 amount, uint256 lockTime, address owner, uint256 positionId) internal
{
uint256 weight = amount * lockTime / maxTimelock;
uint256 currentEpoch = getEpochNumber(block.timestamp);
uint256 unlockEpoch = getEpochNumber(block.timestamp + lockTime);
uint256 decay = weight / lockTime;
vePositions[positionId] = VePositionInfo(block.timestamp + lockTime, amount, collection, decay);
collectionRecords[address(0)][currentEpoch + 1].decayRate += decay;
collectionRecords[address(0)][currentEpoch + 1].weightAtTheStart += weight;
collectionRecords[collection][currentEpoch + 1].decayRate += decay;
collectionRecords[collection][currentEpoch + 1].weightAtTheStart += weight;
collectionRecords[address(0)][unlockEpoch].rateOfIncrease += decay;
collectionRecords[collection][unlockEpoch].rateOfIncrease += decay;
emit VotedForCollection(collection, msg.sender, amount);
}
function computeVectorForEpoch(address collection, uint256 epochIndex) internal view returns (uint256)
{
CollectionRecord storage collectionRecord = collectionRecords[collection][epochIndex];
return collectionRecord.decayRate - collectionRecord.rateOfIncrease;
}
}pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import "IVault.sol";
import "IZooFunctions.sol";
import "ZooGovernance.sol";
import "ListingList.sol";
import "IERC20Metadata.sol";
import "Math.sol";
/// @notice Struct for stages of vote battle.
enum Stage
{
FirstStage,
SecondStage,
ThirdStage,
FourthStage,
FifthStage
}
interface ControllerInterface
{
function claimReward(uint8 rewardType, address holder) external;
}
/// @title NftBattleArena contract.
/// @notice Contract for staking ZOO-Nft for participate in battle votes.
contract NftBattleArena
{
using Math for uint256;
using Math for int256;
IERC20Metadata public zoo; // Zoo token interface.
IERC20Metadata public dai; // DAI token interface
VaultAPI public vault; // Yearn interface.
ZooGovernance public zooGovernance; // zooGovernance contract.
IZooFunctions public zooFunctions; // zooFunctions contract.
ListingList public veZoo;
ControllerInterface public tokenController;
IERC20Metadata public well;
/// @notice Struct with info about rewards, records for epoch.
struct BattleRewardForEpoch
{
int256 yTokensSaldo; // Saldo from deposit in yearn in yTokens.
uint256 votes; // Total amount of votes for nft in this battle in this epoch.
uint256 yTokens; // Amount of yTokens.
uint256 tokensAtBattleStart; // Amount of yTokens at battle start.
uint256 pricePerShareAtBattleStart; // pps at battle start.
uint256 pricePerShareCoef; // pps1*pps2/pps2-pps1
}
/// @notice Struct with info about staker positions.
struct StakerPosition
{
uint256 startEpoch; // Epoch when started to stake.
uint256 endEpoch; // Epoch when unstaked.
uint256 lastRewardedEpoch; // Epoch when last reward were claimed.
uint256 lastUpdateEpoch; // Epoch when last updateInfo called.
address collection; // Address of nft collection contract.
uint256 lastEpochOfIncentiveReward;
}
/// @notice struct with info about voter positions.
struct VotingPosition
{
uint256 stakingPositionId; // Id of staker position voted for.
uint256 daiInvested; // Amount of dai invested in voting position.
uint256 yTokensNumber; // Amount of yTokens got for dai.
uint256 zooInvested; // Amount of Zoo used to boost votes.
uint256 daiVotes; // Amount of votes got from voting with dai.
uint256 votes; // Amount of total votes from dai, zoo and multiplier.
uint256 startEpoch; // Epoch when created voting position.
uint256 endEpoch; // Epoch when liquidated voting position.
uint256 lastRewardedEpoch; // Epoch when last battle reward was claimed.
uint256 lastEpochYTokensWereDeductedForRewards; // Last epoch when yTokens used for rewards in battles were deducted from all voting position's yTokens
uint256 yTokensRewardDebt; // Amount of yTokens which voter can claim for previous epochs before add/withdraw votes.
uint256 lastEpochOfIncentiveReward;
}
/// @notice Struct for records about pairs of Nfts for battle.
struct NftPair
{
uint256 token1; // Id of staker position of 1st candidate.
uint256 token2; // Id of staker position of 2nd candidate.
bool playedInEpoch; // Returns true if winner chosen.
bool win; // Boolean, where true is when 1st candidate wins, and false for 2nd.
}
/// @notice Event about staked nft. FirstStage
event CreatedStakerPosition(uint256 indexed currentEpoch, address indexed staker, uint256 indexed stakingPositionId);
/// @notice Event about withdrawed nft from arena. FirstStage
event RemovedStakerPosition(uint256 indexed currentEpoch, address indexed staker, uint256 indexed stakingPositionId);
/// @notice Event about created voting position. SecondStage
event CreatedVotingPosition(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 daiAmount, uint256 votes, uint256 votingPositionId);
/// @notice Event about liquidated voting position. FirstStage
event LiquidatedVotingPosition(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, address beneficiary, uint256 votingPositionId, uint256 zooReturned, uint256 daiReceived);
/// @notice Event about recomputing votes from dai. SecondStage
event RecomputedDaiVotes(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 votingPositionId, uint256 newVotes, uint256 oldVotes);
/// @notice Event about recomputing votes from zoo. FourthStage
event RecomputedZooVotes(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 votingPositionId, uint256 newVotes, uint256 oldVotes);
/// @notice Event about adding dai to voter position. SecondStage
event AddedDaiToVoting(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 votingPositionId, uint256 amount, uint256 votes);
/// @notice Event about adding zoo to voter position. FourthStage
event AddedZooToVoting(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 votingPositionId, uint256 amount, uint256 votes);
/// @notice Event about withdraw dai from voter position. FirstStage
event WithdrawedDaiFromVoting(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, address beneficiary, uint256 votingPositionId, uint256 daiNumber);
/// @notice Event about withdraw zoo from voter position. FirstStage
event WithdrawedZooFromVoting(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, uint256 votingPositionId, uint256 zooNumber, address beneficiary);
/// @notice Event about claimed reward from voting. FirstStage
event ClaimedRewardFromVoting(uint256 indexed currentEpoch, address indexed voter, uint256 indexed stakingPositionId, address beneficiary, uint256 daiReward, uint256 votingPositionId);
/// @notice Event about claimed reward from staking. FirstStage
event ClaimedRewardFromStaking(uint256 indexed currentEpoch, address indexed staker, uint256 indexed stakingPositionId, address beneficiary, uint256 yTokenReward, uint256 daiReward);
/// @notice Event about paired nfts. ThirdStage
event PairedNft(uint256 indexed currentEpoch, uint256 indexed fighter1, uint256 indexed fighter2, uint256 pairIndex);
/// @notice Event about winners in battles. FifthStage
event ChosenWinner(uint256 indexed currentEpoch, uint256 indexed fighter1, uint256 indexed fighter2, bool winner, uint256 pairIndex, uint256 playedPairsAmount);
/// @notice Event about changing epochs.
event EpochUpdated(uint256 date, uint256 newEpoch);
uint256 public epochStartDate; // Start date of battle epoch.
uint256 public currentEpoch = 1; // Counter for battle epochs.
uint256 public firstStageDuration = 10 minutes;// hours; //todo:change time //3 days; // Duration of first stage(stake).
uint256 public secondStageDuration = 10 minutes;// hours; //todo:change time //7 days; // Duration of second stage(DAI)'.
uint256 public thirdStageDuration = 10 minutes;// hours; //todo:change time //2 days; // Duration of third stage(Pair).
uint256 public fourthStageDuration = 10 minutes;// hours; //todo:change time //5 days; // Duration fourth stage(ZOO).
uint256 public fifthStageDuration = 10 minutes;// hours; //todo:change time //2 days; // Duration of fifth stage(Winner).
uint256 public epochDuration = firstStageDuration + secondStageDuration + thirdStageDuration + fourthStageDuration + fifthStageDuration; // Total duration of battle epoch.
uint256[] public activeStakerPositions; // Array of ZooBattle nfts, which are StakerPositions.
uint256 public numberOfNftsWithNonZeroVotes; // Staker positions with votes for, eligible to pair and battle.
uint256 public nftsInGame; // Amount of Paired nfts in current epoch.
uint256 public numberOfStakingPositions = 1;
uint256 public numberOfVotingPositions = 1;
address public treasury; // Address of ZooDao insurance pool.
address public gasPool; // Address of ZooDao gas fee compensation pool.
address public team; // Address of ZooDao team reward pool.
address public xZoo;
address public jackpotA;
address public jackpotB;
address payable public wGlmr;
address public nftStakingPosition;
address public nftVotingPosition;
uint256 public baseStakerReward = 83333 * 10 ** 18; // 83 333 zoo.
uint256 public baseVoterReward = 2000000 * 10 ** 18; // 2 000 000 zoo.
// epoch number => index => NftPair struct.
mapping (uint256 => NftPair[]) public pairsInEpoch; // Records info of pair in struct per battle epoch.
// epoch number => number of played pairs in epoch.
mapping (uint256 => uint256) public numberOfPlayedPairsInEpoch; // Records amount of pairs with chosen winner in current epoch.
// position id => StakerPosition struct.
mapping (uint256 => StakerPosition) public stakingPositionsValues; // Records info about staker position.
// position id => VotingPosition struct.
mapping (uint256 => VotingPosition) public votingPositionsValues; // Records info about voter position.
// epoch index => collection => number of staked nfts.
mapping (uint256 => mapping (address => uint256)) public numberOfStakedNftsInCollection;
// collection => last epoch when was updated info about numberOfStakedNftsInCollection.
mapping (address => uint256) public lastUpdatesOfStakedNumbers;
// epoch => yvTokens
mapping (uint256 => uint256) public xZooRewards;
// epoch => yvTokens
mapping (uint256 => uint256) public jackpotRewardsAtEpoch;
// staker position id => epoch = > rewards struct.
mapping (uint256 => mapping (uint256 => BattleRewardForEpoch)) public rewardsForEpoch;
// epoch number => timestamp of epoch start
mapping (uint256 => uint256) public epochsStarts;
// epoch number => well claimed
mapping (uint256 => uint256) public wellClaimedByEpoch;
// epoch number => glmr claimed
mapping (uint256 => uint256) public glmrClaimedByEpoch;
modifier only(address who)
{
require(msg.sender == who);
_;
}
/// @notice Contract constructor.
/// @param _zoo - address of Zoo token contract.
/// @param _dai - address of DAI token contract.
/// @param _vault - address of yearn.
/// @param _zooGovernance - address of ZooDao Governance contract.
/// @param _treasuryPool - address of ZooDao treasury pool.
/// @param _gasFeePool - address of ZooDao gas fee compensation pool.
/// @param _teamAddress - address of ZooDao team reward pool.
constructor (
IERC20Metadata _zoo,
IERC20Metadata _dai,
address _vault,
address _zooGovernance,
address _treasuryPool,
address _gasFeePool,
address _teamAddress,
address _nftStakingPosition,
address _nftVotingPosition,
address _veZoo,
address _controller,
IERC20Metadata _well)
{
zoo = _zoo;
dai = _dai;
vault = VaultAPI(_vault);
zooGovernance = ZooGovernance(_zooGovernance);
zooFunctions = IZooFunctions(zooGovernance.zooFunctions());
veZoo = ListingList(_veZoo);
treasury = _treasuryPool;
gasPool = _gasFeePool;
team = _teamAddress;
nftStakingPosition = _nftStakingPosition;
nftVotingPosition = _nftVotingPosition;
//battlesStartDate = block.timestamp;
epochStartDate = block.timestamp; //todo:change time for prod + n days; // Start date of 1st battle.
epochsStarts[currentEpoch] = block.timestamp;
tokenController = ControllerInterface(_controller);
well = _well;
}
function init(address _xZoo, address _jackpotA, address _jackpotB, address payable _wglmr) external
{
require(xZoo == address(0));
xZoo = _xZoo;
jackpotA = _jackpotA;
jackpotB = _jackpotB;
wGlmr = _wglmr;
}
receive() external payable { }
/// @notice Function to get amount of nft in array StakerPositions/staked in battles.
/// @return amount - amount of ZooBattles nft.
function getStakerPositionsLength() public view returns (uint256 amount)
{
return activeStakerPositions.length;
}
/// @notice Function to get amount of nft pairs in epoch.
/// @param epoch - number of epoch.
/// @return length - amount of nft pairs.
function getNftPairLength(uint256 epoch) public view returns(uint256 length)
{
return pairsInEpoch[epoch].length;
}
/// @notice Function to calculate amount of tokens from shares.
/// @param sharesAmount - amount of shares.
/// @return tokens - calculated amount tokens from shares.
function sharesToTokens(uint256 sharesAmount) public view returns (uint256 tokens)
{
return sharesAmount * vault.exchangeRateStored() / (10 ** dai.decimals());
}
/// @notice Function for calculating tokens to shares.
/// @param tokens - amount of tokens to calculate.
/// @return shares - calculated amount of shares.
function tokensToShares(uint256 tokens) public view returns (uint256 shares)
{
return tokens * (10 ** dai.decimals()) / (vault.exchangeRateStored());
}
/// @notice Function for staking NFT in this pool.
/// @param staker address of staker
/// @param token NFT collection address
function createStakerPosition(address staker, address token) public only(nftStakingPosition) returns (uint256)
{
require(getCurrentStage() == Stage.FirstStage, "Wrong stage!"); // Requires to be at first stage in battle epoch.
StakerPosition storage position = stakingPositionsValues[numberOfStakingPositions];
position.startEpoch = currentEpoch; // Records startEpoch.
position.lastRewardedEpoch = currentEpoch; // Records lastRewardedEpoch
position.collection = token; // Address of nft collection.
position.lastEpochOfIncentiveReward = currentEpoch;
numberOfStakedNftsInCollection[currentEpoch][token]++; // Increments amount of nft collection.
activeStakerPositions.push(numberOfStakingPositions); // Records this position to stakers positions array.
emit CreatedStakerPosition(currentEpoch, staker, numberOfStakingPositions); // Emits StakedNft event.
return numberOfStakingPositions++; // Increments amount and id of future positions.
}
/// @notice Function for withdrawing staked nft.
/// @param stakingPositionId - id of staker position.
function removeStakerPosition(uint256 stakingPositionId, address staker) external only(nftStakingPosition)
{
require(getCurrentStage() == Stage.FirstStage, "Wrong stage!"); // Requires to be at first stage in battle epoch.
StakerPosition storage position = stakingPositionsValues[stakingPositionId];
require(position.endEpoch == 0, "Nft unstaked"); // Requires token to be staked.
position.endEpoch = currentEpoch; // Records epoch when unstaked.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
if (rewardsForEpoch[stakingPositionId][currentEpoch].votes > 0) // If votes for position in current epoch more than zero.
{
for(uint256 i = 0; i < numberOfNftsWithNonZeroVotes; i++) // Iterates for non-zero positions.
{
if (activeStakerPositions[i] == stakingPositionId) // Finds this position in array of active positions.
{
// Replace this position with another position from end of array. Then shift zero positions for one point.
activeStakerPositions[i] = activeStakerPositions[numberOfNftsWithNonZeroVotes - 1];
activeStakerPositions[numberOfNftsWithNonZeroVotes - 1] = activeStakerPositions[activeStakerPositions.length - 1];
numberOfNftsWithNonZeroVotes--;//After that decrements number of non zero positions.
break;
}
}
}
else // If votes for position in current epoch are zero, does the same, but without decrement numberOfNftsWithNonZeroVotes.
{
for(uint256 i = numberOfNftsWithNonZeroVotes; i < activeStakerPositions.length; i++)
{
if (activeStakerPositions[i] == stakingPositionId) // Finds this position in array.
{
activeStakerPositions[i] = activeStakerPositions[activeStakerPositions.length - 1];// Swaps to end of array.
break;
}
}
}
updateInfoAboutStakedNumber(position.collection);
numberOfStakedNftsInCollection[currentEpoch][position.collection]--;
activeStakerPositions.pop(); // Removes staker position from array.
emit RemovedStakerPosition(currentEpoch, staker, stakingPositionId); // Emits UnstakedNft event.
}
/// @notice Function for vote for nft in battle.
/// @param stakingPositionId - id of staker position.
/// @param amount - amount of dai to vote.
/// @return votes - computed amount of votes.
function createVotingPosition(uint256 stakingPositionId, address voter, uint256 amount) external only(nftVotingPosition) returns (uint256 votes, uint256 votingPositionId)
{
require(getCurrentStage() == Stage.SecondStage, "Wrong stage!"); // Requires to be at second stage of battle epoch.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
dai.approve(address(vault), type(uint256).max); // Approves Dai for yearn.
uint256 yTokensNumber = vault.mint(amount); // Deposits dai to yearn vault and get yTokens.
(votes, votingPositionId) = _createVotingPosition(stakingPositionId, voter, yTokensNumber, amount);// Calls internal create voting position.
}
/// @dev internal function to modify voting position params without vault deposit, making swap votes possible.
/// @param stakingPositionId ID of staking to create voting for
/// @param voter address of voter
/// @param yTokens amount of yTokens got from Yearn from deposit
/// @param amount daiVotes amount
function _createVotingPosition(uint256 stakingPositionId, address voter, uint256 yTokens, uint256 amount) public only(nftVotingPosition) returns (uint256 votes, uint256 votingPositionId)
{
require(stakingPositionsValues[stakingPositionId].startEpoch != 0 && stakingPositionsValues[stakingPositionId].endEpoch == 0, "Not staked"); // Requires for staking position to be staked.
votes = zooFunctions.computeVotesByDai(amount); // Calculates amount of votes.
VotingPosition storage position = votingPositionsValues[numberOfVotingPositions];
position.stakingPositionId = stakingPositionId; // Records staker position Id voted for.
position.daiInvested = amount; // Records amount of dai invested.
position.yTokensNumber = yTokens; // Records amount of yTokens got from yearn vault.
position.daiVotes = votes; // Records computed amount of votes to daiVotes.
position.votes = votes; // Records computed amount of votes to total votes.
position.startEpoch = currentEpoch; // Records epoch when position created.
position.lastRewardedEpoch = currentEpoch; // Sets starting point for reward to current epoch.
position.lastEpochOfIncentiveReward = currentEpoch;// Sets starting point for incentive rewards calculation.
BattleRewardForEpoch storage battleReward = rewardsForEpoch[stakingPositionId][currentEpoch];
if (battleReward.votes == 0) // If staker position had zero votes before,
{
for(uint256 i = 0; i < activeStakerPositions.length; i++) // Iterate for active staker positions.
{
if (activeStakerPositions[i] == stakingPositionId) // Finds this position.
{
if (stakingPositionId != numberOfNftsWithNonZeroVotes) // if equal, then its already in needed place in array.
{
(activeStakerPositions[i], activeStakerPositions[numberOfNftsWithNonZeroVotes]) = (activeStakerPositions[numberOfNftsWithNonZeroVotes], activeStakerPositions[i]);// Swaps this position in array, moving it to last point of non-zero positions.
}
numberOfNftsWithNonZeroVotes++; // Increases amount of nft eligible for pairing.
break;
}
}
}
battleReward.votes += votes; // Adds votes for staker position for this epoch.
battleReward.yTokens += yTokens; // Adds yTokens for this staker position for this epoch.
votingPositionId = numberOfVotingPositions;
numberOfVotingPositions++;
emit CreatedVotingPosition(currentEpoch, voter, stakingPositionId, amount, votes, votingPositionId);
}
/// @dev Calculates voting position's own yTokens - excludes yTokens that was used for rewards
/// @dev yTokens must be substracted even if voting won in battle (they go to the voting's pending reward)
/// @param votingPositionId ID of voting
function _calculateVotingYTokensExcludingRewards(uint256 votingPositionId) internal view returns(uint256 yTokens)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 stakingPositionId = votingPosition.stakingPositionId;
yTokens = votingPosition.yTokensNumber;
uint256 daiInvested = votingPosition.daiInvested;
uint256 startEpoch = votingPosition.startEpoch;
uint256 endEpoch = computeLastEpoch(votingPositionId);
for (uint256 i = startEpoch; i < endEpoch; i++)
{
if (rewardsForEpoch[stakingPositionId][i].pricePerShareCoef != 0)
{
yTokens -= daiInvested * 10**18 / (rewardsForEpoch[stakingPositionId][i].pricePerShareCoef);
}
}
}
/// @notice Function to recompute votes from dai.
/// @notice Reasonable to call at start of new epoch for better multiplier rate, if voted with low rate before.
/// @param votingPositionId - id of voting position.
function recomputeDaiVotes(uint256 votingPositionId) public
{
require(getCurrentStage() == Stage.SecondStage, "Wrong stage!"); // Requires to be at second stage of battle epoch.
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
_updateVotingRewardDebt(votingPositionId);
uint256 stakingPositionId = votingPosition.stakingPositionId;
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
uint256 daiNumber = votingPosition.daiInvested; // Gets amount of dai from voting position.
uint256 newVotes = zooFunctions.computeVotesByDai(daiNumber); // Recomputes dai to votes.
uint256 votes = votingPosition.votes; // Gets amount of votes from voting position.
require(newVotes > votes, "Recompute to lower value"); // Requires for new votes amount to be bigger than before.
votingPosition.daiVotes = newVotes; // Records new votes amount from dai.
votingPosition.votes = newVotes; // Records new votes amount total.
rewardsForEpoch[stakingPositionId][currentEpoch].votes += newVotes - votes; // Increases rewards for staker position for added amount of votes in this epoch.
emit RecomputedDaiVotes(currentEpoch, msg.sender, stakingPositionId, votingPositionId, newVotes, votes);
}
/// @notice Function to recompute votes from zoo.
/// @param votingPositionId - id of voting position.
function recomputeZooVotes(uint256 votingPositionId) public
{
require(getCurrentStage() == Stage.FourthStage, "Wrong stage!"); // Requires to be at 4th stage.
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
_updateVotingRewardDebt(votingPositionId);
uint256 stakingPositionId = votingPosition.stakingPositionId;
updateInfo(stakingPositionId);
uint256 zooNumber = votingPosition.zooInvested; // Gets amount of zoo invested from voting position.
uint256 newZooVotes = zooFunctions.computeVotesByZoo(zooNumber); // Recomputes zoo to votes.
uint256 oldZooVotes = votingPosition.votes - votingPosition.daiVotes;
require(newZooVotes > oldZooVotes, "Recompute to lower value"); // Requires for new votes amount to be bigger than before.
uint256 delta = newZooVotes + votingPosition.daiVotes / votingPosition.votes; // Gets amount of recently added zoo votes.
rewardsForEpoch[stakingPositionId][currentEpoch].votes += delta; // Adds amount of recently added votes to reward for staker position for current epoch.
votingPosition.votes += delta; // Add amount of recently added votes to total votes in voting position.
emit RecomputedZooVotes(currentEpoch, msg.sender, stakingPositionId, votingPositionId, newZooVotes, oldZooVotes);
}
/// @notice Function to add dai tokens to voting position.
/// @param votingPositionId - id of voting position.
/// @param voter - address of voter.
/// @param amount - amount of dai tokens to add.
/// @param _yTokens - amount of yTokens from previous position when called with swap.
function addDaiToVoting(uint256 votingPositionId, address voter, uint256 amount, uint256 _yTokens) public only(nftVotingPosition) returns (uint256 votes)
{
require(getCurrentStage() == Stage.SecondStage || _yTokens != 0, "Wrong stage!");// Requires to be at second stage of battle epoch.
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets id of staker position.
require(stakingPositionsValues[stakingPositionId].endEpoch == 0, "Position removed");// Requires to be staked.
_updateVotingRewardDebt(votingPositionId);
votes = zooFunctions.computeVotesByDai(amount); // Gets computed amount of votes from multiplier of dai.
if (_yTokens == 0) // if no _yTokens from another position with swap.
{
_yTokens = vault.mint(amount); // Deposits dai to yearn and gets yTokens.
}
votingPosition.yTokensNumber = _calculateVotingYTokensExcludingRewards(votingPositionId) + _yTokens;// Adds yTokens to voting position.
votingPosition.daiInvested += amount; // Adds amount of dai to voting position.
votingPosition.daiVotes += votes; // Adds computed daiVotes amount from to voting position.
votingPosition.votes += votes; // Adds computed votes amount to totalVotes amount for voting position.
votingPosition.startEpoch = currentEpoch;
updateInfo(stakingPositionId);
rewardsForEpoch[stakingPositionId][currentEpoch].votes += votes; // Adds votes to staker position for current epoch.
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens += _yTokens; // Adds yTokens to rewards from staker position for current epoch.
emit AddedDaiToVoting(currentEpoch, voter, stakingPositionId, votingPositionId, amount, votes);
}
/// @notice Function to add zoo tokens to voting position.
/// @param votingPositionId - id of voting position.
/// @param amount - amount of zoo tokens to add.
function addZooToVoting(uint256 votingPositionId, address voter, uint256 amount) external only(nftVotingPosition) returns (uint256 votes)
{
require(getCurrentStage() == Stage.FourthStage, "Wrong stage!"); // Requires to be at 3rd stage.
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
_updateVotingRewardDebt(votingPositionId); // Records current reward for voting position to reward debt.
votes = zooFunctions.computeVotesByZoo(amount); // Gets computed amount of votes from multiplier of zoo.
require(votingPosition.zooInvested + amount <= votingPosition.daiInvested, "Exceed limit");// Requires for votes from zoo to be less than votes from dai.
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets id of staker position.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
rewardsForEpoch[stakingPositionId][currentEpoch].votes += votes; // Adds votes for staker position.
votingPositionsValues[votingPositionId].votes += votes; // Adds votes to voting position.
votingPosition.zooInvested += amount; // Adds amount of zoo tokens to voting position.
emit AddedZooToVoting(currentEpoch, voter, stakingPositionId, votingPositionId, amount, votes);
}
/// @notice Functions to withdraw dai from voting position.
/// @param votingPositionId - id of voting position.
/// @param daiNumber - amount of dai to withdraw.
/// @param beneficiary - address of recipient.
function withdrawDaiFromVoting(uint256 votingPositionId, address voter, address beneficiary, uint256 daiNumber, bool toSwap) public only(nftVotingPosition)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets id of staker position.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
require(getCurrentStage() == Stage.FirstStage || stakingPositionsValues[stakingPositionId].endEpoch != 0, "Wrong stage!"); // Requires correct stage or nft to be unstaked.
require(votingPosition.endEpoch == 0, "Position removed"); // Requires to be not liquidated yet.
_updateVotingRewardDebt(votingPositionId);
_subtractYTokensUserForRewardsFromVotingPosition(votingPositionId);
if (daiNumber >= votingPosition.daiInvested) // If withdraw amount more or equal of maximum invested.
{
_liquidateVotingPosition(votingPositionId, voter, beneficiary, stakingPositionId, toSwap);// Calls liquidate and ends call.
return;
}
uint256 shares = tokensToShares(daiNumber); // If withdraw amount don't require liquidating, get amount of shares and continue.
if (toSwap == false) // If called not through swap.
{
dai.transfer(voter, vault.redeemUnderlying(shares));
}
uint256 deltaVotes = votingPosition.daiVotes * daiNumber / votingPosition.daiInvested;// Gets average amount of votes withdrawed, cause vote price could be different.
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens -= shares; // Decreases amount of shares for epoch.
rewardsForEpoch[stakingPositionId][currentEpoch].votes -= deltaVotes; // Decreases amount of votes for epoch for average votes.
votingPosition.yTokensNumber -= _calculateVotingYTokensExcludingRewards(votingPositionId) - shares;// Decreases amount of shares.
votingPosition.daiVotes -= deltaVotes;
votingPosition.votes -= deltaVotes; // Decreases amount of votes for position.
votingPosition.daiInvested -= daiNumber; // Decreases daiInvested amount of position.
if (votingPosition.zooInvested > votingPosition.daiInvested) // If zooInvested more than daiInvested left in position.
{
_rebalanceExceedZoo(votingPositionId, stakingPositionId, beneficiary); // Withdraws excess zoo to save 1-1 dai-zoo proportion.
}
emit WithdrawedDaiFromVoting(currentEpoch, voter, stakingPositionId, beneficiary, votingPositionId, daiNumber);
}
/// @dev Function to liquidate voting position and claim reward.
/// @param votingPositionId - id of position.
/// @param voter - address of position owner.
/// @param beneficiary - address of recipient.
/// @param stakingPositionId - id of staking position.
/// @param toSwap - boolean for swap votes, True if called from swapVotes function.
function _liquidateVotingPosition(uint256 votingPositionId, address voter, address beneficiary, uint256 stakingPositionId, bool toSwap) internal
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 daiInvested = votingPosition.daiInvested;
uint256 zooInvested = votingPosition.zooInvested;
uint256 yTokens = votingPosition.yTokensNumber;
if (toSwap == false) // If false, withdraws tokens from vault for regular liquidate.
{
dai.transfer(beneficiary, vault.redeemUnderlying(yTokens)); // True when called from swapVotes, ignores withdrawal to re-assign them for another position.
}
_withdrawZoo(zooInvested, beneficiary); // Even if it is swap, withdraws all zoo.
votingPosition.endEpoch = currentEpoch; // Sets endEpoch to currentEpoch.
BattleRewardForEpoch storage battleReward = rewardsForEpoch[stakingPositionId][currentEpoch];
battleReward.votes -= votingPosition.votes;// Decreases votes for staking position in current epoch.
if (battleReward.yTokens >= yTokens) // If withdraws less than in staking position.
{
battleReward.yTokens -= yTokens; // Decreases yTokens for this staking position.
}
else
{
battleReward.yTokens = 0; // Or nullify it if trying to withdraw more yTokens than left in position(because of yTokens current rate)
}
// IF there is votes on position AND staking position is active
if (battleReward.votes == 0 && stakingPositionsValues[stakingPositionId].endEpoch == 0)
{
// Move staking position to part, where staked without votes.
for(uint256 i = 0; i < activeStakerPositions.length; i++)
{
if (activeStakerPositions[i] == stakingPositionId)
{
(activeStakerPositions[i], activeStakerPositions[numberOfNftsWithNonZeroVotes - 1]) = (activeStakerPositions[numberOfNftsWithNonZeroVotes - 1], activeStakerPositions[i]); // Swaps position to end of array
numberOfNftsWithNonZeroVotes--; // Decrements amount of non-zero positions.
break;
}
}
}
emit LiquidatedVotingPosition(currentEpoch, voter, stakingPositionId, beneficiary, votingPositionId, zooInvested * 995 / 1000, daiInvested);
}
function _subtractYTokensUserForRewardsFromVotingPosition(uint256 votingPositionId) internal
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 yTokens = _calculateVotersYTokensExcludingRewards(votingPositionId);
votingPosition.yTokensNumber = yTokens;
votingPosition.lastEpochYTokensWereDeductedForRewards = currentEpoch;
}
/// @dev function to withdraw Zoo number greater than Dai number to save 1-1 dai-zoo proportion.
/// @param votingPositionId ID of voting to calculate yTokens
function _calculateVotersYTokensExcludingRewards(uint256 votingPositionId) internal view returns(uint256 yTokens)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 stakingPositionId = votingPosition.stakingPositionId;
yTokens = votingPosition.yTokensNumber;
uint256 daiInvested = votingPosition.daiInvested;
uint256 startEpoch = votingPosition.lastEpochYTokensWereDeductedForRewards;
uint256 endEpoch = computeLastEpoch(votingPositionId);
// From user yTokens subtract all tokens that go to the rewards
// This way allows to withdraw exact same amount of DAI user invested at the start
for (uint256 i = startEpoch; i < endEpoch; i++)
{
if (rewardsForEpoch[stakingPositionId][i].pricePerShareCoef != 0)
{
yTokens -= daiInvested * 10**18 / (rewardsForEpoch[stakingPositionId][i].pricePerShareCoef);
}
}
}
/// @dev function to withdraw Zoo number greater than Dai number to save 1-1 dai-zoo proportion.
/// @param votingPositionId ID of voting to reduce Zoo number
/// @param stakingPositionId ID of staking to reduce number of votes
/// @param beneficiary address to withdraw Zoo
function _rebalanceExceedZoo(uint256 votingPositionId, uint256 stakingPositionId, address beneficiary) internal
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 zooDelta = votingPosition.zooInvested - votingPosition.daiInvested; // Get amount of zoo exceeding.
_withdrawZoo(zooDelta, beneficiary); // Withdraws exceed zoo.
_reduceZooVotes(votingPositionId, stakingPositionId, zooDelta);
}
/// @dev function to calculate votes from zoo using average price and withdraw it.
function _reduceZooVotes(uint256 votingPositionId, uint256 stakingPositionId, uint256 zooNumber) internal
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 zooVotes = votingPosition.votes - votingPosition.daiVotes; // Calculates amount of votes got from zoo.
uint256 deltaVotes = zooVotes * zooNumber / votingPosition.zooInvested; // Calculates average amount of votes from this amount of zoo.
votingPosition.votes -= deltaVotes; // Decreases amount of votes.
votingPosition.zooInvested -= zooNumber; // Decreases amount of zoo invested.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
rewardsForEpoch[stakingPositionId][currentEpoch].votes -= deltaVotes; // Decreases amount of votes for staking position in current epoch.
}
/// @notice Functions to withdraw zoo from voting position.
/// @param votingPositionId - id of voting position.
/// @param zooNumber - amount of zoo to withdraw.
/// @param beneficiary - address of recipient.
function withdrawZooFromVoting(uint256 votingPositionId, address voter, uint256 zooNumber, address beneficiary) external only(nftVotingPosition)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
_updateVotingRewardDebt(votingPositionId);
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets id of staker position from this voting position.
require(getCurrentStage() == Stage.FirstStage || stakingPositionsValues[stakingPositionId].endEpoch != 0, "Wrong stage!"); // Requires correct stage or nft to be unstaked.
require(votingPosition.endEpoch == 0, "Position removed"); // Requires to be not liquidated yet.
uint256 zooInvested = votingPosition.zooInvested;
if (zooNumber > zooInvested) // If trying to withdraw more than invested, withdraws maximum.
{
zooNumber = zooInvested;
}
_withdrawZoo(zooNumber, beneficiary);
_reduceZooVotes(votingPositionId, stakingPositionId, zooNumber);
emit WithdrawedZooFromVoting(currentEpoch, voter, stakingPositionId, votingPositionId, zooNumber, beneficiary);
}
/// @notice Function to claim reward in yTokens from voting.
/// @param votingPositionId - id of voting position.
/// @param beneficiary - address of recipient of reward.
function claimRewardFromVoting(uint256 votingPositionId, address voter, address beneficiary) external only(nftVotingPosition) returns (uint256 daiReward)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
require(getCurrentStage() == Stage.FirstStage || stakingPositionsValues[votingPosition.stakingPositionId].endEpoch != 0, "Wrong stage!"); // Requires to be at first stage or position should be liquidated.
updateInfo(votingPosition.stakingPositionId);
(uint256 yTokenReward, uint256 wells, uint256 glmrs) = getPendingVoterReward(votingPositionId); // Calculates amount of reward in yTokens.
yTokenReward += votingPosition.yTokensRewardDebt; // Adds reward debt, from previous epochs.
votingPosition.yTokensRewardDebt = 0; // Nullify reward debt.
daiReward = vault.redeemUnderlying(yTokenReward * 980 / 1000); // Withdraws dai from vault for yTokens, minus staker %.
_daiRewardDistribution(beneficiary, votingPosition.stakingPositionId, daiReward); // Distributes reward between recipients, like treasury royalte, etc.
BattleRewardForEpoch storage battleReward = rewardsForEpoch[votingPosition.stakingPositionId][currentEpoch];
if (battleReward.yTokens >= yTokenReward * 980 / 1000)
{
battleReward.yTokens -= yTokenReward * 980 / 1000;// Subtracts yTokens for this position.
}
else
{
battleReward.yTokens = 0;
}
votingPosition.lastRewardedEpoch = computeLastEpoch(votingPositionId); // Records epoch of last reward claimed.
well.transfer(beneficiary, wells);
IERC20Metadata(wGlmr).transfer(beneficiary, glmrs);
emit ClaimedRewardFromVoting(currentEpoch, voter, votingPosition.stakingPositionId, beneficiary, daiReward, votingPositionId);
}
/// @dev Updates yTokensRewardDebt of voting.
/// @dev Called before every action with voting to prevent increasing share % in battle reward.
/// @param votingPositionId ID of voting to be updated.
function _updateVotingRewardDebt(uint256 votingPositionId) internal {
(uint256 reward,,) = getPendingVoterReward(votingPositionId);
if (reward != 0)
{
votingPositionsValues[votingPositionId].yTokensRewardDebt += reward;
}
votingPositionsValues[votingPositionId].lastRewardedEpoch = currentEpoch;
}
/// @notice Function to calculate pending reward from voting for position with this id.
/// @param votingPositionId - id of voter position in battles.
/// @return yTokens - amount of pending reward.
function getPendingVoterReward(uint256 votingPositionId) public view returns (uint256 yTokens, uint256 wells, uint256 glmr)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
uint256 startEpoch = votingPosition.lastRewardedEpoch;
uint256 endEpoch = computeLastEpoch(votingPositionId);
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets staker position id from voter position.
for (uint256 i = startEpoch; i < endEpoch; i++)
{
int256 saldo = rewardsForEpoch[stakingPositionId][i].yTokensSaldo; // Gets saldo from staker position for every epoch in range.
uint256 totalVotes = rewardsForEpoch[stakingPositionId][i].votes; // Gets total votes from staker position.
if (saldo > 0)
{
yTokens += uint256(saldo) * votingPosition.votes / totalVotes; // Calculates yTokens amount for voter.
wells += wellClaimedByEpoch[i] * votingPosition.votes / totalVotes / numberOfPlayedPairsInEpoch[i];
glmr += glmrClaimedByEpoch[i] * votingPosition.votes / totalVotes / numberOfPlayedPairsInEpoch[i];
}
}
return (yTokens, wells, glmr);
}
/// @notice Function to claim reward for staker.
/// @param stakingPositionId - id of staker position.
/// @param beneficiary - address of recipient.
function claimRewardFromStaking(uint256 stakingPositionId, address staker, address beneficiary) public only(nftStakingPosition) returns (uint256 daiReward)
{
StakerPosition storage stakerPosition = stakingPositionsValues[stakingPositionId];
require(getCurrentStage() == Stage.FirstStage || stakerPosition.endEpoch != 0, "Wrong stage!"); // Requires to be at first stage in battle epoch.
updateInfo(stakingPositionId);
(uint256 yTokenReward, uint256 end) = getPendingStakerReward(stakingPositionId);
stakerPosition.lastRewardedEpoch = end; // Records epoch of last reward claim.
daiReward = vault.redeemUnderlying(yTokenReward); // Gets reward from yearn.
dai.transfer(beneficiary, daiReward);
emit ClaimedRewardFromStaking(currentEpoch, staker, stakingPositionId, beneficiary, yTokenReward, daiReward);
}
/// @notice Function to get pending reward fo staker for this position id.
/// @param stakingPositionId - id of staker position.
/// @return stakerReward - reward amount for staker of this nft.
function getPendingStakerReward(uint256 stakingPositionId) public view returns (uint256 stakerReward, uint256 end)
{
StakerPosition storage stakerPosition = stakingPositionsValues[stakingPositionId];
uint256 endEpoch = stakerPosition.endEpoch; // Gets endEpoch from position.
// todo: check that endEpoch (not lastRewardedEpoch)
end = endEpoch == 0 ? currentEpoch : endEpoch; // Sets end variable to endEpoch if it non-zero, otherwise to currentEpoch.
int256 yTokensReward; // Define reward in yTokens.
for (uint256 i = stakerPosition.lastRewardedEpoch; i < end; i++)
{
int256 saldo = rewardsForEpoch[stakingPositionId][i].yTokensSaldo; // Get saldo from staker position.
if (saldo > 0)
{
yTokensReward += saldo * 25 / 975; // Calculates reward for staker.
}
}
stakerReward = uint256(yTokensReward); // Calculates reward amount.
}
/// @notice Function for pair nft for battles.
/// @param stakingPositionId - id of staker position.
function pairNft(uint256 stakingPositionId) external
{
require(getCurrentStage() == Stage.ThirdStage, "Wrong stage!"); // Requires to be at 3 stage of battle epoch.
require(numberOfNftsWithNonZeroVotes / 2 > nftsInGame / 2, "No opponent"); // Requires enough nft for pairing.
uint256 index1; // Index of nft paired for.
uint256 i;
for (i = nftsInGame; i < numberOfNftsWithNonZeroVotes; i++)
{
if (activeStakerPositions[i] == stakingPositionId)
{
index1 = i;
break;
}
}
require(i != numberOfNftsWithNonZeroVotes, "Wrong position"); // Position not found in list of voted for and not paired.
(activeStakerPositions[index1], activeStakerPositions[nftsInGame]) = (activeStakerPositions[nftsInGame], activeStakerPositions[index1]);// Swaps nftsInGame with index.
nftsInGame++; // Increases amount of paired nft.
uint256 random = zooFunctions.computePseudoRandom() % (numberOfNftsWithNonZeroVotes - nftsInGame); // Get random number.
uint256 index2 = random + nftsInGame; // Get index of opponent.
uint256 pairIndex = getNftPairLength(currentEpoch);
uint256 stakingPosition2 = activeStakerPositions[index2]; // Get staker position id of opponent.
pairsInEpoch[currentEpoch].push(NftPair(stakingPositionId, stakingPosition2, false, false));// Pushes nft pair to array of pairs.
updateInfo(stakingPositionId);
updateInfo(stakingPosition2);
BattleRewardForEpoch storage battleReward1 = rewardsForEpoch[stakingPositionId][currentEpoch];
BattleRewardForEpoch storage battleReward2 = rewardsForEpoch[stakingPosition2][currentEpoch];
battleReward1.tokensAtBattleStart = sharesToTokens(battleReward1.yTokens); // Records amount of yTokens on the moment of pairing for candidate.
battleReward2.tokensAtBattleStart = sharesToTokens(battleReward2.yTokens); // Records amount of yTokens on the moment of pairing for opponent.
battleReward1.pricePerShareAtBattleStart = vault.exchangeRateStored();
battleReward2.pricePerShareAtBattleStart = vault.exchangeRateStored();
(activeStakerPositions[index2], activeStakerPositions[nftsInGame]) = (activeStakerPositions[nftsInGame], activeStakerPositions[index2]); // Swaps nftsInGame with index of opponent.
nftsInGame++; // Increases amount of paired nft.
emit PairedNft(currentEpoch, stakingPositionId, stakingPosition2, pairIndex);
}
/// @notice Function to request random once per epoch.
function requestRandom() public
{
require(getCurrentStage() == Stage.FifthStage, "Wrong stage!"); // Requires to be at 5th stage.
uint256 wellInitialBalance = well.balanceOf(address(this));
tokenController.claimReward(0, address(this));
tokenController.claimReward(1, address(this));
wellClaimedByEpoch[currentEpoch] = well.balanceOf(address(this)) - wellInitialBalance;
glmrClaimedByEpoch[currentEpoch] = address(this).balance;
(bool sent, bytes memory data) = address(wGlmr).call{value: address(this).balance}("");
require(sent, "Failed to send Glmr");
zooFunctions.requestRandomNumber(); // Calls generate random number from chainlink or blockhash.
}
/// @notice Function for chosing winner for pair by its index in array.
/// @notice returns error if random number for deciding winner is NOT requested OR fulfilled in ZooFunctions contract
/// @param pairIndex - index of nft pair.
function chooseWinnerInPair(uint256 pairIndex) external
{
require(getCurrentStage() == Stage.FifthStage, "Wrong stage!"); // Requires to be at 5th stage.
NftPair storage pair = pairsInEpoch[currentEpoch][pairIndex];
require(pair.playedInEpoch == false, "Winner already chosen"); // Requires to be not paired before.
uint256 votes1 = rewardsForEpoch[pair.token1][currentEpoch].votes;
uint256 votes2 = rewardsForEpoch[pair.token2][currentEpoch].votes;
uint256 randomNumber = zooFunctions.getRandomResult(); // Gets random number from zooFunctions.
pair.win = zooFunctions.decideWins(votes1, votes2, randomNumber); // Calculates winner and records it.
pair.playedInEpoch = true; // Records that this pair already played this epoch.
numberOfPlayedPairsInEpoch[currentEpoch]++; // Increments amount of pairs played this epoch.
// Getting winner and loser to calculate rewards
(uint256 winner, uint256 loser) = pair.win? (pair.token1, pair.token2) : (pair.token2, pair.token1);
_calculateBattleRewards(winner, loser);
emit ChosenWinner(currentEpoch, pair.token1, pair.token2, pair.win, pairIndex, numberOfPlayedPairsInEpoch[currentEpoch]); // Emits ChosenWinner event.
if (numberOfPlayedPairsInEpoch[currentEpoch] == pairsInEpoch[currentEpoch].length)
{
updateEpoch(); // calls updateEpoch if winner determined in every pair.
}
}
/// @dev Contains calculation logic of battle rewards
/// @param winner stakingPositionId of NFT that WON in battle
/// @param loser stakingPositionId of NFT that LOST in battle
function _calculateBattleRewards(uint256 winner, uint256 loser) internal
{
BattleRewardForEpoch storage winnerRewards = rewardsForEpoch[winner][currentEpoch];
BattleRewardForEpoch storage loserRewards = rewardsForEpoch[loser][currentEpoch];
uint256 pps1 = winnerRewards.pricePerShareAtBattleStart;
// Skip if price per share didn't change since pairing
uint256 currentPps = vault.exchangeRateStored();
if (pps1 == currentPps)
{
return;
}
winnerRewards.pricePerShareCoef = currentPps * pps1 / (currentPps - pps1);
loserRewards.pricePerShareCoef = winnerRewards.pricePerShareCoef;
// Income = yTokens at battle end - yTokens at battle start
uint256 income1 = winnerRewards.yTokens - tokensToShares(winnerRewards.tokensAtBattleStart);
uint256 income2 = loserRewards.yTokens - tokensToShares(loserRewards.tokensAtBattleStart);
uint256 totalIncome = income1 + income2;
uint256 xRewards = totalIncome * 5 / 1000;
uint256 jackpotRewards = totalIncome * 1 / 100;
vault.transfer(xZoo, xRewards); // todo: need to check that all is correct after that
vault.transfer(jackpotA, jackpotRewards);
vault.transfer(jackpotB, jackpotRewards);
xZooRewards[currentEpoch] += xRewards;
jackpotRewardsAtEpoch[currentEpoch] += jackpotRewards;
winnerRewards.yTokensSaldo += int256(totalIncome - xRewards - 2 * jackpotRewards);
loserRewards.yTokensSaldo -= int256(income2);
rewardsForEpoch[winner][currentEpoch + 1].yTokens = winnerRewards.yTokens + totalIncome - xRewards - 2 * jackpotRewards;
rewardsForEpoch[loser][currentEpoch + 1].yTokens = loserRewards.yTokens - income2;
}
/// @dev Function for updating position in case of battle didn't happen after pairing.
function updateInfo(uint256 stakingPositionId) public
{
StakerPosition storage position = stakingPositionsValues[stakingPositionId];
uint256 lastUpdateEpoch = position.lastUpdateEpoch;
if (lastUpdateEpoch == currentEpoch)
return;
BattleRewardForEpoch storage rewardOfCurrentEpoch = rewardsForEpoch[stakingPositionId][currentEpoch];
BattleRewardForEpoch storage rewardOflastUpdateEpoch = rewardsForEpoch[stakingPositionId][lastUpdateEpoch];
rewardOfCurrentEpoch.votes = rewardOflastUpdateEpoch.votes;
rewardOfCurrentEpoch.yTokens = rewardOflastUpdateEpoch.yTokens;
position.lastUpdateEpoch = currentEpoch;
}
/// @notice Function to increment epoch.
function updateEpoch() public {
require(getCurrentStage() == Stage.FifthStage, "Wrong stage!"); // Requires to be at fourth stage.
require(block.timestamp >= epochStartDate + epochDuration || numberOfPlayedPairsInEpoch[currentEpoch] == pairsInEpoch[currentEpoch].length); // Requires fourth stage to end, or determine every pair winner.
zooFunctions = IZooFunctions(zooGovernance.zooFunctions()); // Sets ZooFunctions to contract specified in zooGovernance.
epochStartDate = block.timestamp; // Sets start date of new epoch.
currentEpoch++; // Increments currentEpoch.
epochsStarts[currentEpoch] = block.timestamp; // Records timestamp of new epoch start for ve-Zoo.
nftsInGame = 0; // Nullifies amount of paired nfts.
zooFunctions.resetRandom(); // Resets random in zoo functions.
firstStageDuration = zooFunctions.firstStageDuration();
secondStageDuration = zooFunctions.secondStageDuration();
thirdStageDuration = zooFunctions.thirdStageDuration();
fourthStageDuration = zooFunctions.fourthStageDuration();
fifthStageDuration = zooFunctions.fifthStageDuration();
epochDuration = firstStageDuration + secondStageDuration + thirdStageDuration + fourthStageDuration + fifthStageDuration; // Total duration of battle epoch.
emit EpochUpdated(block.timestamp, currentEpoch);
}
/// @notice Function to calculate incentive reward from ve-Zoo for voter.
function calculateIncentiveRewardForVoter(uint256 votingPositionId) external only(nftVotingPosition) returns (uint256 reward)
{
VotingPosition storage votingPosition = votingPositionsValues[votingPositionId];
address collection = stakingPositionsValues[votingPosition.stakingPositionId].collection;
updateInfo(votingPosition.stakingPositionId);
uint256 lastEpoch = computeLastEpoch(votingPositionId); // Last epoch
veZoo.updateCurrentEpochAndReturnPoolWeight(collection);
veZoo.updateCurrentEpochAndReturnPoolWeight(address(0));
// todo: should to add zooRewardDebt and update it every call with dai operations.
uint256 start = votingPosition.lastEpochOfIncentiveReward;
//reward = 0;
for (uint256 i = votingPosition.lastEpochOfIncentiveReward; i < lastEpoch; i++) // Need different start epoch and last epoch.
{
uint256 endEpoch = veZoo.getEpochNumber(epochsStarts[i + 1]);
if (endEpoch > veZoo.endEpochOfIncentiveRewards())
{
votingPosition.lastEpochOfIncentiveReward = currentEpoch;
return reward;
}
uint256 startEpoch = veZoo.getEpochNumber(epochsStarts[i]);
// todo: should to move calculations to veZoo
for (uint256 j = startEpoch; j < endEpoch; j++)
{
if (veZoo.poolWeight(address(0), j) != 0 && rewardsForEpoch[votingPosition.stakingPositionId][i].votes != 0)
reward += baseVoterReward * votingPosition.daiVotes * veZoo.poolWeight(collection, j) / veZoo.poolWeight(address(0), j) / rewardsForEpoch[votingPosition.stakingPositionId][i].votes;
}
}
votingPosition.lastEpochOfIncentiveReward = currentEpoch;
}
/// @notice Function to calculate incentive reward from ve-Zoo for staker.
function calculateIncentiveRewardForStaker(uint256 stakingPositionId) external only(nftStakingPosition) returns (uint256)
{
StakerPosition storage stakingPosition = stakingPositionsValues[stakingPositionId];
address collection = stakingPosition.collection; // Gets nft collection.
updateInfo(stakingPositionId); // Updates staking position params from previous epochs.
updateInfoAboutStakedNumber(collection); // Updates info about collection.
veZoo.updateCurrentEpochAndReturnPoolWeight(collection); // Updates info in veZoo about collection.
veZoo.updateCurrentEpochAndReturnPoolWeight(address(0)); // Updates info in veZoo for all pools together.
uint256 end = stakingPosition.endEpoch == 0 ? currentEpoch : stakingPosition.endEpoch;// Get recorded end epoch if it's not 0, or current epoch.
uint256 reward = 0;
uint256 start = stakingPosition.lastEpochOfIncentiveReward;
for (uint256 i = start; i < end; i++)
{
uint256 endEpoch = veZoo.getEpochNumber(epochsStarts[i + 1]);
if (endEpoch > veZoo.endEpochOfIncentiveRewards())
{
stakingPosition.lastEpochOfIncentiveReward = currentEpoch;
return reward;
}
uint256 startEpoch = veZoo.getEpochNumber(epochsStarts[i]);
for (uint256 j = startEpoch; j < endEpoch; j++)
{
if (veZoo.poolWeight(address(0), j) != 0)
reward += baseStakerReward * veZoo.poolWeight(collection, j) / veZoo.poolWeight(address(0), j) / numberOfStakedNftsInCollection[i][collection];
}
}
stakingPosition.lastEpochOfIncentiveReward = currentEpoch;
return reward;
}
/// @notice Function to get last epoch.
function computeLastEpoch(uint256 votingPositionId) public view returns (uint256 lastEpochNumber)
{
VotingPosition storage votingposition = votingPositionsValues[votingPositionId];
//uint256 stakingPositionId = votingposition.stakingPositionId; // Gets staker position id from voter position.
uint256 lastEpochOfStaking = stakingPositionsValues[votingposition.stakingPositionId].endEpoch; // Gets endEpoch from staking position.
// Staking - finished, Voting - finished
if (lastEpochOfStaking != 0 && votingposition.endEpoch != 0)
{
lastEpochNumber = Math.min(lastEpochOfStaking, votingposition.endEpoch);
}
// Staking - finished, Voting - existing
else if (lastEpochOfStaking != 0)
{
lastEpochNumber = lastEpochOfStaking;
}
// Staking - exists, Voting - finished
else if (votingposition.endEpoch != 0)
{
lastEpochNumber = votingposition.endEpoch;
}
// Staking - exists, Voting - exists
else
{
lastEpochNumber = currentEpoch;
}
}
function updateInfoAboutStakedNumber(address collection) public
{
uint256 start = lastUpdatesOfStakedNumbers[collection] > 1 ? lastUpdatesOfStakedNumbers[collection] : 1;
for (uint256 i = start; i <= currentEpoch; i++)
{
numberOfStakedNftsInCollection[i][collection] += numberOfStakedNftsInCollection[i - 1][collection];
}
lastUpdatesOfStakedNumbers[collection] = currentEpoch;
}
function _daiRewardDistribution(address beneficiary, uint256 stakingPositionId, uint256 daiReward) internal
{
address collection = stakingPositionsValues[stakingPositionId].collection;
address royalteRecipient = veZoo.royalteRecipient(collection);
dai.transfer(beneficiary, daiReward * 900 / 950); // Transfers voter part of reward.
dai.transfer(treasury, daiReward * 20 / 950); // Transfers treasury part.
dai.transfer(gasPool, daiReward * 10 / 950); // Transfers gasPool part.
dai.transfer(team, daiReward * 15 / 950); // Transfers team part.
dai.transfer(royalteRecipient, daiReward * 5 / 950);
}
/// @notice Internal function to calculate amount of zoo to burn and withdraw.
function _withdrawZoo(uint256 zooAmount, address beneficiary) internal
{
uint256 zooWithdraw = zooAmount * 995 / 1000; // Calculates amount of zoo to withdraw.
//uint256 zooToBurn = zooAmount * 5 / 1000; // Calculates amount of zoo to burn.
zoo.transfer(beneficiary, zooWithdraw); // Transfers zoo to beneficiary.
// We can lock zoo at battle arena forever so we don't need to send zoo for burn to zero address
//zoo.transfer(address(0), zooToBurn);
}
/// @notice Function to view current stage in battle epoch.
/// @return stage - current stage.
function getCurrentStage() public view returns (Stage)
{
uint256 time = epochStartDate + firstStageDuration;
if (block.timestamp < time)
{
return Stage.FirstStage; // Staking stage
}
time += secondStageDuration;
if (block.timestamp < time)
{
return Stage.SecondStage; // Dai vote stage.
}
time += thirdStageDuration;
if (block.timestamp < time)
{
return Stage.ThirdStage; // Pair stage.
}
time += fourthStageDuration;
if (block.timestamp < time)
{
return Stage.FourthStage; // Zoo vote stage.
}
else
{
return Stage.FifthStage; // Choose winner stage.
}
}
}pragma solidity 0.8.13;
pragma experimental ABIEncoderV2;
// SPDX-License-Identifier: MIT
interface VaultAPI {
function mint(uint256 mintAmount) external returns (uint256);
function redeemUnderlying(uint256 redeemAmount) external returns (uint256);
function exchangeRateStored() external view returns (uint);
function transfer(address who, uint256 amount) external returns (bool);
function increaseMockBalance() external;
}pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
/// @title interface of Zoo functions contract.
interface IZooFunctions {
/// @notice returns random number.
function randomResult() external view returns(uint256 random);
/// @notice sets random number in battles back to zero.
function resetRandom() external;
function randomFulfilled() external view returns(bool);
/// @notice Function for choosing winner in battle.
function decideWins(uint256 votesForA, uint256 votesForB, uint256 random) external view returns (bool);
/// @notice Function for generating random number.
function requestRandomNumber() external;
/// @notice Function for getting random number.
function getRandomResult() external returns(uint256);
/// @notice Function for getting random number for selected epoch (historical).
function getRandomResultByEpoch(uint256 epoch) external returns(uint256);
function computePseudoRandom() external view returns (uint256);
/// @notice Function for calculating voting with Dai in vote battles.
function computeVotesByDai(uint256 amount) external view returns (uint256);
/// @notice Function for calculating voting with Zoo in vote battles.
function computeVotesByZoo(uint256 amount) external view returns (uint256);
function firstStageDuration() external view returns (uint256);
function secondStageDuration() external view returns (uint256);
function thirdStageDuration() external view returns (uint256);
function fourthStageDuration() external view returns (uint256);
function fifthStageDuration() external view returns (uint256);
}pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import "IZooFunctions.sol";
import "Ownable.sol";
/// @title Contract ZooGovernance.
/// @notice Contract for Zoo Dao vote proposals.
contract ZooGovernance is Ownable {
address public zooFunctions; // Address of contract with Zoo functions.
/// @notice Contract constructor.
/// @param baseZooFunctions - address of baseZooFunctions contract.
/// @param aragon - address of aragon zoo dao agent.
constructor(address baseZooFunctions, address aragon) {
zooFunctions = baseZooFunctions;
transferOwnership(aragon); // Sets owner to aragon.
}
/// @notice Function for vote for changing Zoo fuctions.
/// @param newZooFunctions - address of new zoo functions contract.
function changeZooFunctionsContract(address newZooFunctions) external onlyOwner
{
zooFunctions = newZooFunctions;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a / b + (a % b == 0 ? 0 : 1);
}
}{
"evmVersion": "istanbul",
"optimizer": {
"enabled": true,
"runs": 200
},
"libraries": {
"NftStakingPosition.sol": {}
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_listingList","type":"address"},{"internalType":"address","name":"_zoo","type":"address"}],"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":"address","name":"nftBattleArena","type":"address"}],"name":"NftBattleArenaSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":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"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"stakingPositionIds","type":"uint256[]"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"batchClaimIncentiveStakerReward","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"stakingPositionIds","type":"uint256[]"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"batchClaimRewardsFromStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"stakingPositionIds","type":"uint256[]"}],"name":"batchUnstakeNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakingPositionId","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"claimIncentiveStakerReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakingPositionId","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"claimRewardFromStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"listingList","outputs":[{"internalType":"contract ListingList","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftBattleArena","outputs":[{"internalType":"contract NftBattleArena","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","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":"address payable","name":"_nftBattleArena","type":"address"}],"name":"setNftBattleArena","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"stakeNft","outputs":[],"stateMutability":"nonpayable","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":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stakingPositionId","type":"uint256"}],"name":"unstakeNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"zoo","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60806040523480156200001157600080fd5b50604051620025f0380380620025f083398101604081905262000034916200029b565b8351849084906200004d9060009060208501906200010b565b508051620000639060019060208401906200010b565b505050620000806200007a620000b560201b60201c565b620000b9565b600880546001600160a01b039384166001600160a01b0319918216179091556009805492909316911617905550620003669050565b3390565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b82805462000119906200032a565b90600052602060002090601f0160209004810192826200013d576000855562000188565b82601f106200015857805160ff191683800117855562000188565b8280016001018555821562000188579182015b82811115620001885782518255916020019190600101906200016b565b50620001969291506200019a565b5090565b5b808211156200019657600081556001016200019b565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620001d957600080fd5b81516001600160401b0380821115620001f657620001f6620001b1565b604051601f8301601f19908116603f01168101908282118183101715620002215762000221620001b1565b816040528381526020925086838588010111156200023e57600080fd5b600091505b8382101562000262578582018301518183018401529082019062000243565b83821115620002745760008385830101525b9695505050505050565b80516001600160a01b03811681146200029657600080fd5b919050565b60008060008060808587031215620002b257600080fd5b84516001600160401b0380821115620002ca57600080fd5b620002d888838901620001c7565b95506020870151915080821115620002ef57600080fd5b50620002fe87828801620001c7565b9350506200030f604086016200027e565b91506200031f606086016200027e565b905092959194509250565b600181811c908216806200033f57607f821691505b6020821081036200036057634e487b7160e01b600052602260045260246000fd5b50919050565b61227a80620003766000396000f3fe608060405234801561001057600080fd5b50600436106101c45760003560e01c8063715018a6116100f9578063a22cb46511610097578063b88d4fde11610071578063b88d4fde146103f7578063c87b56dd1461040a578063e985e9c51461041d578063f2fde38b1461045957600080fd5b8063a22cb465146103be578063a514e0a6146103d1578063aa7c9aa1146103e457600080fd5b806390db6f36116100d357806390db6f361461033e57806395749f9c1461035157806395d89b411461036457806399fbab881461036c57600080fd5b8063715018a6146103125780637b6a87771461031a5780638da5cb5b1461032d57600080fd5b80633158ad6d1161016657806342842e0e1161014057806342842e0e146102c65780636352211e146102d95780636b426000146102ec57806370a08231146102ff57600080fd5b80633158ad6d1461027f5780633660130b146102a05780633f05b6bb146102b357600080fd5b8063081812fc116101a2578063081812fc1461021b578063095ea7b31461024657806323b872dd146102595780632cd779f31461026c57600080fd5b806301ffc9a7146101c957806304f38b95146101f157806306fdde0314610206575b600080fd5b6101dc6101d7366004611bde565b61046c565b60405190151581526020015b60405180910390f35b6102046101ff366004611c47565b6104be565b005b61020e610660565b6040516101e89190611ce1565b61022e610229366004611cf4565b6106f2565b6040516001600160a01b0390911681526020016101e8565b610204610254366004611d22565b610787565b610204610267366004611d4e565b610897565b60075461022e906001600160a01b031681565b61029261028d366004611d8f565b6108c8565b6040519081526020016101e8565b6102046102ae366004611d22565b610a0c565b6102046102c1366004611dbf565b610bf9565b6102046102d4366004611d4e565b610c8d565b61022e6102e7366004611cf4565b610ca8565b6102046102fa366004611cf4565b610d1f565b61029261030d366004611dbf565b610e35565b610204610ebc565b60095461022e906001600160a01b031681565b6006546001600160a01b031661022e565b61020461034c366004611d8f565b610ef2565b60085461022e906001600160a01b031681565b61020e610f9f565b61039f61037a366004611cf4565b600a60205260009081526040902080546001909101546001600160a01b039091169082565b604080516001600160a01b0390931683526020830191909152016101e8565b6102046103cc366004611dea565b610fae565b6102926103df366004611e18565b610fbd565b6102046103f2366004611e18565b611123565b610204610405366004611e85565b61122e565b61020e610418366004611cf4565b611260565b6101dc61042b366004611f65565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b610204610467366004611dbf565b611348565b60006001600160e01b031982166380ac58cd60e01b148061049d57506001600160e01b03198216635b5e139f60e01b145b806104b857506301ffc9a760e01b6001600160e01b03198316145b92915050565b60005b8181101561065b576104ea8383838181106104de576104de611f93565b90506020020135610ca8565b6001600160a01b0316336001600160a01b0316146105235760405162461bcd60e51b815260040161051a90611fa9565b60405180910390fd5b6007546001600160a01b031663302c60de84848481811061054657610546611f93565b6040516001600160e01b031960e086901b16815260209091029290920135600483015250336024820152604401600060405180830381600087803b15801561058d57600080fd5b505af11580156105a1573d6000803e3d6000fd5b505050506000600a60008585858181106105bd576105bd611f93565b6020908102929092013583525081019190915260409081016000208054600182015492516323b872dd60e01b815230600482015233602482015260448101939093529092506001600160a01b0316906323b872dd90606401600060405180830381600087803b15801561062f57600080fd5b505af1158015610643573d6000803e3d6000fd5b5050505050808061065390611fed565b9150506104c1565b505050565b60606000805461066f90612006565b80601f016020809104026020016040519081016040528092919081815260200182805461069b90612006565b80156106e85780601f106106bd576101008083540402835291602001916106e8565b820191906000526020600020905b8154815290600101906020018083116106cb57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661076b5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161051a565b506000908152600460205260409020546001600160a01b031690565b600061079282610ca8565b9050806001600160a01b0316836001600160a01b0316036107ff5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b606482015260840161051a565b336001600160a01b038216148061081b575061081b813361042b565b61088d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606482015260840161051a565b61065b83836113e3565b6108a13382611451565b6108bd5760405162461bcd60e51b815260040161051a90612040565b61065b838383611548565b6000336108d484610ca8565b6001600160a01b03161461091b5760405162461bcd60e51b815260206004820152600e60248201526d4e6f7420746865206f776e65722160901b604482015260640161051a565b60075460405163993072bd60e01b8152600481018590526000916001600160a01b03169063993072bd906024016020604051808303816000875af1158015610967573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098b9190612091565b60095460405163a9059cbb60e01b81526001600160a01b0386811660048301526024820184905292935091169063a9059cbb906044016020604051808303816000875af11580156109e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0491906120aa565b509392505050565b600854604051630cb08b6f60e31b81526001600160a01b038481166004830152909116906365845b7890602401602060405180830381865afa158015610a56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a7a91906120aa565b610ac65760405162461bcd60e51b815260206004820152601d60248201527f4e465420636f6c6c656374696f6e206973206e6f7420616c6c6f776564000000604482015260640161051a565b6040516323b872dd60e01b8152336004820152306024820152604481018290526001600160a01b038316906323b872dd90606401600060405180830381600087803b158015610b1457600080fd5b505af1158015610b28573d6000803e3d6000fd5b505060075460405163ae03588360e01b81523360048201526001600160a01b03868116602483015260009450909116915063ae035883906044016020604051808303816000875af1158015610b81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba59190612091565b9050610bb133826116e4565b6040805180820182526001600160a01b03948516815260208082019485526000938452600a90529120905181546001600160a01b031916931692909217825551600190910155565b6006546001600160a01b03163314610c235760405162461bcd60e51b815260040161051a906120c7565b6007546001600160a01b031615610c3957600080fd5b600780546001600160a01b0319166001600160a01b0383169081179091556040519081527f7a005c6c9516d93fdd58518d35c24fb68736a79353ade45cada8120e6e1f19c89060200160405180910390a150565b61065b8383836040518060200160405280600081525061122e565b6000818152600260205260408120546001600160a01b0316806104b85760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b606482015260840161051a565b33610d2982610ca8565b6001600160a01b031614610d4f5760405162461bcd60e51b815260040161051a90611fa9565b600754604051631816306f60e11b8152600481018390523360248201526001600160a01b039091169063302c60de90604401600060405180830381600087803b158015610d9b57600080fd5b505af1158015610daf573d6000803e3d6000fd5b5050506000828152600a6020526040908190208054600182015492516323b872dd60e01b815230600482015233602482015260448101939093529092506001600160a01b0316906323b872dd90606401600060405180830381600087803b158015610e1957600080fd5b505af1158015610e2d573d6000803e3d6000fd5b505050505050565b60006001600160a01b038216610ea05760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b606482015260840161051a565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610ee65760405162461bcd60e51b815260040161051a906120c7565b610ef060006116fe565b565b33610efc83610ca8565b6001600160a01b031614610f225760405162461bcd60e51b815260040161051a90611fa9565b600754604051637adfad6b60e11b8152600481018490523360248201526001600160a01b0383811660448301529091169063f5bf5ad6906064016020604051808303816000875af1158015610f7b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065b9190612091565b60606001805461066f90612006565b610fb9338383611750565b5050565b6000805b838110156110cf5733610fdf8686848181106104de576104de611f93565b6001600160a01b0316146110265760405162461bcd60e51b815260206004820152600e60248201526d4e6f7420746865206f776e65722160901b604482015260640161051a565b6007546001600160a01b031663993072bd86868481811061104957611049611f93565b905060200201356040518263ffffffff1660e01b815260040161106e91815260200190565b6020604051808303816000875af115801561108d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b19190612091565b6110bb90836120fc565b9150806110c781611fed565b915050610fc1565b5060095460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af11580156109e0573d6000803e3d6000fd5b60005b82811015611228576111438484838181106104de576104de611f93565b6001600160a01b0316336001600160a01b0316146111735760405162461bcd60e51b815260040161051a90611fa9565b6007546001600160a01b031663f5bf5ad685858481811061119657611196611f93565b6040516001600160e01b031960e086901b168152602090910292909201356004830152503360248201526001600160a01b03851660448201526064016020604051808303816000875af11580156111f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112159190612091565b508061122081611fed565b915050611126565b50505050565b6112383383611451565b6112545760405162461bcd60e51b815260040161051a90612040565b6112288484848461181e565b6000818152600260205260409020546060906001600160a01b03166112df5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b606482015260840161051a565b60006112f660408051602081019091526000815290565b905060008151116113165760405180602001604052806000815250611341565b8061132084611851565b604051602001611331929190612114565b6040516020818303038152906040525b9392505050565b6006546001600160a01b031633146113725760405162461bcd60e51b815260040161051a906120c7565b6001600160a01b0381166113d75760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161051a565b6113e0816116fe565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061141882610ca8565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166114ca5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161051a565b60006114d583610ca8565b9050806001600160a01b0316846001600160a01b031614806115105750836001600160a01b0316611505846106f2565b6001600160a01b0316145b8061154057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661155b82610ca8565b6001600160a01b0316146115bf5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b606482015260840161051a565b6001600160a01b0382166116215760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b606482015260840161051a565b61162c6000826113e3565b6001600160a01b0383166000908152600360205260408120805460019290611655908490612143565b90915550506001600160a01b03821660009081526003602052604081208054600192906116839084906120fc565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610fb9828260405180602001604052806000815250611952565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b0316036117b15760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015260640161051a565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611829848484611548565b61183584848484611985565b6112285760405162461bcd60e51b815260040161051a9061215a565b6060816000036118785750506040805180820190915260018152600360fc1b602082015290565b8160005b81156118a2578061188c81611fed565b915061189b9050600a836121c2565b915061187c565b60008167ffffffffffffffff8111156118bd576118bd611e6f565b6040519080825280601f01601f1916602001820160405280156118e7576020820181803683370190505b5090505b8415611540576118fc600183612143565b9150611909600a866121d6565b6119149060306120fc565b60f81b81838151811061192957611929611f93565b60200101906001600160f81b031916908160001a90535061194b600a866121c2565b94506118eb565b61195c8383611a86565b6119696000848484611985565b61065b5760405162461bcd60e51b815260040161051a9061215a565b60006001600160a01b0384163b15611a7b57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906119c99033908990889088906004016121ea565b6020604051808303816000875af1925050508015611a04575060408051601f3d908101601f19168201909252611a0191810190612227565b60015b611a61573d808015611a32576040519150601f19603f3d011682016040523d82523d6000602084013e611a37565b606091505b508051600003611a595760405162461bcd60e51b815260040161051a9061215a565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611540565b506001949350505050565b6001600160a01b038216611adc5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015260640161051a565b6000818152600260205260409020546001600160a01b031615611b415760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161051a565b6001600160a01b0382166000908152600360205260408120805460019290611b6a9084906120fc565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6001600160e01b0319811681146113e057600080fd5b600060208284031215611bf057600080fd5b813561134181611bc8565b60008083601f840112611c0d57600080fd5b50813567ffffffffffffffff811115611c2557600080fd5b6020830191508360208260051b8501011115611c4057600080fd5b9250929050565b60008060208385031215611c5a57600080fd5b823567ffffffffffffffff811115611c7157600080fd5b611c7d85828601611bfb565b90969095509350505050565b60005b83811015611ca4578181015183820152602001611c8c565b838111156112285750506000910152565b60008151808452611ccd816020860160208601611c89565b601f01601f19169290920160200192915050565b6020815260006113416020830184611cb5565b600060208284031215611d0657600080fd5b5035919050565b6001600160a01b03811681146113e057600080fd5b60008060408385031215611d3557600080fd5b8235611d4081611d0d565b946020939093013593505050565b600080600060608486031215611d6357600080fd5b8335611d6e81611d0d565b92506020840135611d7e81611d0d565b929592945050506040919091013590565b60008060408385031215611da257600080fd5b823591506020830135611db481611d0d565b809150509250929050565b600060208284031215611dd157600080fd5b813561134181611d0d565b80151581146113e057600080fd5b60008060408385031215611dfd57600080fd5b8235611e0881611d0d565b91506020830135611db481611ddc565b600080600060408486031215611e2d57600080fd5b833567ffffffffffffffff811115611e4457600080fd5b611e5086828701611bfb565b9094509250506020840135611e6481611d0d565b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215611e9b57600080fd5b8435611ea681611d0d565b93506020850135611eb681611d0d565b925060408501359150606085013567ffffffffffffffff80821115611eda57600080fd5b818701915087601f830112611eee57600080fd5b813581811115611f0057611f00611e6f565b604051601f8201601f19908116603f01168101908382118183101715611f2857611f28611e6f565b816040528281528a6020848701011115611f4157600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611f7857600080fd5b8235611f8381611d0d565b91506020830135611db481611d0d565b634e487b7160e01b600052603260045260246000fd5b602080825260149082015273139bdd081d1a19481bdddb995c881bd98813919560621b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600060018201611fff57611fff611fd7565b5060010190565b600181811c9082168061201a57607f821691505b60208210810361203a57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000602082840312156120a357600080fd5b5051919050565b6000602082840312156120bc57600080fd5b815161134181611ddc565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000821982111561210f5761210f611fd7565b500190565b60008351612126818460208801611c89565b83519083019061213a818360208801611c89565b01949350505050565b60008282101561215557612155611fd7565b500390565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b634e487b7160e01b600052601260045260246000fd5b6000826121d1576121d16121ac565b500490565b6000826121e5576121e56121ac565b500690565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061221d90830184611cb5565b9695505050505050565b60006020828403121561223957600080fd5b815161134181611bc856fea2646970667358221220027b78bf0cc6bb3b1a6c9648d04df795cdd4da99833b6d4d082c6ad1c963f12f64736f6c634300080d0033000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000078d4b15991a8e6e9683fc6e47ebdc82823cb6410000000000000000000000003cec15acac6c67818f047abd8c5731bb10a2041c000000000000000000000000000000000000000000000000000000000000000f7a5374616b6572506f736974696f6e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a53500000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101c45760003560e01c8063715018a6116100f9578063a22cb46511610097578063b88d4fde11610071578063b88d4fde146103f7578063c87b56dd1461040a578063e985e9c51461041d578063f2fde38b1461045957600080fd5b8063a22cb465146103be578063a514e0a6146103d1578063aa7c9aa1146103e457600080fd5b806390db6f36116100d357806390db6f361461033e57806395749f9c1461035157806395d89b411461036457806399fbab881461036c57600080fd5b8063715018a6146103125780637b6a87771461031a5780638da5cb5b1461032d57600080fd5b80633158ad6d1161016657806342842e0e1161014057806342842e0e146102c65780636352211e146102d95780636b426000146102ec57806370a08231146102ff57600080fd5b80633158ad6d1461027f5780633660130b146102a05780633f05b6bb146102b357600080fd5b8063081812fc116101a2578063081812fc1461021b578063095ea7b31461024657806323b872dd146102595780632cd779f31461026c57600080fd5b806301ffc9a7146101c957806304f38b95146101f157806306fdde0314610206575b600080fd5b6101dc6101d7366004611bde565b61046c565b60405190151581526020015b60405180910390f35b6102046101ff366004611c47565b6104be565b005b61020e610660565b6040516101e89190611ce1565b61022e610229366004611cf4565b6106f2565b6040516001600160a01b0390911681526020016101e8565b610204610254366004611d22565b610787565b610204610267366004611d4e565b610897565b60075461022e906001600160a01b031681565b61029261028d366004611d8f565b6108c8565b6040519081526020016101e8565b6102046102ae366004611d22565b610a0c565b6102046102c1366004611dbf565b610bf9565b6102046102d4366004611d4e565b610c8d565b61022e6102e7366004611cf4565b610ca8565b6102046102fa366004611cf4565b610d1f565b61029261030d366004611dbf565b610e35565b610204610ebc565b60095461022e906001600160a01b031681565b6006546001600160a01b031661022e565b61020461034c366004611d8f565b610ef2565b60085461022e906001600160a01b031681565b61020e610f9f565b61039f61037a366004611cf4565b600a60205260009081526040902080546001909101546001600160a01b039091169082565b604080516001600160a01b0390931683526020830191909152016101e8565b6102046103cc366004611dea565b610fae565b6102926103df366004611e18565b610fbd565b6102046103f2366004611e18565b611123565b610204610405366004611e85565b61122e565b61020e610418366004611cf4565b611260565b6101dc61042b366004611f65565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b610204610467366004611dbf565b611348565b60006001600160e01b031982166380ac58cd60e01b148061049d57506001600160e01b03198216635b5e139f60e01b145b806104b857506301ffc9a760e01b6001600160e01b03198316145b92915050565b60005b8181101561065b576104ea8383838181106104de576104de611f93565b90506020020135610ca8565b6001600160a01b0316336001600160a01b0316146105235760405162461bcd60e51b815260040161051a90611fa9565b60405180910390fd5b6007546001600160a01b031663302c60de84848481811061054657610546611f93565b6040516001600160e01b031960e086901b16815260209091029290920135600483015250336024820152604401600060405180830381600087803b15801561058d57600080fd5b505af11580156105a1573d6000803e3d6000fd5b505050506000600a60008585858181106105bd576105bd611f93565b6020908102929092013583525081019190915260409081016000208054600182015492516323b872dd60e01b815230600482015233602482015260448101939093529092506001600160a01b0316906323b872dd90606401600060405180830381600087803b15801561062f57600080fd5b505af1158015610643573d6000803e3d6000fd5b5050505050808061065390611fed565b9150506104c1565b505050565b60606000805461066f90612006565b80601f016020809104026020016040519081016040528092919081815260200182805461069b90612006565b80156106e85780601f106106bd576101008083540402835291602001916106e8565b820191906000526020600020905b8154815290600101906020018083116106cb57829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661076b5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161051a565b506000908152600460205260409020546001600160a01b031690565b600061079282610ca8565b9050806001600160a01b0316836001600160a01b0316036107ff5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b606482015260840161051a565b336001600160a01b038216148061081b575061081b813361042b565b61088d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c0000000000000000606482015260840161051a565b61065b83836113e3565b6108a13382611451565b6108bd5760405162461bcd60e51b815260040161051a90612040565b61065b838383611548565b6000336108d484610ca8565b6001600160a01b03161461091b5760405162461bcd60e51b815260206004820152600e60248201526d4e6f7420746865206f776e65722160901b604482015260640161051a565b60075460405163993072bd60e01b8152600481018590526000916001600160a01b03169063993072bd906024016020604051808303816000875af1158015610967573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098b9190612091565b60095460405163a9059cbb60e01b81526001600160a01b0386811660048301526024820184905292935091169063a9059cbb906044016020604051808303816000875af11580156109e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0491906120aa565b509392505050565b600854604051630cb08b6f60e31b81526001600160a01b038481166004830152909116906365845b7890602401602060405180830381865afa158015610a56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a7a91906120aa565b610ac65760405162461bcd60e51b815260206004820152601d60248201527f4e465420636f6c6c656374696f6e206973206e6f7420616c6c6f776564000000604482015260640161051a565b6040516323b872dd60e01b8152336004820152306024820152604481018290526001600160a01b038316906323b872dd90606401600060405180830381600087803b158015610b1457600080fd5b505af1158015610b28573d6000803e3d6000fd5b505060075460405163ae03588360e01b81523360048201526001600160a01b03868116602483015260009450909116915063ae035883906044016020604051808303816000875af1158015610b81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba59190612091565b9050610bb133826116e4565b6040805180820182526001600160a01b03948516815260208082019485526000938452600a90529120905181546001600160a01b031916931692909217825551600190910155565b6006546001600160a01b03163314610c235760405162461bcd60e51b815260040161051a906120c7565b6007546001600160a01b031615610c3957600080fd5b600780546001600160a01b0319166001600160a01b0383169081179091556040519081527f7a005c6c9516d93fdd58518d35c24fb68736a79353ade45cada8120e6e1f19c89060200160405180910390a150565b61065b8383836040518060200160405280600081525061122e565b6000818152600260205260408120546001600160a01b0316806104b85760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b606482015260840161051a565b33610d2982610ca8565b6001600160a01b031614610d4f5760405162461bcd60e51b815260040161051a90611fa9565b600754604051631816306f60e11b8152600481018390523360248201526001600160a01b039091169063302c60de90604401600060405180830381600087803b158015610d9b57600080fd5b505af1158015610daf573d6000803e3d6000fd5b5050506000828152600a6020526040908190208054600182015492516323b872dd60e01b815230600482015233602482015260448101939093529092506001600160a01b0316906323b872dd90606401600060405180830381600087803b158015610e1957600080fd5b505af1158015610e2d573d6000803e3d6000fd5b505050505050565b60006001600160a01b038216610ea05760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b606482015260840161051a565b506001600160a01b031660009081526003602052604090205490565b6006546001600160a01b03163314610ee65760405162461bcd60e51b815260040161051a906120c7565b610ef060006116fe565b565b33610efc83610ca8565b6001600160a01b031614610f225760405162461bcd60e51b815260040161051a90611fa9565b600754604051637adfad6b60e11b8152600481018490523360248201526001600160a01b0383811660448301529091169063f5bf5ad6906064016020604051808303816000875af1158015610f7b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065b9190612091565b60606001805461066f90612006565b610fb9338383611750565b5050565b6000805b838110156110cf5733610fdf8686848181106104de576104de611f93565b6001600160a01b0316146110265760405162461bcd60e51b815260206004820152600e60248201526d4e6f7420746865206f776e65722160901b604482015260640161051a565b6007546001600160a01b031663993072bd86868481811061104957611049611f93565b905060200201356040518263ffffffff1660e01b815260040161106e91815260200190565b6020604051808303816000875af115801561108d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b19190612091565b6110bb90836120fc565b9150806110c781611fed565b915050610fc1565b5060095460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529091169063a9059cbb906044016020604051808303816000875af11580156109e0573d6000803e3d6000fd5b60005b82811015611228576111438484838181106104de576104de611f93565b6001600160a01b0316336001600160a01b0316146111735760405162461bcd60e51b815260040161051a90611fa9565b6007546001600160a01b031663f5bf5ad685858481811061119657611196611f93565b6040516001600160e01b031960e086901b168152602090910292909201356004830152503360248201526001600160a01b03851660448201526064016020604051808303816000875af11580156111f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112159190612091565b508061122081611fed565b915050611126565b50505050565b6112383383611451565b6112545760405162461bcd60e51b815260040161051a90612040565b6112288484848461181e565b6000818152600260205260409020546060906001600160a01b03166112df5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b606482015260840161051a565b60006112f660408051602081019091526000815290565b905060008151116113165760405180602001604052806000815250611341565b8061132084611851565b604051602001611331929190612114565b6040516020818303038152906040525b9392505050565b6006546001600160a01b031633146113725760405162461bcd60e51b815260040161051a906120c7565b6001600160a01b0381166113d75760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161051a565b6113e0816116fe565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b038416908117909155819061141882610ca8565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b03166114ca5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b606482015260840161051a565b60006114d583610ca8565b9050806001600160a01b0316846001600160a01b031614806115105750836001600160a01b0316611505846106f2565b6001600160a01b0316145b8061154057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b031661155b82610ca8565b6001600160a01b0316146115bf5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b606482015260840161051a565b6001600160a01b0382166116215760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b606482015260840161051a565b61162c6000826113e3565b6001600160a01b0383166000908152600360205260408120805460019290611655908490612143565b90915550506001600160a01b03821660009081526003602052604081208054600192906116839084906120fc565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b610fb9828260405180602001604052806000815250611952565b600680546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b0316036117b15760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c657200000000000000604482015260640161051a565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611829848484611548565b61183584848484611985565b6112285760405162461bcd60e51b815260040161051a9061215a565b6060816000036118785750506040805180820190915260018152600360fc1b602082015290565b8160005b81156118a2578061188c81611fed565b915061189b9050600a836121c2565b915061187c565b60008167ffffffffffffffff8111156118bd576118bd611e6f565b6040519080825280601f01601f1916602001820160405280156118e7576020820181803683370190505b5090505b8415611540576118fc600183612143565b9150611909600a866121d6565b6119149060306120fc565b60f81b81838151811061192957611929611f93565b60200101906001600160f81b031916908160001a90535061194b600a866121c2565b94506118eb565b61195c8383611a86565b6119696000848484611985565b61065b5760405162461bcd60e51b815260040161051a9061215a565b60006001600160a01b0384163b15611a7b57604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906119c99033908990889088906004016121ea565b6020604051808303816000875af1925050508015611a04575060408051601f3d908101601f19168201909252611a0191810190612227565b60015b611a61573d808015611a32576040519150601f19603f3d011682016040523d82523d6000602084013e611a37565b606091505b508051600003611a595760405162461bcd60e51b815260040161051a9061215a565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611540565b506001949350505050565b6001600160a01b038216611adc5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f2061646472657373604482015260640161051a565b6000818152600260205260409020546001600160a01b031615611b415760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604482015260640161051a565b6001600160a01b0382166000908152600360205260408120805460019290611b6a9084906120fc565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6001600160e01b0319811681146113e057600080fd5b600060208284031215611bf057600080fd5b813561134181611bc8565b60008083601f840112611c0d57600080fd5b50813567ffffffffffffffff811115611c2557600080fd5b6020830191508360208260051b8501011115611c4057600080fd5b9250929050565b60008060208385031215611c5a57600080fd5b823567ffffffffffffffff811115611c7157600080fd5b611c7d85828601611bfb565b90969095509350505050565b60005b83811015611ca4578181015183820152602001611c8c565b838111156112285750506000910152565b60008151808452611ccd816020860160208601611c89565b601f01601f19169290920160200192915050565b6020815260006113416020830184611cb5565b600060208284031215611d0657600080fd5b5035919050565b6001600160a01b03811681146113e057600080fd5b60008060408385031215611d3557600080fd5b8235611d4081611d0d565b946020939093013593505050565b600080600060608486031215611d6357600080fd5b8335611d6e81611d0d565b92506020840135611d7e81611d0d565b929592945050506040919091013590565b60008060408385031215611da257600080fd5b823591506020830135611db481611d0d565b809150509250929050565b600060208284031215611dd157600080fd5b813561134181611d0d565b80151581146113e057600080fd5b60008060408385031215611dfd57600080fd5b8235611e0881611d0d565b91506020830135611db481611ddc565b600080600060408486031215611e2d57600080fd5b833567ffffffffffffffff811115611e4457600080fd5b611e5086828701611bfb565b9094509250506020840135611e6481611d0d565b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215611e9b57600080fd5b8435611ea681611d0d565b93506020850135611eb681611d0d565b925060408501359150606085013567ffffffffffffffff80821115611eda57600080fd5b818701915087601f830112611eee57600080fd5b813581811115611f0057611f00611e6f565b604051601f8201601f19908116603f01168101908382118183101715611f2857611f28611e6f565b816040528281528a6020848701011115611f4157600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611f7857600080fd5b8235611f8381611d0d565b91506020830135611db481611d0d565b634e487b7160e01b600052603260045260246000fd5b602080825260149082015273139bdd081d1a19481bdddb995c881bd98813919560621b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600060018201611fff57611fff611fd7565b5060010190565b600181811c9082168061201a57607f821691505b60208210810361203a57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b6000602082840312156120a357600080fd5b5051919050565b6000602082840312156120bc57600080fd5b815161134181611ddc565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000821982111561210f5761210f611fd7565b500190565b60008351612126818460208801611c89565b83519083019061213a818360208801611c89565b01949350505050565b60008282101561215557612155611fd7565b500390565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b634e487b7160e01b600052601260045260246000fd5b6000826121d1576121d16121ac565b500490565b6000826121e5576121e56121ac565b500690565b6001600160a01b038581168252841660208201526040810183905260806060820181905260009061221d90830184611cb5565b9695505050505050565b60006020828403121561223957600080fd5b815161134181611bc856fea2646970667358221220027b78bf0cc6bb3b1a6c9648d04df795cdd4da99833b6d4d082c6ad1c963f12f64736f6c634300080d0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000078d4b15991a8e6e9683fc6e47ebdc82823cb6410000000000000000000000003cec15acac6c67818f047abd8c5731bb10a2041c000000000000000000000000000000000000000000000000000000000000000f7a5374616b6572506f736974696f6e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035a53500000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _name (string): zStakerPosition
Arg [1] : _symbol (string): ZSP
Arg [2] : _listingList (address): 0x078d4B15991A8E6e9683Fc6E47eBDc82823cb641
Arg [3] : _zoo (address): 0x3cec15AcAc6c67818F047abD8c5731bB10a2041C
-----Encoded View---------------
8 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [2] : 000000000000000000000000078d4b15991a8e6e9683fc6e47ebdc82823cb641
Arg [3] : 0000000000000000000000003cec15acac6c67818f047abd8c5731bb10a2041c
Arg [4] : 000000000000000000000000000000000000000000000000000000000000000f
Arg [5] : 7a5374616b6572506f736974696f6e0000000000000000000000000000000000
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [7] : 5a53500000000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in GLMR
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.