Source Code
Overview
APE Balance
APE Value
$0.00More Info
Private Name Tags
ContractCreator
TokenTracker
Multichain Info
N/A
Latest 25 from a total of 198 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Approval For... | 30508094 | 49 days ago | IN | 0 APE | 0.00118831 | ||||
| Advance State | 24070974 | 125 days ago | IN | 0 APE | 0.00123689 | ||||
| Safe Transfer Fr... | 23980456 | 126 days ago | IN | 0 APE | 0.00123081 | ||||
| Safe Transfer Fr... | 23980428 | 126 days ago | IN | 0 APE | 0.00177568 | ||||
| Safe Transfer Fr... | 23980237 | 126 days ago | IN | 0 APE | 0.00123081 | ||||
| Safe Transfer Fr... | 23980197 | 126 days ago | IN | 0 APE | 0.00179561 | ||||
| Safe Transfer Fr... | 23980170 | 126 days ago | IN | 0 APE | 0.00278064 | ||||
| Set Approval For... | 23947374 | 126 days ago | IN | 0 APE | 0.00118831 | ||||
| Set Approval For... | 20670370 | 164 days ago | IN | 0 APE | 0.00118618 | ||||
| Transfer From | 20372497 | 170 days ago | IN | 0 APE | 0.00113216 | ||||
| Transfer From | 20372489 | 170 days ago | IN | 0 APE | 0.00113216 | ||||
| Transfer From | 20372478 | 170 days ago | IN | 0 APE | 0.00169693 | ||||
| Transfer From | 20372474 | 170 days ago | IN | 0 APE | 0.001677 | ||||
| Transfer From | 20372466 | 170 days ago | IN | 0 APE | 0.00169693 | ||||
| Transfer From | 20372249 | 170 days ago | IN | 0 APE | 0.00273829 | ||||
| Transfer From | 19359557 | 194 days ago | IN | 0 APE | 0.00151044 | ||||
| Transfer From | 19348324 | 194 days ago | IN | 0 APE | 0.00113216 | ||||
| Transfer From | 19348313 | 194 days ago | IN | 0 APE | 0.001677 | ||||
| Transfer From | 19348304 | 194 days ago | IN | 0 APE | 0.00173333 | ||||
| Transfer From | 19348295 | 194 days ago | IN | 0 APE | 0.00169693 | ||||
| Transfer From | 19348285 | 194 days ago | IN | 0 APE | 0.00169693 | ||||
| Withdraw A Bottl... | 19336103 | 194 days ago | IN | 0 APE | 0.0008691 | ||||
| Purchase Extra T... | 19335432 | 195 days ago | IN | 4.5 APE | 0.22490937 | ||||
| Change Bottle Mi... | 19335394 | 195 days ago | IN | 0 APE | 0.00117143 | ||||
| Change Extra Bot... | 19335330 | 195 days ago | IN | 0 APE | 0.00078219 |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
CavaNFT
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721A} from "../lib/ERC721A/contracts/ERC721A.sol";
import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import {Base64} from "../lib/openzeppelin-contracts/contracts/utils/Base64.sol";
import {Strings} from "../lib/openzeppelin-contracts/contracts/utils/Strings.sol";
import {ReentrancyGuard} from "../lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import {CavaStaking} from "./CavaStaking.sol";
contract CavaNFT is ERC721A, Ownable, ReentrancyGuard {
error CavaNFT__IncorrectTimeForAging();
error CavaNFT__NoChangeAllowed();
error CavaNFT__InsufficientApeForPurchase(uint256 value);
error CavaNFT__WrongPriceFetched(uint256 price);
error CavaNFT__IncorrectAmount();
error CavaNFT__MaxExtraBottleReached();
error CavaNFT__ZeroTokensnotAllowed();
error CavaNFT__TokensAreAgingAlready();
error CavaNFT__DecisionNotAllowed();
error CavaNFT__NotEnoughNFTs();
error CavaNFT__NoApeIsBeingTranferred();
error CavaNFT__InsufficientAnejoFunds();
error CavaNFT__InsufficientReposadoFunds();
error CavaNFT__ReposadoPriceNotSet();
error CavaNFT__NotOwnerOfToken();
error CavaNFT__AnejoPriceNotSet();
error CavaNFT__ErrorInSell();
error CavaNFT__UseDesignatedDepositFunctions();
error CavaNFT__ZeroPriceBottle();
error CavaNFT__PurchaseNotAllowed();
using Strings for uint256;
struct Token {
AgingState agingState; // -> estado token de reposado y anejo
TokenChoice tokenChoice; // -> age en reposado / sell o bottle
bool noChange;
}
enum AgingState {
Blanco,
Reposado,
Anejo
}
enum TokenChoice {
age,
sell,
bottle
} //age -> cambiar estado // sell o bottle -/> no puede cambiar
// 0 1 2
uint256 public constant MAX_SUPPLY = 5555;
uint256 private constant CANVAS_SIZE = 300;
uint256 private constant BUBBLE_COUNT = 10;
uint256 private constant REPOSADO_TIME = 17 weeks;
uint256 private constant ANEJO_TIME = 48 weeks;
mapping(uint256 tokenId => Token tokenDecision) private s_tokenState;
mapping(string => uint256) private TequilaBalance; // "REPOSADO" "ANEJO" / "BOTTLES"
AgingState private s_currentState;
uint256[] private s_tokensToBurn;
uint256 private s_startingTime;
uint256 private _seedBase;
uint256 private s_MaxExtraBottleSupply = 200;
uint256 private s_TotalExtraBottleSupply;
uint256 private s_bottleMintPrice = 0;
uint256 s_reposadoPrice;
uint256 s_anejoPrice;
bool private s_stakingLockAddress = false;
address private s_CavaStakingAddress;
constructor() ERC721A("CAVA", "CAVA") Ownable(msg.sender) {
s_currentState = AgingState.Blanco;
s_startingTime = block.timestamp;
_seedBase = uint256(keccak256(abi.encodePacked(block.timestamp)));
}
event ReposadoMoneyTransferredToContract(address indexed sender, uint256 amount);
event AnejoMoneyTransferredToContract(address indexed sender, uint256 amount);
event ApeClaimedFromReposado(address sender, uint256 amount);
event ApeClaimedFromAnejo(address sender, uint256 amount);
event BottlesClaimed(AgingState, address indexed sender, uint256 indexed bottles);
receive() external payable {
revert CavaNFT__UseDesignatedDepositFunctions();
}
fallback() external payable {
transferMoneyToContract();
}
function getTokenInfo(uint256 _tokenId) public view returns(Token memory) {
return s_tokenState[_tokenId];
}
function MaxExtraBottleSupply() public view returns(uint256) {
return s_MaxExtraBottleSupply;
}
function ExtraBottleSupply() public view returns(uint256) {
return s_TotalExtraBottleSupply;
}
function BottleMintprice() public view returns(uint256) {
return s_bottleMintPrice;
}
function ReposadoSellprice() public view returns(uint256) {
return s_reposadoPrice;
}
function AnejoSellprice() public view returns(uint256) {
return s_anejoPrice;
}
function currentTequilaState() public view returns(AgingState) {
return s_currentState;
}
function userTokenDecision(
uint256[] calldata _tokens,
uint256 _choice
) public {
if (_choice == 0) revert CavaNFT__TokensAreAgingAlready();
if (s_currentState == AgingState.Blanco)
revert CavaNFT__DecisionNotAllowed();
uint256 currentTime = block.timestamp;
if (s_currentState == AgingState.Reposado) {
if ((currentTime - s_startingTime) <= (REPOSADO_TIME + 5 weeks)) {
for (uint256 i; i < _tokens.length; i++) {
if (ERC721A(address(this)).ownerOf(_tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
s_tokenState[_tokens[i]].agingState = s_currentState;
s_tokenState[_tokens[i]].noChange = true;
if (_choice == 1) {
s_tokenState[_tokens[i]].tokenChoice = TokenChoice.sell;
} else if (_choice == 2) {
s_tokenState[_tokens[i]].tokenChoice = TokenChoice.bottle;
}
}
}
} else {
if ((currentTime - s_startingTime) <= (ANEJO_TIME + 5 weeks)) {
for (uint256 i; i < _tokens.length; i++) {
if (ERC721A(address(this)).ownerOf(_tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
s_tokenState[_tokens[i]].agingState = s_currentState;
s_tokenState[_tokens[i]].noChange = true;
if (_choice == 1) {
s_tokenState[_tokens[i]].tokenChoice = TokenChoice.sell;
} else if (_choice == 2) {
s_tokenState[_tokens[i]].tokenChoice = TokenChoice.bottle;
}
}
}
}
}
function changeBottleMintPrice(uint256 quantity) public onlyOwner {
s_bottleMintPrice = quantity;
}
function changeExtraBottleSupply(uint256 quantity) public onlyOwner {
if (quantity < s_TotalExtraBottleSupply)
revert CavaNFT__IncorrectAmount();
s_MaxExtraBottleSupply = quantity;
}
// Can only be called once by the owner
function setStakingAddress(address stakingAddress) public onlyOwner {
if (s_stakingLockAddress == true) revert CavaNFT__NoChangeAllowed();
s_CavaStakingAddress = stakingAddress;
s_stakingLockAddress = true;
}
function advanceState() external onlyOwner {
uint256 timePassed = block.timestamp;
uint256 time = timePassed - s_startingTime;
if (s_currentState == AgingState.Blanco && time >= REPOSADO_TIME && time < ANEJO_TIME) {
s_currentState = AgingState.Reposado;
} else if (s_currentState == AgingState.Reposado && time >= ANEJO_TIME) {
s_currentState = AgingState.Anejo;
} else {
revert CavaNFT__IncorrectTimeForAging();
}
}
function mint() external nonReentrant {
CavaStaking cava = CavaStaking(s_CavaStakingAddress);
uint256 quantity = cava.getUserTotalStaked(msg.sender);
uint256 alreadyStaked = cava.getUserAlreadyStaked(msg.sender);
if (quantity <= alreadyStaked) revert CavaNFT__NotEnoughNFTs();
uint256 amount = quantity - alreadyStaked;
if (amount == 0) revert CavaNFT__NotEnoughNFTs();
require(totalSupply() + amount <= MAX_SUPPLY, "Max supply");
cava.setAlreadyStaked(msg.sender, quantity);
_seedBase = uint256(
keccak256(abi.encodePacked(_seedBase, block.timestamp))
);
_safeMint(msg.sender, amount);
}
function purchaseExtraTequilaBottle(uint256 quantity) public payable nonReentrant {
if (s_currentState != AgingState.Blanco) revert CavaNFT__PurchaseNotAllowed();
if (s_bottleMintPrice == 0) revert CavaNFT__ZeroPriceBottle();
uint256 requiredApe = quantity * s_bottleMintPrice;
if (requiredApe <= 0) revert CavaNFT__WrongPriceFetched(requiredApe);
if (msg.value < requiredApe)
revert CavaNFT__InsufficientApeForPurchase(msg.value);
if (s_TotalExtraBottleSupply + quantity > s_MaxExtraBottleSupply)
revert CavaNFT__MaxExtraBottleReached();
_safeMint(msg.sender, quantity);
s_TotalExtraBottleSupply += quantity;
TequilaBalance["BOTTLES"] += requiredApe;
// Refund excess
if (msg.value > requiredApe) {
payable(msg.sender).transfer(msg.value - requiredApe);
}
}
function _generateBubbles(
uint256 tokenId
) internal view returns (string memory) {
bytes memory bubbles;
for (uint256 i = 0; i < BUBBLE_COUNT; i++) {
uint256 seed = uint256(
keccak256(abi.encodePacked(_seedBase, tokenId, i))
);
bubbles = abi.encodePacked(bubbles, _buildBubble(seed, i, tokenId));
}
return string(bubbles);
}
function _buildBubble(
uint256 seed,
uint256 index,
uint256 tokenId
) internal view returns (string memory) {
AgingState state;
bool choice = s_tokenState[tokenId].noChange;
AgingState choice2 = s_tokenState[tokenId].agingState;
if (s_currentState == AgingState.Blanco){
state = AgingState.Blanco;
} else if (s_currentState == AgingState.Reposado){
state = AgingState.Reposado;
} else if (s_currentState == AgingState.Anejo && choice == true && choice2 == AgingState.Reposado){
state = AgingState.Reposado;
} else if (s_currentState == AgingState.Anejo && choice == false){
state = AgingState.Anejo;
} else if (s_currentState == AgingState.Anejo && choice == true && choice2 == AgingState.Anejo){
state = AgingState.Anejo;
}
uint256 baseSize = 20 + (seed % 40);
uint256 startX = 30 + ((seed >> 8) % 240);
uint256 startY = 30 + ((seed >> 16) % 240);
int256 moveX = int256((seed >> 24) % 61) - 30;
int256 moveY = int256((seed >> 32) % 61) - 30;
uint256 duration = 4 + ((seed >> 40) % 3);
return
string(
abi.encodePacked(
'<g transform="translate(',
startX.toString(),
",",
startY.toString(),
')">',
'<circle r="',
baseSize.toString(),
'" fill="',
_getColor(seed, state),
'" opacity="0">',
'<animate attributeName="opacity" values="0;0.7;0" dur="',
duration.toString(),
's" ',
'begin="-',
(index % duration).toString(),
's" repeatCount="indefinite"/>',
'<animate attributeName="r" values="',
baseSize.toString(),
";",
(baseSize * 2).toString(),
";",
baseSize.toString(),
'" ',
'dur="',
duration.toString(),
's" repeatCount="indefinite"/>',
'<animateTransform attributeName="transform" type="translate" ',
'values="0,0;',
_intToString(moveX),
",",
_intToString(moveY),
';0,0" ',
'dur="',
duration.toString(),
's" additive="sum" repeatCount="indefinite"/>',
"</circle></g>"
)
);
}
function _intToString(int256 n) internal pure returns (string memory) {
return
n < 0
? string(abi.encodePacked("-", uint256(-n).toString()))
: uint256(n).toString();
}
function _getColor(
uint256 seed,
AgingState state
) internal pure returns (string memory) {
string[5] memory colors;
if (state == AgingState.Blanco) {
colors = ["#87CEEB", "#00BFFF", "#1E90FF", "#4169E1", "#4682B4"];
} else if (state == AgingState.Reposado) {
colors = ["#FFD700", "#FFA500", "#FF8C00", "#FFB90F", "#EEB422"];
} else {
colors = ["#8B0000", "#A52A2A", "#B22222", "#8B4513", "#CD853F"];
}
return colors[seed % 5];
}
function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
require(_exists(tokenId), "Invalid token");
bool choice = s_tokenState[tokenId].noChange;
AgingState choice2 = s_tokenState[tokenId].agingState;
string memory tequilaState;
string memory bgColor;
if (s_currentState == AgingState.Blanco){
bgColor = "#F0F8FF";
tequilaState = "Blanco";
} else if (s_currentState == AgingState.Reposado){
bgColor = "#FFD700";
tequilaState = "Reposado";
} else if (s_currentState == AgingState.Anejo && choice == true && choice2 == AgingState.Reposado){
bgColor = "#FFD700";
tequilaState = "Reposado";
} else if (s_currentState == AgingState.Anejo && choice == false){
bgColor = "#8B0000";
tequilaState = "Anejo";
} else if (s_currentState == AgingState.Anejo && choice == true && choice2 == AgingState.Anejo){
bgColor = "#8B0000";
tequilaState = "Anejo";
}
string memory svg = string(
abi.encodePacked(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300" style="overflow:hidden">',
'<defs><clipPath id="frame"><rect width="300" height="300"/></clipPath></defs>',
'<rect width="300" height="300" fill="',
bgColor,
'"/>',
'<g clip-path="url(#frame)">',
_generateBubbles(tokenId),
"</g></svg>"
)
);
string memory json = Base64.encode(
abi.encodePacked(
'{"name":"CAVA #',
tokenId.toString(),
'","description":"On-chain aged tequila NFT with dynamic animation",',
'"attributes":[{"trait_type":"State","value":"',
tequilaState,
'"}],"image":"data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
'"}'
)
);
return string(abi.encodePacked("data:application/json;base64,", json));
}
function returnTequilaState() external view returns (uint256) {
if (s_currentState == AgingState.Blanco) {
return 0;
} else if (s_currentState == AgingState.Reposado) {
return 1;
} else {
return 2;
}
}
function reposadoBalance() public view returns(uint256){
return TequilaBalance["REPOSADO"];
}
function anejoBalance() public view returns(uint256){
return TequilaBalance["ANEJO"];
}
function bottlesBalance() public view returns(uint256){
return TequilaBalance["BOTTLES"];
}
function getBalance() public view returns(uint256) {
return address(this).balance;
}
function verifyBalances() public view returns (bool){
return getBalance() == (reposadoBalance() + anejoBalance() + bottlesBalance());
}
// public
function withdrawReposado() public onlyOwner nonReentrant {
uint256 amount = TequilaBalance["REPOSADO"];
(bool success, ) = owner().call{value: amount}("");
if (success){
TequilaBalance["REPOSADO"] = 0;
}
}
function withdrawAnejo() public onlyOwner nonReentrant {
uint256 amount = TequilaBalance["ANEJO"];
(bool success, ) = owner().call{value: amount}("");
if (success){
TequilaBalance["ANEJO"] = 0;
}
}
function withdrawABottles() public onlyOwner nonReentrant {
uint256 amount = TequilaBalance["BOTTLES"];
(bool success, ) = owner().call{value: amount}("");
if (success) {
TequilaBalance["BOTTLES"] = 0;
}
}
function transferReposadoMoneyToContract() public payable {
if (msg.value <= 0) revert CavaNFT__NoApeIsBeingTranferred();
TequilaBalance["REPOSADO"] += msg.value;
emit ReposadoMoneyTransferredToContract(msg.sender, msg.value);
}
function transferAnejoMoneyToContract() public payable {
if (msg.value <= 0) revert CavaNFT__NoApeIsBeingTranferred();
TequilaBalance["ANEJO"] += msg.value;
emit AnejoMoneyTransferredToContract(msg.sender, msg.value);
}
function transferMoneyToContract() public payable {
if (msg.value <= 0) revert CavaNFT__NoApeIsBeingTranferred();
TequilaBalance["BOTTLES"] += msg.value;
}
function setReposadoPrice(uint256 _price) public onlyOwner {
s_reposadoPrice = _price;
}
function setAnejoPrice(uint256 _price) public onlyOwner {
s_anejoPrice = _price;
}
function claimReposadoApe(uint256[] calldata tokens) public nonReentrant {
if (s_reposadoPrice <= 0) revert CavaNFT__ReposadoPriceNotSet();
uint256 reposadoPrice = s_reposadoPrice;
uint256 reposadoTotalBottles;
for (uint256 i; i < tokens.length; i++){
if (ERC721A(address(this)).ownerOf(tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
Token memory tokenInfo = s_tokenState[tokens[i]];
if (tokenInfo.agingState == AgingState.Reposado && tokenInfo.tokenChoice == TokenChoice.sell){
reposadoTotalBottles += 1;
s_tokensToBurn.push(tokens[i]);
}
}
uint256[] memory tokensToBurn = s_tokensToBurn;
uint256 totalApe = (reposadoPrice * reposadoTotalBottles);
if (totalApe == 0) revert CavaNFT__ErrorInSell();
if (TequilaBalance["REPOSADO"] < totalApe)
revert CavaNFT__InsufficientReposadoFunds();
// payable(msg.sender).transfer(address(this).balance);
(bool success, ) = msg.sender.call{value: totalApe}("");
require(success);
TequilaBalance["REPOSADO"] -= totalApe;
for (uint256 i; i < tokensToBurn.length; i++){
_burn(tokensToBurn[i]);
}
emit ApeClaimedFromReposado(msg.sender, totalApe);
delete s_tokensToBurn;
}
function claimAnejoApe(uint256[] calldata tokens) public nonReentrant {
if (s_anejoPrice <= 0) revert CavaNFT__AnejoPriceNotSet();
uint256 anejoPrice = s_anejoPrice;
uint256 anejoTotalBottles;
for (uint256 i; i < tokens.length; i++){
if (ERC721A(address(this)).ownerOf(tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
Token memory tokenInfo = s_tokenState[tokens[i]];
if (tokenInfo.agingState == AgingState.Anejo && tokenInfo.tokenChoice == TokenChoice.sell){
anejoTotalBottles += 1;
s_tokensToBurn.push(tokens[i]);
}
}
uint256[] memory tokensToBurn = s_tokensToBurn;
uint256 totalApe = (anejoPrice * anejoTotalBottles);
if (totalApe == 0) revert CavaNFT__ErrorInSell();
if (TequilaBalance["ANEJO"] < totalApe)
revert CavaNFT__InsufficientAnejoFunds();
// payable(msg.sender).transfer(address(this).balance);
(bool success, ) = msg.sender.call{value: totalApe}("");
require(success);
TequilaBalance["ANEJO"] -= totalApe;
for (uint256 i; i < tokensToBurn.length; i++){
_burn(tokensToBurn[i]);
}
emit ApeClaimedFromAnejo(msg.sender, totalApe);
delete s_tokensToBurn;
}
function claimAnejoBottle(uint256[] calldata tokens) public nonReentrant {
uint256 anejoTotalBottles;
for (uint256 i; i < tokens.length; i++){
if (ERC721A(address(this)).ownerOf(tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
Token memory tokenInfo = s_tokenState[tokens[i]];
if (tokenInfo.agingState == AgingState.Anejo && tokenInfo.tokenChoice == TokenChoice.bottle){
anejoTotalBottles += 1;
s_tokensToBurn.push(tokens[i]);
}
}
uint256[] memory tokensToBurn = s_tokensToBurn;
for (uint256 i; i < tokensToBurn.length; i++){
_burn(tokensToBurn[i]);
}
emit BottlesClaimed(AgingState.Anejo, msg.sender, anejoTotalBottles);
delete s_tokensToBurn;
}
function claimReposadoBottle(uint256[] calldata tokens) public nonReentrant {
uint256 reposadoTotalBottles;
for (uint256 i; i < tokens.length; i++){
if (ERC721A(address(this)).ownerOf(tokens[i]) != msg.sender) revert CavaNFT__NotOwnerOfToken();
Token memory tokenInfo = s_tokenState[tokens[i]];
if (tokenInfo.agingState == AgingState.Reposado && tokenInfo.tokenChoice == TokenChoice.bottle){
reposadoTotalBottles += 1;
s_tokensToBurn.push(tokens[i]);
}
}
uint256[] memory tokensToBurn = s_tokensToBurn;
for (uint256 i; i < tokensToBurn.length; i++){
_burn(tokensToBurn[i]);
}
emit BottlesClaimed(AgingState.Reposado, msg.sender, reposadoTotalBottles);
delete s_tokensToBurn;
}
}
// Layout of Contract:
// version *
// imports *
// errors *
// interfaces, libraries, contracts *
// Type declarations
// State variables
// Events
// Modifiers
// Functions
// Layout of Functions:
// constructor
// receive function (if exists)
// fallback function (if exists)
// external
// public
// internal
// private
// internal & private view & pure functions
// external & public view & pure functions// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.3.0
// Creator: Chiru Labs
pragma solidity ^0.8.4;
import './IERC721A.sol';
/**
* @dev Interface of ERC721 token receiver.
*/
interface ERC721A__IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
/**
* @title ERC721A
*
* @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)
* Non-Fungible Token Standard, including the Metadata extension.
* Optimized for lower gas during batch mints.
*
* Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)
* starting from `_startTokenId()`.
*
* The `_sequentialUpTo()` function can be overriden to enable spot mints
* (i.e. non-consecutive mints) for `tokenId`s greater than `_sequentialUpTo()`.
*
* Assumptions:
*
* - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.
* - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).
*/
contract ERC721A is IERC721A {
// Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).
struct TokenApprovalRef {
address value;
}
// =============================================================
// CONSTANTS
// =============================================================
// Mask of an entry in packed address data.
uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;
// The bit position of `numberMinted` in packed address data.
uint256 private constant _BITPOS_NUMBER_MINTED = 64;
// The bit position of `numberBurned` in packed address data.
uint256 private constant _BITPOS_NUMBER_BURNED = 128;
// The bit position of `aux` in packed address data.
uint256 private constant _BITPOS_AUX = 192;
// Mask of all 256 bits in packed address data except the 64 bits for `aux`.
uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;
// The bit position of `startTimestamp` in packed ownership.
uint256 private constant _BITPOS_START_TIMESTAMP = 160;
// The bit mask of the `burned` bit in packed ownership.
uint256 private constant _BITMASK_BURNED = 1 << 224;
// The bit position of the `nextInitialized` bit in packed ownership.
uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;
// The bit mask of the `nextInitialized` bit in packed ownership.
uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;
// The bit position of `extraData` in packed ownership.
uint256 private constant _BITPOS_EXTRA_DATA = 232;
// Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.
uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;
// The mask of the lower 160 bits for addresses.
uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;
// The maximum `quantity` that can be minted with {_mintERC2309}.
// This limit is to prevent overflows on the address data entries.
// For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}
// is required to cause an overflow, which is unrealistic.
uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;
// The `Transfer` event signature is given by:
// `keccak256(bytes("Transfer(address,address,uint256)"))`.
bytes32 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
// =============================================================
// STORAGE
// =============================================================
// The next token ID to be minted.
uint256 private _currentIndex;
// The number of tokens burned.
uint256 private _burnCounter;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to ownership details
// An empty struct value does not necessarily mean the token is unowned.
// See {_packedOwnershipOf} implementation for details.
//
// Bits Layout:
// - [0..159] `addr`
// - [160..223] `startTimestamp`
// - [224] `burned`
// - [225] `nextInitialized`
// - [232..255] `extraData`
mapping(uint256 => uint256) private _packedOwnerships;
// Mapping owner address to address data.
//
// Bits Layout:
// - [0..63] `balance`
// - [64..127] `numberMinted`
// - [128..191] `numberBurned`
// - [192..255] `aux`
mapping(address => uint256) private _packedAddressData;
// Mapping from token ID to approved address.
mapping(uint256 => TokenApprovalRef) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
// The amount of tokens minted above `_sequentialUpTo()`.
// We call these spot mints (i.e. non-sequential mints).
uint256 private _spotMinted;
// =============================================================
// CONSTRUCTOR
// =============================================================
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_currentIndex = _startTokenId();
if (_sequentialUpTo() < _startTokenId()) _revert(SequentialUpToTooSmall.selector);
}
// =============================================================
// TOKEN COUNTING OPERATIONS
// =============================================================
/**
* @dev Returns the starting token ID for sequential mints.
*
* Override this function to change the starting token ID for sequential mints.
*
* Note: The value returned must never change after any tokens have been minted.
*/
function _startTokenId() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev Returns the maximum token ID (inclusive) for sequential mints.
*
* Override this function to return a value less than 2**256 - 1,
* but greater than `_startTokenId()`, to enable spot (non-sequential) mints.
*
* Note: The value returned must never change after any tokens have been minted.
*/
function _sequentialUpTo() internal view virtual returns (uint256) {
return type(uint256).max;
}
/**
* @dev Returns the next token ID to be minted.
*/
function _nextTokenId() internal view virtual returns (uint256) {
return _currentIndex;
}
/**
* @dev Returns the total number of tokens in existence.
* Burned tokens will reduce the count.
* To get the total number of tokens minted, please see {_totalMinted}.
*/
function totalSupply() public view virtual override returns (uint256 result) {
// Counter underflow is impossible as `_burnCounter` cannot be incremented
// more than `_currentIndex + _spotMinted - _startTokenId()` times.
unchecked {
// With spot minting, the intermediate `result` can be temporarily negative,
// and the computation must be unchecked.
result = _currentIndex - _burnCounter - _startTokenId();
if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;
}
}
/**
* @dev Returns the total amount of tokens minted in the contract.
*/
function _totalMinted() internal view virtual returns (uint256 result) {
// Counter underflow is impossible as `_currentIndex` does not decrement,
// and it is initialized to `_startTokenId()`.
unchecked {
result = _currentIndex - _startTokenId();
if (_sequentialUpTo() != type(uint256).max) result += _spotMinted;
}
}
/**
* @dev Returns the total number of tokens burned.
*/
function _totalBurned() internal view virtual returns (uint256) {
return _burnCounter;
}
/**
* @dev Returns the total number of tokens that are spot-minted.
*/
function _totalSpotMinted() internal view virtual returns (uint256) {
return _spotMinted;
}
// =============================================================
// ADDRESS DATA OPERATIONS
// =============================================================
/**
* @dev Returns the number of tokens in `owner`'s account.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
if (owner == address(0)) _revert(BalanceQueryForZeroAddress.selector);
return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the number of tokens minted by `owner`.
*/
function _numberMinted(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the number of tokens burned by or on behalf of `owner`.
*/
function _numberBurned(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
/**
* Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
*/
function _getAux(address owner) internal view returns (uint64) {
return uint64(_packedAddressData[owner] >> _BITPOS_AUX);
}
/**
* Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).
* If there are multiple variables, please pack them into a uint64.
*/
function _setAux(address owner, uint64 aux) internal virtual {
uint256 packed = _packedAddressData[owner];
uint256 auxCasted;
// Cast `aux` with assembly to avoid redundant masking.
assembly {
auxCasted := aux
}
packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);
_packedAddressData[owner] = packed;
}
// =============================================================
// IERC165
// =============================================================
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
* to learn more about how these ids are created.
*
* This function call must use less than 30000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
// The interface IDs are constants representing the first 4 bytes
// of the XOR of all function selectors in the interface.
// See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)
// (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)
return
interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.
interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.
interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.
}
// =============================================================
// IERC721Metadata
// =============================================================
/**
* @dev Returns the token collection name.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the token collection symbol.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) _revert(URIQueryForNonexistentToken.selector);
string memory baseURI = _baseURI();
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';
}
/**
* @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, it can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return '';
}
// =============================================================
// OWNERSHIPS OPERATIONS
// =============================================================
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return address(uint160(_packedOwnershipOf(tokenId)));
}
/**
* @dev Gas spent here starts off proportional to the maximum mint batch size.
* It gradually moves to O(1) as tokens get transferred around over time.
*/
function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnershipOf(tokenId));
}
/**
* @dev Returns the unpacked `TokenOwnership` struct at `index`.
*/
function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnerships[index]);
}
/**
* @dev Returns whether the ownership slot at `index` is initialized.
* An uninitialized slot does not necessarily mean that the slot has no owner.
*/
function _ownershipIsInitialized(uint256 index) internal view virtual returns (bool) {
return _packedOwnerships[index] != 0;
}
/**
* @dev Initializes the ownership slot minted at `index` for efficiency purposes.
*/
function _initializeOwnershipAt(uint256 index) internal virtual {
if (_packedOwnerships[index] == 0) {
_packedOwnerships[index] = _packedOwnershipOf(index);
}
}
/**
* @dev Returns the packed ownership data of `tokenId`.
*/
function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) {
if (_startTokenId() <= tokenId) {
packed = _packedOwnerships[tokenId];
if (tokenId > _sequentialUpTo()) {
if (_packedOwnershipExists(packed)) return packed;
_revert(OwnerQueryForNonexistentToken.selector);
}
// If the data at the starting slot does not exist, start the scan.
if (packed == 0) {
if (tokenId >= _currentIndex) _revert(OwnerQueryForNonexistentToken.selector);
// Invariant:
// There will always be an initialized ownership slot
// (i.e. `ownership.addr != address(0) && ownership.burned == false`)
// before an unintialized ownership slot
// (i.e. `ownership.addr == address(0) && ownership.burned == false`)
// Hence, `tokenId` will not underflow.
//
// We can directly compare the packed value.
// If the address is zero, packed will be zero.
for (;;) {
unchecked {
packed = _packedOwnerships[--tokenId];
}
if (packed == 0) continue;
if (packed & _BITMASK_BURNED == 0) return packed;
// Otherwise, the token is burned, and we must revert.
// This handles the case of batch burned tokens, where only the burned bit
// of the starting slot is set, and remaining slots are left uninitialized.
_revert(OwnerQueryForNonexistentToken.selector);
}
}
// Otherwise, the data exists and we can skip the scan.
// This is possible because we have already achieved the target condition.
// This saves 2143 gas on transfers of initialized tokens.
// If the token is not burned, return `packed`. Otherwise, revert.
if (packed & _BITMASK_BURNED == 0) return packed;
}
_revert(OwnerQueryForNonexistentToken.selector);
}
/**
* @dev Returns the unpacked `TokenOwnership` struct from `packed`.
*/
function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {
ownership.addr = address(uint160(packed));
ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);
ownership.burned = packed & _BITMASK_BURNED != 0;
ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);
}
/**
* @dev Packs ownership data into a single uint256.
*/
function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {
assembly {
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
owner := and(owner, _BITMASK_ADDRESS)
// `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.
result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))
}
}
/**
* @dev Returns the `nextInitialized` flag set if `quantity` equals 1.
*/
function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {
// For branchless setting of the `nextInitialized` flag.
assembly {
// `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.
result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))
}
}
// =============================================================
// APPROVAL OPERATIONS
// =============================================================
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account. See {ERC721A-_approve}.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
*/
function approve(address to, uint256 tokenId) public payable virtual override {
_approve(to, tokenId, true);
}
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
if (!_exists(tokenId)) _revert(ApprovalQueryForNonexistentToken.selector);
return _tokenApprovals[tokenId].value;
}
/**
* @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) public virtual override {
_operatorApprovals[_msgSenderERC721A()][operator] = approved;
emit ApprovalForAll(_msgSenderERC721A(), operator, approved);
}
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @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. See {_mint}.
*/
function _exists(uint256 tokenId) internal view virtual returns (bool result) {
if (_startTokenId() <= tokenId) {
if (tokenId > _sequentialUpTo()) return _packedOwnershipExists(_packedOwnerships[tokenId]);
if (tokenId < _currentIndex) {
uint256 packed;
while ((packed = _packedOwnerships[tokenId]) == 0) --tokenId;
result = packed & _BITMASK_BURNED == 0;
}
}
}
/**
* @dev Returns whether `packed` represents a token that exists.
*/
function _packedOwnershipExists(uint256 packed) private pure returns (bool result) {
assembly {
// The following is equivalent to `owner != address(0) && burned == false`.
// Symbolically tested.
result := gt(and(packed, _BITMASK_ADDRESS), and(packed, _BITMASK_BURNED))
}
}
/**
* @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.
*/
function _isSenderApprovedOrOwner(
address approvedAddress,
address owner,
address msgSender
) private pure returns (bool result) {
assembly {
// Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.
owner := and(owner, _BITMASK_ADDRESS)
// Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.
msgSender := and(msgSender, _BITMASK_ADDRESS)
// `msgSender == owner || msgSender == approvedAddress`.
result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))
}
}
/**
* @dev Returns the storage slot and value for the approved address of `tokenId`.
*/
function _getApprovedSlotAndAddress(uint256 tokenId)
private
view
returns (uint256 approvedAddressSlot, address approvedAddress)
{
TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];
// The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.
assembly {
approvedAddressSlot := tokenApproval.slot
approvedAddress := sload(approvedAddressSlot)
}
}
// =============================================================
// TRANSFER OPERATIONS
// =============================================================
/**
* @dev Transfers `tokenId` from `from` to `to`.
*
* 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
) public payable virtual override {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
// Mask `from` to the lower 160 bits, in case the upper bits somehow aren't clean.
from = address(uint160(uint256(uint160(from)) & _BITMASK_ADDRESS));
if (address(uint160(prevOwnershipPacked)) != from) _revert(TransferFromIncorrectOwner.selector);
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
// The nested ifs save around 20+ gas over a compound boolean condition.
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);
_beforeTokenTransfers(from, to, tokenId, 1);
// Clear approvals from the previous owner.
assembly {
if approvedAddress {
// This is equivalent to `delete _tokenApprovals[tokenId]`.
sstore(approvedAddressSlot, 0)
}
}
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.
unchecked {
// We can directly increment and decrement the balances.
--_packedAddressData[from]; // Updates: `balance -= 1`.
++_packedAddressData[to]; // Updates: `balance += 1`.
// Updates:
// - `address` to the next owner.
// - `startTimestamp` to the timestamp of transfering.
// - `burned` to `false`.
// - `nextInitialized` to `true`.
_packedOwnerships[tokenId] = _packOwnershipData(
to,
_BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)
);
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
// If the next slot's address is zero and not burned (i.e. packed value is zero).
if (_packedOwnerships[nextTokenId] == 0) {
// If the next slot is within bounds.
if (nextTokenId != _currentIndex) {
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;
assembly {
// Emit the `Transfer` event.
log4(
0, // Start of data (0, since no data).
0, // End of data (0, since no data).
_TRANSFER_EVENT_SIGNATURE, // Signature.
from, // `from`.
toMasked, // `to`.
tokenId // `tokenId`.
)
}
if (toMasked == 0) _revert(TransferToZeroAddress.selector);
_afterTokenTransfers(from, to, tokenId, 1);
}
/**
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public payable virtual override {
safeTransferFrom(from, to, tokenId, '');
}
/**
* @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 memory _data
) public payable virtual override {
transferFrom(from, to, tokenId);
if (to.code.length != 0)
if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
}
/**
* @dev Hook that is called before a set of serially-ordered token IDs
* are about to be transferred. This includes minting.
* And also called before burning one token.
*
* `startTokenId` - the first token ID to be transferred.
* `quantity` - the amount to be transferred.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Hook that is called after a set of serially-ordered token IDs
* have been transferred. This includes minting.
* And also called after one token has been burned.
*
* `startTokenId` - the first token ID to be transferred.
* `quantity` - the amount to be transferred.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` has been
* transferred to `to`.
* - When `from` is zero, `tokenId` has been minted for `to`.
* - When `to` is zero, `tokenId` has been burned by `from`.
* - `from` and `to` are never both zero.
*/
function _afterTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
/**
* @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.
*
* `from` - Previous owner of the given token ID.
* `to` - Target address that will receive the token.
* `tokenId` - Token ID to be transferred.
* `_data` - Optional data to send along with the call.
*
* Returns whether the call correctly returned the expected magic value.
*/
function _checkContractOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (
bytes4 retval
) {
return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
assembly {
revert(add(32, reason), mload(reason))
}
}
}
// =============================================================
// MINT OPERATIONS
// =============================================================
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {Transfer} event for each mint.
*/
function _mint(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (quantity == 0) _revert(MintZeroQuantity.selector);
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are incredibly unrealistic.
// `balance` and `numberMinted` have a maximum limit of 2**64.
// `tokenId` has a maximum limit of 2**256.
unchecked {
// Updates:
// - `address` to the owner.
// - `startTimestamp` to the timestamp of minting.
// - `burned` to `false`.
// - `nextInitialized` to `quantity == 1`.
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
// Updates:
// - `balance += quantity`.
// - `numberMinted += quantity`.
//
// We can directly add to the `balance` and `numberMinted`.
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;
if (toMasked == 0) _revert(MintToZeroAddress.selector);
uint256 end = startTokenId + quantity;
uint256 tokenId = startTokenId;
if (end - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);
do {
assembly {
// Emit the `Transfer` event.
log4(
0, // Start of data (0, since no data).
0, // End of data (0, since no data).
_TRANSFER_EVENT_SIGNATURE, // Signature.
0, // `address(0)`.
toMasked, // `to`.
tokenId // `tokenId`.
)
}
// The `!=` check ensures that large values of `quantity`
// that overflows uint256 will make the loop run out of gas.
} while (++tokenId != end);
_currentIndex = end;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Mints `quantity` tokens and transfers them to `to`.
*
* This function is intended for efficient minting only during contract creation.
*
* It emits only one {ConsecutiveTransfer} as defined in
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),
* instead of a sequence of {Transfer} event(s).
*
* Calling this function outside of contract creation WILL make your contract
* non-compliant with the ERC721 standard.
* For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309
* {ConsecutiveTransfer} event is only permissible during contract creation.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `quantity` must be greater than 0.
*
* Emits a {ConsecutiveTransfer} event.
*/
function _mintERC2309(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (to == address(0)) _revert(MintToZeroAddress.selector);
if (quantity == 0) _revert(MintZeroQuantity.selector);
if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) _revert(MintERC2309QuantityExceedsLimit.selector);
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
// Overflows are unrealistic due to the above check for `quantity` to be below the limit.
unchecked {
// Updates:
// - `balance += quantity`.
// - `numberMinted += quantity`.
//
// We can directly add to the `balance` and `numberMinted`.
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
// Updates:
// - `address` to the owner.
// - `startTimestamp` to the timestamp of minting.
// - `burned` to `false`.
// - `nextInitialized` to `quantity == 1`.
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
if (startTokenId + quantity - 1 > _sequentialUpTo()) _revert(SequentialMintExceedsLimit.selector);
emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);
_currentIndex = startTokenId + quantity;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
/**
* @dev Safely mints `quantity` tokens and transfers them to `to`.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement
* {IERC721Receiver-onERC721Received}, which is called for each safe transfer.
* - `quantity` must be greater than 0.
*
* See {_mint}.
*
* Emits a {Transfer} event for each mint.
*/
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
) internal virtual {
_mint(to, quantity);
unchecked {
if (to.code.length != 0) {
uint256 end = _currentIndex;
uint256 index = end - quantity;
do {
if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
} while (index < end);
// This prevents reentrancy to `_safeMint`.
// It does not prevent reentrancy to `_safeMintSpot`.
if (_currentIndex != end) revert();
}
}
}
/**
* @dev Equivalent to `_safeMint(to, quantity, '')`.
*/
function _safeMint(address to, uint256 quantity) internal virtual {
_safeMint(to, quantity, '');
}
/**
* @dev Mints a single token at `tokenId`.
*
* Note: A spot-minted `tokenId` that has been burned can be re-minted again.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` must be greater than `_sequentialUpTo()`.
* - `tokenId` must not exist.
*
* Emits a {Transfer} event for each mint.
*/
function _mintSpot(address to, uint256 tokenId) internal virtual {
if (tokenId <= _sequentialUpTo()) _revert(SpotMintTokenIdTooSmall.selector);
uint256 prevOwnershipPacked = _packedOwnerships[tokenId];
if (_packedOwnershipExists(prevOwnershipPacked)) _revert(TokenAlreadyExists.selector);
_beforeTokenTransfers(address(0), to, tokenId, 1);
// Overflows are incredibly unrealistic.
// The `numberMinted` for `to` is incremented by 1, and has a max limit of 2**64 - 1.
// `_spotMinted` is incremented by 1, and has a max limit of 2**256 - 1.
unchecked {
// Updates:
// - `address` to the owner.
// - `startTimestamp` to the timestamp of minting.
// - `burned` to `false`.
// - `nextInitialized` to `true` (as `quantity == 1`).
_packedOwnerships[tokenId] = _packOwnershipData(
to,
_nextInitializedFlag(1) | _nextExtraData(address(0), to, prevOwnershipPacked)
);
// Updates:
// - `balance += 1`.
// - `numberMinted += 1`.
//
// We can directly add to the `balance` and `numberMinted`.
_packedAddressData[to] += (1 << _BITPOS_NUMBER_MINTED) | 1;
// Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.
uint256 toMasked = uint256(uint160(to)) & _BITMASK_ADDRESS;
if (toMasked == 0) _revert(MintToZeroAddress.selector);
assembly {
// Emit the `Transfer` event.
log4(
0, // Start of data (0, since no data).
0, // End of data (0, since no data).
_TRANSFER_EVENT_SIGNATURE, // Signature.
0, // `address(0)`.
toMasked, // `to`.
tokenId // `tokenId`.
)
}
++_spotMinted;
}
_afterTokenTransfers(address(0), to, tokenId, 1);
}
/**
* @dev Safely mints a single token at `tokenId`.
*
* Note: A spot-minted `tokenId` that has been burned can be re-minted again.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}.
* - `tokenId` must be greater than `_sequentialUpTo()`.
* - `tokenId` must not exist.
*
* See {_mintSpot}.
*
* Emits a {Transfer} event.
*/
function _safeMintSpot(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mintSpot(to, tokenId);
unchecked {
if (to.code.length != 0) {
uint256 currentSpotMinted = _spotMinted;
if (!_checkContractOnERC721Received(address(0), to, tokenId, _data)) {
_revert(TransferToNonERC721ReceiverImplementer.selector);
}
// This prevents reentrancy to `_safeMintSpot`.
// It does not prevent reentrancy to `_safeMint`.
if (_spotMinted != currentSpotMinted) revert();
}
}
}
/**
* @dev Equivalent to `_safeMintSpot(to, tokenId, '')`.
*/
function _safeMintSpot(address to, uint256 tokenId) internal virtual {
_safeMintSpot(to, tokenId, '');
}
// =============================================================
// APPROVAL OPERATIONS
// =============================================================
/**
* @dev Equivalent to `_approve(to, tokenId, false)`.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_approve(to, tokenId, false);
}
/**
* @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:
*
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function _approve(
address to,
uint256 tokenId,
bool approvalCheck
) internal virtual {
address owner = ownerOf(tokenId);
if (approvalCheck && _msgSenderERC721A() != owner)
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
_revert(ApprovalCallerNotOwnerNorApproved.selector);
}
_tokenApprovals[tokenId].value = to;
emit Approval(owner, to, tokenId);
}
// =============================================================
// BURN OPERATIONS
// =============================================================
/**
* @dev Equivalent to `_burn(tokenId, false)`.
*/
function _burn(uint256 tokenId) internal virtual {
_burn(tokenId, false);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
address from = address(uint160(prevOwnershipPacked));
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
if (approvalCheck) {
// The nested ifs save around 20+ gas over a compound boolean condition.
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) _revert(TransferCallerNotOwnerNorApproved.selector);
}
_beforeTokenTransfers(from, address(0), tokenId, 1);
// Clear approvals from the previous owner.
assembly {
if approvedAddress {
// This is equivalent to `delete _tokenApprovals[tokenId]`.
sstore(approvedAddressSlot, 0)
}
}
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
// Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.
unchecked {
// Updates:
// - `balance -= 1`.
// - `numberBurned += 1`.
//
// We can directly decrement the balance, and increment the number burned.
// This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.
_packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;
// Updates:
// - `address` to the last owner.
// - `startTimestamp` to the timestamp of burning.
// - `burned` to `true`.
// - `nextInitialized` to `true`.
_packedOwnerships[tokenId] = _packOwnershipData(
from,
(_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)
);
// If the next slot may not have been initialized (i.e. `nextInitialized == false`) .
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
// If the next slot's address is zero and not burned (i.e. packed value is zero).
if (_packedOwnerships[nextTokenId] == 0) {
// If the next slot is within bounds.
if (nextTokenId != _currentIndex) {
// Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
emit Transfer(from, address(0), tokenId);
_afterTokenTransfers(from, address(0), tokenId, 1);
// Overflow not possible, as `_burnCounter` cannot be exceed `_currentIndex + _spotMinted` times.
unchecked {
_burnCounter++;
}
}
// =============================================================
// EXTRA DATA OPERATIONS
// =============================================================
/**
* @dev Directly sets the extra data for the ownership data `index`.
*/
function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {
uint256 packed = _packedOwnerships[index];
if (packed == 0) _revert(OwnershipNotInitializedForExtraData.selector);
uint256 extraDataCasted;
// Cast `extraData` with assembly to avoid redundant masking.
assembly {
extraDataCasted := extraData
}
packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);
_packedOwnerships[index] = packed;
}
/**
* @dev Called during each token transfer to set the 24bit `extraData` field.
* Intended to be overridden by the cosumer contract.
*
* `previousExtraData` - the value of `extraData` before transfer.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, `from`'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, `tokenId` will be burned by `from`.
* - `from` and `to` are never both zero.
*/
function _extraData(
address from,
address to,
uint24 previousExtraData
) internal view virtual returns (uint24) {}
/**
* @dev Returns the next extra data for the packed ownership data.
* The returned result is shifted into position.
*/
function _nextExtraData(
address from,
address to,
uint256 prevOwnershipPacked
) private view returns (uint256) {
uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);
return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;
}
// =============================================================
// OTHER OPERATIONS
// =============================================================
/**
* @dev Returns the message sender (defaults to `msg.sender`).
*
* If you are writing GSN compatible contracts, you need to override this function.
*/
function _msgSenderERC721A() internal view virtual returns (address) {
return msg.sender;
}
/**
* @dev Converts a uint256 to its ASCII string decimal representation.
*/
function _toString(uint256 value) internal pure virtual returns (string memory str) {
assembly {
// The maximum value of a uint256 contains 78 digits (1 byte per digit), but
// we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
// We will need 1 word for the trailing zeros padding, 1 word for the length,
// and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.
let m := add(mload(0x40), 0xa0)
// Update the free memory pointer to allocate.
mstore(0x40, m)
// Assign the `str` to the end.
str := sub(m, 0x20)
// Zeroize the slot after the string.
mstore(str, 0)
// Cache the end of the memory to calculate the length later.
let end := str
// We write the string from rightmost digit to leftmost digit.
// The following is essentially a do-while loop that also handles the zero case.
// prettier-ignore
for { let temp := value } 1 {} {
str := sub(str, 1)
// Write the character to the pointer.
// The ASCII index of the '0' character is 48.
mstore8(str, add(48, mod(temp, 10)))
// Keep dividing `temp` until zero.
temp := div(temp, 10)
// prettier-ignore
if iszero(temp) { break }
}
let length := sub(end, str)
// Move the pointer 32 bytes leftwards to make room for the length.
str := sub(str, 0x20)
// Store the length.
mstore(str, length)
}
}
/**
* @dev For more efficient reverts.
*/
function _revert(bytes4 errorSelector) internal pure {
assembly {
mstore(0x00, errorSelector)
revert(0x00, 0x04)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Base64.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to operate with Base64 strings.
*/
library Base64 {
/**
* @dev Base64 Encoding/Decoding Table
* See sections 4 and 5 of https://datatracker.ietf.org/doc/html/rfc4648
*/
string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
string internal constant _TABLE_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
/**
* @dev Converts a `bytes` to its Bytes64 `string` representation.
*/
function encode(bytes memory data) internal pure returns (string memory) {
return _encode(data, _TABLE, true);
}
/**
* @dev Converts a `bytes` to its Bytes64Url `string` representation.
* Output is not padded with `=` as specified in https://www.rfc-editor.org/rfc/rfc4648[rfc4648].
*/
function encodeURL(bytes memory data) internal pure returns (string memory) {
return _encode(data, _TABLE_URL, false);
}
/**
* @dev Internal table-agnostic conversion
*/
function _encode(bytes memory data, string memory table, bool withPadding) private pure returns (string memory) {
/**
* Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
*/
if (data.length == 0) return "";
// If padding is enabled, the final length should be `bytes` data length divided by 3 rounded up and then
// multiplied by 4 so that it leaves room for padding the last chunk
// - `data.length + 2` -> Prepare for division rounding up
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
// - `4 *` -> 4 characters for each chunk
// This is equivalent to: 4 * Math.ceil(data.length / 3)
//
// If padding is disabled, the final length should be `bytes` data length multiplied by 4/3 rounded up as
// opposed to when padding is required to fill the last chunk.
// - `4 * data.length` -> 4 characters for each chunk
// - ` + 2` -> Prepare for division rounding up
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
// This is equivalent to: Math.ceil((4 * data.length) / 3)
uint256 resultLength = withPadding ? 4 * ((data.length + 2) / 3) : (4 * data.length + 2) / 3;
string memory result = new string(resultLength);
assembly ("memory-safe") {
// Prepare the lookup table (skip the first "length" byte)
let tablePtr := add(table, 1)
// Prepare result pointer, jump over length
let resultPtr := add(result, 0x20)
let dataPtr := data
let endPtr := add(data, mload(data))
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
// set it to zero to make sure no dirty bytes are read in that section.
let afterPtr := add(endPtr, 0x20)
let afterCache := mload(afterPtr)
mstore(afterPtr, 0x00)
// Run over the input, 3 bytes at a time
for {
} lt(dataPtr, endPtr) {
} {
// Advance 3 bytes
dataPtr := add(dataPtr, 3)
let input := mload(dataPtr)
// To write each character, shift the 3 byte (24 bits) chunk
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
// Use this as an index into the lookup table, mload an entire word
// so the desired character is in the least significant byte, and
// mstore8 this least significant byte into the result and continue.
mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
resultPtr := add(resultPtr, 1) // Advance
}
// Reset the value that was cached
mstore(afterPtr, afterCache)
if withPadding {
// When data `bytes` is not exactly 3 bytes long
// it is padded with `=` characters at the end
switch mod(mload(data), 3)
case 1 {
mstore8(sub(resultPtr, 1), 0x3d)
mstore8(sub(resultPtr, 2), 0x3d)
}
case 2 {
mstore8(sub(resultPtr, 1), 0x3d)
}
}
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
uint256 private constant SPECIAL_CHARS_LOOKUP =
(1 << 0x08) | // backspace
(1 << 0x09) | // tab
(1 << 0x0a) | // newline
(1 << 0x0c) | // form feed
(1 << 0x0d) | // carriage return
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.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) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
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);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress-string} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress-string-uint256-uint256} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
*
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
*
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
* characters that are not in this range, but other tooling may provide different results.
*/
function escapeJSON(string memory input) internal pure returns (string memory) {
bytes memory buffer = bytes(input);
bytes memory output = new bytes(2 * buffer.length); // worst case scenario
uint256 outputLength = 0;
for (uint256 i; i < buffer.length; ++i) {
bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
output[outputLength++] = "\\";
if (char == 0x08) output[outputLength++] = "b";
else if (char == 0x09) output[outputLength++] = "t";
else if (char == 0x0a) output[outputLength++] = "n";
else if (char == 0x0c) output[outputLength++] = "f";
else if (char == 0x0d) output[outputLength++] = "r";
else if (char == 0x5c) output[outputLength++] = "\\";
else if (char == 0x22) {
// solhint-disable-next-line quotes
output[outputLength++] = '"';
}
} else {
output[outputLength++] = char;
}
}
// write the actual length and deallocate unused memory
assembly ("memory-safe") {
mstore(output, outputLength)
mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
}
return string(output);
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* 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;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
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
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// 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;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721A} from "../lib/ERC721A/contracts/ERC721A.sol";
import {Ownable} from "../lib/openzeppelin-contracts/contracts/access/Ownable.sol";
import {CavaNFT} from "./CavaNFT.sol";
contract CavaStaking is Ownable {
error CavaStaking__NotTheOwner(uint256 token);
error CavaStaking__NoTokensOwned();
error CavaStaking__NoStakingAllowed();
error CavaStaking__WrongTimeToUnstake();
error CavaStaking__TokenAlreadyStaked(uint256 token);
error CavaStaking__NotApproved();
error CavaStaking__WrongCaller();
error CavaStaking__NeedToBePaused();
struct User {
uint256 totalStaked;
uint256 alreadyStaked;
uint256[] tokens;
}
address private constant NFT_CONTRACT_ADDRESS = 0x0641fb636e842b043671247989b9F9456643107d;//0x6579cfD742D8982A7cDc4C00102D3087F6c6dd8E; // curtis / apechain
address private constant CAVA_ADDRESS = 0x1965131c250d128a2336F85bC7DEca803762770f; //curtis
bool private s_pause = false;
mapping(address userAddress => User userInfo) private s_user;
mapping(uint256 token => bool staked) private s_stakedTokens;
constructor() Ownable(msg.sender) {}
modifier paused {
if (s_pause == false){
revert CavaStaking__NeedToBePaused();
}
_;
}
function pauseStatus() public view returns(bool) {
return s_pause;
}
function changePauseStatus() public onlyOwner {
s_pause = !s_pause;
}
function getUser(address user) public view returns(User memory) {
return s_user[user];
}
function getUserTotalStaked(address user) public view returns(uint256) {
return s_user[user].totalStaked;
}
function getUserAlreadyStaked(address user) public view returns(uint256) {
return s_user[user].alreadyStaked;
}
function setAlreadyStaked(address _user, uint256 _stakedTokens) external {
if (msg.sender != CAVA_ADDRESS) revert CavaStaking__WrongCaller();
s_user[_user].alreadyStaked = _stakedTokens;
}
function stakeNfts(uint256[] calldata tokenIds) external {
if (CavaNFT(payable(CAVA_ADDRESS)).returnTequilaState() != 0) {
revert CavaStaking__NoStakingAllowed();
}
if (tokenIds.length == 0) {
revert CavaStaking__NoTokensOwned();
}
ERC721A nft = ERC721A(NFT_CONTRACT_ADDRESS);
if (!nft.isApprovedForAll(msg.sender, address(this))) {
revert CavaStaking__NotApproved();
}
User storage user = s_user[msg.sender];
for (uint256 i; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
if (nft.ownerOf(tokenId) != msg.sender) {
revert CavaStaking__NotTheOwner(tokenId);
}
if (s_stakedTokens[tokenId]) {
revert CavaStaking__TokenAlreadyStaked(tokenId);
}
nft.transferFrom(msg.sender, address(this), tokenId);
s_stakedTokens[tokenId] = true;
user.tokens.push(tokenId);
}
user.totalStaked += tokenIds.length;
}
// Function to call single owner nfts back
function unstakeNfts() external {
if (CavaNFT(payable(CAVA_ADDRESS)).returnTequilaState() < 1) {
revert CavaStaking__WrongTimeToUnstake();
}
User storage user = s_user[msg.sender];
if (user.totalStaked == 0) {
revert CavaStaking__NoTokensOwned();
}
ERC721A nft = ERC721A(NFT_CONTRACT_ADDRESS);
uint256[] memory tokens = user.tokens;
for (uint256 i; i < tokens.length; i++) {
uint256 tokenId = tokens[i];
nft.transferFrom(address(this), msg.sender, tokenId);
s_stakedTokens[tokenId] = false;
}
delete user.tokens;
user.totalStaked = 0;
}
// Function to roll back if something fails need to set pause on contract
function unstakeNftsEmergency() paused external {
User storage user = s_user[msg.sender];
if (user.totalStaked == 0) {
revert CavaStaking__NoTokensOwned();
}
ERC721A nft = ERC721A(NFT_CONTRACT_ADDRESS);
uint256[] memory tokens = user.tokens;
for (uint256 i; i < tokens.length; i++) {
uint256 tokenId = tokens[i];
nft.transferFrom(address(this), msg.sender, tokenId);
s_stakedTokens[tokenId] = false;
}
delete user.tokens;
user.totalStaked = 0;
}
function isTokenStaked(uint256 tokenId) public view returns(bool) {
return s_stakedTokens[tokenId];
}
}// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.3.0
// Creator: Chiru Labs
pragma solidity ^0.8.4;
/**
* @dev Interface of ERC721A.
*/
interface IERC721A {
/**
* The caller must own the token or be an approved operator.
*/
error ApprovalCallerNotOwnerNorApproved();
/**
* The token does not exist.
*/
error ApprovalQueryForNonexistentToken();
/**
* Cannot query the balance for the zero address.
*/
error BalanceQueryForZeroAddress();
/**
* Cannot mint to the zero address.
*/
error MintToZeroAddress();
/**
* The quantity of tokens minted must be more than zero.
*/
error MintZeroQuantity();
/**
* The token does not exist.
*/
error OwnerQueryForNonexistentToken();
/**
* The caller must own the token or be an approved operator.
*/
error TransferCallerNotOwnerNorApproved();
/**
* The token must be owned by `from`.
*/
error TransferFromIncorrectOwner();
/**
* Cannot safely transfer to a contract that does not implement the
* ERC721Receiver interface.
*/
error TransferToNonERC721ReceiverImplementer();
/**
* Cannot transfer to the zero address.
*/
error TransferToZeroAddress();
/**
* The token does not exist.
*/
error URIQueryForNonexistentToken();
/**
* The `quantity` minted with ERC2309 exceeds the safety limit.
*/
error MintERC2309QuantityExceedsLimit();
/**
* The `extraData` cannot be set on an unintialized ownership slot.
*/
error OwnershipNotInitializedForExtraData();
/**
* `_sequentialUpTo()` must be greater than `_startTokenId()`.
*/
error SequentialUpToTooSmall();
/**
* The `tokenId` of a sequential mint exceeds `_sequentialUpTo()`.
*/
error SequentialMintExceedsLimit();
/**
* Spot minting requires a `tokenId` greater than `_sequentialUpTo()`.
*/
error SpotMintTokenIdTooSmall();
/**
* Cannot mint over a token that already exists.
*/
error TokenAlreadyExists();
/**
* The feature is not compatible with spot mints.
*/
error NotCompatibleWithSpotMints();
// =============================================================
// STRUCTS
// =============================================================
struct TokenOwnership {
// The address of the owner.
address addr;
// Stores the start time of ownership with minimal overhead for tokenomics.
uint64 startTimestamp;
// Whether the token has been burned.
bool burned;
// Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
uint24 extraData;
}
// =============================================================
// TOKEN COUNTERS
// =============================================================
/**
* @dev Returns the total number of tokens in existence.
* Burned tokens will reduce the count.
* To get the total number of tokens minted, please see {_totalMinted}.
*/
function totalSupply() external view returns (uint256);
// =============================================================
// IERC165
// =============================================================
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
* to learn more about how these ids are created.
*
* This function call must use less than 30000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
// =============================================================
// IERC721
// =============================================================
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables
* (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in `owner`'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`,
* checking first that contract recipients are aware of the ERC721 protocol
* to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move
* this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement
* {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external payable;
/**
* @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external payable;
/**
* @dev Transfers `tokenId` from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom}
* whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token
* by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external payable;
/**
* @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 payable;
/**
* @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);
// =============================================================
// IERC721Metadata
// =============================================================
/**
* @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);
// =============================================================
// IERC2309
// =============================================================
/**
* @dev Emitted when tokens in `fromTokenId` to `toTokenId`
* (inclusive) is transferred from `from` to `to`, as defined in the
* [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
*
* See {_mintERC2309} for more details.
*/
event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(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 towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* 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 {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, 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.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
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⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev 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) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* 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 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}{
"remappings": [
"@pythnetwork/pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"ERC721A/=lib/ERC721A/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"foundry-devops/=lib/foundry-devops/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ApprovalCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"ApprovalQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"BalanceQueryForZeroAddress","type":"error"},{"inputs":[],"name":"CavaNFT__AnejoPriceNotSet","type":"error"},{"inputs":[],"name":"CavaNFT__DecisionNotAllowed","type":"error"},{"inputs":[],"name":"CavaNFT__ErrorInSell","type":"error"},{"inputs":[],"name":"CavaNFT__IncorrectAmount","type":"error"},{"inputs":[],"name":"CavaNFT__IncorrectTimeForAging","type":"error"},{"inputs":[],"name":"CavaNFT__InsufficientAnejoFunds","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"CavaNFT__InsufficientApeForPurchase","type":"error"},{"inputs":[],"name":"CavaNFT__InsufficientReposadoFunds","type":"error"},{"inputs":[],"name":"CavaNFT__MaxExtraBottleReached","type":"error"},{"inputs":[],"name":"CavaNFT__NoApeIsBeingTranferred","type":"error"},{"inputs":[],"name":"CavaNFT__NoChangeAllowed","type":"error"},{"inputs":[],"name":"CavaNFT__NotEnoughNFTs","type":"error"},{"inputs":[],"name":"CavaNFT__NotOwnerOfToken","type":"error"},{"inputs":[],"name":"CavaNFT__PurchaseNotAllowed","type":"error"},{"inputs":[],"name":"CavaNFT__ReposadoPriceNotSet","type":"error"},{"inputs":[],"name":"CavaNFT__TokensAreAgingAlready","type":"error"},{"inputs":[],"name":"CavaNFT__UseDesignatedDepositFunctions","type":"error"},{"inputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"name":"CavaNFT__WrongPriceFetched","type":"error"},{"inputs":[],"name":"CavaNFT__ZeroPriceBottle","type":"error"},{"inputs":[],"name":"CavaNFT__ZeroTokensnotAllowed","type":"error"},{"inputs":[],"name":"MintERC2309QuantityExceedsLimit","type":"error"},{"inputs":[],"name":"MintToZeroAddress","type":"error"},{"inputs":[],"name":"MintZeroQuantity","type":"error"},{"inputs":[],"name":"NotCompatibleWithSpotMints","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"OwnerQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"OwnershipNotInitializedForExtraData","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"SequentialMintExceedsLimit","type":"error"},{"inputs":[],"name":"SequentialUpToTooSmall","type":"error"},{"inputs":[],"name":"SpotMintTokenIdTooSmall","type":"error"},{"inputs":[],"name":"TokenAlreadyExists","type":"error"},{"inputs":[],"name":"TransferCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"TransferFromIncorrectOwner","type":"error"},{"inputs":[],"name":"TransferToNonERC721ReceiverImplementer","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"inputs":[],"name":"URIQueryForNonexistentToken","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"AnejoMoneyTransferredToContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ApeClaimedFromAnejo","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ApeClaimedFromReposado","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum CavaNFT.AgingState","name":"","type":"uint8"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"bottles","type":"uint256"}],"name":"BottlesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"fromTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toTokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"ConsecutiveTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ReposadoMoneyTransferredToContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"AnejoSellprice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BottleMintprice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ExtraBottleSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MaxExtraBottleSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ReposadoSellprice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"advanceState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"anejoBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bottlesBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"changeBottleMintPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"changeExtraBottleSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens","type":"uint256[]"}],"name":"claimAnejoApe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens","type":"uint256[]"}],"name":"claimAnejoBottle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens","type":"uint256[]"}],"name":"claimReposadoApe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokens","type":"uint256[]"}],"name":"claimReposadoBottle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentTequilaState","outputs":[{"internalType":"enum CavaNFT.AgingState","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getTokenInfo","outputs":[{"components":[{"internalType":"enum CavaNFT.AgingState","name":"agingState","type":"uint8"},{"internalType":"enum CavaNFT.TokenChoice","name":"tokenChoice","type":"uint8"},{"internalType":"bool","name":"noChange","type":"bool"}],"internalType":"struct CavaNFT.Token","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"purchaseExtraTequilaBottle","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reposadoBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"returnTequilaState","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"setAnejoPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"setReposadoPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakingAddress","type":"address"}],"name":"setStakingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferAnejoMoneyToContract","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"transferMoneyToContract","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferReposadoMoneyToContract","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tokens","type":"uint256[]"},{"internalType":"uint256","name":"_choice","type":"uint256"}],"name":"userTokenDecision","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"verifyBalances","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdrawABottles","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAnejo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawReposado","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6080604052346101bb576100116101f6565b6100196101f6565b8151916001600160401b0383116101b65761003e83610039600254610226565b61025e565b602090601f841160011461013057928061007192610079955f92610125575b50508160011b915f199060031b1c19161790565b6002556102fd565b5f805533156101115761008b336103d6565b6100956001600a55565b61009f60c8601155565b6100a85f601355565b6100b760ff1960165416601655565b6100c660ff19600d5416600d55565b6100cf42600f55565b61010260405160208101906100fa816100ec428560209181520190565b03601f1981018352826101d3565b519020601055565b604051613b40908161041f8239f35b631e4fbdf760e01b5f90815260045260245ffd5b015190505f8061005d565b60025f52601f19841691907f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace925f5b81811061019e5750916001939186610079979410610186575b505050811b016002556102fd565b01515f1960f88460031b161c191690555f8080610178565b9293602060018192878601518155019501930161015f565b6101bf565b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b038211908210176101b657604052565b60408051919082016001600160401b038111838210176101b65760405260048252634341564160e01b6020830152565b90600182811c92168015610254575b602083101461024057565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610235565b601f811161026a575050565b60025f5260205f20906020601f840160051c830193106102a4575b601f0160051c01905b818110610299575050565b5f815560010161028e565b9091508190610285565b601f82116102bb57505050565b5f5260205f20906020601f840160051c830193106102f3575b601f0160051c01905b8181106102e8575050565b5f81556001016102dd565b90915081906102d4565b80519091906001600160401b0381116101b6576103268161031f600354610226565b60036102ae565b602092601f821160011461035a57610355929382915f926101255750508160011b915f199060031b1c19161790565b600355565b60035f52601f198216937fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b915f5b8681106103be57508360019596106103a6575b505050811b01600355565b01515f1960f88460031b161c191690555f808061039b565b91926020600181928685015181550194019201610388565b600980546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a356fe60806040526004361015610023575b361561001e5761001c612a06565b005b612a36565b5f3560e01c806301ffc9a71461034257806306fdde031461033d578063081812fc14610338578063095ea7b3146103335780630dfe5c541461032e5780630e0e6ba71461032957806312065fe0146103245780631249c58b1461031f57806317edb0471461031a57806318160ddd1461031557806320d5ddda1461031057806323b872dd1461030b5780632dd91ca31461030657806332cb6b0c146103015780633a27e6fb146102fc5780633a7c03ca146102f757806342842e0e146102f2578063441e56f4146102ed57806345b7b54e146102e857806345ca9625146102e357806351b143e4146102de57806357e3fb70146102d957806362175766146102d45780636352211e146102cf5780636765c4ec146102ca57806370a08231146102c5578063715018a6146102c05780637721e567146102bb5780637c0840d1146102b65780637fb54f8b146102b157806384ecdaf6146102ac5780638c7a63ae146102a75780638da5cb5b146102a257806394c37a1c1461029d57806395d89b41146102985780639d540f33146102935780639f8317701461028e578063a22cb46514610289578063adaec91a14610284578063b862b0981461027f578063b88d4fde1461027a578063c87b56dd14610275578063ccddeda714610270578063e02f6ce61461026b578063e7a42fef14610266578063e922fc3f14610261578063e985e9c51461025c578063f2fde38b14610257578063f4e0d9ac146102525763fedf84f60361000e576122ce565b612267565b6121dd565b612179565b612111565b6120f0565b611f2f565b611f1c565b611a72565b6119e7565b61193b565b6118f9565b611868565b61184b565b611668565b6115b3565b611530565b611508565b611484565b611388565b61136b565b6112e2565b611269565b61120e565b6111b3565b611063565b611034565b611013565b610ea7565b610bc8565b610b19565b610af8565b610adb565b610ab7565b610a85565b610a63565b610a47565b61090b565b6108f9565b6108b3565b610892565b610875565b610698565b61067d565b610644565b610621565b610560565b610500565b61040d565b61035d565b6001600160e01b031981160361035957565b5f80fd5b3461035957602036600319011261035957602060043561037c81610347565b63ffffffff60e01b166301ffc9a760e01b81149081156103ba575b81156103a9575b506040519015158152f35b635b5e139f60e01b1490505f61039e565b6380ac58cd60e01b81149150610397565b5f91031261035957565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602061040a9281815201906103d5565b90565b34610359575f366003190112610359576040515f6002548060011c90600181169081156104f6575b6020831082146104e25782855260208501919081156104c95750600114610477575b6104738461046781860382611999565b604051918291826103f9565b0390f35b60025f9081529250907f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b8184106104b55750500161046782610457565b8054848401526020909301926001016104a2565b60ff191682525090151560051b01905061046782610457565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610435565b346103595760203660031901126103595760043561051d81612a45565b15610540575f526006602052602060018060a01b0360405f205416604051908152f35b6333d1c03960e21b5f5260045ffd5b6001600160a01b0381160361035957565b6040366003190112610359576004356105788161054f565b602435906001600160a01b0361058d83612c51565b16908133036105fc575b6105cc816105ad855f52600660205260405f2090565b80546001600160a01b0319166001600160a01b03909216919091179055565b6001600160a01b0316907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a4005b5f82815260076020908152604080832033845290915290205460ff1661059757612a84565b34610359575f36600319011261035957602061063b61234f565b54604051908152f35b3461035957602036600319011261035957600435610660612aeb565b601254811061066e57601155005b634e2e320d60e01b5f5260045ffd5b34610359575f36600319011261035957602047604051908152f35b34610359575f366003190112610359576106b0612b12565b6016546106d6906106ca9060081c6001600160a01b031681565b6001600160a01b031690565b6040516337178b4b60e11b815233600482015290602082602481845afa918215610811575f92610854575b506040516312c6c3ab60e31b8152336004820152602081602481855afa908115610811575f91610825575b50808311156108165761073f9083612398565b908115610816576107696115b36107628461075d5f54600154900390565b6123eb565b11156123f8565b803b1561035957604051632162f0df60e01b815233600482015260248101939093525f908390604490829084905af1918215610811576107ed926107f7575b506107e76010546040516107df816107d160208201944290869091604092825260208201520190565b03601f198101835282611999565b519020601055565b33612b32565b61001c6001600a55565b806108055f61080b93611999565b806103cb565b5f6107a8565b612379565b631b9fb0b360e01b5f5260045ffd5b610847915060203d60201161084d575b61083f8183611999565b81019061236a565b5f61072c565b503d610835565b61086e91925060203d60201161084d5761083f8183611999565b905f610701565b34610359575f366003190112610359576020601454604051908152f35b34610359575f3660031901126103595760205f546001549003604051908152f35b34610359575f36600319011261035957602061063b612431565b6060906003190112610359576004356108e58161054f565b906024356108f28161054f565b9060443590565b61001c610905366108cd565b9161244f565b602036600319011261035957600435610922612b12565b600d5460ff1661093181611432565b610a38576013548015610a29576109489082612618565b908115610a1557813410610a0257610962816012546123eb565b601154106109f3576109838161097b6109889333612b32565b6012546123eb565b601255565b6109a8602760405166424f54544c455360c81b8152600c60078201522090565b6109b38282546123eb565b90558034116109c65761001c6001600a55565b5f80806109d4819434612398565b8181156109ea575b3390f115610811575f6107ed565b506108fc6109dc565b6329722adb60e01b5f5260045ffd5b63db657dd560e01b5f523460045260245ffd5b63012e5f6760e21b5f52600482905260245ffd5b630a8c768360e11b5f5260045ffd5b63c79cd92760e01b5f5260045ffd5b34610359575f3660031901126103595760206040516115b38152f35b34610359575f366003190112610359576020610a7d61262b565b604051908152f35b34610359575f36600319011261035957602061063b602760405166424f54544c455360c81b8152600c60078201522090565b61001c610ac3366108cd565b9060405192610ad3602085611999565b5f845261289b565b34610359575f366003190112610359576020601354604051908152f35b3461035957602036600319011261035957600435610b14612aeb565b601355005b34610359575f36600319011261035957610b31612aeb565b610b39612b12565b5f808080602560405164414e454a4f60d81b8152600c6005820152205460018060a01b03600954165af1610b6b612673565b50610b78575b6001600a55005b5f602560405164414e454a4f60d81b8152600c60058201522055610b71565b9181601f840112156103595782359167ffffffffffffffff8311610359576020808501948460051b01011161035957565b346103595760403660031901126103595760043567ffffffffffffffff811161035957610bf9903690600401610b97565b602435918215610e6957600d5460ff16610c1281611432565b8015610e5a5780610c24600192611432565b03610d7f57610c35600f5442612398565b62cb07001015610c4157005b9060018314905f5b818110610c5257005b610c826020610c628385886126b6565b6040516331a9108f60e11b81529035600482015291829081906024820190565b0381305afa908115610811575f91610d51575b50336001600160a01b0390911603610d4257600190610cdb610cb9600d5460ff1690565b610cd6610cc784878a6126b6565b355f52600b60205260405f2090565b612712565b610cfd610cec610cc78386896126b6565b805462ff0000191662010000179055565b8315610d1f57610d19610d14610cc78386896126b6565b612743565b01610c49565b60028603610d1957610d3d610d38610cc78386896126b6565b61272a565b610d19565b639e68e5cd60e01b5f5260045ffd5b610d72915060203d8111610d78575b610d6a8183611999565b8101906126cb565b5f610c95565b503d610d60565b610d8b600f5442612398565b6301e91c801015610d9857005b9060018314905f5b818110610da957005b610db96020610c628385886126b6565b0381305afa908115610811575f91610e3c575b50336001600160a01b0390911603610d4257600190610df0610cb9600d5460ff1690565b610e01610cec610cc78386896126b6565b8315610e1e57610e18610d14610cc78386896126b6565b01610da0565b60028603610e1857610e37610d38610cc78386896126b6565b610e18565b610e54915060203d8111610d7857610d6a8183611999565b5f610dcc565b63ed21b97f60e01b5f5260045ffd5b631b8a520f60e31b5f5260045ffd5b6020600319820112610359576004359067ffffffffffffffff821161035957610ea391600401610b97565b9091565b3461035957610eb536610e78565b610ebd612b12565b5f915f5b828110610f355783610ed16127e9565b905f5b8251811015610ef95780610ef3610eed60019386612831565b5161356c565b01610ed4565b506040517fc733f2d8c356aef2f8196bcdd071901023a40b280983285669d40da73455d754339180610f2a81611916565b0390a36107ed612845565b610f456020610c628386866126b6565b0381305afa908115610811575f91610ff5575b50336001600160a01b0390911603610d4257610f80610f7b610cc78386866126b6565b61275c565b60018151610f8d81611432565b610f9681611432565b149081610fd4575b50610fac575b600101610ec1565b92610fb86001916123a5565b93610fcd610fc78286866126b6565b3561279d565b9050610fa4565b6002915060200151610fe581611432565b610fee81611432565b145f610f9e565b61100d915060203d8111610d7857610d6a8183611999565b5f610f58565b346103595760203660031901126103595760043561102f612aeb565b601455005b346103595760203660031901126103595760206001600160a01b0361105a600435612c51565b16604051908152f35b346103595761107136610e78565b611079612b12565b5f915f5b8281106110e0578361108d6127e9565b905f5b82518110156110af57806110a9610eed60019386612831565b01611090565b506040517fc733f2d8c356aef2f8196bcdd071901023a40b280983285669d40da73455d754339180610f2a8161192a565b6110f06020610c628386866126b6565b0381305afa908115610811575f91611195575b50336001600160a01b0390911603610d4257611126610f7b610cc78386866126b6565b6002815161113381611432565b61113c81611432565b149081611174575b50611152575b60010161107d565b9261115e6001916123a5565b9361116d610fc78286866126b6565b905061114a565b600291506020015161118581611432565b61118e81611432565b145f611144565b6111ad915060203d8111610d7857610d6a8183611999565b5f611103565b34610359576020366003190112610359576004356111d08161054f565b6001600160a01b031680156111ff575f526005602052602067ffffffffffffffff60405f205416604051908152f35b6323d3ad8160e21b5f5260045ffd5b34610359575f36600319011261035957611226612aeb565b600980546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b5f3660031901126103595734156112d357602560405164414e454a4f60d81b8152600c6005820152208054903482018092116112ce57556040513481527f23199407c520d738b79c0cf7a883c87fef37b99f89519fb5fa671764d76d884460203392a2005b612384565b6338fc0f5560e01b5f5260045ffd5b34610359575f36600319011261035957476028604051675245504f5341444f60c01b8152600c6008820152205490602560405164414e454a4f60d81b8152600c6005820152205482018092116112ce5761135a61047392602760405166424f54544c455360c81b8152600c60078201522054906123eb565b604051911481529081906020820190565b34610359575f366003190112610359576020601154604051908152f35b34610359575f366003190112610359576113a0612aeb565b6113ac600f5442612398565b600d5460ff166113bb81611432565b801580611425575b80611418575b156113d857505061001c6126f9565b806113e4600192611432565b149081611409575b50156113fa5761001c6126e0565b638d2adffd60e01b5f5260045ffd5b6301baf800915010155f6113ec565b506301baf80082106113c9565b50629ce2808210156113c3565b6003111561143c57565b634e487b7160e01b5f52602160045260245ffd5b9190916040806060830194805161146681611432565b8452602081015161147681611432565b602085015201511515910152565b34610359576020366003190112610359576004355f604080516114a681611978565b82815282602082015201525f52600b60205261047360405f2060ff604051916114ce83611978565b548181166114db81611432565b8352818160081c166114ec81611432565b602084015260101c161515604082015260405191829182611450565b34610359575f366003190112610359576009546040516001600160a01b039091168152602090f35b34610359575f36600319011261035957611548612aeb565b611550612b12565b5f8080806028604051675245504f5341444f60c01b8152600c6008820152205460018060a01b03600954165af1611585612673565b50611591576001600a55005b5f6028604051675245504f5341444f60c01b8152600c60088201522055610b71565b34610359575f366003190112610359576040515f6003548060011c906001811690811561165e575b6020831082146104e25782855260208501919081156104c9575060011461160c576104738461046781860382611999565b60035f9081529250907fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b81841061164a5750500161046782610457565b805484840152602090930192600101611637565b91607f16916115db565b346103595761167636610e78565b9061167f612b12565b60145491821561183c575f915f5b82811061176957846116a7856116a16127e9565b92612618565b801561175a57806116b6612431565b541061174b576116d55f80808085335af16116cf612673565b50612894565b6116dd612431565b6116e8828254612398565b90555f5b825181101561170b5780611705610eed60019386612831565b016116ec565b60408051338152602081018490527f1afc46a1f05671e74e4c42ddc0e719050c41a0014666b6c4826c7cfc5fd6931b91819081015b0390a16107ed612845565b63086cd50760e21b5f5260045ffd5b6358b508c960e11b5f5260045ffd5b6117796020610c628386866126b6565b0381305afa908115610811575f9161181e575b50336001600160a01b0390911603610d42576117af610f7b610cc78386866126b6565b600181516117bc81611432565b6117c581611432565b1490816117fd575b506117db575b60010161168d565b926117e76001916123a5565b936117f6610fc78286866126b6565b90506117d3565b600191506020015161180e81611432565b61181781611432565b145f6117cd565b611836915060203d8111610d7857610d6a8183611999565b5f61178c565b636647450560e01b5f5260045ffd5b34610359575f366003190112610359576020601254604051908152f35b34610359576040366003190112610359576004356118858161054f565b6024359081151580920361035957335f9081526007602090815260408083206001600160a01b0385168452909152902060ff1981541660ff841617905560405191825260018060a01b0316907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a3005b34610359575f366003190112610359576020601554604051908152f35b906001602083019261192782611432565b52565b906002602083019261192782611432565b34610359575f36600319011261035957602060ff600d54166040519061196081611432565b8152f35b634e487b7160e01b5f52604160045260245ffd5b6060810190811067ffffffffffffffff82111761199457604052565b611964565b90601f8019910116810190811067ffffffffffffffff82111761199457604052565b906119c96040519283611999565b565b67ffffffffffffffff811161199457601f01601f191660200190565b6080366003190112610359576004356119ff8161054f565b60243590611a0c8261054f565b6044356064359267ffffffffffffffff8411610359573660238501121561035957836004013592611a3c846119cb565b93611a4a6040519586611999565b8085523660248288010111610359576020815f92602461001c9901838901378601015261289b565b3461035957602036600319011261035957600435611a97611a9282612a45565b6128dc565b611ab6611aac825f52600b60205260405f2090565b5460101c60ff1690565b611ad2611acb835f52600b60205260405f2090565b5460ff1690565b6060918291611ae3600d5460ff1690565b91611aed83611432565b82611e23575050505050611aff6129ab565b611b076129d0565b915b611b1281612dce565b604080517f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323060208201527f30302f737667222076696577426f783d2230203020333030203330302220737491810191909152753cb6329e9137bb32b9333637bb9d3434b23232b7111f60511b606082015292839190607683017f3c646566733e3c636c6970506174682069643d226672616d65223e3c7265637481527f2077696474683d2233303022206865696768743d22333030222f3e3c2f636c6960208201526c382830ba341f1e17b232b3399f60991b6040820152604d017f3c726563742077696474683d2233303022206865696768743d2233303022206681526434b6361e9160d91b6020820152602501611c2a916129f4565b6211179f60e91b81526003017f3c6720636c69702d706174683d2275726c28236672616d6529223e00000000008152601b01611c65916129f4565b691e17b39f1e17b9bb339f60b11b8152600a0103601f1981018352611c8a9083611999565b611c93906133af565b90611c9d90613505565b6040516e7b226e616d65223a2243415641202360881b6020820152928392602f8401611cc8916129f4565b7f222c226465736372697074696f6e223a224f6e2d636861696e2061676564207481527f657175696c61204e465420776974682064796e616d696320616e696d6174696f6020820152621b888b60ea1b60408201526043017f2261747472696275746573223a5b7b2274726169745f74797065223a2253746181526c3a329116113b30b63ab2911d1160991b6020820152602d01611d65916129f4565b7f227d5d2c22696d616765223a22646174613a696d6167652f7376672b786d6c3b81526618985cd94d8d0b60ca1b6020820152602701611da4916129f4565b61227d60f01b815260020103601f1981018252611dc19082611999565b611dca90613505565b6040517f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c0000006020820152908190603d8201611e03916129f4565b03601f1981018252611e159082611999565b6040516104738192826103f9565b611e2c83611432565b60018303611e50575050505050611e41612960565b611e49612985565b915b611b09565b611e5983611432565b60028314928380611f10575b80611efd575b15611e7e57505050505050611e41612960565b611e8781611432565b8380611ef5575b15611ea957505050505050611ea1612918565b611e4961293d565b611eb69096949596611432565b82611ee8575b5081611ed4575b5015611e4b57915050611ea1612918565b60029150611ee181611432565b145f611ec3565b151560011491505f611ebc565b508115611e8e565b50611f0783611432565b60018314611e6b565b50600182151514611e65565b5f3660031901126103595761001c612a06565b3461035957611f3d36610e78565b90611f46612b12565b6015549182156120e1575f915f5b82811061200e5784611f68856116a16127e9565b801561175a5780611f7761234f565b5410611fff57611f905f80808085335af16116cf612673565b611f9861234f565b611fa3828254612398565b90555f5b8251811015611fc65780611fc0610eed60019386612831565b01611fa7565b60408051338152602081018490527f8b3d127bdbb0408980985ecd4d18fe6b4b08955cb26b71c096539a4e4c6a1ba39181908101611740565b637f96ce8160e11b5f5260045ffd5b61201e6020610c628386866126b6565b0381305afa908115610811575f916120c3575b50336001600160a01b0390911603610d4257612054610f7b610cc78386866126b6565b6002815161206181611432565b61206a81611432565b1490816120a2575b50612080575b600101611f54565b9261208c6001916123a5565b9361209b610fc78286866126b6565b9050612078565b60019150602001516120b381611432565b6120bc81611432565b145f612072565b6120db915060203d8111610d7857610d6a8183611999565b5f612031565b632b087dc160e11b5f5260045ffd5b346103595760203660031901126103595760043561210c612aeb565b601555005b5f3660031901126103595734156112d3576028604051675245504f5341444f60c01b8152600c6008820152208054903482018092116112ce57556040513481527fec8ef3e5ffbb74357245a84bc2cc890a34d96c5e26d5991f2bb16e43ff913a8160203392a2005b3461035957604036600319011261035957602060ff6121d160043561219d8161054f565b602435906121aa8261054f565b60018060a01b03165f526007845260405f209060018060a01b03165f5260205260405f2090565b54166040519015158152f35b34610359576020366003190112610359576004356121fa8161054f565b612202612aeb565b6001600160a01b0316801561225457600980546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b631e4fbdf760e01b5f525f60045260245ffd5b34610359576020366003190112610359576004356122848161054f565b61228c612aeb565b601654600160ff82161515146122bf576001600160a81b03191660089190911b610100600160a81b031617600117601655005b634ec7eee560e01b5f5260045ffd5b34610359575f366003190112610359576122e6612aeb565b6122ee612b12565b5f808080602760405166424f54544c455360c81b8152600c6007820152205460018060a01b03600954165af1612322612673565b5061232e576001600a55005b5f602760405166424f54544c455360c81b8152600c60078201522055610b71565b602560405164414e454a4f60d81b8152600c60058201522090565b90816020910312610359575190565b6040513d5f823e3d90fd5b634e487b7160e01b5f52601160045260245ffd5b919082039182116112ce57565b90600182018092116112ce57565b60140190816014116112ce57565b601e019081601e116112ce57565b60040190816004116112ce57565b90600282018092116112ce57565b919082018092116112ce57565b156123ff57565b60405162461bcd60e51b815260206004820152600a6024820152694d617820737570706c7960b01b6044820152606490fd5b6028604051675245504f5341444f60c01b8152600c60088201522090565b919061245a82612c51565b6001600160a01b039384169381168490036125e5575f838152600660205260409020805461249b6001600160a01b03871633908114908314171590565b1590565b6125a2575b612599575b506001600160a01b0384165f90815260056020526040902080545f190190556001600160a01b0382165f908152600560205260409020805460010190556001600160a01b0382164260a01b17600160e11b17612509845f52600460205260405f2090565b55600160e11b811615612554575b506001600160a01b03169182907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a41561254f57565b612ab0565b6001830161256a815f52600460205260405f2090565b5415612577575b50612517565b5f54811461257157612591905f52600460205260405f2090565b555f80612571565b5f90555f6124a5565b6125db612497611acb336125c68a60018060a01b03165f52600760205260405f2090565b9060018060a01b03165f5260205260405f2090565b156124a057612aa1565b612a93565b908160011b91808304600214901517156112ce57565b600281901b91906001600160fe1b038116036112ce57565b818102929181159184041417156112ce57565b60ff600d541661263a81611432565b8061264457505f90565b60019061265081611432565b0361265a57600190565b600290565b6040519061266e602083611999565b5f8252565b3d1561269d573d90612684826119cb565b916126926040519384611999565b82523d5f602084013e565b606090565b634e487b7160e01b5f52603260045260245ffd5b91908110156126c65760051b0190565b6126a2565b90816020910312610359575161040a8161054f565b6126ea6002611432565b600260ff19600d541617600d55565b6127036001611432565b600160ff19600d541617600d55565b9061271c81611432565b60ff80198354169116179055565b6127346002611432565b805461ff001916610200179055565b61274d6001611432565b805461ff001916610100179055565b9060405161276981611978565b604060ff82945481811661277c81611432565b8452818160081c1661278d81611432565b602085015260101c161515910152565b600e5468010000000000000000811015611994576001810180600e558110156126c657600e5f527fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd0155565b60405190600e548083528260208101600e5f5260205f20925f5b8181106128185750506119c992500383611999565b8454835260019485019487945060209093019201612803565b80518210156126c65760209160051b010190565b600e545f600e55806128545750565b600e5f527fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd908101905b818110612889575050565b5f815560010161287e565b1561035957565b9291906128a982828661244f565b803b6128b6575b50505050565b6128bf93612da6565b156128cd575f8080806128b0565b6368d2bf6b60e11b5f5260045ffd5b156128e357565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b6044820152606490fd5b60405190612927604083611999565b60078252660233842303030360cc1b6020830152565b6040519061294c604083611999565b6005825264416e656a6f60d81b6020830152565b6040519061296f604083611999565b60078252660234646443730360cc1b6020830152565b60405190612994604083611999565b60088252675265706f7361646f60c01b6020830152565b604051906129ba604083611999565b600782526611a318231c232360c91b6020830152565b604051906129df604083611999565b6006825265426c616e636f60d01b6020830152565b805191908290602001825e015f815290565b34156112d357602760405166424f54544c455360c81b8152600c6007820152208054903482018092116112ce5755565b636edd855560e01b5f5260045ffd5b905f915f548110612a535750565b9091505b805f52600460205260405f205480612a78575080156112ce575f1901612a57565b600160e01b1615919050565b6367d9dca160e11b5f5260045ffd5b62a1148160e81b5f5260045ffd5b632ce44b5f60e11b5f5260045ffd5b633a954ecd60e21b5f5260045ffd5b63b562e8dd60e01b5f5260045ffd5b622e076360e81b5f5260045ffd5b636f96cda160e11b5f5260045ffd5b6009546001600160a01b03163303612aff57565b63118cdaa760e01b5f523360045260245ffd5b6002600a5414612b23576002600a55565b633ee5aeb560e01b5f5260045ffd5b9160405190612b42602083611999565b5f82525f54918315612c4c576001600160a01b0385164260a01b6001861460e11b1717612b77845f52600460205260405f2090565b556001600160a01b0385165f8181526005602052604090208054680100000000000000018702019055938415612c4757808401939560015b15612be2575b5f87875f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4612baf565b9560010195848703612bb557929550929093505f55803b612c0257505050565b9091925f549283039260015b15612c32575b5f612c2761249787600188019787612d07565b15612c0e575b6128cd565b808410612c145792509250505f540361035957565b612ace565b612abf565b612c63815f52600460205260405f2090565b54908115612c7a5750600160e01b8116612adc5790565b90505f54811015612adc575b5f19015f81815260046020526040902054908115612cba5750600160e01b81161561040a57636f96cda160e11b5f5260045ffd5b9050612c86565b90816020910312610359575161040a81610347565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261040a929101906103d5565b91612d2e926020925f604051809681958294630a85bd0160e11b8452843360048601612cd6565b03926001600160a01b03165af15f9181612d75575b50612d5f57612d50612673565b805115612c2d57805190602001fd5b6001600160e01b031916630a85bd0160e11b1490565b612d9891925060203d602011612d9f575b612d908183611999565b810190612cc1565b905f612d43565b503d612d86565b906020925f612d2e959360405196879586948593630a85bd0160e11b85523360048601612cd6565b601054600d546060925f929160ff16908115915b600a8510612df257505050505090565b9091929394604051602081019086825284604082015287606082015260608152612e1d608082611999565b519020905f612e37611aac865f52600b60205260405f2090565b612e4c611acb875f52600b60205260405f2090565b612e5586611432565b87156132aa575050505f5b612e6c602884066123b3565b90612e778460081c90565b60f09006612e84906123c1565b612e8e8560101c90565b60f09006612e9b906123c1565b92612ea68660181c90565b603d9006612eb39061369b565b8b612ebe8860201c90565b603d9006612ecb9061369b565b92612ed68960281c90565b60039006612ee3906123cf565b612eed81966133af565b97612ef7906133af565b99612f01836133af565b97612f0b916139ad565b92612f15826133af565b91612f1f9161367d565b612f28906133af565b612f31836133af565b91612f3b846125ea565b612f44906133af565b93612f4e906133af565b94612f58896133af565b96612f6290613ac3565b97612f6c90613ac3565b98612f76906133af565b6040517f3c67207472616e73666f726d3d227472616e736c61746528000000000000000060208201529d8e9c919b9160388e01612fb2916129f4565b600b60fa1b8152600101612fc5916129f4565b6214911f60e91b81526003016a1e31b4b931b63290391e9160a91b8152600b01612fee916129f4565b6711103334b6361e9160c11b8152600801613008916129f4565b6d111037b830b1b4ba3c9e9118111f60911b8152600e017f3c616e696d617465206174747269627574654e616d653d226f7061636974792281527f2076616c7565733d22303b302e373b3022206475723d220000000000000000006020820152603701613074916129f4565b6203991160ed1b815260030167626567696e3d222d60c01b815260080161309a916129f4565b7f732220726570656174436f756e743d22696e646566696e697465222f3e0000008152601d017f3c616e696d617465206174747269627574654e616d653d2272222076616c7565815262399e9160e91b60208201526023016130fb916129f4565b603b60f81b815260010161310e916129f4565b603b60f81b8152600101613121916129f4565b61011160f51b815260020164323ab91e9160d91b8152600501613143916129f4565b7f732220726570656174436f756e743d22696e646566696e697465222f3e0000008152601d017f3c616e696d6174655472616e73666f726d206174747269627574654e616d653d81527f227472616e73666f726d2220747970653d227472616e736c61746522200000006020820152603d016b76616c7565733d22302c303b60a01b8152600c016131d3916129f4565b600b60fa1b81526001016131e6916129f4565b6501d98161811160d51b815260060164323ab91e9160d91b815260050161320c916129f4565b7f73222061646469746976653d2273756d2220726570656174436f756e743d226981526b373232b334b734ba3291179f60a11b6020820152602c016c1e17b1b4b931b6329f1e17b39f60991b8152600d0103601f198101835261326f9083611999565b60405191829160208301613282916129f4565b61328b916129f4565b03601f198101825261329d9082611999565b9460010193929190612de2565b6132b386611432565b600186036132c65750505060015b612e60565b6132cf86611432565b60028614918280613371575b8061335e575b156132f157505050506001612e60565b6132fa87611432565b8280613356575b1561331157505050506002612e60565b61331a87611432565b82613349575b5081613335575b50156132c157506002612e60565b6002915061334281611432565b145f613327565b151560011491505f613320565b508015613301565b5061336882611432565b600182146132e1565b506001811515146132db565b90613387826119cb565b6133946040519182611999565b82815280926133a5601f19916119cb565b0190602036910137565b805f9172184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8210156134e2575b806d04ee2d6d415b85acef8100000000600a9210156134c6575b662386f26fc100008110156134b1575b6305f5e10081101561349f575b61271081101561348f575b6064811015613480575b1015613475575b61346060216134356001850161337d565b938401015b5f1901916f181899199a1a9b1b9c1cb0b131b232b360811b600a82061a8353600a900490565b801561347057613460909161343a565b505090565b600190910190613424565b6002906064900493019261341d565b6004906127109004930192613413565b6008906305f5e1009004930192613408565b601090662386f26fc1000090049301926133fb565b6020906d04ee2d6d415b85acef810000000090049301926133eb565b506040915072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b81046133d1565b60405161040a91613517606083611999565b604082527f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208301527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f60408301526136ad565b5f61357682612c51565b5f83815260066020526040902080546001600160a01b038316929190613674575b506001600160a01b0382165f90815260056020526040902080546fffffffffffffffffffffffffffffffff0190555f8481526004602052604090206001600160a01b0383164260a01b17600360e01b179055600160e11b81161561362f575b507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a46119c961362a60015460010190565b600155565b60018401613645815f52600460205260405f2090565b5415613652575b506135f6565b8354811461364c5761366c905f52600460205260405f2090565b555f8061364c565b8390555f613597565b8115613687570690565b634e487b7160e01b5f52601260045260245ffd5b90601d1982019182136001166112ce57565b919091805115613783576136db6136d66136d16136ca84516123dd565b6003900490565b612600565b61337d565b90602082019080815182019560208701908151925f83525b888110613735575050600393949596505251068060011461372357600214613719575090565b603d905f19015390565b50603d90815f19820153600119015390565b600360049199969901986001603f8b5182828260121c16870101518453828282600c1c16870101518385015382828260061c16870101516002850153168401015160038201530194976136f3565b50905061040a61265f565b6040519060a061379e8184611999565b825f5b8281106137ad57505050565b6060828201526020016137a1565b604051906137ca604083611999565b60078252662341353241324160c81b6020830152565b604051906137ef604083611999565b600782526611a1191919191960c91b6020830152565b60405190613814604083611999565b60078252662338423435313360c81b6020830152565b60405190613839604083611999565b600782526611a1a21c1a99a360c91b6020830152565b6040519061385e604083611999565b60078252660234646413530360cc1b6020830152565b60405190613883604083611999565b60078252660234646384330360cc1b6020830152565b604051906138a8604083611999565b600782526611a323211c982360c91b6020830152565b604051906138cd604083611999565b600782526611a2a2a11a191960c91b6020830152565b604051906138f2604083611999565b6007825266119c1ba1a2a2a160c91b6020830152565b60405190613917604083611999565b60078252661198182123232360c91b6020830152565b6040519061393c604083611999565b60078252661198a29c98232360c91b6020830152565b60405190613961604083611999565b60078252662334313639453160c81b6020830152565b60405190613986604083611999565b600782526608cd0d8e0c908d60ca1b6020830152565b9060058110156126c65760051b0190565b613a22916139b961378e565b506139c381611432565b80613a265750613a1c6139d660a06119bb565b6139de6138e3565b81526139e8613908565b60208201526139f561392d565b6040820152613a02613952565b6060820152613a0f613977565b6080820152916005900690565b9061399c565b5190565b80613a32600192611432565b03613a7d57613a1c613a4460a06119bb565b613a4c612960565b8152613a5661384f565b6020820152613a63613874565b6040820152613a70613899565b6060820152613a0f6138be565b613a1c613a8a60a06119bb565b613a92612918565b8152613a9c6137bb565b6020820152613aa96137e0565b6040820152613ab6613805565b6060820152613a0f61382a565b5f811215613b0157600160ff1b81146112ce5761040a613ae76107d1925f036133af565b604051928391602d60f81b602084015260218301906129f4565b61040a906133af56fea26469706673582212207f6bfaf7200c96d044c890f9ee0ec3818e4b63ebe7363a9f5af7e4cef192ce4264736f6c634300081c0033
Deployed Bytecode
0x60806040526004361015610023575b361561001e5761001c612a06565b005b612a36565b5f3560e01c806301ffc9a71461034257806306fdde031461033d578063081812fc14610338578063095ea7b3146103335780630dfe5c541461032e5780630e0e6ba71461032957806312065fe0146103245780631249c58b1461031f57806317edb0471461031a57806318160ddd1461031557806320d5ddda1461031057806323b872dd1461030b5780632dd91ca31461030657806332cb6b0c146103015780633a27e6fb146102fc5780633a7c03ca146102f757806342842e0e146102f2578063441e56f4146102ed57806345b7b54e146102e857806345ca9625146102e357806351b143e4146102de57806357e3fb70146102d957806362175766146102d45780636352211e146102cf5780636765c4ec146102ca57806370a08231146102c5578063715018a6146102c05780637721e567146102bb5780637c0840d1146102b65780637fb54f8b146102b157806384ecdaf6146102ac5780638c7a63ae146102a75780638da5cb5b146102a257806394c37a1c1461029d57806395d89b41146102985780639d540f33146102935780639f8317701461028e578063a22cb46514610289578063adaec91a14610284578063b862b0981461027f578063b88d4fde1461027a578063c87b56dd14610275578063ccddeda714610270578063e02f6ce61461026b578063e7a42fef14610266578063e922fc3f14610261578063e985e9c51461025c578063f2fde38b14610257578063f4e0d9ac146102525763fedf84f60361000e576122ce565b612267565b6121dd565b612179565b612111565b6120f0565b611f2f565b611f1c565b611a72565b6119e7565b61193b565b6118f9565b611868565b61184b565b611668565b6115b3565b611530565b611508565b611484565b611388565b61136b565b6112e2565b611269565b61120e565b6111b3565b611063565b611034565b611013565b610ea7565b610bc8565b610b19565b610af8565b610adb565b610ab7565b610a85565b610a63565b610a47565b61090b565b6108f9565b6108b3565b610892565b610875565b610698565b61067d565b610644565b610621565b610560565b610500565b61040d565b61035d565b6001600160e01b031981160361035957565b5f80fd5b3461035957602036600319011261035957602060043561037c81610347565b63ffffffff60e01b166301ffc9a760e01b81149081156103ba575b81156103a9575b506040519015158152f35b635b5e139f60e01b1490505f61039e565b6380ac58cd60e01b81149150610397565b5f91031261035957565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b90602061040a9281815201906103d5565b90565b34610359575f366003190112610359576040515f6002548060011c90600181169081156104f6575b6020831082146104e25782855260208501919081156104c95750600114610477575b6104738461046781860382611999565b604051918291826103f9565b0390f35b60025f9081529250907f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b8184106104b55750500161046782610457565b8054848401526020909301926001016104a2565b60ff191682525090151560051b01905061046782610457565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610435565b346103595760203660031901126103595760043561051d81612a45565b15610540575f526006602052602060018060a01b0360405f205416604051908152f35b6333d1c03960e21b5f5260045ffd5b6001600160a01b0381160361035957565b6040366003190112610359576004356105788161054f565b602435906001600160a01b0361058d83612c51565b16908133036105fc575b6105cc816105ad855f52600660205260405f2090565b80546001600160a01b0319166001600160a01b03909216919091179055565b6001600160a01b0316907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a4005b5f82815260076020908152604080832033845290915290205460ff1661059757612a84565b34610359575f36600319011261035957602061063b61234f565b54604051908152f35b3461035957602036600319011261035957600435610660612aeb565b601254811061066e57601155005b634e2e320d60e01b5f5260045ffd5b34610359575f36600319011261035957602047604051908152f35b34610359575f366003190112610359576106b0612b12565b6016546106d6906106ca9060081c6001600160a01b031681565b6001600160a01b031690565b6040516337178b4b60e11b815233600482015290602082602481845afa918215610811575f92610854575b506040516312c6c3ab60e31b8152336004820152602081602481855afa908115610811575f91610825575b50808311156108165761073f9083612398565b908115610816576107696115b36107628461075d5f54600154900390565b6123eb565b11156123f8565b803b1561035957604051632162f0df60e01b815233600482015260248101939093525f908390604490829084905af1918215610811576107ed926107f7575b506107e76010546040516107df816107d160208201944290869091604092825260208201520190565b03601f198101835282611999565b519020601055565b33612b32565b61001c6001600a55565b806108055f61080b93611999565b806103cb565b5f6107a8565b612379565b631b9fb0b360e01b5f5260045ffd5b610847915060203d60201161084d575b61083f8183611999565b81019061236a565b5f61072c565b503d610835565b61086e91925060203d60201161084d5761083f8183611999565b905f610701565b34610359575f366003190112610359576020601454604051908152f35b34610359575f3660031901126103595760205f546001549003604051908152f35b34610359575f36600319011261035957602061063b612431565b6060906003190112610359576004356108e58161054f565b906024356108f28161054f565b9060443590565b61001c610905366108cd565b9161244f565b602036600319011261035957600435610922612b12565b600d5460ff1661093181611432565b610a38576013548015610a29576109489082612618565b908115610a1557813410610a0257610962816012546123eb565b601154106109f3576109838161097b6109889333612b32565b6012546123eb565b601255565b6109a8602760405166424f54544c455360c81b8152600c60078201522090565b6109b38282546123eb565b90558034116109c65761001c6001600a55565b5f80806109d4819434612398565b8181156109ea575b3390f115610811575f6107ed565b506108fc6109dc565b6329722adb60e01b5f5260045ffd5b63db657dd560e01b5f523460045260245ffd5b63012e5f6760e21b5f52600482905260245ffd5b630a8c768360e11b5f5260045ffd5b63c79cd92760e01b5f5260045ffd5b34610359575f3660031901126103595760206040516115b38152f35b34610359575f366003190112610359576020610a7d61262b565b604051908152f35b34610359575f36600319011261035957602061063b602760405166424f54544c455360c81b8152600c60078201522090565b61001c610ac3366108cd565b9060405192610ad3602085611999565b5f845261289b565b34610359575f366003190112610359576020601354604051908152f35b3461035957602036600319011261035957600435610b14612aeb565b601355005b34610359575f36600319011261035957610b31612aeb565b610b39612b12565b5f808080602560405164414e454a4f60d81b8152600c6005820152205460018060a01b03600954165af1610b6b612673565b50610b78575b6001600a55005b5f602560405164414e454a4f60d81b8152600c60058201522055610b71565b9181601f840112156103595782359167ffffffffffffffff8311610359576020808501948460051b01011161035957565b346103595760403660031901126103595760043567ffffffffffffffff811161035957610bf9903690600401610b97565b602435918215610e6957600d5460ff16610c1281611432565b8015610e5a5780610c24600192611432565b03610d7f57610c35600f5442612398565b62cb07001015610c4157005b9060018314905f5b818110610c5257005b610c826020610c628385886126b6565b6040516331a9108f60e11b81529035600482015291829081906024820190565b0381305afa908115610811575f91610d51575b50336001600160a01b0390911603610d4257600190610cdb610cb9600d5460ff1690565b610cd6610cc784878a6126b6565b355f52600b60205260405f2090565b612712565b610cfd610cec610cc78386896126b6565b805462ff0000191662010000179055565b8315610d1f57610d19610d14610cc78386896126b6565b612743565b01610c49565b60028603610d1957610d3d610d38610cc78386896126b6565b61272a565b610d19565b639e68e5cd60e01b5f5260045ffd5b610d72915060203d8111610d78575b610d6a8183611999565b8101906126cb565b5f610c95565b503d610d60565b610d8b600f5442612398565b6301e91c801015610d9857005b9060018314905f5b818110610da957005b610db96020610c628385886126b6565b0381305afa908115610811575f91610e3c575b50336001600160a01b0390911603610d4257600190610df0610cb9600d5460ff1690565b610e01610cec610cc78386896126b6565b8315610e1e57610e18610d14610cc78386896126b6565b01610da0565b60028603610e1857610e37610d38610cc78386896126b6565b610e18565b610e54915060203d8111610d7857610d6a8183611999565b5f610dcc565b63ed21b97f60e01b5f5260045ffd5b631b8a520f60e31b5f5260045ffd5b6020600319820112610359576004359067ffffffffffffffff821161035957610ea391600401610b97565b9091565b3461035957610eb536610e78565b610ebd612b12565b5f915f5b828110610f355783610ed16127e9565b905f5b8251811015610ef95780610ef3610eed60019386612831565b5161356c565b01610ed4565b506040517fc733f2d8c356aef2f8196bcdd071901023a40b280983285669d40da73455d754339180610f2a81611916565b0390a36107ed612845565b610f456020610c628386866126b6565b0381305afa908115610811575f91610ff5575b50336001600160a01b0390911603610d4257610f80610f7b610cc78386866126b6565b61275c565b60018151610f8d81611432565b610f9681611432565b149081610fd4575b50610fac575b600101610ec1565b92610fb86001916123a5565b93610fcd610fc78286866126b6565b3561279d565b9050610fa4565b6002915060200151610fe581611432565b610fee81611432565b145f610f9e565b61100d915060203d8111610d7857610d6a8183611999565b5f610f58565b346103595760203660031901126103595760043561102f612aeb565b601455005b346103595760203660031901126103595760206001600160a01b0361105a600435612c51565b16604051908152f35b346103595761107136610e78565b611079612b12565b5f915f5b8281106110e0578361108d6127e9565b905f5b82518110156110af57806110a9610eed60019386612831565b01611090565b506040517fc733f2d8c356aef2f8196bcdd071901023a40b280983285669d40da73455d754339180610f2a8161192a565b6110f06020610c628386866126b6565b0381305afa908115610811575f91611195575b50336001600160a01b0390911603610d4257611126610f7b610cc78386866126b6565b6002815161113381611432565b61113c81611432565b149081611174575b50611152575b60010161107d565b9261115e6001916123a5565b9361116d610fc78286866126b6565b905061114a565b600291506020015161118581611432565b61118e81611432565b145f611144565b6111ad915060203d8111610d7857610d6a8183611999565b5f611103565b34610359576020366003190112610359576004356111d08161054f565b6001600160a01b031680156111ff575f526005602052602067ffffffffffffffff60405f205416604051908152f35b6323d3ad8160e21b5f5260045ffd5b34610359575f36600319011261035957611226612aeb565b600980546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b5f3660031901126103595734156112d357602560405164414e454a4f60d81b8152600c6005820152208054903482018092116112ce57556040513481527f23199407c520d738b79c0cf7a883c87fef37b99f89519fb5fa671764d76d884460203392a2005b612384565b6338fc0f5560e01b5f5260045ffd5b34610359575f36600319011261035957476028604051675245504f5341444f60c01b8152600c6008820152205490602560405164414e454a4f60d81b8152600c6005820152205482018092116112ce5761135a61047392602760405166424f54544c455360c81b8152600c60078201522054906123eb565b604051911481529081906020820190565b34610359575f366003190112610359576020601154604051908152f35b34610359575f366003190112610359576113a0612aeb565b6113ac600f5442612398565b600d5460ff166113bb81611432565b801580611425575b80611418575b156113d857505061001c6126f9565b806113e4600192611432565b149081611409575b50156113fa5761001c6126e0565b638d2adffd60e01b5f5260045ffd5b6301baf800915010155f6113ec565b506301baf80082106113c9565b50629ce2808210156113c3565b6003111561143c57565b634e487b7160e01b5f52602160045260245ffd5b9190916040806060830194805161146681611432565b8452602081015161147681611432565b602085015201511515910152565b34610359576020366003190112610359576004355f604080516114a681611978565b82815282602082015201525f52600b60205261047360405f2060ff604051916114ce83611978565b548181166114db81611432565b8352818160081c166114ec81611432565b602084015260101c161515604082015260405191829182611450565b34610359575f366003190112610359576009546040516001600160a01b039091168152602090f35b34610359575f36600319011261035957611548612aeb565b611550612b12565b5f8080806028604051675245504f5341444f60c01b8152600c6008820152205460018060a01b03600954165af1611585612673565b50611591576001600a55005b5f6028604051675245504f5341444f60c01b8152600c60088201522055610b71565b34610359575f366003190112610359576040515f6003548060011c906001811690811561165e575b6020831082146104e25782855260208501919081156104c9575060011461160c576104738461046781860382611999565b60035f9081529250907fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b81841061164a5750500161046782610457565b805484840152602090930192600101611637565b91607f16916115db565b346103595761167636610e78565b9061167f612b12565b60145491821561183c575f915f5b82811061176957846116a7856116a16127e9565b92612618565b801561175a57806116b6612431565b541061174b576116d55f80808085335af16116cf612673565b50612894565b6116dd612431565b6116e8828254612398565b90555f5b825181101561170b5780611705610eed60019386612831565b016116ec565b60408051338152602081018490527f1afc46a1f05671e74e4c42ddc0e719050c41a0014666b6c4826c7cfc5fd6931b91819081015b0390a16107ed612845565b63086cd50760e21b5f5260045ffd5b6358b508c960e11b5f5260045ffd5b6117796020610c628386866126b6565b0381305afa908115610811575f9161181e575b50336001600160a01b0390911603610d42576117af610f7b610cc78386866126b6565b600181516117bc81611432565b6117c581611432565b1490816117fd575b506117db575b60010161168d565b926117e76001916123a5565b936117f6610fc78286866126b6565b90506117d3565b600191506020015161180e81611432565b61181781611432565b145f6117cd565b611836915060203d8111610d7857610d6a8183611999565b5f61178c565b636647450560e01b5f5260045ffd5b34610359575f366003190112610359576020601254604051908152f35b34610359576040366003190112610359576004356118858161054f565b6024359081151580920361035957335f9081526007602090815260408083206001600160a01b0385168452909152902060ff1981541660ff841617905560405191825260018060a01b0316907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a3005b34610359575f366003190112610359576020601554604051908152f35b906001602083019261192782611432565b52565b906002602083019261192782611432565b34610359575f36600319011261035957602060ff600d54166040519061196081611432565b8152f35b634e487b7160e01b5f52604160045260245ffd5b6060810190811067ffffffffffffffff82111761199457604052565b611964565b90601f8019910116810190811067ffffffffffffffff82111761199457604052565b906119c96040519283611999565b565b67ffffffffffffffff811161199457601f01601f191660200190565b6080366003190112610359576004356119ff8161054f565b60243590611a0c8261054f565b6044356064359267ffffffffffffffff8411610359573660238501121561035957836004013592611a3c846119cb565b93611a4a6040519586611999565b8085523660248288010111610359576020815f92602461001c9901838901378601015261289b565b3461035957602036600319011261035957600435611a97611a9282612a45565b6128dc565b611ab6611aac825f52600b60205260405f2090565b5460101c60ff1690565b611ad2611acb835f52600b60205260405f2090565b5460ff1690565b6060918291611ae3600d5460ff1690565b91611aed83611432565b82611e23575050505050611aff6129ab565b611b076129d0565b915b611b1281612dce565b604080517f3c73766720786d6c6e733d22687474703a2f2f7777772e77332e6f72672f323060208201527f30302f737667222076696577426f783d2230203020333030203330302220737491810191909152753cb6329e9137bb32b9333637bb9d3434b23232b7111f60511b606082015292839190607683017f3c646566733e3c636c6970506174682069643d226672616d65223e3c7265637481527f2077696474683d2233303022206865696768743d22333030222f3e3c2f636c6960208201526c382830ba341f1e17b232b3399f60991b6040820152604d017f3c726563742077696474683d2233303022206865696768743d2233303022206681526434b6361e9160d91b6020820152602501611c2a916129f4565b6211179f60e91b81526003017f3c6720636c69702d706174683d2275726c28236672616d6529223e00000000008152601b01611c65916129f4565b691e17b39f1e17b9bb339f60b11b8152600a0103601f1981018352611c8a9083611999565b611c93906133af565b90611c9d90613505565b6040516e7b226e616d65223a2243415641202360881b6020820152928392602f8401611cc8916129f4565b7f222c226465736372697074696f6e223a224f6e2d636861696e2061676564207481527f657175696c61204e465420776974682064796e616d696320616e696d6174696f6020820152621b888b60ea1b60408201526043017f2261747472696275746573223a5b7b2274726169745f74797065223a2253746181526c3a329116113b30b63ab2911d1160991b6020820152602d01611d65916129f4565b7f227d5d2c22696d616765223a22646174613a696d6167652f7376672b786d6c3b81526618985cd94d8d0b60ca1b6020820152602701611da4916129f4565b61227d60f01b815260020103601f1981018252611dc19082611999565b611dca90613505565b6040517f646174613a6170706c69636174696f6e2f6a736f6e3b6261736536342c0000006020820152908190603d8201611e03916129f4565b03601f1981018252611e159082611999565b6040516104738192826103f9565b611e2c83611432565b60018303611e50575050505050611e41612960565b611e49612985565b915b611b09565b611e5983611432565b60028314928380611f10575b80611efd575b15611e7e57505050505050611e41612960565b611e8781611432565b8380611ef5575b15611ea957505050505050611ea1612918565b611e4961293d565b611eb69096949596611432565b82611ee8575b5081611ed4575b5015611e4b57915050611ea1612918565b60029150611ee181611432565b145f611ec3565b151560011491505f611ebc565b508115611e8e565b50611f0783611432565b60018314611e6b565b50600182151514611e65565b5f3660031901126103595761001c612a06565b3461035957611f3d36610e78565b90611f46612b12565b6015549182156120e1575f915f5b82811061200e5784611f68856116a16127e9565b801561175a5780611f7761234f565b5410611fff57611f905f80808085335af16116cf612673565b611f9861234f565b611fa3828254612398565b90555f5b8251811015611fc65780611fc0610eed60019386612831565b01611fa7565b60408051338152602081018490527f8b3d127bdbb0408980985ecd4d18fe6b4b08955cb26b71c096539a4e4c6a1ba39181908101611740565b637f96ce8160e11b5f5260045ffd5b61201e6020610c628386866126b6565b0381305afa908115610811575f916120c3575b50336001600160a01b0390911603610d4257612054610f7b610cc78386866126b6565b6002815161206181611432565b61206a81611432565b1490816120a2575b50612080575b600101611f54565b9261208c6001916123a5565b9361209b610fc78286866126b6565b9050612078565b60019150602001516120b381611432565b6120bc81611432565b145f612072565b6120db915060203d8111610d7857610d6a8183611999565b5f612031565b632b087dc160e11b5f5260045ffd5b346103595760203660031901126103595760043561210c612aeb565b601555005b5f3660031901126103595734156112d3576028604051675245504f5341444f60c01b8152600c6008820152208054903482018092116112ce57556040513481527fec8ef3e5ffbb74357245a84bc2cc890a34d96c5e26d5991f2bb16e43ff913a8160203392a2005b3461035957604036600319011261035957602060ff6121d160043561219d8161054f565b602435906121aa8261054f565b60018060a01b03165f526007845260405f209060018060a01b03165f5260205260405f2090565b54166040519015158152f35b34610359576020366003190112610359576004356121fa8161054f565b612202612aeb565b6001600160a01b0316801561225457600980546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3005b631e4fbdf760e01b5f525f60045260245ffd5b34610359576020366003190112610359576004356122848161054f565b61228c612aeb565b601654600160ff82161515146122bf576001600160a81b03191660089190911b610100600160a81b031617600117601655005b634ec7eee560e01b5f5260045ffd5b34610359575f366003190112610359576122e6612aeb565b6122ee612b12565b5f808080602760405166424f54544c455360c81b8152600c6007820152205460018060a01b03600954165af1612322612673565b5061232e576001600a55005b5f602760405166424f54544c455360c81b8152600c60078201522055610b71565b602560405164414e454a4f60d81b8152600c60058201522090565b90816020910312610359575190565b6040513d5f823e3d90fd5b634e487b7160e01b5f52601160045260245ffd5b919082039182116112ce57565b90600182018092116112ce57565b60140190816014116112ce57565b601e019081601e116112ce57565b60040190816004116112ce57565b90600282018092116112ce57565b919082018092116112ce57565b156123ff57565b60405162461bcd60e51b815260206004820152600a6024820152694d617820737570706c7960b01b6044820152606490fd5b6028604051675245504f5341444f60c01b8152600c60088201522090565b919061245a82612c51565b6001600160a01b039384169381168490036125e5575f838152600660205260409020805461249b6001600160a01b03871633908114908314171590565b1590565b6125a2575b612599575b506001600160a01b0384165f90815260056020526040902080545f190190556001600160a01b0382165f908152600560205260409020805460010190556001600160a01b0382164260a01b17600160e11b17612509845f52600460205260405f2090565b55600160e11b811615612554575b506001600160a01b03169182907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a41561254f57565b612ab0565b6001830161256a815f52600460205260405f2090565b5415612577575b50612517565b5f54811461257157612591905f52600460205260405f2090565b555f80612571565b5f90555f6124a5565b6125db612497611acb336125c68a60018060a01b03165f52600760205260405f2090565b9060018060a01b03165f5260205260405f2090565b156124a057612aa1565b612a93565b908160011b91808304600214901517156112ce57565b600281901b91906001600160fe1b038116036112ce57565b818102929181159184041417156112ce57565b60ff600d541661263a81611432565b8061264457505f90565b60019061265081611432565b0361265a57600190565b600290565b6040519061266e602083611999565b5f8252565b3d1561269d573d90612684826119cb565b916126926040519384611999565b82523d5f602084013e565b606090565b634e487b7160e01b5f52603260045260245ffd5b91908110156126c65760051b0190565b6126a2565b90816020910312610359575161040a8161054f565b6126ea6002611432565b600260ff19600d541617600d55565b6127036001611432565b600160ff19600d541617600d55565b9061271c81611432565b60ff80198354169116179055565b6127346002611432565b805461ff001916610200179055565b61274d6001611432565b805461ff001916610100179055565b9060405161276981611978565b604060ff82945481811661277c81611432565b8452818160081c1661278d81611432565b602085015260101c161515910152565b600e5468010000000000000000811015611994576001810180600e558110156126c657600e5f527fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd0155565b60405190600e548083528260208101600e5f5260205f20925f5b8181106128185750506119c992500383611999565b8454835260019485019487945060209093019201612803565b80518210156126c65760209160051b010190565b600e545f600e55806128545750565b600e5f527fbb7b4a454dc3493923482f07822329ed19e8244eff582cc204f8554c3620c3fd908101905b818110612889575050565b5f815560010161287e565b1561035957565b9291906128a982828661244f565b803b6128b6575b50505050565b6128bf93612da6565b156128cd575f8080806128b0565b6368d2bf6b60e11b5f5260045ffd5b156128e357565b60405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b2103a37b5b2b760991b6044820152606490fd5b60405190612927604083611999565b60078252660233842303030360cc1b6020830152565b6040519061294c604083611999565b6005825264416e656a6f60d81b6020830152565b6040519061296f604083611999565b60078252660234646443730360cc1b6020830152565b60405190612994604083611999565b60088252675265706f7361646f60c01b6020830152565b604051906129ba604083611999565b600782526611a318231c232360c91b6020830152565b604051906129df604083611999565b6006825265426c616e636f60d01b6020830152565b805191908290602001825e015f815290565b34156112d357602760405166424f54544c455360c81b8152600c6007820152208054903482018092116112ce5755565b636edd855560e01b5f5260045ffd5b905f915f548110612a535750565b9091505b805f52600460205260405f205480612a78575080156112ce575f1901612a57565b600160e01b1615919050565b6367d9dca160e11b5f5260045ffd5b62a1148160e81b5f5260045ffd5b632ce44b5f60e11b5f5260045ffd5b633a954ecd60e21b5f5260045ffd5b63b562e8dd60e01b5f5260045ffd5b622e076360e81b5f5260045ffd5b636f96cda160e11b5f5260045ffd5b6009546001600160a01b03163303612aff57565b63118cdaa760e01b5f523360045260245ffd5b6002600a5414612b23576002600a55565b633ee5aeb560e01b5f5260045ffd5b9160405190612b42602083611999565b5f82525f54918315612c4c576001600160a01b0385164260a01b6001861460e11b1717612b77845f52600460205260405f2090565b556001600160a01b0385165f8181526005602052604090208054680100000000000000018702019055938415612c4757808401939560015b15612be2575b5f87875f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4612baf565b9560010195848703612bb557929550929093505f55803b612c0257505050565b9091925f549283039260015b15612c32575b5f612c2761249787600188019787612d07565b15612c0e575b6128cd565b808410612c145792509250505f540361035957565b612ace565b612abf565b612c63815f52600460205260405f2090565b54908115612c7a5750600160e01b8116612adc5790565b90505f54811015612adc575b5f19015f81815260046020526040902054908115612cba5750600160e01b81161561040a57636f96cda160e11b5f5260045ffd5b9050612c86565b90816020910312610359575161040a81610347565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261040a929101906103d5565b91612d2e926020925f604051809681958294630a85bd0160e11b8452843360048601612cd6565b03926001600160a01b03165af15f9181612d75575b50612d5f57612d50612673565b805115612c2d57805190602001fd5b6001600160e01b031916630a85bd0160e11b1490565b612d9891925060203d602011612d9f575b612d908183611999565b810190612cc1565b905f612d43565b503d612d86565b906020925f612d2e959360405196879586948593630a85bd0160e11b85523360048601612cd6565b601054600d546060925f929160ff16908115915b600a8510612df257505050505090565b9091929394604051602081019086825284604082015287606082015260608152612e1d608082611999565b519020905f612e37611aac865f52600b60205260405f2090565b612e4c611acb875f52600b60205260405f2090565b612e5586611432565b87156132aa575050505f5b612e6c602884066123b3565b90612e778460081c90565b60f09006612e84906123c1565b612e8e8560101c90565b60f09006612e9b906123c1565b92612ea68660181c90565b603d9006612eb39061369b565b8b612ebe8860201c90565b603d9006612ecb9061369b565b92612ed68960281c90565b60039006612ee3906123cf565b612eed81966133af565b97612ef7906133af565b99612f01836133af565b97612f0b916139ad565b92612f15826133af565b91612f1f9161367d565b612f28906133af565b612f31836133af565b91612f3b846125ea565b612f44906133af565b93612f4e906133af565b94612f58896133af565b96612f6290613ac3565b97612f6c90613ac3565b98612f76906133af565b6040517f3c67207472616e73666f726d3d227472616e736c61746528000000000000000060208201529d8e9c919b9160388e01612fb2916129f4565b600b60fa1b8152600101612fc5916129f4565b6214911f60e91b81526003016a1e31b4b931b63290391e9160a91b8152600b01612fee916129f4565b6711103334b6361e9160c11b8152600801613008916129f4565b6d111037b830b1b4ba3c9e9118111f60911b8152600e017f3c616e696d617465206174747269627574654e616d653d226f7061636974792281527f2076616c7565733d22303b302e373b3022206475723d220000000000000000006020820152603701613074916129f4565b6203991160ed1b815260030167626567696e3d222d60c01b815260080161309a916129f4565b7f732220726570656174436f756e743d22696e646566696e697465222f3e0000008152601d017f3c616e696d617465206174747269627574654e616d653d2272222076616c7565815262399e9160e91b60208201526023016130fb916129f4565b603b60f81b815260010161310e916129f4565b603b60f81b8152600101613121916129f4565b61011160f51b815260020164323ab91e9160d91b8152600501613143916129f4565b7f732220726570656174436f756e743d22696e646566696e697465222f3e0000008152601d017f3c616e696d6174655472616e73666f726d206174747269627574654e616d653d81527f227472616e73666f726d2220747970653d227472616e736c61746522200000006020820152603d016b76616c7565733d22302c303b60a01b8152600c016131d3916129f4565b600b60fa1b81526001016131e6916129f4565b6501d98161811160d51b815260060164323ab91e9160d91b815260050161320c916129f4565b7f73222061646469746976653d2273756d2220726570656174436f756e743d226981526b373232b334b734ba3291179f60a11b6020820152602c016c1e17b1b4b931b6329f1e17b39f60991b8152600d0103601f198101835261326f9083611999565b60405191829160208301613282916129f4565b61328b916129f4565b03601f198101825261329d9082611999565b9460010193929190612de2565b6132b386611432565b600186036132c65750505060015b612e60565b6132cf86611432565b60028614918280613371575b8061335e575b156132f157505050506001612e60565b6132fa87611432565b8280613356575b1561331157505050506002612e60565b61331a87611432565b82613349575b5081613335575b50156132c157506002612e60565b6002915061334281611432565b145f613327565b151560011491505f613320565b508015613301565b5061336882611432565b600182146132e1565b506001811515146132db565b90613387826119cb565b6133946040519182611999565b82815280926133a5601f19916119cb565b0190602036910137565b805f9172184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8210156134e2575b806d04ee2d6d415b85acef8100000000600a9210156134c6575b662386f26fc100008110156134b1575b6305f5e10081101561349f575b61271081101561348f575b6064811015613480575b1015613475575b61346060216134356001850161337d565b938401015b5f1901916f181899199a1a9b1b9c1cb0b131b232b360811b600a82061a8353600a900490565b801561347057613460909161343a565b505090565b600190910190613424565b6002906064900493019261341d565b6004906127109004930192613413565b6008906305f5e1009004930192613408565b601090662386f26fc1000090049301926133fb565b6020906d04ee2d6d415b85acef810000000090049301926133eb565b506040915072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b81046133d1565b60405161040a91613517606083611999565b604082527f4142434445464748494a4b4c4d4e4f505152535455565758595a61626364656660208301527f6768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f60408301526136ad565b5f61357682612c51565b5f83815260066020526040902080546001600160a01b038316929190613674575b506001600160a01b0382165f90815260056020526040902080546fffffffffffffffffffffffffffffffff0190555f8481526004602052604090206001600160a01b0383164260a01b17600360e01b179055600160e11b81161561362f575b507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a46119c961362a60015460010190565b600155565b60018401613645815f52600460205260405f2090565b5415613652575b506135f6565b8354811461364c5761366c905f52600460205260405f2090565b555f8061364c565b8390555f613597565b8115613687570690565b634e487b7160e01b5f52601260045260245ffd5b90601d1982019182136001166112ce57565b919091805115613783576136db6136d66136d16136ca84516123dd565b6003900490565b612600565b61337d565b90602082019080815182019560208701908151925f83525b888110613735575050600393949596505251068060011461372357600214613719575090565b603d905f19015390565b50603d90815f19820153600119015390565b600360049199969901986001603f8b5182828260121c16870101518453828282600c1c16870101518385015382828260061c16870101516002850153168401015160038201530194976136f3565b50905061040a61265f565b6040519060a061379e8184611999565b825f5b8281106137ad57505050565b6060828201526020016137a1565b604051906137ca604083611999565b60078252662341353241324160c81b6020830152565b604051906137ef604083611999565b600782526611a1191919191960c91b6020830152565b60405190613814604083611999565b60078252662338423435313360c81b6020830152565b60405190613839604083611999565b600782526611a1a21c1a99a360c91b6020830152565b6040519061385e604083611999565b60078252660234646413530360cc1b6020830152565b60405190613883604083611999565b60078252660234646384330360cc1b6020830152565b604051906138a8604083611999565b600782526611a323211c982360c91b6020830152565b604051906138cd604083611999565b600782526611a2a2a11a191960c91b6020830152565b604051906138f2604083611999565b6007825266119c1ba1a2a2a160c91b6020830152565b60405190613917604083611999565b60078252661198182123232360c91b6020830152565b6040519061393c604083611999565b60078252661198a29c98232360c91b6020830152565b60405190613961604083611999565b60078252662334313639453160c81b6020830152565b60405190613986604083611999565b600782526608cd0d8e0c908d60ca1b6020830152565b9060058110156126c65760051b0190565b613a22916139b961378e565b506139c381611432565b80613a265750613a1c6139d660a06119bb565b6139de6138e3565b81526139e8613908565b60208201526139f561392d565b6040820152613a02613952565b6060820152613a0f613977565b6080820152916005900690565b9061399c565b5190565b80613a32600192611432565b03613a7d57613a1c613a4460a06119bb565b613a4c612960565b8152613a5661384f565b6020820152613a63613874565b6040820152613a70613899565b6060820152613a0f6138be565b613a1c613a8a60a06119bb565b613a92612918565b8152613a9c6137bb565b6020820152613aa96137e0565b6040820152613ab6613805565b6060820152613a0f61382a565b5f811215613b0157600160ff1b81146112ce5761040a613ae76107d1925f036133af565b604051928391602d60f81b602084015260218301906129f4565b61040a906133af56fea26469706673582212207f6bfaf7200c96d044c890f9ee0ec3818e4b63ebe7363a9f5af7e4cef192ce4264736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.