Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- PulseKitten
- Optimization enabled
- true
- Compiler version
- v0.8.17+commit.8df45f5f
- Optimization runs
- 369
- EVM Version
- default
- Verified at
- 2023-05-23T07:53:27.417932Z
Constructor Arguments
0x64547f9933b53bdcff0ebc3a6e77f58c426209d80fd73547349556ae224107570000000000000000000000006961e9d9a17b9bb860b48a6c2f6c3584ff21147e0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001b68747470733a2f2f6170692e70756c73656b697474656e732e696f0000000000
Arg [0] (bytes32) : 64547f9933b53bdcff0ebc3a6e77f58c426209d80fd73547349556ae22410757
Arg [1] (address) : 0x6961e9d9a17b9bb860b48a6c2f6c3584ff21147e
Arg [2] (string) : https://api.pulsekittens.io
contracts/PulseKitten.sol
// SPDX-License-Identifier: UNLICENSED
/// @custom:security-contact dev@pulsekittens.io
// Merkel ROOT can be verified here.
// https://gitlab.com/pulse-kittens/merkle
// Launching on PulseChain
// https://pulsekittens.io
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "../config/settings.sol";
import "../contracts/Emissions.sol";
import "../contracts/PetRegistry.sol";
import "../contracts/PKNFT.sol";
import { ABDKMath64x64 as Math } from "abdk-libraries-solidity/ABDKMath64x64.sol";
contract PulseKitten is ERC20 {
// Launch day
uint64 immutable public DAYZERO;
// Pet Registry
PetRegistry immutable public REGISTRY;
// NFT Minter
PKNFT immutable public NFT;
// PKTTN Emissions
Emissions immutable public EMISSIONS;
// Merkle root
bytes32 immutable public ROOT;
// Cyber Vet Address (CVA)
address immutable public CVA;
// Users that have claimed
mapping(address => bool) public claimers;
// Last day a user actvity
mapping(address => uint64) public activity;
// Last mint
uint64 private _totalmints;
uint64 private _lastmint;
// Events
event Claimed(address indexed addr, uint256 amount, uint256 bonus, uint256 sac, uint256 drops);
constructor(
bytes32 root,
address cva,
string memory host
) ERC20("PulseKitten", "PKTTN") {
// Contract day zero (UTC)
DAYZERO = today();
// Start a new registry
REGISTRY = new PetRegistry();
// Deploy NFT factory
NFT = new PKNFT(address(REGISTRY), host);
// Deploy Emissions
EMISSIONS = new Emissions(
address(this),
PKPUR_RAMP_FREQ,
PKPUR_EMIT_RATE,
PKPUR_DEPOSIT_FEE,
PKPUR_WITHDRAW_FEE,
PKPUR_REWARD,
PKPUR_NAME,
PKPUR_TOKEN
);
// Approve Emissions
_approve(address(this), address(EMISSIONS), type(uint256).max);
// Set the merkle root
ROOT = root;
// Set the CVA
CVA = cva;
// Set the last mint to now
_lastmint = uint64(block.timestamp);
}
function today() public view returns (uint64) {
return uint64((block.timestamp / 1 days) * 1 days);
}
// @dev address balance inclusive of additional yield
function balanceOf(address addr) public view override returns (uint256) {
// Get current balance
uint256 balance = super.balanceOf(addr);
// Include current yield
balance += calculateYield(addr);
return balance;
}
// @dev calculated additional yield generated by NFTs
function calculateYield(address addr) public view returns (uint256) {
// Last activity
uint64 since = activity[addr] > 0 ? activity[addr] : today();
// Days since
uint64 elapsed = (today() - since) / 1 days;
return _calculateYield(addr, elapsed);
}
// @dev estimate future additional yield generated by NFTs
function estimateYield(address addr, uint64 elapsed) public view returns (uint256) {
return _calculateYield(addr, elapsed);
}
function nextDrop() external view returns (uint64) {
return uint64( ((block.timestamp / NFT_DISCOUNT_FREQ) + 1) * NFT_DISCOUNT_FREQ);
}
function sinceMint() external view returns (uint64) {
return _sinceMint();
}
function mintCost() public view returns (uint256) {
return _mintCost(_totalmints, _sinceMint());
}
// @dev allow for forward looking estimates
function estimateMintCost(uint64 minted, uint64 since) external view returns (uint256) {
return _mintCost(minted, since);
}
// @dev allow caller to claim
function claim(uint256 value, bytes32[] calldata proof) external returns(uint256, uint256, uint256, uint256) {
return _distribute(msg.sender, value, proof);
}
// @dev distribute launch allocation to an address
function distribute(address addr, uint256 value, bytes32[] calldata proof) external returns(uint256, uint256, uint256, uint256) {
return _distribute(addr, value, proof);
}
// @dev rebase then transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_rebase(msg.sender);
_rebase(recipient);
return super.transfer(recipient, amount);
}
// @dev rebase then transfer
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_rebase(sender);
_rebase(recipient);
return super.transferFrom(sender, recipient, amount);
}
// @dev allow PKNFT minting
function mintKitten(uint256 amount) external returns (uint256) {
return _mintNFT(msg.sender, amount, msg.sender);
}
// @dev allow PKNFT minting
function mintKittenFor(address to, uint256 amount) external returns (uint256) {
return _mintNFT(msg.sender, amount, to);
}
// @dev used for PKNFT cost basis
function _liquid() internal view returns(uint256) {
// 10% of claims
uint256 balance = balanceOf(CVA);
// 20% of CVA
if(balance > 0) {
balance = balance / 5;
}
return balance;
}
// @dev allow PKNFT minting
function _mintNFT(address from, uint256 amount, address holder) internal returns (uint256) {
require(amount >= mintCost(), "PKTTN: Below minimum");
require(amount <= balanceOf(from), "PKTTN: Insufficient balance");
_rebase(from);
_transfer(from, address(this), amount);
// Now fund future rewards
EMISSIONS.fund(amount);
// Update last mint
_lastmint = uint64(block.timestamp);
// Track total non claimed mints
_totalmints++;
// Mint Kitten: baseline of 5% + 7% random
return NFT.mintKitten(holder, 5 + (uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp))) % 7));
}
// @dev number of drop cycles that have passed withinout minting
function _sinceMint() internal view returns (uint64) {
if(_lastmint > 0) {
return uint64((block.timestamp - _lastmint) / NFT_DISCOUNT_FREQ);
}
return 0;
}
function _calculateYield(address addr, uint64 elapsed) internal view returns (uint256) {
// Get the current herding total
uint256 equity = EMISSIONS.balanceOf(addr);
// Get yield bonus for holder
uint256 bonus = NFT.getHolderBonus(addr);
uint256 boost = 0;
// Calculate boost since
if( bonus > 0 && equity > 0 && elapsed > 0 ) {
boost = (((equity * bonus) / 100) * elapsed) / 365;
}
// Return any bonus
return boost;
}
// @dev gets exponential harder after each mint, discount applies with time
function _mintCost(uint64 minted, uint64 since) internal view returns (uint256) {
// Get basis
uint256 basis = _liquid();
// Sensible safety
if(basis < NFT_MIN_BASIS) {
basis = NFT_MIN_BASIS;
}
// Sensible safety
if(basis > NFT_MAX_BASIS) {
basis = NFT_MAX_BASIS;
}
if(minted > NFT_MAX_RANGE) {
minted = NFT_MAX_RANGE;
}
if(since > NFT_MAX_RANGE) {
since = NFT_MAX_RANGE;
}
int128 difficulty = Math.div(NFT_DIFFICULTY * 10 ** 16, 10 ** 18) + 1; // 1.03
uint256 cost = (Math.mulu(Math.div(Math.pow(difficulty, minted), Math.pow(difficulty, since)), basis) / 10 ** 18) * 10 ** 18;
// Sensible safety
if(cost < NFT_MIN_COST) {
cost = NFT_MIN_COST;
}
return cost;
}
// @dev distribute implementation
function _distribute(address addr, uint256 value, bytes32[] calldata proof) private returns(uint256, uint256, uint256, uint256) {
// Check if already claimed
require(!claimers[addr], "Already distributed");
// Check merkle
require(_verify(_leaf(value, addr), proof), "Invalid merkle proof");
// Record claimed
claimers[addr] = true;
// Unpack values
uint256 drops = value >> 80;
uint256 bonus = (value << 176) >> 248;
uint256 sac = (value << 184) >> 248;
uint256 amount = ((value << 192) >> 192) * 10 ** decimals();
// val = ethers.BigNumber.from(item.drops).shl(8).add(item.bonus).shl(8).add(item.sac).shl(64).add(item.amt)
// Check if airdrop claim to open
if( sac == 0 ) {
require(today() < DAYZERO + 90 days, "Claim phase has passed");
}
// Mint tokens
_mint(addr, amount);
// Mint NFT is bonus category
if(bonus > 0) {
// Mint Kitten: baseline of 10% + 5% per bracket + 5% random
NFT.mintKitten(addr, 10 + (5 * ( bonus - 1)) + (uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp))) % 5));
}
// Set the last activity to today
activity[addr] = today();
// Fund future herding rewards (emissions)
uint256 rewards = (amount * REWARD_COPY) / 100;
_mint(address(this), rewards);
EMISSIONS.fund(rewards);
// Mint CVA claim copy
_mint(CVA, (amount * CVA_COPY) / 100);
// Emit claimed event
emit Claimed(addr, amount, bonus, sac, drops);
return (amount, bonus, sac, drops);
}
// @dev rebase if required
function _rebase(address addr) private {
// Check current basis
if(activity[addr] != today()) {
// Check for a yield boody
uint256 yield = calculateYield(addr);
// Set the last activity to today
activity[addr] = today();
// Mint anything outstanding
if( yield > 0) {
_mint(addr, yield);
}
}
}
function _leaf(uint256 value, address account) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(value, account));
}
function _verify(bytes32 leaf, bytes32[] memory proof) internal view returns (bool) {
return MerkleProof.verify(proof, ROOT, leaf);
}
}
@openzeppelin/contracts/interfaces/IERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165.sol";
/**
* @dev Interface for the NFT Royalty Standard.
*
* A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
* support for royalty payments across all NFT marketplaces and ecosystem participants.
*
* _Available since v4.5._
*/
interface IERC2981 is IERC165 {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
@openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/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.openzeppelin.com/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, allowance(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 = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* 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;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_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;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_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;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_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 Updates `owner` s allowance for `spender` based on spent `amount`.
*
* 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 {}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// 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);
}
@openzeppelin/contracts/token/ERC721/ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.2) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @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: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
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) {
_requireMinted(tokenId);
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 overridden 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 token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
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: caller is not token owner or 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: caller is not token owner or 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 the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @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 _ownerOf(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) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == 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, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @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, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {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 an {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 Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @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 {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual {}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
* being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
* that `ownerOf(tokenId)` is `a`.
*/
// solhint-disable-next-line func-name-mixedcase
function __unsafe_increaseBalance(address account, uint256 amount) internal {
_balances[account] += amount;
}
}
@openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (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 `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
// Will only trigger during construction. Batch transferring (minting) is not available afterwards.
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
@openzeppelin/contracts/token/common/ERC2981.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/common/ERC2981.sol)
pragma solidity ^0.8.0;
import "../../interfaces/IERC2981.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
*
* Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
* specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
*
* Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
* fee is specified in basis points by default.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*
* _Available since v4.5._
*/
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @inheritdoc IERC2981
*/
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[_tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (_salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
/**
* @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
* fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
* override.
*/
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
/**
* @dev Sets the royalty information that all ids in this contract will default to.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Removes default royalty information.
*/
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
/**
* @dev Sets the royalty information for a specific token id, overriding the global default.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setTokenRoyalty(
uint256 tokenId,
address receiver,
uint96 feeNumerator
) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Resets royalty information for the token id back to the global default.
*/
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
}
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/utils/Context.sol
// 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;
}
}
@openzeppelin/contracts/utils/Counters.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import { Math as MathS } from "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathS.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathS.log256(value) + 1);
}
}
/**
* @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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
@openzeppelin/contracts/utils/cryptography/MerkleProof.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Tree proofs.
*
* The tree and the proofs can be generated using our
* https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
* You will find a quickstart guide in the readme.
*
* WARNING: You should avoid using leaf values that are 64 bytes long prior to
* hashing, or use a hash function other than keccak256 for hashing leaves.
* This is because the concatenation of a sorted pair of internal nodes in
* the merkle tree could be reinterpreted as a leaf value.
* OpenZeppelin's JavaScript library generates merkle trees that are safe
* against this attack out of the box.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Calldata version of {verify}
*
* _Available since v4.7._
*/
function verifyCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProofCalldata(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Calldata version of {processProof}
*
* _Available since v4.7._
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
computedHash = _hashPair(computedHash, proof[i]);
}
return computedHash;
}
/**
* @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by
* `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerify(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProof(proof, proofFlags, leaves) == root;
}
/**
* @dev Calldata version of {multiProofVerify}
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function multiProofVerifyCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32 root,
bytes32[] memory leaves
) internal pure returns (bool) {
return processMultiProofCalldata(proof, proofFlags, leaves) == root;
}
/**
* @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
* proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
* leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
* respectively.
*
* CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
* is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
* tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
*
* _Available since v4.7._
*/
function processMultiProof(
bytes32[] memory proof,
bool[] memory proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
/**
* @dev Calldata version of {processMultiProof}.
*
* CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
*
* _Available since v4.7._
*/
function processMultiProofCalldata(
bytes32[] calldata proof,
bool[] calldata proofFlags,
bytes32[] memory leaves
) internal pure returns (bytes32 merkleRoot) {
// This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
// consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
// `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
// the merkle tree.
uint256 leavesLen = leaves.length;
uint256 totalHashes = proofFlags.length;
// Check proof validity.
require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof");
// The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
// `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
// At each step, we compute the next hash using two values:
// - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
// get the next hash.
// - depending on the flag, either another value for the "main queue" (merging branches) or an element from the
// `proof` array.
for (uint256 i = 0; i < totalHashes; i++) {
bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++];
hashes[i] = _hashPair(a, b);
}
if (totalHashes > 0) {
return hashes[totalHashes - 1];
} else if (leavesLen > 0) {
return leaves[0];
} else {
return proof[0];
}
}
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
@openzeppelin/contracts/utils/introspection/ERC165.sol
// 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;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// 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);
}
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
abdk-libraries-solidity/ABDKMath64x64.sol
// SPDX-License-Identifier: BSD-4-Clause
/*
* ABDK Math 64.64 Smart Contract Library. Copyright © 2019 by ABDK Consulting.
* Author: Mikhail Vladimirov <mikhail.vladimirov@gmail.com>
*/
pragma solidity ^0.8.0;
/**
* Smart contract library of mathematical functions operating with signed
* 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is
* basically a simple fraction whose numerator is signed 128-bit integer and
* denominator is 2^64. As long as denominator is always the same, there is no
* need to store it, thus in Solidity signed 64.64-bit fixed point numbers are
* represented by int128 type holding only the numerator.
*/
library ABDKMath64x64 {
/*
* Minimum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
/*
* Maximum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Convert signed 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromInt (int256 x) internal pure returns (int128) {
unchecked {
require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
return int128 (x << 64);
}
}
/**
* Convert signed 64.64 fixed point number into signed 64-bit integer number
* rounding down.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64-bit integer number
*/
function toInt (int128 x) internal pure returns (int64) {
unchecked {
return int64 (x >> 64);
}
}
/**
* Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromUInt (uint256 x) internal pure returns (int128) {
unchecked {
require (x <= 0x7FFFFFFFFFFFFFFF);
return int128 (int256 (x << 64));
}
}
/**
* Convert signed 64.64 fixed point number into unsigned 64-bit integer
* number rounding down. Revert on underflow.
*
* @param x signed 64.64-bit fixed point number
* @return unsigned 64-bit integer number
*/
function toUInt (int128 x) internal pure returns (uint64) {
unchecked {
require (x >= 0);
return uint64 (uint128 (x >> 64));
}
}
/**
* Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
* number rounding down. Revert on overflow.
*
* @param x signed 128.128-bin fixed point number
* @return signed 64.64-bit fixed point number
*/
function from128x128 (int256 x) internal pure returns (int128) {
unchecked {
int256 result = x >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Convert signed 64.64 fixed point number into signed 128.128 fixed point
* number.
*
* @param x signed 64.64-bit fixed point number
* @return signed 128.128 fixed point number
*/
function to128x128 (int128 x) internal pure returns (int256) {
unchecked {
return int256 (x) << 64;
}
}
/**
* Calculate x + y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function add (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x - y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sub (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding down. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function mul (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
* number and y is signed 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y signed 256-bit integer number
* @return signed 256-bit integer number
*/
function muli (int128 x, int256 y) internal pure returns (int256) {
unchecked {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
}
/**
* Calculate x * y rounding down, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y unsigned 256-bit integer number
* @return unsigned 256-bit integer number
*/
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (int256 (x)) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
}
/**
* Calculate x / y rounding towards zero. Revert on overflow or when y is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function div (int128 x, int128 y) internal pure returns (int128) {
unchecked {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x / y rounding towards zero, where x and y are signed 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x signed 256-bit integer number
* @param y signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divi (int256 x, int256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x; // We rely on overflow behavior here
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult); // We rely on overflow behavior here
}
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divu (uint256 x, uint256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
}
/**
* Calculate -x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function neg (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return -x;
}
}
/**
* Calculate |x|. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function abs (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
}
/**
* Calculate 1 / x rounding towards zero. Revert on overflow or when x is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function inv (int128 x) internal pure returns (int128) {
unchecked {
require (x != 0);
int256 result = int256 (0x100000000000000000000000000000000) / x;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function avg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
return int128 ((int256 (x) + int256 (y)) >> 1);
}
}
/**
* Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
* Revert on overflow or in case x * y is negative.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function gavg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 m = int256 (x) * int256 (y);
require (m >= 0);
require (m <
0x4000000000000000000000000000000000000000000000000000000000000000);
return int128 (sqrtu (uint256 (m)));
}
}
/**
* Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y uint256 value
* @return signed 64.64-bit fixed point number
*/
function pow (int128 x, uint256 y) internal pure returns (int128) {
unchecked {
bool negative = x < 0 && y & 1 == 1;
uint256 absX = uint128 (x < 0 ? -x : x);
uint256 absResult;
absResult = 0x100000000000000000000000000000000;
if (absX <= 0x10000000000000000) {
absX <<= 63;
while (y != 0) {
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x2 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x4 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x8 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
y >>= 4;
}
absResult >>= 64;
} else {
uint256 absXShift = 63;
if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }
uint256 resultShift = 0;
while (y != 0) {
require (absXShift < 64);
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
resultShift += absXShift;
if (absResult > 0x100000000000000000000000000000000) {
absResult >>= 1;
resultShift += 1;
}
}
absX = absX * absX >> 127;
absXShift <<= 1;
if (absX >= 0x100000000000000000000000000000000) {
absX >>= 1;
absXShift += 1;
}
y >>= 1;
}
require (resultShift < 64);
absResult >>= 64 - resultShift;
}
int256 result = negative ? -int256 (absResult) : int256 (absResult);
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate sqrt (x) rounding down. Revert if x < 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sqrt (int128 x) internal pure returns (int128) {
unchecked {
require (x >= 0);
return int128 (sqrtu (uint256 (int256 (x)) << 64));
}
}
/**
* Calculate binary logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function log_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
int256 msb = 0;
int256 xc = x;
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
int256 result = msb - 64 << 64;
uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
ux *= ux;
uint256 b = ux >> 255;
ux >>= 127 + b;
result += bit * int256 (b);
}
return int128 (result);
}
}
/**
* Calculate natural logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function ln (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
return int128 (int256 (
uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
}
}
/**
* Calculate binary exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= uint256 (int256 (63 - (x >> 64)));
require (result <= uint256 (int256 (MAX_64x64)));
return int128 (int256 (result));
}
}
/**
* Calculate natural exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return unsigned 64.64-bit fixed point number
*/
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
unchecked {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
result += xh == hi >> 128 ? xl / y : 1;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
}
/**
* Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
* number.
*
* @param x unsigned 256-bit integer number
* @return unsigned 128-bit integer number
*/
function sqrtu (uint256 x) private pure returns (uint128) {
unchecked {
if (x == 0) return 0;
else {
uint256 xx = x;
uint256 r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x4) { r <<= 1; }
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
}
}
config/settings.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
uint256 constant NFT_DISCOUNT_FREQ = 30 minutes;
uint256 constant NFT_MIN_COST = 1000 * 10 ** 18;
uint256 constant NFT_MIN_BASIS = 1000 * 10 ** 18;
uint256 constant NFT_MAX_BASIS = 1000000000 * 10 ** 18;
int128 constant NFT_DIFFICULTY = 104;
uint64 constant NFT_MAX_RANGE = 1000;
uint256 constant REWARD_COPY = 30;
uint256 constant CVA_COPY = 10;
uint256 constant PKPUR_RAMP_FREQ = 1 days;
int128 constant PKPUR_EMIT_RATE = 1690 * 10 ** 14;
int128 constant PKPUR_DEPOSIT_FEE = 0 * 10 ** 14;
int128 constant PKPUR_WITHDRAW_FEE = 0 * 10 ** 14;
int128 constant PKPUR_REWARD = 1 * 10 ** 14;
string constant PKPUR_NAME = 'PKTTN-Rewards';
string constant PKPUR_TOKEN = 'PKPUR';
int128 constant CLAIM_DAYS = 45;
contracts/Emissions.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import { ABDKMath64x64 as Math } from "abdk-libraries-solidity/ABDKMath64x64.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
/**
* @dev Emissions contract
*
* Releases funded token to depositers proportionally
* Supports deposit, withdraw fees and hooks
* Thanks to helgo.io for their support here
* Check them out they are GOAT
*/
contract Emissions is ERC20, ReentrancyGuard {
struct Emission {
uint256 timestamp;
uint256 amount;
int128 yield;
}
struct Globals {
uint256 reserves; // reserves to emit
uint256 emissions; // reserves emitted
uint256 deposited; // total deposited
uint256 withdrawn; // total withdrawn
uint256 deposits; // total deposited less withdrawn
uint256 fees; // total fees
uint256 lastramp; // last ramp timestamp
int128 basis; // increases daily
uint256 frequency; // ramp frequency
int128 rate; // yearly emission rate
int128 depositfee; // fee on deposit
int128 withdrawfee; // fee on withdrawal
}
IERC20 immutable public TOKEN; // API of ERC used for emissions
uint256 public reserves; // reserves to emit
uint256 public emissions; // reserves emitted
uint256 public deposited; // total deposited
uint256 public withdrawn; // total withdrawn
uint256 public fees; // total fees
uint256 public lastramp; // last ramp timestamp
int128 public basis; // increases daily
uint256 public FREQUENCY; // ramp frequency
int128 public RATE; // yearly emission rate
int128 public DEPOSITFEE; // fee on deposit
int128 public WITHDRAWFEE; // fee on withdrawal
int128 public REWARD; // public function reward
mapping(address => int128) private _depositbasis;
Emission[] public history;
event Ramped(uint256 timestamp, uint256 emission, int128 yield);
event Reward(address indexed addr, uint256 amount);
event Funded(address indexed addr, uint256 amount);
event Deposited(address indexed addr, uint256 amount, uint256 net);
event Withdrawed(address indexed addr, uint256 amount, uint256 net);
constructor(
address addr,
uint256 frequency,
int128 rate,
int128 depositefee,
int128 widthdrawfee,
int128 reward,
string memory name,
string memory symbol
)
ERC20(name, symbol)
{
require(frequency > 0, "Frequency must be greater than 0");
require(rate > 0, "Rate must be greater than zero");
require(rate < Math.fromInt(1), "Rate must be less than 100%");
require(depositefee < Math.fromInt(1), "Deposit fee must be less than 100%");
require(widthdrawfee < Math.fromInt(1), "Deposit fee must be less than 100%");
basis = Math.fromInt(1);
TOKEN = IERC20(addr);
FREQUENCY = frequency;
RATE = Math.div(rate, 10 ** 18) + 1;
if(depositefee > 0)
DEPOSITFEE = Math.div(depositefee, 10 ** 18) + 1;
if(widthdrawfee > 0)
WITHDRAWFEE = Math.div(widthdrawfee, 10 ** 18) + 1;
if(reward > 0)
REWARD = Math.div(reward, 10 ** 18) + 1;
}
function globals() public view virtual returns (Globals memory) {
return Globals(
reserves,
emissions,
deposited,
withdrawn,
_deposits(),
fees,
lastramp,
basis,
FREQUENCY,
RATE,
DEPOSITFEE,
WITHDRAWFEE
);
}
// @notify token emitting to emit
function token() public view virtual returns (IERC20) {
return TOKEN;
}
// @notify total current deposits
function deposits() public view virtual returns(uint256) {
return _deposits();
}
// @notify current emission period
function period() public virtual view returns(uint256){
return (block.timestamp / FREQUENCY) * FREQUENCY;
}
// @notify should ramp
function should() public virtual view returns(bool){
return period() > lastramp;
}
// @notifty address balance inclusive of emissions
function balanceOf(address addr) public view override returns (uint256) {
// Get current balance
uint256 balance = super.balanceOf(addr);
// Get user basis
int128 userbasis = _depositbasis[addr];
// Return adjusted balance
if(balance > 0 && userbasis > 0) {
balance = Math.mulu(Math.div(basis, userbasis), balance);
}
return balance;
}
// @notifty return the next emission
function emitting() public view returns (Emission memory) {
return _emission(lastramp + FREQUENCY);
}
// @notifty fund by adding to reserves
function fund(uint256 amount) external nonReentrant {
require(amount > 0, "Fund amount must be greater than zero");
_autoramp();
reserves += amount;
_mint(address(this), amount);
TOKEN.transferFrom(msg.sender, address(this), amount);
emit Funded(msg.sender, amount);
}
// @notifty deposit to earn share of emissions
function deposit(uint256 amount) external nonReentrant {
_autoramp();
_deposit(msg.sender, amount);
}
// @notifty withdraw deposit and any share of emissions
function withdraw(uint256 amount) external nonReentrant {
_autoramp();
_withdraw(msg.sender, amount);
}
// @notifty withdraw full deposit and any share of emissions
function withdrawAll() external nonReentrant {
_autoramp();
_withdraw(msg.sender, balanceOf(msg.sender));
}
// @notifty publically callable, reward if set
function ramp() external nonReentrant returns (Emission memory) {
_checkramp();
uint256 reward;
// Call internal
Emission memory emission = _ramp();
// Calulate reward
if(REWARD > 0)
reward = Math.mulu(REWARD, emission.amount);
// Give reward
if(reward > 0) {
// Remove reward from reserves
reserves -= reward;
_burn(address(this), reward);
TOKEN.transfer(msg.sender, reward);
}
return emission;
}
// @dev rebase then transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_rebase(msg.sender);
_rebase(recipient);
return super.transfer(recipient, amount);
}
// @dev rebase then transfer
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_rebase(sender);
_rebase(recipient);
return super.transferFrom(sender, recipient, amount);
}
// @notify limit ramp frequency
function _checkramp() internal view {
require(reserves > 0, "no reserves");
require(deposits() > 0, "nothing deposited");
require(should(), "too soon for ramp");
}
// @notify automatically ramp on fund, desposit, withdraw
function _autoramp() internal {
if(lastramp == 0)
lastramp = period();
if(reserves > 0 && deposits() > 0 && should())
_ramp();
}
// @notify deposit token for share of emissions
function _deposit(address addr, uint256 amount) private {
require(amount > 0, "Deposit amount must be greater than zero");
// Before hook
uint256 net = _beforeDeposit(amount);
// Internal
deposited += net;
// Rebase
_rebase(addr);
// Mint the amount
_mint(addr, net);
emit Deposited(addr, amount, net);
// Deposit full amount
TOKEN.transferFrom(addr, address(this), amount);
// After hook
_afterDeposit(net);
}
// @notify withdraw depost and any share of emissions
function _withdraw(address addr, uint256 amount) private {
require(balanceOf(addr) >= amount, "withdraw amount exceeds deposit");
// Rebase
_rebase(addr);
// Remove fees
uint256 net = _beforeWithdraw(amount);
// Internal
withdrawn += net;
// Burn full amount
_burn(addr, amount);
emit Withdrawed(msg.sender, amount, net);
// Transfer TOKEN
TOKEN.transfer(addr, net);
// After hook
_afterWithdraw(net);
}
// @notify rebase and address
function _rebase(address addr) private {
// Check current basis
if(_depositbasis[addr] != basis) {
uint256 balance = super.balanceOf(addr);
uint256 difference = balanceOf(addr) - balance;
// set new basis
_depositbasis[addr] = basis;
// issue due
if(difference > 0) {
_transfer(address(this), addr, difference);
}
}
}
// @notify total current deposits
function _deposits() private view returns(uint256) {
if(deposited < withdrawn + fees) {
return 0;
}
return deposited - (withdrawn + fees);
}
// @notify calculated emmission for timestamp
function _emission(uint256 timestamp) internal virtual view returns (Emission memory) {
uint256 since = timestamp - lastramp;
// Zero if no deposits
if(deposits() == 0 || reserves == 0 || since <= 0) {
return Emission(
timestamp,
0,
0
);
}
// Cap annually
if(since > 365 days) {
since = 365 days;
}
int128 increase = Math.mul(RATE, Math.divu(since, 365 days));
uint256 amount = Math.mulu(increase, reserves);
int128 yield = Math.divu(amount, deposits()) + 1;
return Emission(
timestamp,
amount,
yield
);
}
// @notify release emmissions by ramping basis
function _ramp() private returns (Emission memory) {
// Calculate emission
Emission memory emission = _emission(period());
// Set last ramp timestamp
lastramp = period();
reserves -= emission.amount;
emissions += emission.amount;
basis += emission.yield;
emit Ramped(
emission.timestamp,
emission.amount,
emission.yield
);
return emission;
}
// @dev called before deposit, returns amount to deposit (after any fees).
function _beforeDeposit(
uint256 amount
) internal virtual returns (uint256) {
if(DEPOSITFEE == 0)
return amount;
uint256 fee = Math.mulu(DEPOSITFEE, amount);
fees += fee;
reserves += fee;
_mint(address(this),fee);
return amount - fee;
}
// @dev called after withdraw
function _afterDeposit(
uint256 amount
) internal virtual {
}
// @dev called before withdraw, returns amount to withdraw (after any fees).
function _beforeWithdraw(
uint256 amount
) internal virtual returns (uint256) {
if(WITHDRAWFEE == 0)
return amount;
uint256 fee = Math.mulu(WITHDRAWFEE, amount);
fees += fee;
reserves += fee;
_mint(address(this),fee);
return amount - fee;
}
// @dev called after withdraw
function _afterWithdraw(
uint256 amount
) internal virtual {
}
}
contracts/PKNFT.sol
// SPDX-License-Identifier: UNLICENSED
/// @custom:security-contact dev@pulsekittens.io
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/common/ERC2981.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "../interfaces/iPetRegistry.sol";
contract PKNFT is ERC2981, ERC721Enumerable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
address immutable SHEPHERD;
iPetRegistry immutable REGISTRY;
string private HOST;
constructor(address registry, string memory host) ERC721("PulseKitten NFT", "PKNFT") {
// Not an admin key, only PulseKittens contract is allowed to mint
SHEPHERD = msg.sender;
// Main pet registry
REGISTRY = iPetRegistry(registry);
// Domain / host
HOST = host;
}
function getTokenBonus(uint256 tokenId) external view returns (uint256) {
return REGISTRY.getTokenBonus(tokenId);
}
function getHolderBonus(address holder) external view returns (uint256) {
return REGISTRY.getHolderBonus(holder);
}
function mintKitten(address holder, uint256 bonus) external returns (uint256) {
// Only Shephard can mint
require(msg.sender == SHEPHERD, "PKNFT: Not SHEPARD");
require(bonus <= 100, "PKNFT: Bonus too high");
require(bonus >= 0, "PKNFT: Bonus negative");
// New id
_tokenIds.increment();
uint256 tokenId = _tokenIds.current();
// Mint to holder
_mint(holder, tokenId);
// NFT marketplace support
_setTokenRoyalty(tokenId, SHEPHERD, 0);
// Register Pet
REGISTRY.register(holder, tokenId, bonus);
return tokenId;
}
function _baseURI() internal view virtual override returns (string memory) {
return string(abi.encodePacked(HOST, "/", symbol(), "/", Strings.toString(block.chainid), "/"));
}
// Used for Market places
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
return super.tokenURI(tokenId);
}
function owner() public view returns (address) {
return SHEPHERD;
}
function contractURI() public view returns (string memory) {
return string(abi.encodePacked(_baseURI(), "meta-data"));
}
function supportsInterface(bytes4 interfaceId)
public
view
override (ERC2981, ERC721Enumerable)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId, batchSize);
REGISTRY.transfer(from, to, tokenId);
}
}
contracts/PetRegistry.sol
// SPDX-License-Identifier: UNLICENSED
/// @custom:security-contact dev@pulsepets.io
pragma solidity ^0.8.9;
struct PetHolder {
uint256 pets;
uint256 bonus;
}
contract PetRegistry {
// Mapping from PET721 to list of owned token IDs
mapping(address => uint256) private _totalPets;
mapping(address => uint256) private _totalBonus;
mapping(address => mapping(uint256 => address)) private _tokenOwner;
mapping(address => mapping(uint256 => uint256)) private _tokenBonus;
mapping(address => mapping(address => PetHolder)) private _tokenHolder;
event Registered(address indexed pet, address holder, uint256 tokenId, uint256 bonus);
event Unregistered(address indexed pet, address holder, uint256 tokenId, uint256 bonus);
// @dev total number of pets registered
function getTotalPets(address pet) external view returns(uint256) {
return _totalPets[pet];
}
// @dev get bonus for any pet and holder
function getTotalBonuses(address pet) external view returns(uint256) {
return _totalBonus[pet];
}
// @dev get bonus for pet token
function getTokenBonus(uint256 tokenId) external view returns(uint256) {
return _tokenBonus[msg.sender][tokenId];
}
// @dev get number of holder pets
function getHolderPets(address holder) external view returns(uint256) {
PetHolder memory ph = _tokenHolder[msg.sender][holder];
return ph.pets;
}
// @dev get total bonus for a holder
function getHolderBonus(address holder) external view returns(uint256) {
PetHolder memory ph = _tokenHolder[msg.sender][holder];
return ph.bonus;
}
// @dev get bonus for any pet and holder
function getPetHolderBonus(address pet, address holder) external view returns(uint256) {
PetHolder memory ph = _tokenHolder[pet][holder];
return ph.bonus;
}
// @dev get bonus for any pet and holder
function getPetTokenBonus(address pet, uint256 tokenId) external view returns(uint256) {
return _tokenBonus[pet][tokenId];
}
// @dev get bonus for any pet and holder
function getPetHolderPets(address pet, address holder) external view returns(uint256) {
PetHolder memory ph = _tokenHolder[pet][holder];
return ph.pets;
}
// @dev allow any contract to register that contracts tokens
function register(address holder, uint256 tokenId, uint256 bonus) external returns (uint256) {
require(holder != address(0), "Holder can not be 0x0");
_totalPets[msg.sender]++;
_totalBonus[msg.sender] += bonus;
_tokenOwner[msg.sender][tokenId] = holder;
_tokenBonus[msg.sender][tokenId] = bonus;
emit Registered(msg.sender, holder, tokenId, bonus);
return _add(msg.sender, holder, bonus);
}
// @dev allow any contract to remove that contracts tokens
function unregister(address holder, uint256 tokenId) external returns (uint256) {
require(_tokenOwner[msg.sender][tokenId] != address(0), "No holder");
uint256 bonus = _tokenBonus[msg.sender][tokenId];
_totalPets[msg.sender]--;
_totalBonus[msg.sender] -= bonus;
_tokenOwner[msg.sender][tokenId] = address(0);
_tokenBonus[msg.sender][tokenId] = 0;
emit Unregistered(msg.sender, holder, tokenId, bonus);
return _sub(msg.sender, holder, bonus);
}
// @dev allow any contract to remove that contracts tokens
function transfer(
address from,
address to,
uint256 tokenId
) external {
uint256 bonus = _tokenBonus[msg.sender][tokenId];
_tokenOwner[msg.sender][tokenId] = to;
if(from != address(0)) {
_sub(msg.sender, from, bonus);
}
_add(msg.sender, to, bonus);
}
// @dev add to a holders pets
function _add(address pet, address holder, uint256 bonus) internal returns (uint256) {
PetHolder storage ph = _tokenHolder[pet][holder];
ph.pets++;
ph.bonus += bonus;
return ph.bonus;
}
// @dev subtract from a holders pets
function _sub(address pet, address holder, uint256 bonus) internal returns (uint256) {
PetHolder storage ph = _tokenHolder[pet][holder];
ph.pets--;
ph.bonus -= bonus;
return ph.bonus;
}
}
interfaces/iPetRegistry.sol
// SPDX-License-Identifier: UNLICENSED
// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v0.6.6. SEE SOURCE BELOW. !!
pragma solidity >=0.7.0 <0.9.0;
interface iPetRegistry {
event Registered(
address indexed pet,
address holder,
uint256 tokenId,
uint256 bonus
);
event Unregistered(
address indexed pet,
address holder,
uint256 tokenId,
uint256 bonus
);
function getHolderBonus(address holder) external view returns (uint256);
function getHolderPets(address holder) external view returns (uint256);
function getPetHolderBonus(address pet, address holder)
external
view
returns (uint256);
function getPetHolderPets(address pet, address holder)
external
view
returns (uint256);
function getPetTokenBonus(address pet, uint256 tokenId)
external
view
returns (uint256);
function getTokenBonus(uint256 tokenId) external view returns (uint256);
function getTotalBonuses(address pet) external view returns (uint256);
function getTotalPets(address pet) external view returns (uint256);
function register(
address holder,
uint256 tokenId,
uint256 bonus
) external returns (uint256);
function transfer(
address from,
address to,
uint256 tokenId
) external;
function unregister(address holder, uint256 tokenId)
external
returns (uint256);
}
// THIS FILE WAS AUTOGENERATED FROM THE FOLLOWING ABI JSON:
/*
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pet","type":"address"},{"indexed":false,"internalType":"address","name":"holder","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonus","type":"uint256"}],"name":"Registered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pet","type":"address"},{"indexed":false,"internalType":"address","name":"holder","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonus","type":"uint256"}],"name":"Unregistered","type":"event"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"getHolderBonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"getHolderPets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pet","type":"address"},{"internalType":"address","name":"holder","type":"address"}],"name":"getPetHolderBonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pet","type":"address"},{"internalType":"address","name":"holder","type":"address"}],"name":"getPetHolderPets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pet","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getPetTokenBonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getTokenBonus","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pet","type":"address"}],"name":"getTotalBonuses","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pet","type":"address"}],"name":"getTotalPets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"bonus","type":"uint256"}],"name":"register","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"unregister","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
*/
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":369,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","inputs":[{"type":"bytes32","name":"root","internalType":"bytes32"},{"type":"address","name":"cva","internalType":"address"},{"type":"string","name":"host","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"CVA","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"DAYZERO","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract Emissions"}],"name":"EMISSIONS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract PKNFT"}],"name":"NFT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract PetRegistry"}],"name":"REGISTRY","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"ROOT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"activity","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"allowance","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"spender","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"approve","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"calculateYield","inputs":[{"type":"address","name":"addr","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"claim","inputs":[{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes32[]","name":"proof","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"claimers","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"decimals","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"decreaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"subtractedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"}],"name":"distribute","inputs":[{"type":"address","name":"addr","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes32[]","name":"proof","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimateMintCost","inputs":[{"type":"uint64","name":"minted","internalType":"uint64"},{"type":"uint64","name":"since","internalType":"uint64"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"estimateYield","inputs":[{"type":"address","name":"addr","internalType":"address"},{"type":"uint64","name":"elapsed","internalType":"uint64"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"increaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"addedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintCost","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintKitten","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mintKittenFor","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"nextDrop","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"sinceMint","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint64","name":"","internalType":"uint64"}],"name":"today","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transfer","inputs":[{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transferFrom","inputs":[{"type":"address","name":"sender","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","indexed":true},{"type":"address","name":"spender","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false},{"type":"event","name":"Claimed","inputs":[{"type":"address","name":"addr","indexed":true},{"type":"uint256","name":"amount","indexed":false},{"type":"uint256","name":"bonus","indexed":false},{"type":"uint256","name":"sac","indexed":false},{"type":"uint256","name":"drops","indexed":false}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","indexed":true},{"type":"address","name":"to","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false}]
Contract Creation Code
0x6101406040523480156200001257600080fd5b5060405162007d3f38038062007d3f8339810160408190526200003591620003f3565b6040518060400160405280600b81526020016a283ab639b2a5b4ba3a32b760a91b815250604051806040016040528060058152602001642825aa2a2760d91b815250816003908162000088919062000567565b50600462000097828262000567565b50620000a59150506200023c565b6001600160401b0316608052604051620000bf906200038d565b604051809103906000f080158015620000dc573d6000803e3d6000fd5b506001600160a01b031660a08190526040518290620000fb906200039b565b6200010892919062000661565b604051809103906000f08015801562000125573d6000803e3d6000fd5b506001600160a01b031660c0816001600160a01b0316815250503062015180670258689ac70a8000600080655af3107a40006040518060400160405280600d81526020016c504b54544e2d5265776172647360981b815250604051806040016040528060058152602001642825a82aa960d91b815250604051620001a990620003a9565b620001bc9897969594939291906200068f565b604051809103906000f080158015620001d9573d6000803e3d6000fd5b506001600160a01b031660e0819052620001f890309060001962000261565b50610100919091526001600160a01b03166101205260078054600160401b600160801b03191668010000000000000000426001600160401b03160217905562000751565b60006200024d620151804262000702565b6200025c906201518062000725565b905090565b6001600160a01b038316620002c95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084015b60405180910390fd5b6001600160a01b0382166200032c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401620002c0565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b61088c806200298f83390190565b6123a9806200321b83390190565b61277b80620055c483390190565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620003ea578181015183820152602001620003d0565b50506000910152565b6000806000606084860312156200040957600080fd5b835160208501519093506001600160a01b03811681146200042957600080fd5b60408501519092506001600160401b03808211156200044757600080fd5b818601915086601f8301126200045c57600080fd5b815181811115620004715762000471620003b7565b604051601f8201601f19908116603f011681019083821181831017156200049c576200049c620003b7565b81604052828152896020848701011115620004b657600080fd5b620004c9836020830160208801620003cd565b80955050505050509250925092565b600181811c90821680620004ed57607f821691505b6020821081036200050e57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200056257600081815260208120601f850160051c810160208610156200053d5750805b601f850160051c820191505b818110156200055e5782815560010162000549565b5050505b505050565b81516001600160401b03811115620005835762000583620003b7565b6200059b81620005948454620004d8565b8462000514565b602080601f831160018114620005d35760008415620005ba5750858301515b600019600386901b1c1916600185901b1785556200055e565b600085815260208120601f198616915b828110156200060457888601518255948401946001909101908401620005e3565b5085821015620006235787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600081518084526200064d816020860160208601620003cd565b601f01601f19169290920160200192915050565b6001600160a01b0383168152604060208201819052600090620006879083018462000633565b949350505050565b600061010060018060a01b038b16835289602084015288600f0b604084015287600f0b606084015286600f0b608084015285600f0b60a08401528060c0840152620006dd8184018662000633565b905082810360e0840152620006f3818562000633565b9b9a5050505050505050505050565b6000826200072057634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176200074b57634e487b7160e01b600052601160045260246000fd5b92915050565b60805160a05160c05160e05161010051610120516121a8620007e760003960008181610298015281816110ea015261182001526000818161034d01526117f301526000818161043101528181610a8c0152818161108101526111b001526000818161038701528181610b5601528181610efd0152611240015260006101e40152600081816103c10152610e5c01526121a86000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80637c0b8de211610104578063a9059cbb116100a2578063d457c62811610071578063d457c6281461049c578063da62fba9146104a4578063dd62ed3e146104c7578063df6aa1401461050057600080fd5b8063a9059cbb14610466578063ab1089be14610479578063b74e452b1461048c578063bdb4b8481461049457600080fd5b806384b504c8116100de57806384b504c8146103fb57806395d89b41146104245780639c1e56d31461042c578063a457c2d71461045357600080fd5b80637c0b8de21461038257806380af56a3146103a957806381b3b1fb146103bc57600080fd5b80632f52ebb71161017c578063567add641161014b578063567add6414610322578063583e22dc146103355780635909c12f1461034857806370a082311461036f57600080fd5b80632f52ebb7146102ba578063313ce567146102ed57806339509351146102fc578063447d92061461030f57600080fd5b806318160ddd116101b857806318160ddd1461025b5780631a1daf081461026d57806323b872dd1461028057806327b114531461029357600080fd5b806306433b1b146101df57806306fdde0314610223578063095ea7b314610238575b600080fd5b6102067f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b61022b610508565b60405161021a9190611c0e565b61024b610246366004611c73565b61059a565b604051901515815260200161021a565b6002545b60405190815260200161021a565b61025f61027b366004611c73565b6105b4565b61024b61028e366004611c9d565b6105c8565b6102067f000000000000000000000000000000000000000000000000000000000000000081565b6102cd6102c8366004611d24565b6105ef565b60408051948552602085019390935291830152606082015260800161021a565b6040516012815260200161021a565b61024b61030a366004611c73565b610612565b61025f61031d366004611d86565b610651565b61025f610330366004611db9565b61065d565b61025f610343366004611dd4565b6106e6565b61025f7f000000000000000000000000000000000000000000000000000000000000000081565b61025f61037d366004611db9565b6106f3565b6102067f000000000000000000000000000000000000000000000000000000000000000081565b61025f6103b7366004611ded565b61071f565b6103e37f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160401b03909116815260200161021a565b6103e3610409366004611db9565b6006602052600090815260409020546001600160401b031681565b61022b61072b565b6102067f000000000000000000000000000000000000000000000000000000000000000081565b61024b610461366004611c73565b61073a565b61024b610474366004611c73565b6107dc565b6102cd610487366004611e09565b6107fa565b6103e361081e565b61025f61083f565b6103e361085f565b61024b6104b2366004611db9565b60056020526000908152604090205460ff1681565b61025f6104d5366004611e62565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6103e3610869565b60606003805461051790611e8c565b80601f016020809104026020016040519081016040528092919081815260200182805461054390611e8c565b80156105905780601f1061056557610100808354040283529160200191610590565b820191906000526020600020905b81548152906001019060200180831161057357829003601f168201915b5050505050905090565b6000336105a881858561088d565b60019150505b92915050565b60006105c13383856109b1565b9392505050565b60006105d384610c3f565b6105dc83610c3f565b6105e7848484610cd3565b949350505050565b60008060008061060133888888610cec565b935093509350935093509350935093565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906105a8908290869061064c908790611edc565b61088d565b60006105c1838361118c565b6001600160a01b03811660009081526006602052604081205481906001600160401b03166106925761068d61081e565b6106b5565b6001600160a01b0383166000908152600660205260409020546001600160401b03165b9050600062015180826106c661081e565b6106d09190611eef565b6106da9190611f2c565b90506105e7848261118c565b60006105ae3383336109b1565b6001600160a01b0381166000908152602081905260408120546107158361065d565b6105c19082611edc565b60006105c1838361131b565b60606004805461051790611e8c565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156107c45760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6107d1828686840361088d565b506001949350505050565b60006107e733610c3f565b6107f083610c3f565b6105c18383611451565b60008060008061080c88888888610cec565b929b919a509850909650945050505050565b600061082d6201518042611f52565b61083a9062015180611f66565b905090565b60075460009061083a906001600160401b031661085a61145f565b61131b565b600061083a61145f565b60006107086108788142611f52565b610883906001611edc565b61083a9190611f66565b6001600160a01b0383166108ef5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016107bb565b6001600160a01b0382166109505760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016107bb565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006109bb61083f565b831015610a0a5760405162461bcd60e51b815260206004820152601460248201527f504b54544e3a2042656c6f77206d696e696d756d00000000000000000000000060448201526064016107bb565b610a13846106f3565b831115610a625760405162461bcd60e51b815260206004820152601b60248201527f504b54544e3a20496e73756666696369656e742062616c616e6365000000000060448201526064016107bb565b610a6b84610c3f565b610a768430856114ab565b60405163ca1d209d60e01b8152600481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ca1d209d90602401600060405180830381600087803b158015610ad857600080fd5b505af1158015610aec573d6000803e3d6000fd5b5050600780546001600160401b03428116600160401b026fffffffffffffffff0000000000000000198316811784558116911617925090506000610b2f83611f7d565b91906101000a8154816001600160401b0302191690836001600160401b03160217905550507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635536882f8360074442604051602001610ba2929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c610bc59190611fa3565b610bd0906005611edc565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610c1b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105e79190611fb7565b610c4761081e565b6001600160a01b0382166000908152600660205260409020546001600160401b03908116911614610cd0576000610c7d8261065d565b9050610c8761081e565b6001600160a01b0383166000908152600660205260409020805467ffffffffffffffff19166001600160401b03929092169190911790558015610cce57610cce8282611651565b505b50565b600033610ce1858285611711565b6107d18585856114ab565b6001600160a01b03841660009081526005602052604081205481908190819060ff1615610d5b5760405162461bcd60e51b815260206004820152601360248201527f416c72656164792064697374726962757465640000000000000000000000000060448201526064016107bb565b610da1610d68888a61179d565b8787808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506117eb92505050565b610ded5760405162461bcd60e51b815260206004820152601460248201527f496e76616c6964206d65726b6c652070726f6f6600000000000000000000000060448201526064016107bb565b6001600160a01b038816600090815260056020526040808220805460ff19166001179055605089901c9160488a901c60ff908116928b901c1690610e2f601290565b610e3a90600a6120b4565b610e4d906001600160401b038d16611f66565b905081600003610eeb57610e847f00000000000000000000000000000000000000000000000000000000000000006276a7006120c3565b6001600160401b0316610e9561081e565b6001600160401b031610610eeb5760405162461bcd60e51b815260206004820152601660248201527f436c61696d20706861736520686173207061737365640000000000000000000060448201526064016107bb565b610ef58c82611651565b8215611008577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635536882f8d60054442604051602001610f49929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c610f6c9190611fa3565b610f776001886120e3565b610f82906005611f66565b610f8d90600a611edc565b610f979190611edc565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610fe2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110069190611fb7565b505b61101061081e565b6001600160a01b038d166000908152600660205260408120805467ffffffffffffffff19166001600160401b0393909316929092179091556064611055601e84611f66565b61105f9190611f52565b905061106b3082611651565b60405163ca1d209d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ca1d209d90602401600060405180830381600087803b1580156110cd57600080fd5b505af11580156110e1573d6000803e3d6000fd5b505050506111277f00000000000000000000000000000000000000000000000000000000000000006064600a856111189190611f66565b6111229190611f52565b611651565b6040805183815260208101869052908101849052606081018690526001600160a01b038e16907f7708755c9b641bf197be5047b04002d2e88fa658c173a351067747eb5dfc568a9060800160405180910390a2509b919a509850909650945050505050565b6040516370a0823160e01b81526001600160a01b03838116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa1580156111f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061121b9190611fb7565b604051630338e01760e11b81526001600160a01b0386811660048301529192506000917f00000000000000000000000000000000000000000000000000000000000000001690630671c02e90602401602060405180830381865afa158015611287573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ab9190611fb7565b9050600080821180156112be5750600083115b80156112d357506000856001600160401b0316115b156113125761016d6001600160401b03861660646112f18587611f66565b6112fb9190611f52565b6113059190611f66565b61130f9190611f52565b90505b95945050505050565b600080611326611818565b9050683635c9adc5dea000008110156113455750683635c9adc5dea000005b6b033b2e3c9fd0803ce800000081111561136857506b033b2e3c9fd0803ce80000005b6103e86001600160401b0385161115611381576103e893505b6103e86001600160401b038416111561139a576103e892505b60006113bf6113b16068662386f26fc100006120f6565b670de0b6b3a764000061185f565b6113ca906001612116565b90506000670de0b6b3a764000061140e6114086113f0858a6001600160401b03166118b7565b611403868a6001600160401b03166118b7565b61185f565b85611af7565b6114189190611f52565b61142a90670de0b6b3a7640000611f66565b9050683635c9adc5dea000008110156113125750683635c9adc5dea0000095945050505050565b6000336105a88185856114ab565b600754600090600160401b90046001600160401b0316156114a5576007546107089061149b90600160401b90046001600160401b0316426120e3565b61083a9190611f52565b50600090565b6001600160a01b03831661150f5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016107bb565b6001600160a01b0382166115715760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016107bb565b6001600160a01b038316600090815260208190526040902054818110156115e95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016107bb565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35b50505050565b6001600160a01b0382166116a75760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016107bb565b80600260008282546116b99190611edc565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610cce565b6001600160a01b03838116600090815260016020908152604080832093861683529290522054600019811461164b57818110156117905760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016107bb565b61164b848484840361088d565b600082826040516020016117cd92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b60006105c1827f000000000000000000000000000000000000000000000000000000000000000085611b7c565b6000806118447f00000000000000000000000000000000000000000000000000000000000000006106f3565b9050801561185a57611857600582611f52565b90505b919050565b600081600f0b60000361187157600080fd5b600082600f0b604085600f0b901b8161188c5761188c611f16565b05905060016001607f1b031981128015906118ae575060016001607f1b038113155b6105c157600080fd5b600080600084600f0b1280156118d05750826001166001145b905060008085600f0b126118e457846118e9565b846000035b6fffffffffffffffffffffffffffffffff169050600160801b600160401b821161198757603f82901b91505b841561197f57600185161561192a578102607f1c5b908002607f1c906002851615611940578102607f1c5b908002607f1c906004851615611956578102607f1c5b908002607f1c90600885161561196c578102607f1c5b60049490941c93908002607f1c90611915565b60401c611ab1565b603f6c010000000000000000000000008310156119aa5760209290921b91601f19015b6e0100000000000000000000000000008310156119cd5760109290921b91600f19015b600160781b8310156119e55760089290921b91600719015b6001607c1b8310156119fd5760049290921b91600319015b6001607e1b831015611a155760029290921b91600119015b6001607f1b831015611a2d5760019290921b91600019015b60005b8615611a9a5760408210611a4357600080fd5b6001871615611a6957918302607f1c918101600160801b831115611a6957600192831c92015b928002607f1c9260019190911b90600160801b8410611a8e57600193841c9391909101905b600187901c9650611a30565b60408110611aa757600080fd5b6040039190911c90505b600083611abe5781611ac3565b816000035b905060016001607f1b03198112801590611ae4575060016001607f1b038113155b611aed57600080fd5b9695505050505050565b600081600003611b09575060006105ae565b600083600f0b1215611b1a57600080fd5b600f83900b6fffffffffffffffffffffffffffffffff8316810260401c90608084901c0277ffffffffffffffffffffffffffffffffffffffffffffffff811115611b6357600080fd5b60401b8119811115611b7457600080fd5b019392505050565b600082611b898584611b92565b14949350505050565b600081815b8451811015611bd757611bc382868381518110611bb657611bb6612143565b6020026020010151611bdf565b915080611bcf81612159565b915050611b97565b509392505050565b6000818310611bfb5760008281526020849052604090206105c1565b60008381526020839052604090206105c1565b600060208083528351808285015260005b81811015611c3b57858101830151858201604001528201611c1f565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461185a57600080fd5b60008060408385031215611c8657600080fd5b611c8f83611c5c565b946020939093013593505050565b600080600060608486031215611cb257600080fd5b611cbb84611c5c565b9250611cc960208501611c5c565b9150604084013590509250925092565b60008083601f840112611ceb57600080fd5b5081356001600160401b03811115611d0257600080fd5b6020830191508360208260051b8501011115611d1d57600080fd5b9250929050565b600080600060408486031215611d3957600080fd5b8335925060208401356001600160401b03811115611d5657600080fd5b611d6286828701611cd9565b9497909650939450505050565b80356001600160401b038116811461185a57600080fd5b60008060408385031215611d9957600080fd5b611da283611c5c565b9150611db060208401611d6f565b90509250929050565b600060208284031215611dcb57600080fd5b6105c182611c5c565b600060208284031215611de657600080fd5b5035919050565b60008060408385031215611e0057600080fd5b611da283611d6f565b60008060008060608587031215611e1f57600080fd5b611e2885611c5c565b93506020850135925060408501356001600160401b03811115611e4a57600080fd5b611e5687828801611cd9565b95989497509550505050565b60008060408385031215611e7557600080fd5b611e7e83611c5c565b9150611db060208401611c5c565b600181811c90821680611ea057607f821691505b602082108103611ec057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156105ae576105ae611ec6565b6001600160401b03828116828216039080821115611f0f57611f0f611ec6565b5092915050565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b0380841680611f4657611f46611f16565b92169190910492915050565b600082611f6157611f61611f16565b500490565b80820281158282048414176105ae576105ae611ec6565b60006001600160401b03808316818103611f9957611f99611ec6565b6001019392505050565b600082611fb257611fb2611f16565b500690565b600060208284031215611fc957600080fd5b5051919050565b600181815b8085111561200b578160001904821115611ff157611ff1611ec6565b80851615611ffe57918102915b93841c9390800290611fd5565b509250929050565b600082612022575060016105ae565b8161202f575060006105ae565b8160018114612045576002811461204f5761206b565b60019150506105ae565b60ff84111561206057612060611ec6565b50506001821b6105ae565b5060208310610133831016604e8410600b841016171561208e575081810a6105ae565b6120988383611fd0565b80600019048211156120ac576120ac611ec6565b029392505050565b60006105c160ff841683612013565b6001600160401b03818116838216019080821115611f0f57611f0f611ec6565b818103818111156105ae576105ae611ec6565b600082600f0b82600f0b0280600f0b9150808214611f0f57611f0f611ec6565b600f81810b9083900b0160016001607f1b03811360016001607f1b0319821217156105ae576105ae611ec6565b634e487b7160e01b600052603260045260246000fd5b60006001820161216b5761216b611ec6565b506001019056fea2646970667358221220f3cb860925856294cc4dce31efd031f4075e9591de388589c2ea5c6fc8703c0d64736f6c63430008110033608060405234801561001057600080fd5b5061086c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b95760003560e01c80639d5f25d411610081578063cba837d41161005b578063cba837d41461020b578063e9a7a8e01461025f578063f9454f3f146102b257600080fd5b80639d5f25d414610197578063beabacc8146101c0578063cb98425d146101d557600080fd5b80630671c02e146100be57806312dbfd9c1461011d57806349a02c84146101305780634da9eea6146101595780634e8c85c014610184575b600080fd5b61010b6100cc3660046106c3565b3360009081526004602090815260408083206001600160a01b039490941683529281529082902082518084019093528054835260010154910181905290565b60405190815260200160405180910390f35b61010b61012b3660046106e5565b6102c5565b61010b61013e3660046106c3565b6001600160a01b031660009081526020819052604090205490565b61010b610167366004610718565b336000908152600360209081526040808320938352929052205490565b61010b610192366004610731565b610309565b61010b6101a53660046106c3565b6001600160a01b031660009081526001602052604090205490565b6101d36101ce36600461075b565b61045b565b005b61010b6101e3366004610731565b6001600160a01b03919091166000908152600360209081526040808320938352929052205490565b61010b6102193660046106e5565b6001600160a01b03918216600090815260046020908152604080832093909416825291825282902082518084019093528054808452600190910154929091019190915290565b61010b61026d3660046106c3565b3360009081526004602090815260408083206001600160a01b039490941683529281529082902082518084019093528054808452600190910154929091019190915290565b61010b6102c0366004610797565b6104cc565b6001600160a01b0380831660009081526004602090815260408083209385168352928152908290208251808401909352805483526001015491018190525b92915050565b3360009081526002602090815260408083208484529091528120546001600160a01b031661036a5760405162461bcd60e51b81526020600482015260096024820152682737903437b63232b960b91b60448201526064015b60405180910390fd5b33600081815260036020908152604080832086845282528083205493835290829052812080549161039a836107e0565b909155505033600090815260016020526040812080548392906103be9084906107f7565b9091555050336000818152600260209081526040808320878452825280832080546001600160a01b03191690558383526003825280832087845282528083209290925581516001600160a01b03881681529081018690529081018390527fb9f291e0ffefbf4bc674385d04958dd56891b94355135d35e6f8571184ebb6e19060600160405180910390a26104533385836105fc565b949350505050565b33600081815260036020908152604080832085845282528083205493835260028252808320858452909152902080546001600160a01b0319166001600160a01b03858116919091179091558416156104ba576104b83385836105fc565b505b6104c533848361065a565b5050505050565b60006001600160a01b0384166105245760405162461bcd60e51b815260206004820152601560248201527f486f6c6465722063616e206e6f742062652030783000000000000000000000006044820152606401610361565b33600090815260208190526040812080549161053f8361080a565b90915550503360009081526001602052604081208054849290610563908490610823565b9091555050336000818152600260209081526040808320878452825280832080546001600160a01b0319166001600160a01b038a1690811790915584845260038352818420888552835292819020869055805192835290820186905281018490527ffc6ca567323d11e0a46d02199a9136c71eca09c84436e3fe38446d17028ceae19060600160405180910390a261045333858461065a565b6001600160a01b038084166000908152600460209081526040808320938616835292905290812080548183610630836107e0565b91905055508281600101600082825461064991906107f7565b909155505060010154949350505050565b6001600160a01b03808416600090815260046020908152604080832093861683529290529081208054818361068e8361080a565b9190505550828160010160008282546106499190610823565b80356001600160a01b03811681146106be57600080fd5b919050565b6000602082840312156106d557600080fd5b6106de826106a7565b9392505050565b600080604083850312156106f857600080fd5b610701836106a7565b915061070f602084016106a7565b90509250929050565b60006020828403121561072a57600080fd5b5035919050565b6000806040838503121561074457600080fd5b61074d836106a7565b946020939093013593505050565b60008060006060848603121561077057600080fd5b610779846106a7565b9250610787602085016106a7565b9150604084013590509250925092565b6000806000606084860312156107ac57600080fd5b6107b5846106a7565b95602085013595506040909401359392505050565b634e487b7160e01b600052601160045260246000fd5b6000816107ef576107ef6107ca565b506000190190565b81810381811115610303576103036107ca565b60006001820161081c5761081c6107ca565b5060010190565b80820180821115610303576103036107ca56fea2646970667358221220c6d259729badcec2db948239477a3b5e7faad153f692428228d38aeee3bcd23a64736f6c6343000811003360c06040523480156200001157600080fd5b50604051620023a9380380620023a98339810160408190526200003491620000db565b6040518060400160405280600f81526020016e141d5b1cd952da5d1d195b88139195608a1b815250604051806040016040528060058152602001641412d3919560da1b81525081600290816200008b919062000260565b5060036200009a828262000260565b505033608052506001600160a01b03821660a052600d620000bc828262000260565b5050506200032c565b634e487b7160e01b600052604160045260246000fd5b60008060408385031215620000ef57600080fd5b82516001600160a01b03811681146200010757600080fd5b602084810151919350906001600160401b03808211156200012757600080fd5b818601915086601f8301126200013c57600080fd5b815181811115620001515762000151620000c5565b604051601f8201601f19908116603f011681019083821181831017156200017c576200017c620000c5565b8160405282815289868487010111156200019557600080fd5b600093505b82841015620001b957848401860151818501870152928501926200019a565b60008684830101528096505050505050509250929050565b600181811c90821680620001e657607f821691505b6020821081036200020757634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200025b57600081815260208120601f850160051c81016020861015620002365750805b601f850160051c820191505b81811015620002575782815560010162000242565b5050505b505050565b81516001600160401b038111156200027c576200027c620000c5565b62000294816200028d8454620001d1565b846200020d565b602080601f831160018114620002cc5760008415620002b35750858301515b600019600386901b1c1916600185901b17855562000257565b600085815260208120601f198616915b82811015620002fd57888601518255948401946001909101908401620002dc565b50858210156200031c5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a05161203462000375600039600081816103b5015281816107e3015281816109f6015261148c0152600081816102d9015281816108ba01526109a301526120346000f3fe608060405234801561001057600080fd5b50600436106101625760003560e01c80634f6ccce7116100c857806395d89b411161008c578063c87b56dd11610066578063c87b56dd1461032b578063e8a3d4851461033e578063e985e9c51461034657600080fd5b806395d89b41146102fd578063a22cb46514610305578063b88d4fde1461031857600080fd5b80634f6ccce71461028b5780635536882f1461029e5780636352211e146102b157806370a08231146102c45780638da5cb5b146102d757600080fd5b806318160ddd1161012a5780632f745c59116101045780632f745c591461025257806342842e0e146102655780634da9eea61461027857600080fd5b806318160ddd1461020557806323b872dd1461020d5780632a55205a1461022057600080fd5b806301ffc9a7146101675780630671c02e1461018f57806306fdde03146101b0578063081812fc146101c5578063095ea7b3146101f0575b600080fd5b61017a610175366004611ac6565b610382565b60405190151581526020015b60405180910390f35b6101a261019d366004611aff565b610393565b604051908152602001610186565b6101b8610423565b6040516101869190611b6a565b6101d86101d3366004611b7d565b6104b5565b6040516001600160a01b039091168152602001610186565b6102036101fe366004611b96565b6104dc565b005b600a546101a2565b61020361021b366004611bc0565b6105f6565b61023361022e366004611bfc565b61066d565b604080516001600160a01b039093168352602083019190915201610186565b6101a2610260366004611b96565b610719565b610203610273366004611bc0565b6107af565b6101a2610286366004611b7d565b6107ca565b6101a2610299366004611b7d565b61081a565b6101a26102ac366004611b96565b6108ad565b6101d86102bf366004611b7d565b610a6b565b6101a26102d2366004611aff565b610ad0565b7f00000000000000000000000000000000000000000000000000000000000000006101d8565b6101b8610b56565b610203610313366004611c1e565b610b65565b610203610326366004611c70565b610b74565b6101b8610339366004611b7d565b610bf2565b6101b8610bfd565b61017a610354366004611d4c565b6001600160a01b03918216600090815260076020908152604080832093909416825291909152205460ff1690565b600061038d82610c2b565b92915050565b604051630338e01760e11b81526001600160a01b0382811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690630671c02e906024015b602060405180830381865afa1580156103ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038d9190611d7f565b60606002805461043290611d98565b80601f016020809104026020016040519081016040528092919081815260200182805461045e90611d98565b80156104ab5780601f10610480576101008083540402835291602001916104ab565b820191906000526020600020905b81548152906001019060200180831161048e57829003601f168201915b5050505050905090565b60006104c082610c50565b506000908152600660205260409020546001600160a01b031690565b60006104e782610a6b565b9050806001600160a01b0316836001600160a01b0316036105595760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b038216148061057557506105758133610354565b6105e75760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610550565b6105f18383610cb7565b505050565b6106003382610d25565b6106625760405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608401610550565b6105f1838383610da4565b60008281526001602090815260408083208151808301909252546001600160a01b038116808352600160a01b9091046001600160601b03169282019290925282916106e25750604080518082019091526000546001600160a01b0381168252600160a01b90046001600160601b031660208201525b602081015160009061271090610701906001600160601b031687611de8565b61070b9190611dff565b915196919550909350505050565b600061072483610ad0565b82106107865760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610550565b506001600160a01b03919091166000908152600860209081526040808320938352929052205490565b6105f183838360405180602001604052806000815250610b74565b6040516326d4f75360e11b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634da9eea6906024016103e2565b6000610825600a5490565b82106108885760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610550565b600a828154811061089b5761089b611e21565b90600052602060002001549050919050565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109275760405162461bcd60e51b815260206004820152601260248201527f504b4e46543a204e6f74205348455041524400000000000000000000000000006044820152606401610550565b60648211156109785760405162461bcd60e51b815260206004820152601560248201527f504b4e46543a20426f6e757320746f6f206869676800000000000000000000006044820152606401610550565b610986600c80546001019055565b6000610991600c5490565b905061099d8482610f91565b6109c9817f0000000000000000000000000000000000000000000000000000000000000000600061112a565b60405163f9454f3f60e01b81526001600160a01b03858116600483015260248201839052604482018590527f0000000000000000000000000000000000000000000000000000000000000000169063f9454f3f906064016020604051808303816000875af1158015610a3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a639190611d7f565b509392505050565b6000818152600460205260408120546001600160a01b03168061038d5760405162461bcd60e51b815260206004820152601860248201527f4552433732313a20696e76616c696420746f6b656e20494400000000000000006044820152606401610550565b60006001600160a01b038216610b3a5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610550565b506001600160a01b031660009081526005602052604090205490565b60606003805461043290611d98565b610b70338383611238565b5050565b610b7e3383610d25565b610be05760405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608401610550565b610bec84848484611306565b50505050565b606061038d82611384565b6060610c076113eb565b604051602001610c179190611e53565b604051602081830303815290604052905090565b60006001600160e01b0319821663780e9d6360e01b148061038d575061038d82611412565b6000818152600460205260409020546001600160a01b0316610cb45760405162461bcd60e51b815260206004820152601860248201527f4552433732313a20696e76616c696420746f6b656e20494400000000000000006044820152606401610550565b50565b600081815260066020526040902080546001600160a01b0319166001600160a01b0384169081179091558190610cec82610a6b565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b600080610d3183610a6b565b9050806001600160a01b0316846001600160a01b03161480610d7857506001600160a01b0380821660009081526007602090815260408083209388168352929052205460ff165b80610d9c5750836001600160a01b0316610d91846104b5565b6001600160a01b0316145b949350505050565b826001600160a01b0316610db782610a6b565b6001600160a01b031614610e1b5760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610550565b6001600160a01b038216610e7d5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610550565b610e8a8383836001611452565b826001600160a01b0316610e9d82610a6b565b6001600160a01b031614610f015760405162461bcd60e51b815260206004820152602560248201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060448201526437bbb732b960d91b6064820152608401610550565b600081815260066020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260058552838620805460001901905590871680865283862080546001019055868652600490945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b6001600160a01b038216610fe75760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610550565b6000818152600460205260409020546001600160a01b03161561104c5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610550565b61105a600083836001611452565b6000818152600460205260409020546001600160a01b0316156110bf5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606401610550565b6001600160a01b038216600081815260056020908152604080832080546001019055848352600490915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b6127106001600160601b03821611156111985760405162461bcd60e51b815260206004820152602a60248201527f455243323938313a20726f79616c7479206665652077696c6c206578636565646044820152692073616c65507269636560b01b6064820152608401610550565b6001600160a01b0382166111ee5760405162461bcd60e51b815260206004820152601b60248201527f455243323938313a20496e76616c696420706172616d657465727300000000006044820152606401610550565b6040805180820182526001600160a01b0393841681526001600160601b0392831660208083019182526000968752600190529190942093519051909116600160a01b029116179055565b816001600160a01b0316836001600160a01b0316036112995760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c6572000000000000006044820152606401610550565b6001600160a01b03838116600081815260076020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b611311848484610da4565b61131d848484846114ee565b610bec5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608401610550565b606061138f82610c50565b60006113996113eb565b905060008151116113b957604051806020016040528060008152506113e4565b806113c38461163a565b6040516020016113d4929190611e80565b6040516020818303038152906040525b9392505050565b6060600d6113f7610b56565b6114004661163a565b604051602001610c1793929190611eaf565b60006001600160e01b031982166380ac58cd60e01b148061144357506001600160e01b03198216635b5e139f60e01b145b8061038d575061038d826116cd565b61145e84848484611702565b6040516317d5759960e31b81526001600160a01b0385811660048301528481166024830152604482018490527f0000000000000000000000000000000000000000000000000000000000000000169063beabacc890606401600060405180830381600087803b1580156114d057600080fd5b505af11580156114e4573d6000803e3d6000fd5b5050505050505050565b60006001600160a01b0384163b1561162f57604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290611532903390899088908890600401611f86565b6020604051808303816000875af192505050801561156d575060408051601f3d908101601f1916820190925261156a91810190611fb8565b60015b611615573d80801561159b576040519150601f19603f3d011682016040523d82523d6000602084013e6115a0565b606091505b50805160000361160d5760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608401610550565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050610d9c565b506001949350505050565b606060006116478361183e565b600101905060008167ffffffffffffffff81111561166757611667611c5a565b6040519080825280601f01601f191660200182016040528015611691576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461169b57509392505050565b60006001600160e01b0319821663152a902d60e11b148061038d57506301ffc9a760e01b6001600160e01b031983161461038d565b60018111156117795760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e736563757469766520747260448201527f616e7366657273206e6f7420737570706f7274656400000000000000000000006064820152608401610550565b816001600160a01b0385166117d5576117d081600a80546000838152600b60205260408120829055600182018355919091527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80155565b6117f8565b836001600160a01b0316856001600160a01b0316146117f8576117f88582611920565b6001600160a01b0384166118145761180f816119bd565b611837565b846001600160a01b0316846001600160a01b031614611837576118378482611a6c565b5050505050565b6000807a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310611887577a184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000830492506040015b6d04ee2d6d415b85acef810000000083106118b3576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106118d157662386f26fc10000830492506010015b6305f5e10083106118e9576305f5e100830492506008015b61271083106118fd57612710830492506004015b6064831061190f576064830492506002015b600a831061038d5760010192915050565b6000600161192d84610ad0565b6119379190611fd5565b60008381526009602052604090205490915080821461198a576001600160a01b03841660009081526008602090815260408083208584528252808320548484528184208190558352600990915290208190555b5060009182526009602090815260408084208490556001600160a01b039094168352600881528383209183525290812055565b600a546000906119cf90600190611fd5565b6000838152600b6020526040812054600a80549394509092849081106119f7576119f7611e21565b9060005260206000200154905080600a8381548110611a1857611a18611e21565b6000918252602080832090910192909255828152600b9091526040808220849055858252812055600a805480611a5057611a50611fe8565b6001900381819060005260206000200160009055905550505050565b6000611a7783610ad0565b6001600160a01b039093166000908152600860209081526040808320868452825280832085905593825260099052919091209190915550565b6001600160e01b031981168114610cb457600080fd5b600060208284031215611ad857600080fd5b81356113e481611ab0565b80356001600160a01b0381168114611afa57600080fd5b919050565b600060208284031215611b1157600080fd5b6113e482611ae3565b60005b83811015611b35578181015183820152602001611b1d565b50506000910152565b60008151808452611b56816020860160208601611b1a565b601f01601f19169290920160200192915050565b6020815260006113e46020830184611b3e565b600060208284031215611b8f57600080fd5b5035919050565b60008060408385031215611ba957600080fd5b611bb283611ae3565b946020939093013593505050565b600080600060608486031215611bd557600080fd5b611bde84611ae3565b9250611bec60208501611ae3565b9150604084013590509250925092565b60008060408385031215611c0f57600080fd5b50508035926020909101359150565b60008060408385031215611c3157600080fd5b611c3a83611ae3565b915060208301358015158114611c4f57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60008060008060808587031215611c8657600080fd5b611c8f85611ae3565b9350611c9d60208601611ae3565b925060408501359150606085013567ffffffffffffffff80821115611cc157600080fd5b818701915087601f830112611cd557600080fd5b813581811115611ce757611ce7611c5a565b604051601f8201601f19908116603f01168101908382118183101715611d0f57611d0f611c5a565b816040528281528a6020848701011115611d2857600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008060408385031215611d5f57600080fd5b611d6883611ae3565b9150611d7660208401611ae3565b90509250929050565b600060208284031215611d9157600080fd5b5051919050565b600181811c90821680611dac57607f821691505b602082108103611dcc57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761038d5761038d611dd2565b600082611e1c57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b60008151611e49818560208601611b1a565b9290920192915050565b60008251611e65818460208701611b1a565b686d6574612d6461746160b81b920191825250600901919050565b60008351611e92818460208801611b1a565b835190830190611ea6818360208801611b1a565b01949350505050565b600080855481600182811c915080831680611ecb57607f831692505b60208084108203611eea57634e487b7160e01b86526022600452602486fd5b818015611efe5760018114611f1357611f40565b60ff1986168952841515850289019650611f40565b60008c81526020902060005b86811015611f385781548b820152908501908301611f1f565b505084890196505b505050505050611f7c611f69611f76611f69611f6385602f60f81b815260010190565b89611e37565b602f60f81b815260010190565b86611e37565b9695505050505050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152611f7c6080830184611b3e565b600060208284031215611fca57600080fd5b81516113e481611ab0565b8181038181111561038d5761038d611dd2565b634e487b7160e01b600052603160045260246000fdfea264697066735822122026ac077df10752294491fe98b0a10506da7a8576672b1d62efb561a1147a4a5064736f6c6343000811003360a06040523480156200001157600080fd5b506040516200277b3803806200277b833981016040819052620000349162000562565b81816003620000448382620006d1565b506004620000538282620006d1565b505060016005555086620000ae5760405162461bcd60e51b815260206004820181905260248201527f4672657175656e6379206d7573742062652067726561746572207468616e203060448201526064015b60405180910390fd5b600086600f0b13620001035760405162461bcd60e51b815260206004820152601e60248201527f52617465206d7573742062652067726561746572207468616e207a65726f00006044820152606401620000a5565b6200011a6001620003eb60201b62000c071760201c565b600f0b86600f0b12620001705760405162461bcd60e51b815260206004820152601b60248201527f52617465206d757374206265206c657373207468616e203130302500000000006044820152606401620000a5565b620001876001620003eb60201b62000c071760201c565b600f0b85600f0b12620001d75760405162461bcd60e51b815260206004820152602260248201526000805160206200275b833981519152604482015261302560f01b6064820152608401620000a5565b620001ee6001620003eb60201b62000c071760201c565b600f0b84600f0b126200023e5760405162461bcd60e51b815260206004820152602260248201526000805160206200275b833981519152604482015261302560f01b6064820152608401620000a5565b620002556001620003eb60201b62000c071760201c565b600c80546001600160801b0319166001600160801b03929092169190911790556001600160a01b038816608052600d879055620002a786670de0b6b3a76400006200041e602090811b62000c3a17901c565b620002b49060016200079d565b600e80546001600160801b0319166001600160801b03929092169190911790556000600f86900b13156200032c576200030185670de0b6b3a76400006200041e60201b62000c3a1760201c565b6200030e9060016200079d565b600e80546001600160801b03928316600160801b0292169190911790555b600084600f0b131562000386576200035884670de0b6b3a76400006200041e60201b62000c3a1760201c565b620003659060016200079d565b600f80546001600160801b0319166001600160801b03929092169190911790555b600083600f0b1315620003dd57620003b283670de0b6b3a76400006200041e60201b62000c3a1760201c565b620003bf9060016200079d565b600f80546001600160801b03928316600160801b0292169190911790555b5050505050505050620007ef565b600060016001603f1b031982121580156200040d575060016001603f1b038213155b6200041757600080fd5b5060401b90565b600081600f0b6000036200043157600080fd5b600082600f0b604085600f0b901b816200044f576200044f620007d9565b05905060016001607f1b0319811280159062000472575060016001607f1b038113155b6200047c57600080fd5b90505b92915050565b8051600f81900b81146200049857600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600082601f830112620004c557600080fd5b81516001600160401b0380821115620004e257620004e26200049d565b604051601f8301601f19908116603f011681019082821181831017156200050d576200050d6200049d565b816040528381526020925086838588010111156200052a57600080fd5b600091505b838210156200054e57858201830151818301840152908201906200052f565b600093810190920192909252949350505050565b600080600080600080600080610100898b0312156200058057600080fd5b88516001600160a01b03811681146200059857600080fd5b60208a01519098509650620005b060408a0162000485565b9550620005c060608a0162000485565b9450620005d060808a0162000485565b9350620005e060a08a0162000485565b60c08a01519093506001600160401b0380821115620005fe57600080fd5b6200060c8c838d01620004b3565b935060e08b01519150808211156200062357600080fd5b50620006328b828c01620004b3565b9150509295985092959890939650565b600181811c908216806200065757607f821691505b6020821081036200067857634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620006cc57600081815260208120601f850160051c81016020861015620006a75750805b601f850160051c820191505b81811015620006c857828155600101620006b3565b5050505b505050565b81516001600160401b03811115620006ed57620006ed6200049d565b6200070581620006fe845462000642565b846200067e565b602080601f8311600181146200073d5760008415620007245750858301515b600019600386901b1c1916600185901b178555620006c8565b600085815260208120601f198616915b828110156200076e578886015182559484019460019091019084016200074d565b50858210156200078d5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600f81810b9083900b0160016001607f1b03811360016001607f1b0319821217156200047f57634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b608051611f2d6200082e60003960008181610356015281816104db015281816106c101528181610b380152818161149b01526116640152611f2d6000f3fe608060405234801561001057600080fd5b506004361061021c5760003560e01c806395d89b4111610125578063ca1d209d116100ad578063e799df621161007c578063e799df62146104a7578063eef49ee3146104bb578063ef78d4fd146104c4578063f385cecb146104cc578063fc0c546a146104d957600080fd5b8063ca1d209d1461043a578063cab34c081461044d578063ce35de5814610462578063dd62ed3e1461046e57600080fd5b8063a9059cbb116100f4578063a9059cbb146103ed578063b6b55f2514610400578063c229d75014610413578063c31245251461041c578063c80ec5221461043157600080fd5b806395d89b41146103985780639af1d35a146103a0578063a457c2d7146103a9578063a7a38f0b146103bc57600080fd5b80632e1a7d4d116101a8578063664e970411610177578063664e97041461031557806370a082311461033557806375172a8b1461034857806382bfefc814610351578063853828b61461039057600080fd5b80632e1a7d4d146102d6578063313ce567146102eb578063323a5e0b146102fa578063395093511461030257600080fd5b8063099af18a116101ef578063099af18a146102a257806315d276e1146102aa57806318160ddd146102b25780632267716c146102ba57806323b872dd146102c357600080fd5b806303a632151461022157806306fdde031461023d5780630781f4d214610252578063095ea7b31461027f575b600080fd5b61022a600b5481565b6040519081526020015b60405180910390f35b6102456104ff565b6040516102349190611bf8565b61025a610591565b60408051825181526020808401519082015291810151600f0b90820152606001610234565b61029261028d366004611c62565b6105d5565b6040519015158152602001610234565b6102926105ef565b61025a610602565b60025461022a565b61022a60075481565b6102926102d1366004611c8c565b610748565b6102e96102e4366004611cc8565b61076f565b005b60405160128152602001610234565b61022a610796565b610292610310366004611c62565b6107a0565b600e5461032290600f0b81565b604051600f9190910b8152602001610234565b61022a610343366004611ce1565b6107df565b61022a60065481565b6103787f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610234565b6102e961083f565b61024561086d565b61022a600a5481565b6102926103b7366004611c62565b61087c565b6103cf6103ca366004611cc8565b61091e565b604080519384526020840192909252600f0b90820152606001610234565b6102926103fb366004611c62565b610954565b6102e961040e366004611cc8565b610979565b61022a600d5481565b610424610993565b6040516102349190611cfc565b61022a60095481565b6102e9610448366004611cc8565b610a86565b600f805461032291600160801b909104900b81565b600f8054610322910b81565b61022a61047c366004611db0565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600e5461032290600160801b9004600f0b81565b61022a60085481565b61022a610bed565b600c5461032290600f0b81565b7f0000000000000000000000000000000000000000000000000000000000000000610378565b60606003805461050e90611de3565b80601f016020809104026020016040519081016040528092919081815260200182805461053a90611de3565b80156105875780601f1061055c57610100808354040283529160200191610587565b820191906000526020600020905b81548152906001019060200180831161056a57829003601f168201915b5050505050905090565b6105b8604051806060016040528060008152602001600081526020016000600f0b81525090565b6105d0600d54600b546105cb9190611e33565b610c92565b905090565b6000336105e3818585610d97565b60019150505b92915050565b6000600b546105fc610bed565b11905090565b610629604051806060016040528060008152602001600081526020016000600f0b81525090565b610631610ebc565b610639610f15565b600080610644610fe8565b600f80549192506000600160801b909204900b131561067d5761067a600f60109054906101000a9004600f0b8260200151611102565b91505b81156107385781600660008282546106959190611e46565b909155506106a59050308361116d565b60405163a9059cbb60e01b8152336004820152602481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610712573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107369190611e59565b505b9150506107456001600555565b90565b60006107538461129c565b61075c8361129c565b610767848484611346565b949350505050565b610777610ebc565b61077f61135f565b61078933826113aa565b6107936001600555565b50565b60006105d061150f565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906105e390829086906107da908790611e33565b610d97565b6001600160a01b038116600090815260208181526040808320546010909252822054600f0b81158015906108165750600081600f0b135b1561083857600c546108359061082f90600f0b83610c3a565b83611102565b91505b5092915050565b610847610ebc565b61084f61135f565b6108613361085c336107df565b6113aa565b61086b6001600555565b565b60606004805461050e90611de3565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156109065760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6109138286868403610d97565b506001949350505050565b6011818154811061092e57600080fd5b6000918252602090912060039091020180546001820154600290920154909250600f0b83565b600061095f3361129c565b6109688361129c565b610972838361154d565b9392505050565b610981610ebc565b61098961135f565b610789338261155b565b610a03604051806101800160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000600f0b8152602001600081526020016000600f0b81526020016000600f0b81526020016000600f0b81525090565b6040518061018001604052806006548152602001600754815260200160085481526020016009548152602001610a3761150f565b8152600a546020820152600b546040820152600c54600f90810b6060830152600d546080830152600e5480820b60a0840152600160801b9004810b60c08301528054900b60e090910152919050565b610a8e610ebc565b60008111610aec5760405162461bcd60e51b815260206004820152602560248201527f46756e6420616d6f756e74206d7573742062652067726561746572207468616e604482015264207a65726f60d81b60648201526084016108fd565b610af461135f565b8060066000828254610b069190611e33565b90915550610b1690503082611693565b6040516323b872dd60e01b8152336004820152306024820152604481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015610b89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bad9190611e59565b5060405181815233907f5af8184bef8e4b45eb9f6ed7734d04da38ced226495548f46e0c8ff8d7d9a5249060200160405180910390a26107936001600555565b600d54600090610bfd8142611e91565b6105d09190611eb3565b6000677fffffffffffffff198212158015610c2a5750677fffffffffffffff8213155b610c3357600080fd5b5060401b90565b600081600f0b600003610c4c57600080fd5b600082600f0b604085600f0b901b81610c6757610c67611e7b565b05905060016001607f1b03198112801590610c89575060016001607f1b038113155b61097257600080fd5b610cb9604051806060016040528060008152602001600081526020016000600f0b81525090565b6000600b5483610cc99190611e46565b9050610cd3610796565b1580610cdf5750600654155b80610ce8575080155b15610d0c575050604080516060810182529182526000602083018190529082015290565b6301e13380811115610d1f57506301e133805b600e54600090610d3f90600f0b610d3a846301e13380611752565b61178c565b90506000610d4f82600654611102565b90506000610d6482610d5f610796565b611752565b610d6f906001611eca565b604080516060810182529788526020880193909352600f0b9186019190915250929392505050565b6001600160a01b038316610df95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016108fd565b6001600160a01b038216610e5a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016108fd565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b600260055403610f0e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108fd565b6002600555565b600060065411610f555760405162461bcd60e51b815260206004820152600b60248201526a6e6f20726573657276657360a81b60448201526064016108fd565b6000610f5f610796565b11610fa05760405162461bcd60e51b81526020600482015260116024820152701b9bdd1a1a5b99c819195c1bdcda5d1959607a1b60448201526064016108fd565b610fa86105ef565b61086b5760405162461bcd60e51b81526020600482015260116024820152700746f6f20736f6f6e20666f722072616d7607c1b60448201526064016108fd565b61100f604051806060016040528060008152602001600081526020016000600f0b81525090565b600061101c6105cb610bed565b9050611026610bed565b600b55602081015160068054600090611040908490611e46565b909155505060208101516007805460009061105c908490611e33565b90915550506040810151600c805460009061107b908490600f0b611eca565b92506101000a8154816001600160801b030219169083600f0b6001600160801b031602179055507fd3314ddde63b6c46f7a1a5649605990b76d3886f0f202dabe4be0fedeed298e48160000151826020015183604001516040516110f5939291909283526020830191909152600f0b604082015260600190565b60405180910390a1919050565b600081600003611114575060006105e9565b600083600f0b121561112557600080fd5b600f83900b6001600160801b038316810260401c90608084901c026001600160c01b0381111561115457600080fd5b60401b811981111561116557600080fd5b019392505050565b6001600160a01b0382166111cd5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016108fd565b6001600160a01b038216600090815260208190526040902054818110156112415760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b60648201526084016108fd565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9101610eaf565b505050565b600c546001600160a01b038216600090815260106020526040902054600f91820b910b14610793576001600160a01b03811660009081526020819052604081205490816112e8846107df565b6112f29190611e46565b600c546001600160a01b038516600090815260106020526040902080546fffffffffffffffffffffffffffffffff19166001600160801b0390921691909117905590508015611297576112973084836117c2565b600033611354858285611967565b6109138585856117c2565b600b5460000361137557611371610bed565b600b555b600060065411801561138e5750600061138c610796565b115b801561139d575061139d6105ef565b1561086b57610793610fe8565b806113b4836107df565b10156114025760405162461bcd60e51b815260206004820152601f60248201527f776974686472617720616d6f756e742065786365656473206465706f7369740060448201526064016108fd565b61140b8261129c565b6000611416826119f3565b9050806009600082825461142a9190611e33565b9091555061143a9050838361116d565b604080518381526020810183905233917f4cdcd27ae88503b2d4d3034a348b78aec00eca6369f48e5002ca3df8686b9b3e910160405180910390a260405163a9059cbb60e01b81526001600160a01b038481166004830152602482018390527f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb906044015b6020604051808303816000875af11580156114e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115099190611e59565b50505050565b6000600a546009546115219190611e33565b60085410156115305750600090565b600a546009546115409190611e33565b6008546105d09190611e46565b6000336105e38185856117c2565b600081116115bc5760405162461bcd60e51b815260206004820152602860248201527f4465706f73697420616d6f756e74206d7573742062652067726561746572207460448201526768616e207a65726f60c01b60648201526084016108fd565b60006115c782611a5f565b905080600860008282546115db9190611e33565b909155506115ea90508361129c565b6115f48382611693565b60408051838152602081018390526001600160a01b038516917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a26040516323b872dd60e01b81526001600160a01b038481166004830152306024830152604482018490527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016114c6565b6001600160a01b0382166116e95760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016108fd565b80600260008282546116fb9190611e33565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b60008160000361176157600080fd5b600061176d8484611a93565b905060016001607f1b036001600160801b038216111561097257600080fd5b6000600f83810b9083900b0260401d60016001607f1b03198112801590610c89575060016001607f1b0381131561097257600080fd5b6001600160a01b0383166118265760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016108fd565b6001600160a01b0382166118885760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016108fd565b6001600160a01b038316600090815260208190526040902054818110156119005760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016108fd565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a350505050565b6001600160a01b03838116600090815260016020908152604080832093861683529290522054600019811461150957818110156119e65760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016108fd565b6115098484848403610d97565b600f80546000910b8103611a05575090565b600f8054600091611a1891900b84611102565b905080600a6000828254611a2c9190611e33565b925050819055508060066000828254611a459190611e33565b90915550611a5590503082611693565b6109728184611e46565b600e54600090600160801b9004600f0b8103611a79575090565b600e54600090611a1890600160801b9004600f0b84611102565b600081600003611aa257600080fd5b60006001600160c01b038411611acd5782604085901b81611ac557611ac5611e7b565b049050611be4565b60c084811c6401000000008110611ae6576020918201911c5b620100008110611af8576010918201911c5b6101008110611b09576008918201911c5b60108110611b19576004918201911c5b60048110611b29576002918201911c5b60028110611b38576001820191505b60bf820360018603901c6001018260ff0387901b81611b5957611b59611e7b565b0492506001600160801b03831115611b7057600080fd5b608085901c83026001600160801b038616840260c088901c604089901b82811015611b9c576001820391505b608084901b92900382811015611bb3576001820391505b829003608084901c8214611bc8576001611bd9565b888181611bd757611bd7611e7b565b045b870196505050505050505b6001600160801b0381111561097257600080fd5b600060208083528351808285015260005b81811015611c2557858101830151858201604001528201611c09565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114611c5d57600080fd5b919050565b60008060408385031215611c7557600080fd5b611c7e83611c46565b946020939093013593505050565b600080600060608486031215611ca157600080fd5b611caa84611c46565b9250611cb860208501611c46565b9150604084013590509250925092565b600060208284031215611cda57600080fd5b5035919050565b600060208284031215611cf357600080fd5b61097282611c46565b600061018082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e0830151611d5960e0840182600f0b9052565b50610100838101519083015261012080840151611d7a82850182600f0b9052565b505061014080840151611d9182850182600f0b9052565b505061016080840151611da882850182600f0b9052565b505092915050565b60008060408385031215611dc357600080fd5b611dcc83611c46565b9150611dda60208401611c46565b90509250929050565b600181811c90821680611df757607f821691505b602082108103611e1757634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156105e9576105e9611e1d565b818103818111156105e9576105e9611e1d565b600060208284031215611e6b57600080fd5b8151801515811461097257600080fd5b634e487b7160e01b600052601260045260246000fd5b600082611eae57634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176105e9576105e9611e1d565b600f81810b9083900b0160016001607f1b03811360016001607f1b0319821217156105e9576105e9611e1d56fea2646970667358221220d540c7e9caae2f7bfc99d141b42620d46cc4bb5221379a61f5b18e6466c7403464736f6c634300081100334465706f73697420666565206d757374206265206c657373207468616e20313064547f9933b53bdcff0ebc3a6e77f58c426209d80fd73547349556ae224107570000000000000000000000006961e9d9a17b9bb860b48a6c2f6c3584ff21147e0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001b68747470733a2f2f6170692e70756c73656b697474656e732e696f0000000000
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106101da5760003560e01c80637c0b8de211610104578063a9059cbb116100a2578063d457c62811610071578063d457c6281461049c578063da62fba9146104a4578063dd62ed3e146104c7578063df6aa1401461050057600080fd5b8063a9059cbb14610466578063ab1089be14610479578063b74e452b1461048c578063bdb4b8481461049457600080fd5b806384b504c8116100de57806384b504c8146103fb57806395d89b41146104245780639c1e56d31461042c578063a457c2d71461045357600080fd5b80637c0b8de21461038257806380af56a3146103a957806381b3b1fb146103bc57600080fd5b80632f52ebb71161017c578063567add641161014b578063567add6414610322578063583e22dc146103355780635909c12f1461034857806370a082311461036f57600080fd5b80632f52ebb7146102ba578063313ce567146102ed57806339509351146102fc578063447d92061461030f57600080fd5b806318160ddd116101b857806318160ddd1461025b5780631a1daf081461026d57806323b872dd1461028057806327b114531461029357600080fd5b806306433b1b146101df57806306fdde0314610223578063095ea7b314610238575b600080fd5b6102067f0000000000000000000000005be0555d16ea7d391d80347c0df20407c6006c4c81565b6040516001600160a01b0390911681526020015b60405180910390f35b61022b610508565b60405161021a9190611c0e565b61024b610246366004611c73565b61059a565b604051901515815260200161021a565b6002545b60405190815260200161021a565b61025f61027b366004611c73565b6105b4565b61024b61028e366004611c9d565b6105c8565b6102067f0000000000000000000000006961e9d9a17b9bb860b48a6c2f6c3584ff21147e81565b6102cd6102c8366004611d24565b6105ef565b60408051948552602085019390935291830152606082015260800161021a565b6040516012815260200161021a565b61024b61030a366004611c73565b610612565b61025f61031d366004611d86565b610651565b61025f610330366004611db9565b61065d565b61025f610343366004611dd4565b6106e6565b61025f7f64547f9933b53bdcff0ebc3a6e77f58c426209d80fd73547349556ae2241075781565b61025f61037d366004611db9565b6106f3565b6102067f0000000000000000000000007896814143a2e8b86d58e702a072a3e2c8937d7581565b61025f6103b7366004611ded565b61071f565b6103e37f000000000000000000000000000000000000000000000000000000006466bc0081565b6040516001600160401b03909116815260200161021a565b6103e3610409366004611db9565b6006602052600090815260409020546001600160401b031681565b61022b61072b565b6102067f0000000000000000000000001291b9a7e5b36a7d2fd1d565a6be82fcfbb8234f81565b61024b610461366004611c73565b61073a565b61024b610474366004611c73565b6107dc565b6102cd610487366004611e09565b6107fa565b6103e361081e565b61025f61083f565b6103e361085f565b61024b6104b2366004611db9565b60056020526000908152604090205460ff1681565b61025f6104d5366004611e62565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6103e3610869565b60606003805461051790611e8c565b80601f016020809104026020016040519081016040528092919081815260200182805461054390611e8c565b80156105905780601f1061056557610100808354040283529160200191610590565b820191906000526020600020905b81548152906001019060200180831161057357829003601f168201915b5050505050905090565b6000336105a881858561088d565b60019150505b92915050565b60006105c13383856109b1565b9392505050565b60006105d384610c3f565b6105dc83610c3f565b6105e7848484610cd3565b949350505050565b60008060008061060133888888610cec565b935093509350935093509350935093565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091906105a8908290869061064c908790611edc565b61088d565b60006105c1838361118c565b6001600160a01b03811660009081526006602052604081205481906001600160401b03166106925761068d61081e565b6106b5565b6001600160a01b0383166000908152600660205260409020546001600160401b03165b9050600062015180826106c661081e565b6106d09190611eef565b6106da9190611f2c565b90506105e7848261118c565b60006105ae3383336109b1565b6001600160a01b0381166000908152602081905260408120546107158361065d565b6105c19082611edc565b60006105c1838361131b565b60606004805461051790611e8c565b3360008181526001602090815260408083206001600160a01b0387168452909152812054909190838110156107c45760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6107d1828686840361088d565b506001949350505050565b60006107e733610c3f565b6107f083610c3f565b6105c18383611451565b60008060008061080c88888888610cec565b929b919a509850909650945050505050565b600061082d6201518042611f52565b61083a9062015180611f66565b905090565b60075460009061083a906001600160401b031661085a61145f565b61131b565b600061083a61145f565b60006107086108788142611f52565b610883906001611edc565b61083a9190611f66565b6001600160a01b0383166108ef5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016107bb565b6001600160a01b0382166109505760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016107bb565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006109bb61083f565b831015610a0a5760405162461bcd60e51b815260206004820152601460248201527f504b54544e3a2042656c6f77206d696e696d756d00000000000000000000000060448201526064016107bb565b610a13846106f3565b831115610a625760405162461bcd60e51b815260206004820152601b60248201527f504b54544e3a20496e73756666696369656e742062616c616e6365000000000060448201526064016107bb565b610a6b84610c3f565b610a768430856114ab565b60405163ca1d209d60e01b8152600481018490527f0000000000000000000000001291b9a7e5b36a7d2fd1d565a6be82fcfbb8234f6001600160a01b03169063ca1d209d90602401600060405180830381600087803b158015610ad857600080fd5b505af1158015610aec573d6000803e3d6000fd5b5050600780546001600160401b03428116600160401b026fffffffffffffffff0000000000000000198316811784558116911617925090506000610b2f83611f7d565b91906101000a8154816001600160401b0302191690836001600160401b03160217905550507f0000000000000000000000007896814143a2e8b86d58e702a072a3e2c8937d756001600160a01b0316635536882f8360074442604051602001610ba2929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c610bc59190611fa3565b610bd0906005611edc565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610c1b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105e79190611fb7565b610c4761081e565b6001600160a01b0382166000908152600660205260409020546001600160401b03908116911614610cd0576000610c7d8261065d565b9050610c8761081e565b6001600160a01b0383166000908152600660205260409020805467ffffffffffffffff19166001600160401b03929092169190911790558015610cce57610cce8282611651565b505b50565b600033610ce1858285611711565b6107d18585856114ab565b6001600160a01b03841660009081526005602052604081205481908190819060ff1615610d5b5760405162461bcd60e51b815260206004820152601360248201527f416c72656164792064697374726962757465640000000000000000000000000060448201526064016107bb565b610da1610d68888a61179d565b8787808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506117eb92505050565b610ded5760405162461bcd60e51b815260206004820152601460248201527f496e76616c6964206d65726b6c652070726f6f6600000000000000000000000060448201526064016107bb565b6001600160a01b038816600090815260056020526040808220805460ff19166001179055605089901c9160488a901c60ff908116928b901c1690610e2f601290565b610e3a90600a6120b4565b610e4d906001600160401b038d16611f66565b905081600003610eeb57610e847f000000000000000000000000000000000000000000000000000000006466bc006276a7006120c3565b6001600160401b0316610e9561081e565b6001600160401b031610610eeb5760405162461bcd60e51b815260206004820152601660248201527f436c61696d20706861736520686173207061737365640000000000000000000060448201526064016107bb565b610ef58c82611651565b8215611008577f0000000000000000000000007896814143a2e8b86d58e702a072a3e2c8937d756001600160a01b0316635536882f8d60054442604051602001610f49929190918252602082015260400190565b6040516020818303038152906040528051906020012060001c610f6c9190611fa3565b610f776001886120e3565b610f82906005611f66565b610f8d90600a611edc565b610f979190611edc565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610fe2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110069190611fb7565b505b61101061081e565b6001600160a01b038d166000908152600660205260408120805467ffffffffffffffff19166001600160401b0393909316929092179091556064611055601e84611f66565b61105f9190611f52565b905061106b3082611651565b60405163ca1d209d60e01b8152600481018290527f0000000000000000000000001291b9a7e5b36a7d2fd1d565a6be82fcfbb8234f6001600160a01b03169063ca1d209d90602401600060405180830381600087803b1580156110cd57600080fd5b505af11580156110e1573d6000803e3d6000fd5b505050506111277f0000000000000000000000006961e9d9a17b9bb860b48a6c2f6c3584ff21147e6064600a856111189190611f66565b6111229190611f52565b611651565b6040805183815260208101869052908101849052606081018690526001600160a01b038e16907f7708755c9b641bf197be5047b04002d2e88fa658c173a351067747eb5dfc568a9060800160405180910390a2509b919a509850909650945050505050565b6040516370a0823160e01b81526001600160a01b03838116600483015260009182917f0000000000000000000000001291b9a7e5b36a7d2fd1d565a6be82fcfbb8234f16906370a0823190602401602060405180830381865afa1580156111f7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061121b9190611fb7565b604051630338e01760e11b81526001600160a01b0386811660048301529192506000917f0000000000000000000000007896814143a2e8b86d58e702a072a3e2c8937d751690630671c02e90602401602060405180830381865afa158015611287573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ab9190611fb7565b9050600080821180156112be5750600083115b80156112d357506000856001600160401b0316115b156113125761016d6001600160401b03861660646112f18587611f66565b6112fb9190611f52565b6113059190611f66565b61130f9190611f52565b90505b95945050505050565b600080611326611818565b9050683635c9adc5dea000008110156113455750683635c9adc5dea000005b6b033b2e3c9fd0803ce800000081111561136857506b033b2e3c9fd0803ce80000005b6103e86001600160401b0385161115611381576103e893505b6103e86001600160401b038416111561139a576103e892505b60006113bf6113b16068662386f26fc100006120f6565b670de0b6b3a764000061185f565b6113ca906001612116565b90506000670de0b6b3a764000061140e6114086113f0858a6001600160401b03166118b7565b611403868a6001600160401b03166118b7565b61185f565b85611af7565b6114189190611f52565b61142a90670de0b6b3a7640000611f66565b9050683635c9adc5dea000008110156113125750683635c9adc5dea0000095945050505050565b6000336105a88185856114ab565b600754600090600160401b90046001600160401b0316156114a5576007546107089061149b90600160401b90046001600160401b0316426120e3565b61083a9190611f52565b50600090565b6001600160a01b03831661150f5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016107bb565b6001600160a01b0382166115715760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016107bb565b6001600160a01b038316600090815260208190526040902054818110156115e95760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016107bb565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35b50505050565b6001600160a01b0382166116a75760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016107bb565b80600260008282546116b99190611edc565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610cce565b6001600160a01b03838116600090815260016020908152604080832093861683529290522054600019811461164b57818110156117905760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016107bb565b61164b848484840361088d565b600082826040516020016117cd92919091825260601b6bffffffffffffffffffffffff1916602082015260340190565b60405160208183030381529060405280519060200120905092915050565b60006105c1827f64547f9933b53bdcff0ebc3a6e77f58c426209d80fd73547349556ae2241075785611b7c565b6000806118447f0000000000000000000000006961e9d9a17b9bb860b48a6c2f6c3584ff21147e6106f3565b9050801561185a57611857600582611f52565b90505b919050565b600081600f0b60000361187157600080fd5b600082600f0b604085600f0b901b8161188c5761188c611f16565b05905060016001607f1b031981128015906118ae575060016001607f1b038113155b6105c157600080fd5b600080600084600f0b1280156118d05750826001166001145b905060008085600f0b126118e457846118e9565b846000035b6fffffffffffffffffffffffffffffffff169050600160801b600160401b821161198757603f82901b91505b841561197f57600185161561192a578102607f1c5b908002607f1c906002851615611940578102607f1c5b908002607f1c906004851615611956578102607f1c5b908002607f1c90600885161561196c578102607f1c5b60049490941c93908002607f1c90611915565b60401c611ab1565b603f6c010000000000000000000000008310156119aa5760209290921b91601f19015b6e0100000000000000000000000000008310156119cd5760109290921b91600f19015b600160781b8310156119e55760089290921b91600719015b6001607c1b8310156119fd5760049290921b91600319015b6001607e1b831015611a155760029290921b91600119015b6001607f1b831015611a2d5760019290921b91600019015b60005b8615611a9a5760408210611a4357600080fd5b6001871615611a6957918302607f1c918101600160801b831115611a6957600192831c92015b928002607f1c9260019190911b90600160801b8410611a8e57600193841c9391909101905b600187901c9650611a30565b60408110611aa757600080fd5b6040039190911c90505b600083611abe5781611ac3565b816000035b905060016001607f1b03198112801590611ae4575060016001607f1b038113155b611aed57600080fd5b9695505050505050565b600081600003611b09575060006105ae565b600083600f0b1215611b1a57600080fd5b600f83900b6fffffffffffffffffffffffffffffffff8316810260401c90608084901c0277ffffffffffffffffffffffffffffffffffffffffffffffff811115611b6357600080fd5b60401b8119811115611b7457600080fd5b019392505050565b600082611b898584611b92565b14949350505050565b600081815b8451811015611bd757611bc382868381518110611bb657611bb6612143565b6020026020010151611bdf565b915080611bcf81612159565b915050611b97565b509392505050565b6000818310611bfb5760008281526020849052604090206105c1565b60008381526020839052604090206105c1565b600060208083528351808285015260005b81811015611c3b57858101830151858201604001528201611c1f565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461185a57600080fd5b60008060408385031215611c8657600080fd5b611c8f83611c5c565b946020939093013593505050565b600080600060608486031215611cb257600080fd5b611cbb84611c5c565b9250611cc960208501611c5c565b9150604084013590509250925092565b60008083601f840112611ceb57600080fd5b5081356001600160401b03811115611d0257600080fd5b6020830191508360208260051b8501011115611d1d57600080fd5b9250929050565b600080600060408486031215611d3957600080fd5b8335925060208401356001600160401b03811115611d5657600080fd5b611d6286828701611cd9565b9497909650939450505050565b80356001600160401b038116811461185a57600080fd5b60008060408385031215611d9957600080fd5b611da283611c5c565b9150611db060208401611d6f565b90509250929050565b600060208284031215611dcb57600080fd5b6105c182611c5c565b600060208284031215611de657600080fd5b5035919050565b60008060408385031215611e0057600080fd5b611da283611d6f565b60008060008060608587031215611e1f57600080fd5b611e2885611c5c565b93506020850135925060408501356001600160401b03811115611e4a57600080fd5b611e5687828801611cd9565b95989497509550505050565b60008060408385031215611e7557600080fd5b611e7e83611c5c565b9150611db060208401611c5c565b600181811c90821680611ea057607f821691505b602082108103611ec057634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b808201808211156105ae576105ae611ec6565b6001600160401b03828116828216039080821115611f0f57611f0f611ec6565b5092915050565b634e487b7160e01b600052601260045260246000fd5b60006001600160401b0380841680611f4657611f46611f16565b92169190910492915050565b600082611f6157611f61611f16565b500490565b80820281158282048414176105ae576105ae611ec6565b60006001600160401b03808316818103611f9957611f99611ec6565b6001019392505050565b600082611fb257611fb2611f16565b500690565b600060208284031215611fc957600080fd5b5051919050565b600181815b8085111561200b578160001904821115611ff157611ff1611ec6565b80851615611ffe57918102915b93841c9390800290611fd5565b509250929050565b600082612022575060016105ae565b8161202f575060006105ae565b8160018114612045576002811461204f5761206b565b60019150506105ae565b60ff84111561206057612060611ec6565b50506001821b6105ae565b5060208310610133831016604e8410600b841016171561208e575081810a6105ae565b6120988383611fd0565b80600019048211156120ac576120ac611ec6565b029392505050565b60006105c160ff841683612013565b6001600160401b03818116838216019080821115611f0f57611f0f611ec6565b818103818111156105ae576105ae611ec6565b600082600f0b82600f0b0280600f0b9150808214611f0f57611f0f611ec6565b600f81810b9083900b0160016001607f1b03811360016001607f1b0319821217156105ae576105ae611ec6565b634e487b7160e01b600052603260045260246000fd5b60006001820161216b5761216b611ec6565b506001019056fea2646970667358221220f3cb860925856294cc4dce31efd031f4075e9591de388589c2ea5c6fc8703c0d64736f6c63430008110033