Source Code
Overview
GLMR Balance
GLMR Value
$0.00Latest 1 from a total of 1 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Nft Battle A... | 2167416 | 1188 days ago | IN | 0 GLMR | 0.0045162 |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
XZoo
Compiler Version
v0.8.13+commit.abaa5c0e
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity 0.8.13;
import "IERC20.sol";
import "ERC721.sol";
import "NftBattleArena.sol";
import "IVault.sol";
contract XZoo is ERC721
{
struct ZooStakerPosition
{
uint256 amount;
uint256 startEpoch;
uint256 endEpoch;
uint256 yTokensDebt;
}
IERC20 public stablecoin;
IERC20 public zoo;
VaultAPI public vault;
NftBattleArena public arena;
uint256 public indexCounter = 1;
mapping (uint256 => ZooStakerPosition) public xZooPositions;
// epoch => total staked zoo
mapping (uint256 => int256) public totalStakedZoo;
mapping (address => uint256[]) public tokenOfOwnerByIndex;
uint256 public lastEpochWhereTotalStakedUpdated;
event ZooStaked(address indexed staker, address indexed beneficiary, uint256 amount, uint256 positionId);
event ZooWithdrawal(address indexed staker, address beneficiary, uint256 amount, uint256 positionId);
event Claimed(address indexed staker, address beneficiary, uint256 amount, uint256 positionId);
event NftBattleArenaSet(address nftBattleArena);
constructor (string memory _name, string memory _symbol, address _stablecoin, address _zoo, address _vault) ERC721(_name, _symbol)
{
zoo = IERC20(_zoo);
stablecoin = IERC20(_stablecoin);
vault = VaultAPI(_vault);
}
function setNftBattleArena(address _nftBattleArena) external
{
require(address(arena) == address(0));
arena = NftBattleArena(_nftBattleArena);
emit NftBattleArenaSet(_nftBattleArena);
}
function stakeZoo(uint256 amount, address beneficiary) external returns (uint256 xZooPositionId)
{
zoo.transferFrom(msg.sender, address(this), amount);
xZooPositions[indexCounter].amount = amount;
xZooPositions[indexCounter].startEpoch = arena.currentEpoch() + 1;
totalStakedZoo[arena.currentEpoch() + 1] += int256(amount);
tokenOfOwnerByIndex[beneficiary].push(indexCounter);
_mint(beneficiary, indexCounter);
emit ZooStaked(msg.sender, beneficiary, amount, indexCounter);
return indexCounter++;
}
function claimRewards(uint256 positionId, address beneficiary) external returns (uint256 amountOfstablecoins)
{
require(ownerOf(positionId) == msg.sender);
updateTotalStakedUpdated();
ZooStakerPosition storage position = xZooPositions[positionId];
uint256 rewards = getPendingReward(positionId);
position.yTokensDebt = 0;
position.startEpoch = arena.currentEpoch();
amountOfstablecoins = vault.redeemUnderlying(rewards, beneficiary);
emit Claimed(msg.sender, beneficiary, amountOfstablecoins, positionId);
}
function unlockZoo(uint256 positionId, address beneficiary) external returns (uint256 amountOfZoo)
{
require(ownerOf(positionId) == msg.sender);
updateTotalStakedUpdated();
ZooStakerPosition storage position = xZooPositions[positionId];
require(position.endEpoch == 0);
position.endEpoch = arena.currentEpoch();
zoo.transfer(beneficiary, position.amount);
totalStakedZoo[arena.currentEpoch() + 1] -= int256(position.amount);
emit ZooWithdrawal(msg.sender, beneficiary, position.amount, positionId);
return position.amount;
}
function unlockAndClaim(uint256 positionId, address beneficiary) external returns (uint256 amountOfZoo, uint256 rewardsForClaimer)
{
require(ownerOf(positionId) == msg.sender);
updateTotalStakedUpdated();
ZooStakerPosition storage position = xZooPositions[positionId];
uint256 rewards = getPendingReward(positionId);
position.yTokensDebt = 0;
position.startEpoch = arena.currentEpoch();
uint256 amountOfstablecoins = vault.redeemUnderlying(rewards, beneficiary);
position.endEpoch = arena.currentEpoch();
zoo.transfer(beneficiary, position.amount);
totalStakedZoo[arena.currentEpoch() + 1] -= int256(position.amount);
emit Claimed(msg.sender, beneficiary, amountOfstablecoins, positionId);
emit ZooWithdrawal(msg.sender, beneficiary, position.amount, positionId);
return (position.amount, amountOfstablecoins);
}
function addZoo(uint256 positionId, uint256 amount) external
{
require(ownerOf(positionId) == msg.sender);
ZooStakerPosition storage position = xZooPositions[positionId];
require(position.endEpoch == 0);
updateTotalStakedUpdated();
zoo.transferFrom(msg.sender, address(this), amount);
position.yTokensDebt = getPendingReward(positionId);
position.startEpoch = arena.currentEpoch();
position.amount += amount;
totalStakedZoo[arena.currentEpoch() + 1] += int256(amount);
emit ZooStaked(msg.sender, ownerOf(positionId), amount, positionId);
}
function withdrawZoo(uint256 positionId, uint256 amount, address beneficiary) external
{
require(ownerOf(positionId) == msg.sender);
updateTotalStakedUpdated();
ZooStakerPosition storage position = xZooPositions[positionId];
require(position.endEpoch == 0);
position.yTokensDebt = getPendingReward(positionId);
position.startEpoch = arena.currentEpoch();
position.amount -= amount;
totalStakedZoo[arena.currentEpoch() + 1] -= int256(amount);
zoo.transfer(beneficiary, amount);
emit ZooWithdrawal(msg.sender, beneficiary, amount, positionId);
}
function updateTotalStakedUpdated() public
{
for (uint256 i = lastEpochWhereTotalStakedUpdated + 1; i < arena.currentEpoch(); i++)
{
totalStakedZoo[i] += totalStakedZoo[i - 1];
}
}
function getPendingReward(uint256 positionId) public view returns (uint256 yvTokens)
{
ZooStakerPosition storage position = xZooPositions[positionId];
uint256 end = position.endEpoch == 0 ? arena.currentEpoch() : position.endEpoch;
yvTokens += position.yTokensDebt;
for (uint256 epoch = position.startEpoch; epoch < end; epoch++)
{
yvTokens += position.amount * arena.xZooRewards(epoch) / uint256(totalStakedZoo[epoch]);
}
}
}// 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);
}// 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;
}
}pragma solidity 0.8.13;
// SPDX-License-Identifier: MIT
import "IVault.sol";
import "IZooFunctions.sol";
import "ZooGovernance.sol";
import "ListingList.sol";
import "ERC20.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;
ERC20 public zoo; // Zoo token interface.
ERC20 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;
ERC20 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 startDate;
uint256 startEpoch; // Epoch when started to stake.
uint256 endDate;
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 startDate;
uint256 endDate;
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 swapping votes from one position to another.
event SwappedPositionVotes(uint256 indexed currentEpoch, address indexed voter, uint256 indexed newStakingPositionId, address beneficiary, uint256 votingPositionId, uint256 daiNumber, uint256 newVotingPositionId);
/// @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 yTokenReward, 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 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;
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 (
address _zoo,
address _dai,
address _vault,
address _zooGovernance,
address _treasuryPool,
address _gasFeePool,
address _teamAddress,
address _nftStakingPosition,
address _nftVotingPosition,
address _veZoo,
address _controller,
address _well)
{
zoo = ERC20(_zoo);
dai = ERC20(_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 = ERC20(_well);
}
function init(address _xZoo, address _jackpotA, address _jackpotB) external
{
require(xZoo == address(0));
xZoo = _xZoo;
jackpotA = _jackpotA;
jackpotB = _jackpotB;
}
/// @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.
// todo: Possible need to change to stakingPositionsValues[numberOfStakingPositions] = StakerPosition(...);
StakerPosition storage position = stakingPositionsValues[numberOfStakingPositions];
position.startEpoch = currentEpoch; // Records startEpoch.
position.startDate = block.timestamp;
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.
require(stakingPositionsValues[stakingPositionId].endEpoch == 0, "Nft unstaked"); // Requires token to be staked.
stakingPositionsValues[stakingPositionId].endEpoch = currentEpoch; // Records epoch when unstaked.
stakingPositionsValues[stakingPositionId].endDate = block.timestamp;
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;
}
}
}
address collection = stakingPositionsValues[stakingPositionId].collection;
updateInfoAboutStakedNumber(collection);
numberOfStakedNftsInCollection[currentEpoch][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), amount); // 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) internal returns (uint256 votes, uint256 votingPositionId)
{
require(stakingPositionsValues[stakingPositionId].startDate != 0 && stakingPositionsValues[stakingPositionId].endEpoch == 0, "Not staked"); // Requires for staking position to be staked.
votes = zooFunctions.computeVotesByDai(amount); // Calculates amount of votes.
votingPositionsValues[numberOfVotingPositions].stakingPositionId = stakingPositionId; // Records staker position Id voted for.
votingPositionsValues[numberOfVotingPositions].startDate = block.timestamp;
votingPositionsValues[numberOfVotingPositions].daiInvested = amount; // Records amount of dai invested.
votingPositionsValues[numberOfVotingPositions].yTokensNumber = yTokens; // Records amount of yTokens got from yearn vault.
votingPositionsValues[numberOfVotingPositions].daiVotes = votes; // Records computed amount of votes to daiVotes.
votingPositionsValues[numberOfVotingPositions].votes = votes; // Records computed amount of votes to total votes.
votingPositionsValues[numberOfVotingPositions].startEpoch = currentEpoch; // Records epoch when position created.
votingPositionsValues[numberOfVotingPositions].lastRewardedEpoch = currentEpoch; // Sets starting point for reward to current epoch.
votingPositionsValues[numberOfVotingPositions].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 swap votes from one position to another.
/// @param votingPositionId ID of voting
/// @param voter address
/// @param beneficiary address to withdraw exceed ZOO
/// @param daiNumber amount of DAI to withdraw from old voting and to add to the new one
/// @param newStakingPositionId ID of staking to get votes from previous staking
/// @param newVotingPositionId ID of newly created voting to transfer votes
function swapPositionVotes(uint256 votingPositionId, address voter, address beneficiary, uint256 daiNumber, uint256 newStakingPositionId, uint256 newVotingPositionId) external only(nftVotingPosition) returns (uint256 createdVotingId)
{
uint256 stakingPositionId = votingPositionsValues[votingPositionId].stakingPositionId; // Gets id of staker position.
updateInfo(stakingPositionId);
require(getCurrentStage() == Stage.FirstStage, "Wrong stage!"); // Requires correct stage.
uint256 daiInvested = votingPositionsValues[votingPositionId].daiInvested;
if (daiNumber > daiInvested) // If swap amount more than invested.
{
daiNumber = daiInvested; // Set swap amount to maximum, same as in withdrawDai.
}
uint256 yTokens = tokensToShares(daiNumber);
withdrawDaiFromVoting(votingPositionId, voter, beneficiary, daiNumber, true); // Calls internal withdrawDai.
if (newVotingPositionId == 0) // If zero, i.e. new position doesn't exist.
{
(, createdVotingId) = _createVotingPosition(newStakingPositionId, voter, yTokens, daiNumber); // Creates new position to swap there.
newVotingPositionId = createdVotingId;
}
else // If position existing, swap to it.
{
require(votingPositionsValues[newVotingPositionId].endDate == 0, "unstaked"); // Requires for position to exist and still be staked.
addDaiToVoting(newVotingPositionId, msg.sender, daiNumber, yTokens); // swap votes to existing position.
newStakingPositionId = votingPositionsValues[newVotingPositionId].stakingPositionId;
}
emit SwappedPositionVotes(currentEpoch, voter, newStakingPositionId, beneficiary, votingPositionId, daiNumber, newVotingPositionId);
}
/// @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.
{
dai.approve(address(vault), amount); // Approves dai to yearn.
_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].endDate != 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.
{
vault.redeemUnderlying(shares, voter);
}
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.
{
vault.redeemUnderlying(yTokens, beneficiary); // 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.
votingPosition.endDate = block.timestamp; // Records end date.
rewardsForEpoch[stakingPositionId][currentEpoch].votes -= votingPosition.votes;// Decreases votes for staking position in current epoch.
if (rewardsForEpoch[stakingPositionId][currentEpoch].yTokens >= yTokens) // If withdraws less than in staking position.
{
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens -= yTokens; // Decreases yTokens for this staking position.
}
else
{
rewardsForEpoch[stakingPositionId][currentEpoch].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 (rewardsForEpoch[stakingPositionId][currentEpoch].votes == 0 && stakingPositionsValues[stakingPositionId].endDate == 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].endDate != 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];
uint256 stakingPositionId = votingPosition.stakingPositionId; // Gets staker position id from voter position.
require(getCurrentStage() == Stage.FirstStage || stakingPositionsValues[stakingPositionId].endDate != 0, "Wrong stage!"); // Requires to be at first stage or position should be liquidated.
updateInfo(stakingPositionId);
(uint256 yTokenReward, uint256 wells) = 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, address(this)); // Withdraws dai from vault for yTokens, minus staker %.
_daiRewardDistribution(beneficiary, stakingPositionId, daiReward); // Distributes reward between recipients, like treasury royalte, etc.
if (rewardsForEpoch[stakingPositionId][currentEpoch].yTokens >= yTokenReward * 980 / 1000)
{
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens -= yTokenReward * 980 / 1000;// Subtracts yTokens for this position.
}
else
{
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens = 0;
}
votingPosition.lastRewardedEpoch = computeLastEpoch(votingPositionId); // Records epoch of last reward claimed.
well.transfer(beneficiary, wells);
emit ClaimedRewardFromVoting(currentEpoch, voter, stakingPositionId, beneficiary, yTokenReward, 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)
{
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 / 10;
}
}
return (yTokens, wells);
}
/// @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)
{
require(getCurrentStage() == Stage.FirstStage || stakingPositionsValues[stakingPositionId].endDate != 0, "Wrong stage!"); // Requires to be at first stage in battle epoch.
updateInfo(stakingPositionId);
(uint256 yTokenReward, uint256 end) = getPendingStakerReward(stakingPositionId);
stakingPositionsValues[stakingPositionId].lastRewardedEpoch = end; // Records epoch of last reward claim.
daiReward = vault.redeemUnderlying(yTokenReward, beneficiary); // Gets reward from yearn.
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)
{
uint256 endEpoch = stakingPositionsValues[stakingPositionId].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 = stakingPositionsValues[stakingPositionId].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);
rewardsForEpoch[stakingPositionId][currentEpoch].tokensAtBattleStart = sharesToTokens(rewardsForEpoch[stakingPositionId][currentEpoch].yTokens); // Records amount of yTokens on the moment of pairing for candidate.
rewardsForEpoch[stakingPosition2][currentEpoch].tokensAtBattleStart = sharesToTokens(rewardsForEpoch[stakingPosition2][currentEpoch].yTokens); // Records amount of yTokens on the moment of pairing for opponent.
rewardsForEpoch[stakingPositionId][currentEpoch].pricePerShareAtBattleStart = vault.exchangeRateStored();
rewardsForEpoch[stakingPosition2][currentEpoch].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.
vault.increaseMockBalance(); // simulates reward from yearn vault for open testnet. Todo: remove.
uint256 wellInitialBalance = well.balanceOf(address(this));
tokenController.claimReward(0, address(this));
wellClaimedByEpoch[currentEpoch] = well.balanceOf(address(this)) - wellInitialBalance;
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
if (pps1 == vault.exchangeRateStored())
{
return;
}
winnerRewards.pricePerShareCoef = vault.exchangeRateStored() * pps1 / (vault.exchangeRateStored() - 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 xRewards = (income1 + income2) * 5 / 1000;
uint256 jackpotRewards = (income1 + income2) * 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(income1 + income2 - xRewards - 2 * jackpotRewards);
loserRewards.yTokensSaldo -= int256(income2);
rewardsForEpoch[winner][currentEpoch + 1].yTokens = winnerRewards.yTokens + income1 + income2 - 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
{
uint256 lastUpdateEpoch = stakingPositionsValues[stakingPositionId].lastUpdateEpoch;
if (lastUpdateEpoch == currentEpoch)
return;
rewardsForEpoch[stakingPositionId][currentEpoch].votes = rewardsForEpoch[stakingPositionId][lastUpdateEpoch].votes;
rewardsForEpoch[stakingPositionId][currentEpoch].yTokens = rewardsForEpoch[stakingPositionId][lastUpdateEpoch].yTokens;
stakingPositionsValues[stakingPositionId].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)
{
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;
uint256 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;
return reward;
}
/// @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)
{
uint256 stakingPositionId = votingPositionsValues[votingPositionId].stakingPositionId; // Gets staker position id from voter position.
uint256 lastEpochOfStaking = stakingPositionsValues[stakingPositionId].endEpoch; // Gets endEpoch from staking position.
// Staking - finished, Voting - finished
if (lastEpochOfStaking != 0 && votingPositionsValues[votingPositionId].endEpoch != 0)
{
lastEpochNumber = Math.min(lastEpochOfStaking, votingPositionsValues[votingPositionId].endEpoch);
}
// Staking - finished, Voting - existing
else if (lastEpochOfStaking != 0)
{
lastEpochNumber = lastEpochOfStaking;
}
// Staking - exists, Voting - finished
else if (votingPositionsValues[votingPositionId].endEpoch != 0)
{
lastEpochNumber = votingPositionsValues[votingPositionId].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.
zoo.transfer(address(1), zooToBurn);
}
/// @notice Function to view current stage in battle epoch.
/// @return stage - current stage.
function getCurrentStage() public view returns (Stage)
{
if (block.timestamp < epochStartDate + firstStageDuration)
{
return Stage.FirstStage; // Staking stage
}
else if (block.timestamp < epochStartDate + firstStageDuration + secondStageDuration)
{
return Stage.SecondStage; // Dai vote stage.
}
else if (block.timestamp < epochStartDate + firstStageDuration + secondStageDuration + thirdStageDuration)
{
return Stage.ThirdStage; // Pair stage.
}
else if (block.timestamp < epochStartDate + firstStageDuration + secondStageDuration + thirdStageDuration + fourthStageDuration)
{
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, address recipient) 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 (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);
}
}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);
tokenOfOwnerByIndex[msg.sender].push(vePositionIndex);
_mint(msg.sender, vePositionIndex++);
}
function unlockZoo(uint256 positionId) external
{
VePositionInfo storage vePosition = vePositions[positionId];
require(ownerOf(positionId) == msg.sender);
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");
VePositionInfo storage vePosition = vePositions[positionId];
require(ownerOf(positionId) == msg.sender);
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)
{
collectionRecords[collection][expirationEpoch].rateOfIncrease -= decayRate;
collectionRecords[collection][getEpochNumber(block.timestamp)].rateOfIncrease += decayRate;
}
addRecordForNewPosition(collection, vePosition.zooLocked, lockTime, msg.sender);
}
function addRecordForNewPosition(address collection, uint256 amount, uint256 lockTime, address owner) internal
{
uint256 weight = amount * lockTime / maxTimelock;
uint256 currentEpoch = getEpochNumber(block.timestamp);
uint256 unlockEpoch = getEpochNumber(block.timestamp + lockTime);
uint256 decay = weight / lockTime;
vePositions[vePositionIndex] = 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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "IERC20.sol";
import "IERC20Metadata.sol";
import "Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, _allowances[owner][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = _allowances[owner][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Spend `amount` form the allowance of `owner` toward `spender`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens 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 amount
) 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, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}// 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": {
"xZoo.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":"_stablecoin","type":"address"},{"internalType":"address","name":"_zoo","type":"address"},{"internalType":"address","name":"_vault","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":true,"internalType":"address","name":"staker","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"Claimed","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":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"staker","type":"address"},{"indexed":true,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"ZooStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"staker","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"ZooWithdrawal","type":"event"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"addZoo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"arena","outputs":[{"internalType":"contract NftBattleArena","name":"","type":"address"}],"stateMutability":"view","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":"positionId","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"claimRewards","outputs":[{"internalType":"uint256","name":"amountOfstablecoins","type":"uint256"}],"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":"uint256","name":"positionId","type":"uint256"}],"name":"getPendingReward","outputs":[{"internalType":"uint256","name":"yvTokens","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"indexCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"lastEpochWhereTotalStakedUpdated","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"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","name":"_nftBattleArena","type":"address"}],"name":"setNftBattleArena","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stablecoin","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"stakeZoo","outputs":[{"internalType":"uint256","name":"xZooPositionId","type":"uint256"}],"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":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"totalStakedZoo","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"unlockAndClaim","outputs":[{"internalType":"uint256","name":"amountOfZoo","type":"uint256"},{"internalType":"uint256","name":"rewardsForClaimer","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"unlockZoo","outputs":[{"internalType":"uint256","name":"amountOfZoo","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateTotalStakedUpdated","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract VaultAPI","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"name":"withdrawZoo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"xZooPositions","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"startEpoch","type":"uint256"},{"internalType":"uint256","name":"endEpoch","type":"uint256"},{"internalType":"uint256","name":"yTokensDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"zoo","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60806040526001600a553480156200001657600080fd5b5060405162002bfa38038062002bfa83398101604081905262000039916200023f565b84518590859062000052906000906020850190620000af565b50805162000068906001906020840190620000af565b5050600780546001600160a01b03199081166001600160a01b03958616179091556006805482169585169590951790945550600880549093169116179055506200031d9050565b828054620000bd90620002e1565b90600052602060002090601f016020900481019282620000e157600085556200012c565b82601f10620000fc57805160ff19168380011785556200012c565b828001600101855582156200012c579182015b828111156200012c5782518255916020019190600101906200010f565b506200013a9291506200013e565b5090565b5b808211156200013a57600081556001016200013f565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200017d57600080fd5b81516001600160401b03808211156200019a576200019a62000155565b604051601f8301601f19908116603f01168101908282118183101715620001c557620001c562000155565b81604052838152602092508683858801011115620001e257600080fd5b600091505b83821015620002065785820183015181830184015290820190620001e7565b83821115620002185760008385830101525b9695505050505050565b80516001600160a01b03811681146200023a57600080fd5b919050565b600080600080600060a086880312156200025857600080fd5b85516001600160401b03808211156200027057600080fd5b6200027e89838a016200016b565b965060208801519150808211156200029557600080fd5b50620002a4888289016200016b565b945050620002b56040870162000222565b9250620002c56060870162000222565b9150620002d56080870162000222565b90509295509295909350565b600181811c90821680620002f657607f821691505b6020821081036200031757634e487b7160e01b600052602260045260246000fd5b50919050565b6128cd806200032d6000396000f3fe608060405234801561001057600080fd5b50600436106101e55760003560e01c80636c7b69cb1161010f578063a268ba99116100a2578063e985e9c511610071578063e985e9c514610464578063e9cbd822146104a0578063fbfa77cf146104b3578063fd3705f9146104c657600080fd5b8063a268ba99146103d6578063b88d4fde1461042b578063c40b6b911461043e578063c87b56dd1461045157600080fd5b80637b6a8777116100de5780637b6a87771461039f578063871d1794146103b257806395d89b41146103bb578063a22cb465146103c357600080fd5b80636c7b69cb1461035357806370a08231146103665780637211bbc91461037957806372b525671461038c57600080fd5b80632f745c59116101875780635beb192c116101565780635beb192c146103055780636352211e1461030d578063666ae487146103205780636b1be8ba1461034057600080fd5b80632f745c59146102a45780633f05b6bb146102b757806342842e0e146102ca5780634da8cfa9146102dd57600080fd5b8063095ea7b3116101c3578063095ea7b3146102525780630f5bef1b1461026757806323b872dd1461027e5780632f1741e51461029157600080fd5b806301ffc9a7146101ea57806306fdde0314610212578063081812fc14610227575b600080fd5b6101fd6101f8366004612267565b6104d9565b60405190151581526020015b60405180910390f35b61021a61052b565b60405161020991906122dc565b61023a6102353660046122ef565b6105bd565b6040516001600160a01b039091168152602001610209565b610265610260366004612324565b610657565b005b610270600e5481565b604051908152602001610209565b61026561028c36600461234e565b61076c565b61026561029f36600461238a565b61079d565b6102706102b2366004612324565b6109e7565b6102656102c53660046123bf565b610a18565b6102656102d836600461234e565b610a82565b6102f06102eb3660046123da565b610a9d565b60408051928352602083019190915201610209565b610265610e01565b61023a61031b3660046122ef565b610eee565b61027061032e3660046122ef565b600c6020526000908152604090205481565b61027061034e3660046123da565b610f65565b6102706103613660046123da565b611192565b6102706103743660046123bf565b611314565b6102706103873660046122ef565b61139b565b61027061039a3660046123da565b611512565b60075461023a906001600160a01b031681565b610270600a5481565b61021a61176e565b6102656103d1366004612414565b61177d565b61040b6103e43660046122ef565b600b6020526000908152604090208054600182015460028301546003909301549192909184565b604080519485526020850193909352918301526060820152608001610209565b610265610439366004612461565b61178c565b61026561044c36600461253d565b6117c4565b61021a61045f3660046122ef565b611a2b565b6101fd61047236600461255f565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60065461023a906001600160a01b031681565b60085461023a906001600160a01b031681565b60095461023a906001600160a01b031681565b60006001600160e01b031982166380ac58cd60e01b148061050a57506001600160e01b03198216635b5e139f60e01b145b8061052557506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461053a90612589565b80601f016020809104026020016040519081016040528092919081815260200182805461056690612589565b80156105b35780601f10610588576101008083540402835291602001916105b3565b820191906000526020600020905b81548152906001019060200180831161059657829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661063b5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061066282610eee565b9050806001600160a01b0316836001600160a01b0316036106cf5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610632565b336001600160a01b03821614806106eb57506106eb8133610472565b61075d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610632565b6107678383611b13565b505050565b6107763382611b81565b6107925760405162461bcd60e51b8152600401610632906125c3565b610767838383611c78565b336107a784610eee565b6001600160a01b0316146107ba57600080fd5b6107c2610e01565b6000838152600b602052604090206002810154156107df57600080fd5b6107e88461139b565b600382015560095460408051630ecce30160e31b815290516001600160a01b03909216916376671808916004808201926020929091908290030181865afa158015610837573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085b9190612614565b6001820155805483908290600090610874908490612643565b9250508190555082600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f79190612614565b61090290600161265a565b8152602001908152602001600020600082825461091f9190612672565b909155505060075460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018690529091169063a9059cbb906044016020604051808303816000875af1158015610977573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099b91906126b1565b50336001600160a01b03167f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f8385876040516109d9939291906126ce565b60405180910390a250505050565b600d6020528160005260406000208181548110610a0357600080fd5b90600052602060002001600091509150505481565b6009546001600160a01b031615610a2e57600080fd5b600980546001600160a01b0319166001600160a01b0383169081179091556040519081527f7a005c6c9516d93fdd58518d35c24fb68736a79353ade45cada8120e6e1f19c89060200160405180910390a150565b6107678383836040518060200160405280600081525061178c565b60008033610aaa85610eee565b6001600160a01b031614610abd57600080fd5b610ac5610e01565b6000848152600b6020526040812090610add8661139b565b6000600384015560095460408051630ecce30160e31b815290519293506001600160a01b03909116916376671808916004808201926020929091908290030181865afa158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b559190612614565b6001830155600854604051631e1266d360e31b8152600481018390526001600160a01b038781166024830152600092169063f0933698906044016020604051808303816000875af1158015610bae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd29190612614565b9050600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4b9190612614565b6002840155600754835460405163a9059cbb60e01b81526001600160a01b038981166004830152602482019290925291169063a9059cbb906044016020604051808303816000875af1158015610ca5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc991906126b1565b508260000154600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4a9190612614565b610d5590600161265a565b81526020019081526020016000206000828254610d729190612672565b909155505060405133907f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e6890610dad90899085908c906126ce565b60405180910390a2825460405133917f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f91610deb918a918c906126ce565b60405180910390a2915496919550909350505050565b6000600e546001610e12919061265a565b90505b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8c9190612614565b811015610eeb57600c6000610ea2600184612643565b815260200190815260200160002054600c60008381526020019081526020016000206000828254610ed391906126ef565b90915550819050610ee381612730565b915050610e15565b50565b6000818152600260205260408120546001600160a01b0316806105255760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610632565b600033610f7184610eee565b6001600160a01b031614610f8457600080fd5b610f8c610e01565b6000838152600b60205260409020600281015415610fa957600080fd5b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ffc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110209190612614565b6002820155600754815460405163a9059cbb60e01b81526001600160a01b038681166004830152602482019290925291169063a9059cbb906044016020604051808303816000875af115801561107a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109e91906126b1565b508060000154600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111f9190612614565b61112a90600161265a565b815260200190815260200160002060008282546111479190612672565b9091555050805460405133917f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f9161118291879189906126ce565b60405180910390a2549392505050565b60003361119e84610eee565b6001600160a01b0316146111b157600080fd5b6111b9610e01565b6000838152600b60205260408120906111d18561139b565b6000600384015560095460408051630ecce30160e31b815290519293506001600160a01b03909116916376671808916004808201926020929091908290030181865afa158015611225573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112499190612614565b6001830155600854604051631e1266d360e31b8152600481018390526001600160a01b0386811660248301529091169063f0933698906044016020604051808303816000875af11580156112a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c59190612614565b9250336001600160a01b03167f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e68858588604051611304939291906126ce565b60405180910390a2505092915050565b60006001600160a01b03821661137f5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610632565b506001600160a01b031660009081526003602052604090205490565b6000818152600b6020526040812060028101548290156113bf578160020154611436565b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015611412573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114369190612614565b9050816003015483611448919061265a565b60018301549093505b8181101561150a576000818152600c602052604090819020546009549151630e27a04560e11b81526004810184905290916001600160a01b031690631c4f408a90602401602060405180830381865afa1580156114b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114d69190612614565b84546114e29190612749565b6114ec919061277e565b6114f6908561265a565b93508061150281612730565b915050611451565b505050919050565b6007546040516323b872dd60e01b8152336004820152306024820152604481018490526000916001600160a01b0316906323b872dd906064016020604051808303816000875af115801561156a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061158e91906126b1565b50600a546000908152600b60209081526040918290208590556009548251630ecce30160e31b815292516001600160a01b039091169263766718089260048083019391928290030181865afa1580156115eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061160f9190612614565b61161a90600161265a565b600a546000908152600b60209081526040808320600101939093556009548351630ecce30160e31b815293518794600c94936001600160a01b03909316926376671808926004808401938290030181865afa15801561167d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a19190612614565b6116ac90600161265a565b815260200190815260200160002060008282546116c991906126ef565b90915550506001600160a01b0382166000908152600d602090815260408220600a8054825460018101845592855292909320015554611709908390611e14565b600a546040805185815260208101929092526001600160a01b0384169133917fb0f38e7266c13e7919926b80638ae0e3920d3be832e21a1176fe2adfee3995cc910160405180910390a3600a805490600061176383612730565b909155509392505050565b60606001805461053a90612589565b611788338383611f56565b5050565b6117963383611b81565b6117b25760405162461bcd60e51b8152600401610632906125c3565b6117be8484848461201c565b50505050565b336117ce83610eee565b6001600160a01b0316146117e157600080fd5b6000828152600b602052604090206002810154156117fe57600080fd5b611806610e01565b6007546040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b03909116906323b872dd906064016020604051808303816000875af115801561185d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188191906126b1565b5061188b8361139b565b600382015560095460408051630ecce30160e31b815290516001600160a01b03909216916376671808916004808201926020929091908290030181865afa1580156118da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fe9190612614565b600182015580548290829060009061191790849061265a565b9250508190555081600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015611976573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061199a9190612614565b6119a590600161265a565b815260200190815260200160002060008282546119c291906126ef565b909155506119d1905083610eee565b6001600160a01b0316336001600160a01b03167fb0f38e7266c13e7919926b80638ae0e3920d3be832e21a1176fe2adfee3995cc8486604051611a1e929190918252602082015260400190565b60405180910390a3505050565b6000818152600260205260409020546060906001600160a01b0316611aaa5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610632565b6000611ac160408051602081019091526000815290565b90506000815111611ae15760405180602001604052806000815250611b0c565b80611aeb8461204f565b604051602001611afc929190612792565b6040516020818303038152906040525b9392505050565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611b4882610eee565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b0316611bfa5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610632565b6000611c0583610eee565b9050806001600160a01b0316846001600160a01b03161480611c405750836001600160a01b0316611c35846105bd565b6001600160a01b0316145b80611c7057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c8b82610eee565b6001600160a01b031614611cef5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610632565b6001600160a01b038216611d515760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610632565b611d5c600082611b13565b6001600160a01b0383166000908152600360205260408120805460019290611d85908490612643565b90915550506001600160a01b0382166000908152600360205260408120805460019290611db390849061265a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6001600160a01b038216611e6a5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610632565b6000818152600260205260409020546001600160a01b031615611ecf5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610632565b6001600160a01b0382166000908152600360205260408120805460019290611ef890849061265a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b816001600160a01b0316836001600160a01b031603611fb75760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610632565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319101611a1e565b612027848484611c78565b61203384848484612150565b6117be5760405162461bcd60e51b8152600401610632906127c1565b6060816000036120765750506040805180820190915260018152600360fc1b602082015290565b8160005b81156120a0578061208a81612730565b91506120999050600a8361277e565b915061207a565b60008167ffffffffffffffff8111156120bb576120bb61244b565b6040519080825280601f01601f1916602001820160405280156120e5576020820181803683370190505b5090505b8415611c70576120fa600183612643565b9150612107600a86612813565b61211290603061265a565b60f81b81838151811061212757612127612827565b60200101906001600160f81b031916908160001a905350612149600a8661277e565b94506120e9565b60006001600160a01b0384163b1561224657604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061219490339089908890889060040161283d565b6020604051808303816000875af19250505080156121cf575060408051601f3d908101601f191682019092526121cc9181019061287a565b60015b61222c573d8080156121fd576040519150601f19603f3d011682016040523d82523d6000602084013e612202565b606091505b5080516000036122245760405162461bcd60e51b8152600401610632906127c1565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611c70565b506001949350505050565b6001600160e01b031981168114610eeb57600080fd5b60006020828403121561227957600080fd5b8135611b0c81612251565b60005b8381101561229f578181015183820152602001612287565b838111156117be5750506000910152565b600081518084526122c8816020860160208601612284565b601f01601f19169290920160200192915050565b602081526000611b0c60208301846122b0565b60006020828403121561230157600080fd5b5035919050565b80356001600160a01b038116811461231f57600080fd5b919050565b6000806040838503121561233757600080fd5b61234083612308565b946020939093013593505050565b60008060006060848603121561236357600080fd5b61236c84612308565b925061237a60208501612308565b9150604084013590509250925092565b60008060006060848603121561239f57600080fd5b83359250602084013591506123b660408501612308565b90509250925092565b6000602082840312156123d157600080fd5b611b0c82612308565b600080604083850312156123ed57600080fd5b823591506123fd60208401612308565b90509250929050565b8015158114610eeb57600080fd5b6000806040838503121561242757600080fd5b61243083612308565b9150602083013561244081612406565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b6000806000806080858703121561247757600080fd5b61248085612308565b935061248e60208601612308565b925060408501359150606085013567ffffffffffffffff808211156124b257600080fd5b818701915087601f8301126124c657600080fd5b8135818111156124d8576124d861244b565b604051601f8201601f19908116603f011681019083821181831017156125005761250061244b565b816040528281528a602084870101111561251957600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b6000806040838503121561255057600080fd5b50508035926020909101359150565b6000806040838503121561257257600080fd5b61257b83612308565b91506123fd60208401612308565b600181811c9082168061259d57607f821691505b6020821081036125bd57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60006020828403121561262657600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000828210156126555761265561262d565b500390565b6000821982111561266d5761266d61262d565b500190565b60008083128015600160ff1b8501841216156126905761269061262d565b6001600160ff1b03840183138116156126ab576126ab61262d565b50500390565b6000602082840312156126c357600080fd5b8151611b0c81612406565b6001600160a01b039390931683526020830191909152604082015260600190565b600080821280156001600160ff1b03849003851316156127115761271161262d565b600160ff1b839003841281161561272a5761272a61262d565b50500190565b6000600182016127425761274261262d565b5060010190565b60008160001904831182151516156127635761276361262d565b500290565b634e487b7160e01b600052601260045260246000fd5b60008261278d5761278d612768565b500490565b600083516127a4818460208801612284565b8351908301906127b8818360208801612284565b01949350505050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60008261282257612822612768565b500690565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612870908301846122b0565b9695505050505050565b60006020828403121561288c57600080fd5b8151611b0c8161225156fea264697066735822122097689c035676d80312202fec6504551a85056898f591b4f54371041a361ecb6964736f6c634300080d003300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000009de882a68616fa96622ca5d032cb7f7416823b0c000000000000000000000000469bb20f4d2122275fb1fd715e7bafca1b36a50a000000000000000000000000e584fd6751376d7622eda18eda1e5aef2f44e17d0000000000000000000000000000000000000000000000000000000000000004785a6f6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004585a4f4f00000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101e55760003560e01c80636c7b69cb1161010f578063a268ba99116100a2578063e985e9c511610071578063e985e9c514610464578063e9cbd822146104a0578063fbfa77cf146104b3578063fd3705f9146104c657600080fd5b8063a268ba99146103d6578063b88d4fde1461042b578063c40b6b911461043e578063c87b56dd1461045157600080fd5b80637b6a8777116100de5780637b6a87771461039f578063871d1794146103b257806395d89b41146103bb578063a22cb465146103c357600080fd5b80636c7b69cb1461035357806370a08231146103665780637211bbc91461037957806372b525671461038c57600080fd5b80632f745c59116101875780635beb192c116101565780635beb192c146103055780636352211e1461030d578063666ae487146103205780636b1be8ba1461034057600080fd5b80632f745c59146102a45780633f05b6bb146102b757806342842e0e146102ca5780634da8cfa9146102dd57600080fd5b8063095ea7b3116101c3578063095ea7b3146102525780630f5bef1b1461026757806323b872dd1461027e5780632f1741e51461029157600080fd5b806301ffc9a7146101ea57806306fdde0314610212578063081812fc14610227575b600080fd5b6101fd6101f8366004612267565b6104d9565b60405190151581526020015b60405180910390f35b61021a61052b565b60405161020991906122dc565b61023a6102353660046122ef565b6105bd565b6040516001600160a01b039091168152602001610209565b610265610260366004612324565b610657565b005b610270600e5481565b604051908152602001610209565b61026561028c36600461234e565b61076c565b61026561029f36600461238a565b61079d565b6102706102b2366004612324565b6109e7565b6102656102c53660046123bf565b610a18565b6102656102d836600461234e565b610a82565b6102f06102eb3660046123da565b610a9d565b60408051928352602083019190915201610209565b610265610e01565b61023a61031b3660046122ef565b610eee565b61027061032e3660046122ef565b600c6020526000908152604090205481565b61027061034e3660046123da565b610f65565b6102706103613660046123da565b611192565b6102706103743660046123bf565b611314565b6102706103873660046122ef565b61139b565b61027061039a3660046123da565b611512565b60075461023a906001600160a01b031681565b610270600a5481565b61021a61176e565b6102656103d1366004612414565b61177d565b61040b6103e43660046122ef565b600b6020526000908152604090208054600182015460028301546003909301549192909184565b604080519485526020850193909352918301526060820152608001610209565b610265610439366004612461565b61178c565b61026561044c36600461253d565b6117c4565b61021a61045f3660046122ef565b611a2b565b6101fd61047236600461255f565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b60065461023a906001600160a01b031681565b60085461023a906001600160a01b031681565b60095461023a906001600160a01b031681565b60006001600160e01b031982166380ac58cd60e01b148061050a57506001600160e01b03198216635b5e139f60e01b145b8061052557506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461053a90612589565b80601f016020809104026020016040519081016040528092919081815260200182805461056690612589565b80156105b35780601f10610588576101008083540402835291602001916105b3565b820191906000526020600020905b81548152906001019060200180831161059657829003601f168201915b5050505050905090565b6000818152600260205260408120546001600160a01b031661063b5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b60648201526084015b60405180910390fd5b506000908152600460205260409020546001600160a01b031690565b600061066282610eee565b9050806001600160a01b0316836001600160a01b0316036106cf5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610632565b336001600160a01b03821614806106eb57506106eb8133610472565b61075d5760405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f7760448201527f6e6572206e6f7220617070726f76656420666f7220616c6c00000000000000006064820152608401610632565b6107678383611b13565b505050565b6107763382611b81565b6107925760405162461bcd60e51b8152600401610632906125c3565b610767838383611c78565b336107a784610eee565b6001600160a01b0316146107ba57600080fd5b6107c2610e01565b6000838152600b602052604090206002810154156107df57600080fd5b6107e88461139b565b600382015560095460408051630ecce30160e31b815290516001600160a01b03909216916376671808916004808201926020929091908290030181865afa158015610837573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085b9190612614565b6001820155805483908290600090610874908490612643565b9250508190555082600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f79190612614565b61090290600161265a565b8152602001908152602001600020600082825461091f9190612672565b909155505060075460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018690529091169063a9059cbb906044016020604051808303816000875af1158015610977573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061099b91906126b1565b50336001600160a01b03167f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f8385876040516109d9939291906126ce565b60405180910390a250505050565b600d6020528160005260406000208181548110610a0357600080fd5b90600052602060002001600091509150505481565b6009546001600160a01b031615610a2e57600080fd5b600980546001600160a01b0319166001600160a01b0383169081179091556040519081527f7a005c6c9516d93fdd58518d35c24fb68736a79353ade45cada8120e6e1f19c89060200160405180910390a150565b6107678383836040518060200160405280600081525061178c565b60008033610aaa85610eee565b6001600160a01b031614610abd57600080fd5b610ac5610e01565b6000848152600b6020526040812090610add8661139b565b6000600384015560095460408051630ecce30160e31b815290519293506001600160a01b03909116916376671808916004808201926020929091908290030181865afa158015610b31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b559190612614565b6001830155600854604051631e1266d360e31b8152600481018390526001600160a01b038781166024830152600092169063f0933698906044016020604051808303816000875af1158015610bae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bd29190612614565b9050600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4b9190612614565b6002840155600754835460405163a9059cbb60e01b81526001600160a01b038981166004830152602482019290925291169063a9059cbb906044016020604051808303816000875af1158015610ca5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc991906126b1565b508260000154600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4a9190612614565b610d5590600161265a565b81526020019081526020016000206000828254610d729190612672565b909155505060405133907f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e6890610dad90899085908c906126ce565b60405180910390a2825460405133917f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f91610deb918a918c906126ce565b60405180910390a2915496919550909350505050565b6000600e546001610e12919061265a565b90505b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e68573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8c9190612614565b811015610eeb57600c6000610ea2600184612643565b815260200190815260200160002054600c60008381526020019081526020016000206000828254610ed391906126ef565b90915550819050610ee381612730565b915050610e15565b50565b6000818152600260205260408120546001600160a01b0316806105255760405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608401610632565b600033610f7184610eee565b6001600160a01b031614610f8457600080fd5b610f8c610e01565b6000838152600b60205260409020600281015415610fa957600080fd5b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ffc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110209190612614565b6002820155600754815460405163a9059cbb60e01b81526001600160a01b038681166004830152602482019290925291169063a9059cbb906044016020604051808303816000875af115801561107a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061109e91906126b1565b508060000154600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061111f9190612614565b61112a90600161265a565b815260200190815260200160002060008282546111479190612672565b9091555050805460405133917f23f46302ba0e9bff14c2280af975e37499ad0457af9876536f6b21d453292f1f9161118291879189906126ce565b60405180910390a2549392505050565b60003361119e84610eee565b6001600160a01b0316146111b157600080fd5b6111b9610e01565b6000838152600b60205260408120906111d18561139b565b6000600384015560095460408051630ecce30160e31b815290519293506001600160a01b03909116916376671808916004808201926020929091908290030181865afa158015611225573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112499190612614565b6001830155600854604051631e1266d360e31b8152600481018390526001600160a01b0386811660248301529091169063f0933698906044016020604051808303816000875af11580156112a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c59190612614565b9250336001600160a01b03167f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e68858588604051611304939291906126ce565b60405180910390a2505092915050565b60006001600160a01b03821661137f5760405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608401610632565b506001600160a01b031660009081526003602052604090205490565b6000818152600b6020526040812060028101548290156113bf578160020154611436565b600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015611412573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114369190612614565b9050816003015483611448919061265a565b60018301549093505b8181101561150a576000818152600c602052604090819020546009549151630e27a04560e11b81526004810184905290916001600160a01b031690631c4f408a90602401602060405180830381865afa1580156114b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114d69190612614565b84546114e29190612749565b6114ec919061277e565b6114f6908561265a565b93508061150281612730565b915050611451565b505050919050565b6007546040516323b872dd60e01b8152336004820152306024820152604481018490526000916001600160a01b0316906323b872dd906064016020604051808303816000875af115801561156a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061158e91906126b1565b50600a546000908152600b60209081526040918290208590556009548251630ecce30160e31b815292516001600160a01b039091169263766718089260048083019391928290030181865afa1580156115eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061160f9190612614565b61161a90600161265a565b600a546000908152600b60209081526040808320600101939093556009548351630ecce30160e31b815293518794600c94936001600160a01b03909316926376671808926004808401938290030181865afa15801561167d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116a19190612614565b6116ac90600161265a565b815260200190815260200160002060008282546116c991906126ef565b90915550506001600160a01b0382166000908152600d602090815260408220600a8054825460018101845592855292909320015554611709908390611e14565b600a546040805185815260208101929092526001600160a01b0384169133917fb0f38e7266c13e7919926b80638ae0e3920d3be832e21a1176fe2adfee3995cc910160405180910390a3600a805490600061176383612730565b909155509392505050565b60606001805461053a90612589565b611788338383611f56565b5050565b6117963383611b81565b6117b25760405162461bcd60e51b8152600401610632906125c3565b6117be8484848461201c565b50505050565b336117ce83610eee565b6001600160a01b0316146117e157600080fd5b6000828152600b602052604090206002810154156117fe57600080fd5b611806610e01565b6007546040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b03909116906323b872dd906064016020604051808303816000875af115801561185d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188191906126b1565b5061188b8361139b565b600382015560095460408051630ecce30160e31b815290516001600160a01b03909216916376671808916004808201926020929091908290030181865afa1580156118da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118fe9190612614565b600182015580548290829060009061191790849061265a565b9250508190555081600c6000600960009054906101000a90046001600160a01b03166001600160a01b031663766718086040518163ffffffff1660e01b8152600401602060405180830381865afa158015611976573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061199a9190612614565b6119a590600161265a565b815260200190815260200160002060008282546119c291906126ef565b909155506119d1905083610eee565b6001600160a01b0316336001600160a01b03167fb0f38e7266c13e7919926b80638ae0e3920d3be832e21a1176fe2adfee3995cc8486604051611a1e929190918252602082015260400190565b60405180910390a3505050565b6000818152600260205260409020546060906001600160a01b0316611aaa5760405162461bcd60e51b815260206004820152602f60248201527f4552433732314d657461646174613a2055524920717565727920666f72206e6f60448201526e3732bc34b9ba32b73a103a37b5b2b760891b6064820152608401610632565b6000611ac160408051602081019091526000815290565b90506000815111611ae15760405180602001604052806000815250611b0c565b80611aeb8461204f565b604051602001611afc929190612792565b6040516020818303038152906040525b9392505050565b600081815260046020526040902080546001600160a01b0319166001600160a01b0384169081179091558190611b4882610eee565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000818152600260205260408120546001600160a01b0316611bfa5760405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608401610632565b6000611c0583610eee565b9050806001600160a01b0316846001600160a01b03161480611c405750836001600160a01b0316611c35846105bd565b6001600160a01b0316145b80611c7057506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b949350505050565b826001600160a01b0316611c8b82610eee565b6001600160a01b031614611cef5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610632565b6001600160a01b038216611d515760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610632565b611d5c600082611b13565b6001600160a01b0383166000908152600360205260408120805460019290611d85908490612643565b90915550506001600160a01b0382166000908152600360205260408120805460019290611db390849061265a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b0386811691821790925591518493918716917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6001600160a01b038216611e6a5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610632565b6000818152600260205260409020546001600160a01b031615611ecf5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610632565b6001600160a01b0382166000908152600360205260408120805460019290611ef890849061265a565b909155505060008181526002602052604080822080546001600160a01b0319166001600160a01b03861690811790915590518392907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b816001600160a01b0316836001600160a01b031603611fb75760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610632565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c319101611a1e565b612027848484611c78565b61203384848484612150565b6117be5760405162461bcd60e51b8152600401610632906127c1565b6060816000036120765750506040805180820190915260018152600360fc1b602082015290565b8160005b81156120a0578061208a81612730565b91506120999050600a8361277e565b915061207a565b60008167ffffffffffffffff8111156120bb576120bb61244b565b6040519080825280601f01601f1916602001820160405280156120e5576020820181803683370190505b5090505b8415611c70576120fa600183612643565b9150612107600a86612813565b61211290603061265a565b60f81b81838151811061212757612127612827565b60200101906001600160f81b031916908160001a905350612149600a8661277e565b94506120e9565b60006001600160a01b0384163b1561224657604051630a85bd0160e11b81526001600160a01b0385169063150b7a029061219490339089908890889060040161283d565b6020604051808303816000875af19250505080156121cf575060408051601f3d908101601f191682019092526121cc9181019061287a565b60015b61222c573d8080156121fd576040519150601f19603f3d011682016040523d82523d6000602084013e612202565b606091505b5080516000036122245760405162461bcd60e51b8152600401610632906127c1565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050611c70565b506001949350505050565b6001600160e01b031981168114610eeb57600080fd5b60006020828403121561227957600080fd5b8135611b0c81612251565b60005b8381101561229f578181015183820152602001612287565b838111156117be5750506000910152565b600081518084526122c8816020860160208601612284565b601f01601f19169290920160200192915050565b602081526000611b0c60208301846122b0565b60006020828403121561230157600080fd5b5035919050565b80356001600160a01b038116811461231f57600080fd5b919050565b6000806040838503121561233757600080fd5b61234083612308565b946020939093013593505050565b60008060006060848603121561236357600080fd5b61236c84612308565b925061237a60208501612308565b9150604084013590509250925092565b60008060006060848603121561239f57600080fd5b83359250602084013591506123b660408501612308565b90509250925092565b6000602082840312156123d157600080fd5b611b0c82612308565b600080604083850312156123ed57600080fd5b823591506123fd60208401612308565b90509250929050565b8015158114610eeb57600080fd5b6000806040838503121561242757600080fd5b61243083612308565b9150602083013561244081612406565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b6000806000806080858703121561247757600080fd5b61248085612308565b935061248e60208601612308565b925060408501359150606085013567ffffffffffffffff808211156124b257600080fd5b818701915087601f8301126124c657600080fd5b8135818111156124d8576124d861244b565b604051601f8201601f19908116603f011681019083821181831017156125005761250061244b565b816040528281528a602084870101111561251957600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b6000806040838503121561255057600080fd5b50508035926020909101359150565b6000806040838503121561257257600080fd5b61257b83612308565b91506123fd60208401612308565b600181811c9082168061259d57607f821691505b6020821081036125bd57634e487b7160e01b600052602260045260246000fd5b50919050565b60208082526031908201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6040820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b606082015260800190565b60006020828403121561262657600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b6000828210156126555761265561262d565b500390565b6000821982111561266d5761266d61262d565b500190565b60008083128015600160ff1b8501841216156126905761269061262d565b6001600160ff1b03840183138116156126ab576126ab61262d565b50500390565b6000602082840312156126c357600080fd5b8151611b0c81612406565b6001600160a01b039390931683526020830191909152604082015260600190565b600080821280156001600160ff1b03849003851316156127115761271161262d565b600160ff1b839003841281161561272a5761272a61262d565b50500190565b6000600182016127425761274261262d565b5060010190565b60008160001904831182151516156127635761276361262d565b500290565b634e487b7160e01b600052601260045260246000fd5b60008261278d5761278d612768565b500490565b600083516127a4818460208801612284565b8351908301906127b8818360208801612284565b01949350505050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b60008261282257612822612768565b500690565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090612870908301846122b0565b9695505050505050565b60006020828403121561288c57600080fd5b8151611b0c8161225156fea264697066735822122097689c035676d80312202fec6504551a85056898f591b4f54371041a361ecb6964736f6c634300080d0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000009de882a68616fa96622ca5d032cb7f7416823b0c000000000000000000000000469bb20f4d2122275fb1fd715e7bafca1b36a50a000000000000000000000000e584fd6751376d7622eda18eda1e5aef2f44e17d0000000000000000000000000000000000000000000000000000000000000004785a6f6f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004585a4f4f00000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _name (string): xZoo
Arg [1] : _symbol (string): XZOO
Arg [2] : _stablecoin (address): 0x9dE882A68616FA96622ca5d032Cb7F7416823B0c
Arg [3] : _zoo (address): 0x469bb20F4D2122275fB1fD715e7BaFCA1B36a50A
Arg [4] : _vault (address): 0xe584FD6751376D7622eDA18eDa1E5AeF2F44E17d
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [2] : 0000000000000000000000009de882a68616fa96622ca5d032cb7f7416823b0c
Arg [3] : 000000000000000000000000469bb20f4d2122275fb1fd715e7bafca1b36a50a
Arg [4] : 000000000000000000000000e584fd6751376d7622eda18eda1e5aef2f44e17d
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [6] : 785a6f6f00000000000000000000000000000000000000000000000000000000
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [8] : 585a4f4f00000000000000000000000000000000000000000000000000000000
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.