Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Latest 25 from a total of 243 transactions
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Unlock Tokens | 18994582 | 807 days ago | IN | 0 ETH | 0.00195736 | ||||
| Unlock Tokens | 18994541 | 807 days ago | IN | 0 ETH | 0.00203085 | ||||
| Unlock Tokens | 18887080 | 822 days ago | IN | 0 ETH | 0.00258029 | ||||
| Unlock Tokens | 18883174 | 823 days ago | IN | 0 ETH | 0.00101002 | ||||
| Unlock Tokens | 18883174 | 823 days ago | IN | 0 ETH | 0.00488187 | ||||
| Unlock Tokens | 18879169 | 823 days ago | IN | 0 ETH | 0.00353133 | ||||
| Unlock Tokens | 18854775 | 827 days ago | IN | 0 ETH | 0.00296519 | ||||
| Unlock Tokens | 18854148 | 827 days ago | IN | 0 ETH | 0.00303489 | ||||
| Unlock Tokens | 18845795 | 828 days ago | IN | 0 ETH | 0.00329908 | ||||
| Unlock Tokens | 18845736 | 828 days ago | IN | 0 ETH | 0.00417774 | ||||
| Unlock Tokens | 18845012 | 828 days ago | IN | 0 ETH | 0.00343419 | ||||
| Unlock Tokens | 18843271 | 828 days ago | IN | 0 ETH | 0.00564713 | ||||
| Unlock Tokens | 18842040 | 828 days ago | IN | 0 ETH | 0.00629796 | ||||
| Unlock Tokens | 18841462 | 828 days ago | IN | 0 ETH | 0.00454131 | ||||
| Unlock Tokens | 18841290 | 828 days ago | IN | 0 ETH | 0.00386369 | ||||
| Unlock Tokens | 18841273 | 828 days ago | IN | 0 ETH | 0.00420758 | ||||
| Unlock Tokens | 18841259 | 828 days ago | IN | 0 ETH | 0.00371735 | ||||
| Unlock Tokens | 18841105 | 828 days ago | IN | 0 ETH | 0.00395343 | ||||
| Unlock Tokens | 18841055 | 828 days ago | IN | 0 ETH | 0.00090672 | ||||
| Unlock Tokens | 18841048 | 828 days ago | IN | 0 ETH | 0.00423681 | ||||
| Unlock Tokens | 18841023 | 828 days ago | IN | 0 ETH | 0.00605547 | ||||
| Unlock Tokens | 18840946 | 828 days ago | IN | 0 ETH | 0.00393237 | ||||
| Unlock Tokens | 18840785 | 828 days ago | IN | 0 ETH | 0.00437837 | ||||
| Unlock Tokens | 18840742 | 828 days ago | IN | 0 ETH | 0.00507699 | ||||
| Unlock Tokens | 18840489 | 829 days ago | IN | 0 ETH | 0.0052558 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
Lottery
Compiler Version
v0.8.21+commit.d9974bed
Optimization Enabled:
Yes with 100 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.21;
import { IUniswapV2Pair } from "./uniswap/IUniswapV2Pair.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { Time } from "@openzeppelin/contracts/utils/types/Time.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { VRFConsumerBaseV2 } from "./chainlink/VRFConsumerBaseV2.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import { IReferralStorage } from "./referrals/interfaces/IReferralStorage.sol";
import { Checkpoints } from "@openzeppelin/contracts/utils/structs/Checkpoints.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { VRFCoordinatorV2Interface } from "./chainlink/VRFCoordinatorV2Interface.sol";
import { ERC1155Supply } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import { ERC1155URIStorage } from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
contract Lottery is Ownable, ERC1155Supply, ERC1155URIStorage, VRFConsumerBaseV2 {
using Math for uint256;
using SafeERC20 for ERC20;
using Checkpoints for Checkpoints.Trace208;
///////////////////////////////////////////
////////// CONSTANTS //////////////////////
///////////////////////////////////////////
/// @dev The max buyback and burn percentage to take from prize pot.
uint256 constant MAX_BUYBACK_BURN = 2e17;
/// @dev Chainlink VRF Keyhash.
bytes32 constant VRF_KEYHASH = 0xff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92;
///////////////////////////////////////////
////////// IMMUTABLES AND MISC ////////////
///////////////////////////////////////////
/// @dev The VRF Coordinator.
address immutable vrfCoordinator;
/// @dev The 888 token.
address immutable lucky8Token;
/// @dev The 888/USDC LP token.
address immutable lucky8LpToken;
/// @dev USDC Token.
address immutable usdcToken;
/// @dev The buyback and burn address.
address buybackBurnAddress;
/// @dev Referral storage.
IReferralStorage public referralStorage;
/// @dev Chainlink VRF Subscription ID.
uint64 public chainlinkSubscriptionId;
/// @dev Chainlink VRF minimum request confirmations.
uint16 chainlinkMinimumRequestConfirmations = 70;
/// @dev Chainlink VRF callback gas limit.
uint32 chainlinkCallbackGas = 500_000;
///////////////////////////////////////////
////////// DEPOSITS STATE /////////////////
///////////////////////////////////////////
/// @dev Amount of locked tokens using a certain referral code.
mapping(bytes32 => Checkpoints.Trace208) private _lockedTokensPerReferralCode;
/// @dev Amount of locked LP tokens using a certain referral code.
mapping(bytes32 => Checkpoints.Trace208) private _lockedLpTokensPerReferralCode;
/// @dev Maps address to snapshots of locked tokens.
mapping(address => Checkpoints.Trace208) private _lockedTokens;
/// @dev Maps address to snapshots of locked LP tokens.
mapping(address => Checkpoints.Trace208) private _lockedLpTokens;
/// @dev Snapshot of total locked tokens.
Checkpoints.Trace208 private _totalTokenCheckpoint;
/// @dev Snapshot of total locked LP tokens.
Checkpoints.Trace208 private _totalLpTokenCheckpoint;
///////////////////////////////////////////
////////// ROUND STORAGE VARS /////////////
///////////////////////////////////////////
/// @dev Indicates whether the round is ongoing.
bool public isRoundOngoing;
/// @dev Last round.
uint256 public roundNumber;
/// @dev Round info struct
struct RoundInfo {
// Indicates whether the raffle has been executed.
bool isRaffleExecuted;
// Number of winners.
uint8 nWinners;
// Start timepoint.
uint48 startTimepoint;
// Raffle execution timepoint.
uint48 raffleExecutionTimepoint;
// Minting window duration.
uint48 mintingWindowDuration;
// Claiming window duration.
uint48 claimingWindowDuration;
// Chainlink VRF request id.
uint256 reqId;
// Prize pot.
uint256 prizePot;
// $888 amount per LP wei.
uint256 tokensPerLpWei;
// Winning numbers.
uint256[] winningNumbers;
}
/// @dev Round info for each round.
RoundInfo[] public roundInfo;
/// @dev Maps a round id to a Chainlink VRF request id.
mapping(uint256 => uint256) public requestIdToRound;
/// @dev Tickets ranges for users.
/// @dev The first mapping is the round number.
mapping(uint256 => mapping(address => uint256[2])) public userTicketsRanges;
///////////////////////////////////////////
////////// EVENTS /////////////////////////
///////////////////////////////////////////
/// @dev Emitted when the referral storage is set.
event SetReferralStorage(address indexed referralStorage);
/// @dev Emitted when the buyback and burn address is set.
event SetBuybackBurnAddress(address indexed buybackBurnAddress);
/// @dev Emitted when tokens are locked.
event TokensLocked(address indexed account, uint256 amount, bytes32 referralCode);
/// @dev Emitted when LP tokens are locked.
event LpTokensLocked(address indexed account, uint256 amount, bytes32 referralCode);
/// @dev Emitted when tokens are unlocked.
event TokensUnlocked(address indexed account, uint256 amount, bytes32 referralCode);
/// @dev Emitted when LP tokens are unlocked.
event LpTokensUnlocked(address indexed account, uint256 amount, bytes32 referralCode);
/// @dev Emitted when tickets are minted.
event TicketsMinted(address indexed account, uint256 round, uint256 amount);
/// @dev Emitted when the prize is claimed.
event PrizeClaimed(address indexed account, uint256 round, uint256 amount);
/// @dev Emitted when a round is started.
event RoundStarted(
uint256 indexed round,
uint256 prizePot,
uint256 nWinners,
uint48 mintingWindowDuration,
uint48 claimingWindowDuration,
uint256 buyBackPct,
uint256 tokensPerLpWei
);
/// @dev Emitted when a raffle is made.
event RaffleExecuted(uint256 indexed round, uint256[] winningNumbers);
/// @dev Emitted when a round is finalized.
event RoundFinalized(uint256 indexed round);
/// @dev Emitted when tickets are burned.
event TicketsBurned(address indexed account, uint256 round, uint256 amount);
// solhint-disable-next-line empty-blocks
constructor(
address _lucky8Token,
address _lucky8LpToken,
address _usdcToken,
address _buyBackBurnAddress,
string memory _uri,
IReferralStorage _referralStorage,
address _vrfCoordinator,
uint64 _chainlinkSubscriptionId
)
Ownable(msg.sender)
ERC1155(_uri)
VRFConsumerBaseV2(_vrfCoordinator)
{
// Initialize immutables and miscs
lucky8Token = _lucky8Token;
lucky8LpToken = _lucky8LpToken;
usdcToken = _usdcToken;
buybackBurnAddress = _buyBackBurnAddress;
referralStorage = _referralStorage;
vrfCoordinator = _vrfCoordinator;
chainlinkSubscriptionId = _chainlinkSubscriptionId;
}
/// @dev Clock used for flagging checkpoints.
function clock() public view virtual returns (uint48) {
return Time.timestamp();
}
/// @dev Machine-readable description of the clock as specified in EIP-6372.
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public view virtual returns (string memory) {
require(clock() == Time.timestamp(), "Lottery: inconsistent clock");
return "mode=timestamp";
}
///////////////////////////////////////////
///////////// VIEW FUNCTIONS /////////////
//////////////////////////////////////////
/// @dev Method used to get the amount of $888 tokens per LP wei.
function tokensPerLpWei() external view returns (uint256) {
return _tokensPerLpWei();
}
/// @dev Method used to get the amount of locked tokens.
function totalLockedTokens() external view returns (uint256) {
return _totalTokenCheckpoint.upperLookupRecent(clock());
}
/// @dev Method used to get the amount of locked LP tokens.
function totalLockedLpTokens() external view returns (uint256) {
return _totalLpTokenCheckpoint.upperLookupRecent(clock());
}
/// @dev Method used to get the amount of locked tokens for a given time.
function totalLockedTokensForTime(uint48 time) external view returns (uint256) {
return _totalTokenCheckpoint.upperLookupRecent(time);
}
/// @dev Method used to get the amount of locked lp tokens for a given time.
function totalLockedLpTokensForTime(uint48 time) external view returns (uint256) {
return _totalLpTokenCheckpoint.upperLookupRecent(time);
}
/// @dev Method used to get the amount of mintable tickets for an account.
/// @dev This method is used by the frontend to display the amount of tickets that can be minted by the user.
function mintableTicketsForAccount(address _account)
external
view
returns (
uint256 ticketsAmount,
uint256 lockedTokensTicketsAmount,
uint256 lockedLpTokensTicketsAmount,
uint256 bonusAmount
)
{
if (!isRoundOngoing) {
(ticketsAmount, lockedTokensTicketsAmount, lockedLpTokensTicketsAmount, bonusAmount) =
_mintableTicketsForAccount(_account, clock(), _tokensPerLpWei());
} else {
// Get current round info.
uint256 currentRound = roundNumber;
RoundInfo memory currentRoundInfo = roundInfo[currentRound - 1];
// Check that the round is in still in minting phase.
if (clock() <= currentRoundInfo.startTimepoint + currentRoundInfo.mintingWindowDuration) {
(ticketsAmount, lockedTokensTicketsAmount, lockedLpTokensTicketsAmount, bonusAmount) =
_mintableTicketsForAccount(_account, currentRoundInfo.startTimepoint, currentRoundInfo.tokensPerLpWei);
}
}
}
/// @dev Method used to infos about users.
function getUserInfo(address account)
external
view
returns (
uint256 tokensLocked,
uint256 lpTokensLocked,
uint256 referredTokensLocked,
uint256 referredLpTokensLocked
)
{
// Get current clock.
uint48 currentClock = clock();
tokensLocked = _lockedTokens[account].upperLookupRecent(currentClock);
lpTokensLocked = _lockedLpTokens[account].upperLookupRecent(currentClock);
bytes32 userRefCode = referralStorage.accountCodeOwned(account);
if (userRefCode != bytes32(0)) {
referredTokensLocked = _lockedTokensPerReferralCode[userRefCode].upperLookupRecent(currentClock);
referredLpTokensLocked = _lockedLpTokensPerReferralCode[userRefCode].upperLookupRecent(currentClock);
}
}
/// @dev Method used to get infos about a round.
function getRoundInfo(uint256 roundId) external view returns (RoundInfo memory) {
return roundInfo[roundId - 1];
}
///////////////////////////////////////////
///////////// USER FUNCTIONS /////////////
//////////////////////////////////////////
/// @dev Method used to lock tokens.
function lockTokens(uint256 amount, bytes32 _referralCode) external {
// Transfer the amount of tokens to lock in this contract.
ERC20(lucky8Token).safeTransferFrom(msg.sender, address(this), amount);
// Update the total locked tokens for the user and the global total locked tokens.
_push(_lockedTokens[msg.sender], _add, SafeCast.toUint208(amount));
_push(_totalTokenCheckpoint, _add, SafeCast.toUint208(amount));
// Set the account referral code if needed.
_setAccountReferralCode(msg.sender, _referralCode);
// Check if the user has registered a referral code to use.
(bytes32 referralCode,) = referralStorage.getAccountReferralInfo(msg.sender);
// If so, update the total locked tokens for the code.
if (referralCode != bytes32(0)) {
_push(_lockedTokensPerReferralCode[referralCode], _add, SafeCast.toUint208(amount));
}
// Emit `TokensLocked` event.
emit TokensLocked(msg.sender, amount, referralCode);
}
/// @dev Method used to lock LP tokens.
function lockLpTokens(uint256 amount, bytes32 _referralCode) external {
// Transfer the amount of lp tokens to lock in this contract.
ERC20(lucky8LpToken).safeTransferFrom(msg.sender, address(this), amount);
// Update the total locked lp tokens for the user and the global total locked lp tokens.
_push(_lockedLpTokens[msg.sender], _add, SafeCast.toUint208(amount));
_push(_totalLpTokenCheckpoint, _add, SafeCast.toUint208(amount));
// Set the account referral code if needed.
_setAccountReferralCode(msg.sender, _referralCode);
// Check if the user has registered a referral code to use.
(bytes32 referralCode,) = referralStorage.getAccountReferralInfo(msg.sender);
// If so, update the total locked tokens for the code.
if (referralCode != bytes32(0)) {
_push(_lockedLpTokensPerReferralCode[referralCode], _add, SafeCast.toUint208(amount));
}
// Emit `LpTokensLocked` event.
emit LpTokensLocked(msg.sender, amount, referralCode);
}
/// @dev Method used to unlock tokens.
function unlockTokens(uint256 amount) external {
require(!isRoundOngoing, "Lottery: round ongoing");
// Get current clock and check that the user has enough locked tokens.
uint48 currentClock = clock();
uint208 lockedTokens = _lockedTokens[msg.sender].upperLookupRecent(currentClock);
require(lockedTokens >= amount, "Lottery: not enough locked tokens");
// Update the user locked tokens and the global locked tokens.
_push(_lockedTokens[msg.sender], _subtract, SafeCast.toUint208(amount));
_push(_totalTokenCheckpoint, _subtract, SafeCast.toUint208(amount));
// Check if the user has registered a referral code to use.
(bytes32 referralCode,) = referralStorage.getAccountReferralInfo(msg.sender);
// If so, update the total locked tokens for the code.
if (referralCode != bytes32(0)) {
_push(_lockedTokensPerReferralCode[referralCode], _subtract, SafeCast.toUint208(amount));
}
// Transfer the amount of tokens back to the user.
ERC20(lucky8Token).safeTransfer(msg.sender, amount);
// Emit `TokensUnlocked` event.
emit TokensUnlocked(msg.sender, amount, referralCode);
}
/// @dev Method used to unlock LP tokens.
/// todo: find a way to reduce tokens locked for referrer when user change referral code.
function unlockLpTokens(uint256 amount) external {
require(!isRoundOngoing, "Lottery: round ongoing");
// Get current clock and check that the user has enough locked lp tokens.
uint48 currentClock = clock();
uint208 lockedLpTokens = _lockedLpTokens[msg.sender].upperLookupRecent(currentClock);
require(lockedLpTokens >= amount, "Lottery: not enough locked tokens");
// Update the user locked lp tokens and the global locked lp tokens.
_push(_lockedLpTokens[msg.sender], _subtract, SafeCast.toUint208(amount));
_push(_totalLpTokenCheckpoint, _subtract, SafeCast.toUint208(amount));
// Check if the user has registered a referral code to use.
(bytes32 referralCode,) = referralStorage.getAccountReferralInfo(msg.sender);
// If so, update the total locked lp tokens for the code.
if (referralCode != bytes32(0)) {
_push(_lockedLpTokensPerReferralCode[referralCode], _subtract, SafeCast.toUint208(amount));
}
// Transfer the amount of lp tokens back to the user.
ERC20(lucky8LpToken).safeTransfer(msg.sender, amount);
// Emit `LpTokensUnlocked` event.
emit LpTokensUnlocked(msg.sender, amount, referralCode);
}
/// @dev Method used to mint raffle tickets.
function mintTickets() external returns (uint256) {
require(isRoundOngoing, "Lottery: no round ongoing");
// Get current round number and round info.
uint256 currentRound = roundNumber;
RoundInfo memory currentRoundInfo = roundInfo[currentRound - 1];
// Check that we are in the minting window.
require(
clock() <= currentRoundInfo.startTimepoint + currentRoundInfo.mintingWindowDuration,
"Lottery: not in minting window"
);
// Check if the user has already minted tickets for this round.
uint256 userTickets = balanceOf(msg.sender, currentRound);
require(userTickets == 0, "Lottery: user already minted tickets");
// Get the amount of claimable tickets for the user.
(uint256 mintableTickets,,,) =
_mintableTicketsForAccount(msg.sender, currentRoundInfo.startTimepoint, currentRoundInfo.tokensPerLpWei);
uint256 totalSupplyBeforeMinting = totalSupply(currentRound);
_mint(msg.sender, currentRound, mintableTickets, "");
uint256 totalSupplyAfterMinting = totalSupply(currentRound);
// Update the user tickets ranges.
userTicketsRanges[currentRound][msg.sender][0] = totalSupplyBeforeMinting;
userTicketsRanges[currentRound][msg.sender][1] = totalSupplyAfterMinting - 1;
// Emit `TicketsMinted` event.
emit TicketsMinted(msg.sender, currentRound, mintableTickets);
return mintableTickets;
}
/// @dev Method used to claim the prize.
function claimPrize() external returns (uint256) {
// Check that there's an ongoing round.
require(isRoundOngoing, "Lottery: no round ongoing");
// Get current round number and round info.
uint48 currentClock = clock();
uint256 currentRound = roundNumber;
RoundInfo memory currentRoundInfo = roundInfo[currentRound - 1];
// Check that the user has at least one ticket.
uint256 userTickets = balanceOf(msg.sender, currentRound);
require(userTickets > 0, "Lottery: no tickets");
// Check that the raffle has been executed.
require(currentRoundInfo.isRaffleExecuted, "Lottery: raffle not executed yet");
// Check that we are in the claiming window.
require(
currentClock > currentRoundInfo.raffleExecutionTimepoint
&& currentClock <= currentRoundInfo.raffleExecutionTimepoint + currentRoundInfo.claimingWindowDuration,
"Lottery: claiming window not started yet or still ongoing"
);
// Get the ticket range for the user.
uint256[2] memory userTicketsRange = userTicketsRanges[currentRound][msg.sender];
// Check if the user has won.
uint256[] memory winningNumbers = currentRoundInfo.winningNumbers;
// Initialize the amount of winning tickets.
uint256 prize;
uint256 winningTickets;
uint256 winningTicketPrize = currentRoundInfo.prizePot.ceilDiv(currentRoundInfo.nWinners);
for (uint256 i = 0; i < winningNumbers.length; i++) {
// Check if the winning number is in the user ticket range.
if (winningNumbers[i] >= userTicketsRange[0] && winningNumbers[i] <= userTicketsRange[1]) {
// Add the amount of winning tickets and the prize.
winningTickets += 1;
prize += winningTicketPrize;
}
}
// Check if the user has won.
require(winningTickets != 0, "Lottery: no winning tickets");
// Burn the all the users tickets.
_burn(msg.sender, currentRound, userTickets);
// Check if the user used a referral code.
// Check if the user has registered a referral code to use.
(bytes32 referralCode, address referrer) = referralStorage.getAccountReferralInfo(msg.sender);
// If so, update the total locked lp tokens for the code.
if (referralCode != bytes32(0)) {
// 10% goes to the referrer.
uint256 referrerShare = prize.mulDiv(5e16, 1e18, Math.Rounding.Floor);
prize = prize - referrerShare;
ERC20(usdcToken).safeTransfer(referrer, referrerShare);
}
// Transfer the prize to the user.
ERC20(usdcToken).safeTransfer(msg.sender, prize);
// Emit `PrizeClaimed` event.
emit PrizeClaimed(msg.sender, currentRound, prize);
return prize;
}
/// @dev Method used to burn user's tickets.
function burnTickets(uint256 round) external {
// Check that the user has at least one ticket.
uint256 userTickets = balanceOf(msg.sender, round);
require(userTickets != 0, "Lottery: no tickets");
// Burn the all the user's tickets.
_burn(msg.sender, round, userTickets);
// Emit `TicketsBurned` event.
emit TicketsBurned(msg.sender, round, userTickets);
}
///////////////////////////////////////////
///////////// ADMIN FUNCTIONS /////////////
///////////////////////////////////////////
/// @dev Function used to set the token URI.
function setURI(string calldata _uri) external onlyOwner {
_setURI(_uri);
}
/// @dev Function used to withdraw tokens from the contract.
/// @dev This function can be used to withdraw tokens that are not $888 or $888/USDC LP tokens.
/// @dev This function can only be called by the owner.
function withdrawTokens(address token, uint256 amount) external onlyOwner {
require(token != lucky8Token, "Lottery: cannot withdraw 888 tokens");
require(token != lucky8LpToken, "Lottery: cannot withdraw 888/USDC LP tokens");
ERC20(token).safeTransfer(msg.sender, amount);
}
/// @dev Function used to set the referral storage.
function setReferralStorage(IReferralStorage _referralStorage) external onlyOwner {
referralStorage = _referralStorage;
emit SetReferralStorage(address(_referralStorage));
}
/// @dev Function used to set the buyback and burn address.
function setBuybackBurnAddress(address _buybackBurnAddress) external onlyOwner {
buybackBurnAddress = _buybackBurnAddress;
emit SetBuybackBurnAddress(_buybackBurnAddress);
}
/// @dev Function used to set the chainlink subscription id.
function setChainlinkSubscriptionId(uint64 _chainlinkSubscriptionId) external onlyOwner {
chainlinkSubscriptionId = _chainlinkSubscriptionId;
}
/// @dev Function used to set the chainlink minimum request confirmations.
function setChainlinkMinimumRequestConfirmations(uint16 _chainlinkMinimumRequestConfirmations) external onlyOwner {
chainlinkMinimumRequestConfirmations = _chainlinkMinimumRequestConfirmations;
}
/// @dev Function used to set the chainlink callback gas.
function setChainlinkCallbackGas(uint32 _chainlinkCallbackGas) external onlyOwner {
chainlinkCallbackGas = _chainlinkCallbackGas;
}
/// @dev Init params for initializing a new round.
struct InitParams {
string tokenUri;
uint8 nWinners;
uint48 mintingWindowDuration;
uint48 claimingWindowDuration;
uint256 buyBackPct;
uint256 lpWeiValue;
}
/// @dev Function used to start a new raffle round.
/// @dev This function snapshots the state of the contract (total token and LP token locked)
/// and updates the latest raffle timepoint. From this point on users can then mint the
/// ERC-1155 token representing their raffle tickets.
///
/// @dev This function can only be called by the owner.
function startNewRound(InitParams calldata params) public onlyOwner {
// Check that a round is not ongoing.
require(!isRoundOngoing, "Lottery: round already ongoing");
// Check that the `mintingWindowDuration` is not 0.
require(params.mintingWindowDuration != 0, "Lottery: minting window duration must be greater than 0");
// Check that the `claimingWindowDuration` is not 0.
require(params.claimingWindowDuration != 0, "Lottery: claiming window duration must be greater than 0");
// Check that the `buyBackPct` is not greater than the max buyback and burn percentage.
require(params.buyBackPct <= MAX_BUYBACK_BURN, "Lottery: buyback and burn percentage too high");
// Get the current clock
uint48 currentClock = clock();
// Get the amount of total locked tokens and lp tokens.
uint208 totalToken = _totalTokenCheckpoint.upperLookupRecent(currentClock);
uint208 totalLpToken = _totalLpTokenCheckpoint.upperLookupRecent(currentClock);
// Update the total locked tokens and lp tokens checkpoints for the current clock value.
_totalTokenCheckpoint.push(currentClock, SafeCast.toUint208(totalToken));
_totalLpTokenCheckpoint.push(currentClock, SafeCast.toUint208(totalLpToken));
// Compute the prize pot and transfer amount for buyback and burn.
uint256 usdcBalance = ERC20(usdcToken).balanceOf(address(this));
uint256 buyBackAmount = usdcBalance.mulDiv(params.buyBackPct, 1e18);
uint256 rollOverAmount = usdcBalance.mulDiv(1e17, 1e18);
// Transfer the buyback amount to the buyback and burn address.
ERC20(usdcToken).safeTransfer(buybackBurnAddress, buyBackAmount);
uint256 prizePot = usdcBalance - (buyBackAmount + rollOverAmount);
// Initialize the round infos
RoundInfo memory round = RoundInfo({
isRaffleExecuted: false,
prizePot: prizePot,
tokensPerLpWei: params.lpWeiValue,
raffleExecutionTimepoint: 0,
startTimepoint: currentClock,
nWinners: params.nWinners,
reqId: 0,
mintingWindowDuration: params.mintingWindowDuration,
claimingWindowDuration: params.claimingWindowDuration,
winningNumbers: new uint256[](0)
});
// Update the round number and round info.
roundNumber += 1;
roundInfo.push(round);
// Set the global state as ongoing round.
isRoundOngoing = true;
// Set the token URI for the round.
_setURI(roundNumber, params.tokenUri);
// Emit `RoundStarted` event.
emit RoundStarted(
roundNumber,
prizePot,
params.nWinners,
params.mintingWindowDuration,
params.claimingWindowDuration,
params.buyBackPct,
params.lpWeiValue
);
}
/// @dev Function used to execute the raffle.
/// @dev This function can only be called by the owner.
function executeRaffle() public onlyOwner {
uint48 currentClock = clock();
RoundInfo storage currentRound = roundInfo[roundNumber - 1];
require(!currentRound.isRaffleExecuted, "Lottery: raffle already executed");
require(
currentClock > currentRound.startTimepoint + currentRound.mintingWindowDuration,
"Lottery: raffle not started yet"
);
// Get the amount of winners to draw.
uint8 nWinners = currentRound.nWinners;
// Use the Chainlink VRF to get a random number.
// This will initiate the request but we will need to wait for the request to be fulfilled.
// See the method `fulfillRandomWords` for the callback.
uint256 requestId = VRFCoordinatorV2Interface(vrfCoordinator).requestRandomWords(
VRF_KEYHASH, // keyHash
chainlinkSubscriptionId,
chainlinkMinimumRequestConfirmations, // minimumRequestConfirmations
chainlinkCallbackGas, // callbackGasLimit
nWinners // numWords
);
// Update current round request id and mapping between request id and round number.
currentRound.reqId = requestId;
requestIdToRound[requestId] = roundNumber;
}
/// @dev Function used to finalize the current round.
/// @dev This function can only be called by the owner.
function finalizeRound() public onlyOwner {
require(isRoundOngoing, "Lottery: no round ongoing");
uint256 _roundNumber = roundNumber;
RoundInfo storage currentRound = roundInfo[_roundNumber - 1];
// Require that the raffle has been executed.
require(currentRound.isRaffleExecuted, "Lottery: raffle not executed yet");
// And that the claiming window is over.
require(
clock() > currentRound.raffleExecutionTimepoint + currentRound.claimingWindowDuration,
"Lottery: claiming window not started yet or still ongoing"
);
isRoundOngoing = false;
emit RoundFinalized(_roundNumber);
}
/// @dev Function used to finalize the current round without checks.
/// @dev This function can only be called by the owner.
/// @dev THIS SHOULD BE USED ONLY IN EMERGENCY CASES.
function forceFinalizeRound() public onlyOwner {
require(isRoundOngoing, "Lottery: no round ongoing");
isRoundOngoing = false;
emit RoundFinalized(roundNumber);
}
///////////////////////////////////////////
////////// ERC-1155 OVERRIDES /////////////
///////////////////////////////////////////
/// @dev Override needed to make the tickets non-transferable.
function safeTransferFrom(
address, /* from */
address, /* to */
uint256, /* id */
uint256, /* value */
bytes memory /* data */
)
public
pure
override
{
revert("Lottery: Tickets are non-transferable");
}
/// @dev Override needed to make the tickets non-transferable.
function safeBatchTransferFrom(
address, /* from */
address, /* to */
uint256[] memory, /* ids */
uint256[] memory, /* values */
bytes memory /* data */
)
public
pure
override
{
revert("Lottery: Tickets are non-transferable");
}
/// @dev Override needed to get token id URI.
function uri(uint256 id) public view override(ERC1155URIStorage, ERC1155) returns (string memory) {
return super.uri(id);
}
/// @dev Override needed to update balances for ERC-1155 tokens.
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
)
internal
override(ERC1155Supply, ERC1155)
{
super._update(from, to, ids, values);
}
///////////////////////////////////////////
////////// INTERNAL FUNCTIONS /////////////
///////////////////////////////////////////
/// @dev Method used to get the amount of $888 tokens per LP wei.
function _tokensPerLpWei() internal view returns (uint256) {
(uint112 r0, uint112 r1,) = IUniswapV2Pair(lucky8LpToken).getReserves();
uint256 pairReserves = (IUniswapV2Pair(lucky8LpToken).token0() == lucky8Token) ? r0 : r1;
uint256 lpTokenSupply = ERC20(lucky8LpToken).totalSupply();
// We multiply the reserves by 3 because LP token holders are entitled to a 1.5x bonus.
return (3 * pairReserves) / lpTokenSupply;
}
/// @dev Method used to get the amount of claimable tickets.
function _mintableTicketsForAccount(
address _account,
uint48 _startTimepoint,
uint256 _tokensPerLpWeiAmount
)
internal
view
returns (uint256, uint256, uint256, uint256)
{
// Initialize the bonus amount.
uint256 bonusAmount;
// Check the amount of locked tokens and LP tokens for the user.
uint208 lockedTokens = _lockedTokens[_account].upperLookupRecent(_startTimepoint);
uint208 lockedLpTokens = _lockedLpTokens[_account].upperLookupRecent(_startTimepoint);
// The total amount of locked tokens is equal to the sum of locked tokens and (locked LP tokens * tickets per lp
// wei).
// note: This quantity is (tickets * 1e18).
uint256 userLockedTokens = lockedTokens + (lockedLpTokens * _tokensPerLpWeiAmount);
// If the user used a referral code add a 10% bonus.
(bytes32 referralCode,) = referralStorage.getAccountReferralInfo(_account);
if (referralCode != bytes32(0)) {
bonusAmount = userLockedTokens.mulDiv(1e17, 1e18, Math.Rounding.Floor);
}
// If the user has no locked tokens, return 0.
if (userLockedTokens == 0) return (0, 0, 0, 0);
// Check if the user has a referrer code.
bytes32 referrerCode = referralStorage.accountCodeOwned(_account);
// If so, check the amount of locked tokens and LP tokens for the referrer.
if (referrerCode != bytes32(0)) {
uint208 lockedReferralTokens = _lockedTokensPerReferralCode[referrerCode].upperLookupRecent(_startTimepoint);
uint208 lockedReferralLpTokens =
_lockedLpTokensPerReferralCode[referrerCode].upperLookupRecent(_startTimepoint);
// The total amount of locked tokens is equal to the sum of locked tokens and (locked LP tokens * tickets
// per lp wei).
uint256 referralLockedTokens = lockedReferralTokens + (lockedReferralLpTokens * _tokensPerLpWeiAmount);
// The ratio between referral locked tokens and user locked tokens is used to calculate the bonus amount.
uint256 ratio = referralLockedTokens.mulDiv(1e18, userLockedTokens, Math.Rounding.Floor);
// The bonus multiplier is the min between ratio and 10.
uint256 bonusMultiplier = Math.min(ratio, 1e19);
// The bonus amount is equal to (user locked tokens * bonus multiplier).
bonusAmount = bonusAmount + userLockedTokens.mulDiv(bonusMultiplier, 1e18, Math.Rounding.Floor);
}
// The mintable tickets is equal to (user locked tokens + bonus amount) / 1e18.
uint256 mintableTickets = (userLockedTokens + bonusAmount).ceilDiv(1e18);
return (
mintableTickets,
uint256(lockedTokens).ceilDiv(1e18),
uint256(lockedLpTokens).ceilDiv(1e18),
bonusAmount.ceilDiv(1e18)
);
}
/// @dev Callback function used by the Chainlink VRF.
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {
// Check that a round is ongoing.
require(isRoundOngoing, "Lottery: no round ongoing");
// Get the round number for the request id.
uint256 round = requestIdToRound[requestId];
// Get the round info.
RoundInfo storage currentRound = roundInfo[round - 1];
// Check that the round has the same request id.
require(currentRound.reqId == requestId, "Lottery: wrong request id");
// Check that the round raffle has not been executed yet.
require(
!currentRound.isRaffleExecuted && currentRound.raffleExecutionTimepoint == 0,
"Lottery: raffle already executed"
);
uint48 currentClock = clock();
// Check that the round is not in the minting phase.
require(
currentClock > currentRound.startTimepoint + currentRound.mintingWindowDuration,
"Lottery: raffle minting phase ongoing"
);
// Iterate over the random words and get the winning numbers.
for (uint256 i = 0; i < currentRound.nWinners; i++) {
uint256 winningNumber = randomWords[i] % totalSupply(round);
currentRound.winningNumbers.push(winningNumber);
}
// Finalize the round.
currentRound.isRaffleExecuted = true;
currentRound.raffleExecutionTimepoint = currentClock;
// Emit `RaffleExecuted` event.
emit RaffleExecuted(round, currentRound.winningNumbers);
}
/// @dev Internal utility function used to set the referral code for an account.
function _setAccountReferralCode(address _account, bytes32 _referralCode) internal {
// skip if referral code is null
if (_referralCode == bytes32(0)) return;
// skip if referral storage is not set
if (address(referralStorage) == address(0)) return;
// skip if the account already has a referral code set
if (referralStorage.accountReferralCode(_account) != bytes32(0)) return;
referralStorage.setAccountReferralCode(_account, _referralCode);
}
/// @dev Pushes a new checkpoint to a given tracer.
function _push(
Checkpoints.Trace208 storage store,
function(uint208, uint208) view returns (uint208) op,
uint208 delta
)
private
returns (uint208, uint208)
{
return store.push(clock(), op(store.latest(), delta));
}
/// @dev Adds two numbers.
function _add(uint208 a, uint208 b) private pure returns (uint208) {
return a + b;
}
/// @dev Subtracts two numbers.
function _subtract(uint208 a, uint208 b) private pure returns (uint208) {
return a - b;
}
}/// SPDX-License-Identifier: UNLICENSED
pragma solidity >= 0.8.21;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
)
external;
event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function mint(address to) external returns (uint256 liquidity);
function burn(address to) external returns (uint256 amount0, uint256 amount1);
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds 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.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 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 prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @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 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @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.0.0) (utils/types/Time.sol)
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
import {SafeCast} from "../math/SafeCast.sol";
/**
* @dev This library provides helpers for manipulating time-related objects.
*
* It uses the following types:
* - `uint48` for timepoints
* - `uint32` for durations
*
* While the library doesn't provide specific types for timepoints and duration, it does provide:
* - a `Delay` type to represent duration that can be programmed to change value automatically at a given point
* - additional helper functions
*/
library Time {
using Time for *;
/**
* @dev Get the block timestamp as a Timepoint.
*/
function timestamp() internal view returns (uint48) {
return SafeCast.toUint48(block.timestamp);
}
/**
* @dev Get the block number as a Timepoint.
*/
function blockNumber() internal view returns (uint48) {
return SafeCast.toUint48(block.number);
}
// ==================================================== Delay =====================================================
/**
* @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the
* future. The "effect" timepoint describes when the transitions happens from the "old" value to the "new" value.
* This allows updating the delay applied to some operation while keeping some guarantees.
*
* In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for
* some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set
* the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should
* still apply for some time.
*
*
* The `Delay` type is 112 bits long, and packs the following:
*
* ```
* | [uint48]: effect date (timepoint)
* | | [uint32]: value before (duration)
* ↓ ↓ ↓ [uint32]: value after (duration)
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
* ```
*
* NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
* supported.
*/
type Delay is uint112;
/**
* @dev Wrap a duration into a Delay to add the one-step "update in the future" feature
*/
function toDelay(uint32 duration) internal pure returns (Delay) {
return Delay.wrap(duration);
}
/**
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
*/
function _getFullAt(Delay self, uint48 timepoint) private pure returns (uint32, uint32, uint48) {
(uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
}
/**
* @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the
* effect timepoint is 0, then the pending value should not be considered.
*/
function getFull(Delay self) internal view returns (uint32, uint32, uint48) {
return _getFullAt(self, timestamp());
}
/**
* @dev Get the current value.
*/
function get(Delay self) internal view returns (uint32) {
(uint32 delay, , ) = self.getFull();
return delay;
}
/**
* @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to
* enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
* new delay becomes effective.
*/
function withUpdate(
Delay self,
uint32 newValue,
uint32 minSetback
) internal view returns (Delay updatedDelay, uint48 effect) {
uint32 value = self.get();
uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
effect = timestamp() + setback;
return (pack(value, newValue, effect), effect);
}
/**
* @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
*/
function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
uint112 raw = Delay.unwrap(self);
valueAfter = uint32(raw);
valueBefore = uint32(raw >> 32);
effect = uint48(raw >> 64);
return (valueBefore, valueAfter, effect);
}
/**
* @dev pack the components into a Delay object.
*/
function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {
return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));
}
}// 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.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
*
* @notice Interface for contracts using VRF randomness
* *****************************************************************************
* @dev PURPOSE
*
* @dev Reggie the Random Oracle (not his real job) wants to provide randomness
* @dev to Vera the verifier in such a way that Vera can be sure he's not
* @dev making his output up to suit himself. Reggie provides Vera a public key
* @dev to which he knows the secret key. Each time Vera provides a seed to
* @dev Reggie, he gives back a value which is computed completely
* @dev deterministically from the seed and the secret key.
*
* @dev Reggie provides a proof by which Vera can verify that the output was
* @dev correctly computed once Reggie tells it to her, but without that proof,
* @dev the output is indistinguishable to her from a uniform random sample
* @dev from the output space.
*
* @dev The purpose of this contract is to make it easy for unrelated contracts
* @dev to talk to Vera the verifier about the work Reggie is doing, to provide
* @dev simple access to a verifiable source of randomness. It ensures 2 things:
* @dev 1. The fulfillment came from the VRFCoordinator
* @dev 2. The consumer contract implements fulfillRandomWords.
* *****************************************************************************
* @dev USAGE
*
* @dev Calling contracts must inherit from VRFConsumerBase, and can
* @dev initialize VRFConsumerBase's attributes in their constructor as
* @dev shown:
*
* @dev contract VRFConsumer {
* @dev constructor(<other arguments>, address _vrfCoordinator, address _link)
* @dev VRFConsumerBase(_vrfCoordinator) public {
* @dev <initialization with other arguments goes here>
* @dev }
* @dev }
*
* @dev The oracle will have given you an ID for the VRF keypair they have
* @dev committed to (let's call it keyHash). Create subscription, fund it
* @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface
* @dev subscription management functions).
* @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,
* @dev callbackGasLimit, numWords),
* @dev see (VRFCoordinatorInterface for a description of the arguments).
*
* @dev Once the VRFCoordinator has received and validated the oracle's response
* @dev to your request, it will call your contract's fulfillRandomWords method.
*
* @dev The randomness argument to fulfillRandomWords is a set of random words
* @dev generated from your requestId and the blockHash of the request.
*
* @dev If your contract could have concurrent requests open, you can use the
* @dev requestId returned from requestRandomWords to track which response is associated
* @dev with which randomness request.
* @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind,
* @dev if your contract could have multiple requests in flight simultaneously.
*
* @dev Colliding `requestId`s are cryptographically impossible as long as seeds
* @dev differ.
*
* *****************************************************************************
* @dev SECURITY CONSIDERATIONS
*
* @dev A method with the ability to call your fulfillRandomness method directly
* @dev could spoof a VRF response with any random value, so it's critical that
* @dev it cannot be directly called by anything other than this base contract
* @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).
*
* @dev For your users to trust that your contract's random behavior is free
* @dev from malicious interference, it's best if you can write it so that all
* @dev behaviors implied by a VRF response are executed *during* your
* @dev fulfillRandomness method. If your contract must store the response (or
* @dev anything derived from it) and use it later, you must ensure that any
* @dev user-significant behavior which depends on that stored value cannot be
* @dev manipulated by a subsequent VRF request.
*
* @dev Similarly, both miners and the VRF oracle itself have some influence
* @dev over the order in which VRF responses appear on the blockchain, so if
* @dev your contract could have multiple VRF requests in flight simultaneously,
* @dev you must ensure that the order in which the VRF responses arrive cannot
* @dev be used to manipulate your contract's user-significant behavior.
*
* @dev Since the block hash of the block which contains the requestRandomness
* @dev call is mixed into the input to the VRF *last*, a sufficiently powerful
* @dev miner could, in principle, fork the blockchain to evict the block
* @dev containing the request, forcing the request to be included in a
* @dev different block with a different hash, and therefore a different input
* @dev to the VRF. However, such an attack would incur a substantial economic
* @dev cost. This cost scales with the number of blocks the VRF oracle waits
* @dev until it calls responds to a request. It is for this reason that
* @dev that you can signal to an oracle you'd like them to wait longer before
* @dev responding to the request (however this is not enforced in the contract
* @dev and so remains effective only in the case of unmodified oracle software).
*/
abstract contract VRFConsumerBaseV2 {
error OnlyCoordinatorCanFulfill(address have, address want);
// solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
address private immutable vrfCoordinator;
/**
* @param _vrfCoordinator address of VRFCoordinator contract
*/
constructor(address _vrfCoordinator) {
vrfCoordinator = _vrfCoordinator;
}
/**
* @notice fulfillRandomness handles the VRF response. Your contract must
* @notice implement it. See "SECURITY CONSIDERATIONS" above for important
* @notice principles to keep in mind when implementing your fulfillRandomness
* @notice method.
*
* @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this
* @dev signature, and will call it once it has verified the proof
* @dev associated with the randomness. (It is triggered via a call to
* @dev rawFulfillRandomness, below.)
*
* @param requestId The Id initially returned by requestRandomness
* @param randomWords the VRF output expanded to the requested number of words
*/
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;
// rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF
// proof. rawFulfillRandomness then calls fulfillRandomness, after validating
// the origin of the call
function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {
if (msg.sender != vrfCoordinator) {
revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);
}
fulfillRandomWords(requestId, randomWords);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 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);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "./IERC1155.sol";
import {IERC1155Receiver} from "./IERC1155Receiver.sol";
import {IERC1155MetadataURI} from "./extensions/IERC1155MetadataURI.sol";
import {Context} from "../../utils/Context.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {Arrays} from "../../utils/Arrays.sol";
import {IERC1155Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*/
abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
using Arrays for uint256[];
using Arrays for address[];
mapping(uint256 id => mapping(address account => uint256)) private _balances;
mapping(address account => mapping(address operator => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/**
* @dev See {_setURI}.
*/
constructor(string memory uri_) {
_setURI(uri_);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC1155).interfaceId ||
interfaceId == type(IERC1155MetadataURI).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256 /* id */) public view virtual returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*/
function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
) public view virtual returns (uint256[] memory) {
if (accounts.length != ids.length) {
revert ERC1155InvalidArrayLength(ids.length, accounts.length);
}
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i));
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeTransferFrom(from, to, id, value, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_safeBatchTransferFrom(from, to, ids, values, data);
}
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
* (or `to`) is the zero address.
*
* Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received}
* or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value.
* - `ids` and `values` must have the same length.
*
* NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead.
*/
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual {
if (ids.length != values.length) {
revert ERC1155InvalidArrayLength(ids.length, values.length);
}
address operator = _msgSender();
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids.unsafeMemoryAccess(i);
uint256 value = values.unsafeMemoryAccess(i);
if (from != address(0)) {
uint256 fromBalance = _balances[id][from];
if (fromBalance < value) {
revert ERC1155InsufficientBalance(from, fromBalance, value, id);
}
unchecked {
// Overflow not possible: value <= fromBalance
_balances[id][from] = fromBalance - value;
}
}
if (to != address(0)) {
_balances[id][to] += value;
}
}
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
emit TransferSingle(operator, from, to, id, value);
} else {
emit TransferBatch(operator, from, to, ids, values);
}
}
/**
* @dev Version of {_update} that performs the token acceptance check by calling
* {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it
* contains code (eg. is a smart contract at the moment of execution).
*
* IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any
* update to the contract state after this function would break the check-effect-interaction pattern. Consider
* overriding {_update} instead.
*/
function _updateWithAcceptanceCheck(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal virtual {
_update(from, to, ids, values);
if (to != address(0)) {
address operator = _msgSender();
if (ids.length == 1) {
uint256 id = ids.unsafeMemoryAccess(0);
uint256 value = values.unsafeMemoryAccess(0);
_doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
} else {
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
}
}
}
/**
* @dev Transfers a `value` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
* - `ids` and `values` must have the same length.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, to, ids, values, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the values in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
}
/**
* @dev Destroys a `value` amount of tokens of type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
*/
function _burn(address from, uint256 id, uint256 value) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `value` amount of tokens of type `id`.
* - `ids` and `values` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
if (from == address(0)) {
revert ERC1155InvalidSender(address(0));
}
_updateWithAcceptanceCheck(from, address(0), ids, values, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the zero address.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC1155InvalidOperator(address(0));
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Performs an acceptance check by calling {IERC1155-onERC1155Received} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 value,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Performs a batch acceptance check by calling {IERC1155-onERC1155BatchReceived} on the `to` address
* if it contains code at the moment of execution.
*/
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) private {
if (to.code.length > 0) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
// Tokens rejected
revert ERC1155InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-ERC1155Receiver implementer
revert ERC1155InvalidReceiver(to);
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
}
/**
* @dev Creates an array in memory with only one value for each of the elements provided.
*/
function _asSingletonArrays(
uint256 element1,
uint256 element2
) private pure returns (uint256[] memory array1, uint256[] memory array2) {
/// @solidity memory-safe-assembly
assembly {
// Load the free memory pointer
array1 := mload(0x40)
// Set array length to 1
mstore(array1, 1)
// Store the single element at the next word after the length (where content starts)
mstore(add(array1, 0x20), element1)
// Repeat for next array locating it right after the first array
array2 := add(array1, 0x40)
mstore(array2, 1)
mstore(add(array2, 0x20), element2)
// Update the free memory pointer by pointing after the second array
mstore(0x40, add(array2, 0x40))
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.21;
interface IReferralStorage {
function codeOwner(bytes32 _code) external view returns (address);
function accountCodeOwned(address _account) external view returns (bytes32);
function accountReferralCode(address _account) external view returns (bytes32);
function setAccountReferralCode(address _account, bytes32 _code) external;
function getAccountReferralInfo(address _account) external view returns (bytes32, address);
function adminSetCodeOwner(bytes32 _code, address _newAccount) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/Checkpoints.sol)
// This file was procedurally generated from scripts/generate/templates/Checkpoints.js.
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
/**
* @dev This library defines the `Trace*` struct, for checkpointing values as they change at different points in
* time, and later looking up past values by block number. See {Votes} as an example.
*
* To create a history of checkpoints define a variable type `Checkpoints.Trace*` in your contract, and store a new
* checkpoint for the current transaction block using the {push} function.
*/
library Checkpoints {
/**
* @dev A value was attempted to be inserted on a past checkpoint.
*/
error CheckpointUnorderedInsertion();
struct Trace224 {
Checkpoint224[] _checkpoints;
}
struct Checkpoint224 {
uint32 _key;
uint224 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace224 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint32).max` key set will disable the
* library.
*/
function push(Trace224 storage self, uint32 key, uint224 value) internal returns (uint224, uint224) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace224 storage self, uint32 key) internal view returns (uint224) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace224 storage self) internal view returns (uint224) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace224 storage self) internal view returns (bool exists, uint32 _key, uint224 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint224 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace224 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace224 storage self, uint32 pos) internal view returns (Checkpoint224 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint224[] storage self, uint32 key, uint224 value) private returns (uint224, uint224) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint224 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint224({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint224({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint224[] storage self,
uint32 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint224[] storage self,
uint32 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint224[] storage self,
uint256 pos
) private pure returns (Checkpoint224 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
struct Trace208 {
Checkpoint208[] _checkpoints;
}
struct Checkpoint208 {
uint48 _key;
uint208 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace208 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the
* library.
*/
function push(Trace208 storage self, uint48 key, uint208 value) internal returns (uint208, uint208) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace208 storage self, uint48 key) internal view returns (uint208) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace208 storage self) internal view returns (uint208) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace208 storage self) internal view returns (bool exists, uint48 _key, uint208 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint208 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace208 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace208 storage self, uint32 pos) internal view returns (Checkpoint208 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint208[] storage self, uint48 key, uint208 value) private returns (uint208, uint208) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint208 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint208({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint208({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint208[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint208[] storage self,
uint48 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint208[] storage self,
uint256 pos
) private pure returns (Checkpoint208 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
struct Trace160 {
Checkpoint160[] _checkpoints;
}
struct Checkpoint160 {
uint96 _key;
uint160 _value;
}
/**
* @dev Pushes a (`key`, `value`) pair into a Trace160 so that it is stored as the checkpoint.
*
* Returns previous value and new value.
*
* IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint96).max` key set will disable the
* library.
*/
function push(Trace160 storage self, uint96 key, uint160 value) internal returns (uint160, uint160) {
return _insert(self._checkpoints, key, value);
}
/**
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if
* there is none.
*/
function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);
return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*/
function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero
* if there is none.
*
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high
* keys).
*/
function upperLookupRecent(Trace160 storage self, uint96 key) internal view returns (uint160) {
uint256 len = self._checkpoints.length;
uint256 low = 0;
uint256 high = len;
if (len > 5) {
uint256 mid = len - Math.sqrt(len);
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
high = mid;
} else {
low = mid + 1;
}
}
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
*/
function latest(Trace160 storage self) internal view returns (uint160) {
uint256 pos = self._checkpoints.length;
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
}
/**
* @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value
* in the most recent checkpoint.
*/
function latestCheckpoint(Trace160 storage self) internal view returns (bool exists, uint96 _key, uint160 _value) {
uint256 pos = self._checkpoints.length;
if (pos == 0) {
return (false, 0, 0);
} else {
Checkpoint160 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);
return (true, ckpt._key, ckpt._value);
}
}
/**
* @dev Returns the number of checkpoint.
*/
function length(Trace160 storage self) internal view returns (uint256) {
return self._checkpoints.length;
}
/**
* @dev Returns checkpoint at given position.
*/
function at(Trace160 storage self, uint32 pos) internal view returns (Checkpoint160 memory) {
return self._checkpoints[pos];
}
/**
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
* or by updating the last one.
*/
function _insert(Checkpoint160[] storage self, uint96 key, uint160 value) private returns (uint160, uint160) {
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
Checkpoint160 memory last = _unsafeAccess(self, pos - 1);
// Checkpoint keys must be non-decreasing.
if (last._key > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last._key == key) {
_unsafeAccess(self, pos - 1)._value = value;
} else {
self.push(Checkpoint160({_key: key, _value: value}));
}
return (last._value, value);
} else {
self.push(Checkpoint160({_key: key, _value: value}));
return (0, value);
}
}
/**
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`
* if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive
* `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _upperBinaryLookup(
Checkpoint160[] storage self,
uint96 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key > key) {
high = mid;
} else {
low = mid + 1;
}
}
return high;
}
/**
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or
* `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and
* exclusive `high`.
*
* WARNING: `high` should not be greater than the array's length.
*/
function _lowerBinaryLookup(
Checkpoint160[] storage self,
uint96 key,
uint256 low,
uint256 high
) private view returns (uint256) {
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(self, mid)._key < key) {
low = mid + 1;
} else {
high = mid;
}
}
return high;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
*/
function _unsafeAccess(
Checkpoint160[] storage self,
uint256 pos
) private pure returns (Checkpoint160 storage result) {
assembly {
mstore(0, self.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface VRFCoordinatorV2Interface {
/**
* @notice Get configuration relevant for making requests
* @return minimumRequestConfirmations global min for request confirmations
* @return maxGasLimit global max for request gas limit
* @return s_provingKeyHashes list of registered key hashes
*/
function getRequestConfig() external view returns (uint16, uint32, bytes32[] memory);
/**
* @notice Request a set of random words.
* @param keyHash - Corresponds to a particular oracle job which uses
* that key for generating the VRF proof. Different keyHash's have different gas price
* ceilings, so you can select a specific one to bound your maximum per request cost.
* @param subId - The ID of the VRF subscription. Must be funded
* with the minimum subscription balance required for the selected keyHash.
* @param minimumRequestConfirmations - How many blocks you'd like the
* oracle to wait before responding to the request. See SECURITY CONSIDERATIONS
* for why you may want to request more. The acceptable range is
* [minimumRequestBlockConfirmations, 200].
* @param callbackGasLimit - How much gas you'd like to receive in your
* fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords
* may be slightly less than this amount because of gas used calling the function
* (argument decoding etc.), so you may need to request slightly more than you expect
* to have inside fulfillRandomWords. The acceptable range is
* [0, maxGasLimit]
* @param numWords - The number of uint256 random values you'd like to receive
* in your fulfillRandomWords callback. Note these numbers are expanded in a
* secure way by the VRFCoordinator from a single random value supplied by the oracle.
* @return requestId - A unique identifier of the request. Can be used to match
* a request to a response in fulfillRandomWords.
*/
function requestRandomWords(
bytes32 keyHash,
uint64 subId,
uint16 minimumRequestConfirmations,
uint32 callbackGasLimit,
uint32 numWords
)
external
returns (uint256 requestId);
/**
* @notice Create a VRF subscription.
* @return subId - A unique subscription id.
* @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.
* @dev Note to fund the subscription, use transferAndCall. For example
* @dev LINKTOKEN.transferAndCall(
* @dev address(COORDINATOR),
* @dev amount,
* @dev abi.encode(subId));
*/
function createSubscription() external returns (uint64 subId);
/**
* @notice Get a VRF subscription.
* @param subId - ID of the subscription
* @return balance - LINK balance of the subscription in juels.
* @return reqCount - number of requests for this subscription, determines fee tier.
* @return owner - owner of the subscription.
* @return consumers - list of consumer address which are able to use this subscription.
*/
function getSubscription(uint64 subId)
external
view
returns (uint96 balance, uint64 reqCount, address owner, address[] memory consumers);
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @param newOwner - proposed new owner of the subscription
*/
function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @dev will revert if original owner of subId has
* not requested that msg.sender become the new owner.
*/
function acceptSubscriptionOwnerTransfer(uint64 subId) external;
/**
* @notice Add a consumer to a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - New consumer which can use the subscription
*/
function addConsumer(uint64 subId, address consumer) external;
/**
* @notice Remove a consumer from a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - Consumer to remove from the subscription
*/
function removeConsumer(uint64 subId, address consumer) external;
/**
* @notice Cancel a subscription
* @param subId - ID of the subscription
* @param to - Where to send the remaining LINK to
*/
function cancelSubscription(uint64 subId, address to) external;
/*
* @notice Check to see if there exists a request commitment consumers
* for all consumers and keyhashes for a given sub.
* @param subId - ID of the subscription
* @return true if there exists at least one unfulfilled request for the subscription, false
* otherwise.
*/
function pendingRequestExists(uint64 subId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/ERC1155Supply.sol)
pragma solidity ^0.8.20;
import {ERC1155} from "../ERC1155.sol";
/**
* @dev Extension of ERC1155 that adds tracking of total supply per id.
*
* Useful for scenarios where Fungible and Non-fungible tokens have to be
* clearly identified. Note: While a totalSupply of 1 might mean the
* corresponding is an NFT, there is no guarantees that no other token with the
* same id are not going to be minted.
*
* NOTE: This contract implies a global limit of 2**256 - 1 to the number of tokens
* that can be minted.
*
* CAUTION: This extension should not be added in an upgrade to an already deployed contract.
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 id => uint256) private _totalSupply;
uint256 private _totalSupplyAll;
/**
* @dev Total value of tokens in with a given id.
*/
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
/**
* @dev Total value of tokens.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupplyAll;
}
/**
* @dev Indicates whether any token exist with a given id, or not.
*/
function exists(uint256 id) public view virtual returns (bool) {
return totalSupply(id) > 0;
}
/**
* @dev See {ERC1155-_update}.
*/
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal virtual override {
super._update(from, to, ids, values);
if (from == address(0)) {
uint256 totalMintValue = 0;
for (uint256 i = 0; i < ids.length; ++i) {
uint256 value = values[i];
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply[ids[i]] += value;
totalMintValue += value;
}
// Overflow check required: The rest of the code assumes that totalSupplyAll never overflows
_totalSupplyAll += totalMintValue;
}
if (to == address(0)) {
uint256 totalBurnValue = 0;
for (uint256 i = 0; i < ids.length; ++i) {
uint256 value = values[i];
unchecked {
// Overflow not possible: values[i] <= balanceOf(from, ids[i]) <= totalSupply(ids[i])
_totalSupply[ids[i]] -= value;
// Overflow not possible: sum_i(values[i]) <= sum_i(totalSupply(ids[i])) <= totalSupplyAll
totalBurnValue += value;
}
}
unchecked {
// Overflow not possible: totalBurnValue = sum_i(values[i]) <= sum_i(totalSupply(ids[i])) <= totalSupplyAll
_totalSupplyAll -= totalBurnValue;
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/ERC1155URIStorage.sol)
pragma solidity ^0.8.20;
import {Strings} from "../../../utils/Strings.sol";
import {ERC1155} from "../ERC1155.sol";
/**
* @dev ERC1155 token with storage based token URI management.
* Inspired by the ERC721URIStorage extension
*/
abstract contract ERC1155URIStorage is ERC1155 {
using Strings for uint256;
// Optional base URI
string private _baseURI = "";
// Optional mapping for token URIs
mapping(uint256 tokenId => string) private _tokenURIs;
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the concatenation of the `_baseURI`
* and the token-specific uri if the latter is set
*
* This enables the following behaviors:
*
* - if `_tokenURIs[tokenId]` is set, then the result is the concatenation
* of `_baseURI` and `_tokenURIs[tokenId]` (keep in mind that `_baseURI`
* is empty per default);
*
* - if `_tokenURIs[tokenId]` is NOT set then we fallback to `super.uri()`
* which in most cases will contain `ERC1155._uri`;
*
* - if `_tokenURIs[tokenId]` is NOT set, and if the parents do not have a
* uri value set, then the result is empty.
*/
function uri(uint256 tokenId) public view virtual override returns (string memory) {
string memory tokenURI = _tokenURIs[tokenId];
// If token URI is set, concatenate base URI and tokenURI (via string.concat).
return bytes(tokenURI).length > 0 ? string.concat(_baseURI, tokenURI) : super.uri(tokenId);
}
/**
* @dev Sets `tokenURI` as the tokenURI of `tokenId`.
*/
function _setURI(uint256 tokenId, string memory tokenURI) internal virtual {
_tokenURIs[tokenId] = tokenURI;
emit URI(uri(tokenId), tokenId);
}
/**
* @dev Sets `baseURI` as the `_baseURI` for all tokens
*/
function _setBaseURI(string memory baseURI) internal virtual {
_baseURI = baseURI;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the value of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155Received} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `value` amount.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
*
* WARNING: This function can potentially allow a reentrancy attack when transferring tokens
* to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
* Ensure to follow the checks-effects-interactions pattern and consider employing
* reentrancy guards when interacting with untrusted contracts.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `values` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.20;
import {IERC1155} from "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*/
interface IERC1155MetadataURI is IERC1155 {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using StorageSlot for bytes32;
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* `array` is expected to be sorted in ascending order, and to contain no
* repeated elements.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
// We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
// following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.
/// @solidity memory-safe-assembly
assembly {
mstore(0, arr.slot)
slot := add(keccak256(0, 0x20), pos)
}
return slot.getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @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;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), 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 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));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return 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 {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}{
"remappings": [
"@prb/test/=lib/prb-test/src/",
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"prb-test/=lib/prb-test/src/"
],
"optimizer": {
"enabled": true,
"runs": 100
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_lucky8Token","type":"address"},{"internalType":"address","name":"_lucky8LpToken","type":"address"},{"internalType":"address","name":"_usdcToken","type":"address"},{"internalType":"address","name":"_buyBackBurnAddress","type":"address"},{"internalType":"string","name":"_uri","type":"string"},{"internalType":"contract IReferralStorage","name":"_referralStorage","type":"address"},{"internalType":"address","name":"_vrfCoordinator","type":"address"},{"internalType":"uint64","name":"_chainlinkSubscriptionId","type":"uint64"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"CheckpointUnorderedInsertion","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC1155InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC1155InvalidApprover","type":"error"},{"inputs":[{"internalType":"uint256","name":"idsLength","type":"uint256"},{"internalType":"uint256","name":"valuesLength","type":"uint256"}],"name":"ERC1155InvalidArrayLength","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC1155InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC1155InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC1155InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC1155MissingApprovalForAll","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","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":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"LpTokensLocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"LpTokensUnlocked","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":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"PrizeClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"winningNumbers","type":"uint256[]"}],"name":"RaffleExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"}],"name":"RoundFinalized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"prizePot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nWinners","type":"uint256"},{"indexed":false,"internalType":"uint48","name":"mintingWindowDuration","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"claimingWindowDuration","type":"uint48"},{"indexed":false,"internalType":"uint256","name":"buyBackPct","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensPerLpWei","type":"uint256"}],"name":"RoundStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buybackBurnAddress","type":"address"}],"name":"SetBuybackBurnAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"referralStorage","type":"address"}],"name":"SetReferralStorage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TicketsBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TicketsMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"TokensLocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"TokensUnlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[],"name":"CLOCK_MODE","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"round","type":"uint256"}],"name":"burnTickets","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"chainlinkSubscriptionId","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimPrize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"clock","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"executeRaffle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalizeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"forceFinalizeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"roundId","type":"uint256"}],"name":"getRoundInfo","outputs":[{"components":[{"internalType":"bool","name":"isRaffleExecuted","type":"bool"},{"internalType":"uint8","name":"nWinners","type":"uint8"},{"internalType":"uint48","name":"startTimepoint","type":"uint48"},{"internalType":"uint48","name":"raffleExecutionTimepoint","type":"uint48"},{"internalType":"uint48","name":"mintingWindowDuration","type":"uint48"},{"internalType":"uint48","name":"claimingWindowDuration","type":"uint48"},{"internalType":"uint256","name":"reqId","type":"uint256"},{"internalType":"uint256","name":"prizePot","type":"uint256"},{"internalType":"uint256","name":"tokensPerLpWei","type":"uint256"},{"internalType":"uint256[]","name":"winningNumbers","type":"uint256[]"}],"internalType":"struct Lottery.RoundInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getUserInfo","outputs":[{"internalType":"uint256","name":"tokensLocked","type":"uint256"},{"internalType":"uint256","name":"lpTokensLocked","type":"uint256"},{"internalType":"uint256","name":"referredTokensLocked","type":"uint256"},{"internalType":"uint256","name":"referredLpTokensLocked","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isRoundOngoing","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"_referralCode","type":"bytes32"}],"name":"lockLpTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32","name":"_referralCode","type":"bytes32"}],"name":"lockTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintTickets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"mintableTicketsForAccount","outputs":[{"internalType":"uint256","name":"ticketsAmount","type":"uint256"},{"internalType":"uint256","name":"lockedTokensTicketsAmount","type":"uint256"},{"internalType":"uint256","name":"lockedLpTokensTicketsAmount","type":"uint256"},{"internalType":"uint256","name":"bonusAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"rawFulfillRandomWords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"referralStorage","outputs":[{"internalType":"contract IReferralStorage","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requestIdToRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"roundInfo","outputs":[{"internalType":"bool","name":"isRaffleExecuted","type":"bool"},{"internalType":"uint8","name":"nWinners","type":"uint8"},{"internalType":"uint48","name":"startTimepoint","type":"uint48"},{"internalType":"uint48","name":"raffleExecutionTimepoint","type":"uint48"},{"internalType":"uint48","name":"mintingWindowDuration","type":"uint48"},{"internalType":"uint48","name":"claimingWindowDuration","type":"uint48"},{"internalType":"uint256","name":"reqId","type":"uint256"},{"internalType":"uint256","name":"prizePot","type":"uint256"},{"internalType":"uint256","name":"tokensPerLpWei","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_buybackBurnAddress","type":"address"}],"name":"setBuybackBurnAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_chainlinkCallbackGas","type":"uint32"}],"name":"setChainlinkCallbackGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_chainlinkMinimumRequestConfirmations","type":"uint16"}],"name":"setChainlinkMinimumRequestConfirmations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_chainlinkSubscriptionId","type":"uint64"}],"name":"setChainlinkSubscriptionId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IReferralStorage","name":"_referralStorage","type":"address"}],"name":"setReferralStorage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_uri","type":"string"}],"name":"setURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"tokenUri","type":"string"},{"internalType":"uint8","name":"nWinners","type":"uint8"},{"internalType":"uint48","name":"mintingWindowDuration","type":"uint48"},{"internalType":"uint48","name":"claimingWindowDuration","type":"uint48"},{"internalType":"uint256","name":"buyBackPct","type":"uint256"},{"internalType":"uint256","name":"lpWeiValue","type":"uint256"}],"internalType":"struct Lottery.InitParams","name":"params","type":"tuple"}],"name":"startNewRound","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":"tokensPerLpWei","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLockedLpTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"time","type":"uint48"}],"name":"totalLockedLpTokensForTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLockedTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint48","name":"time","type":"uint48"}],"name":"totalLockedTokensForTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unlockLpTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unlockTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"userTicketsRanges","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
61014060405260006101209081526006906200001c90826200022d565b5060098054602360e11b61ffff60e01b19909116179055600a805463ffffffff19166207a1201790553480156200005257600080fd5b5060405162005a7738038062005a7783398101604081905262000075916200033c565b818433806200009e57604051631e4fbdf760e01b81526000600482015260240160405180910390fd5b620000a98162000126565b50620000b58162000176565b506001600160a01b0390811660805297881660c05295871660e05293861661010052600880546001600160a01b03191693871693909317909255506009805492851660a05293166001600160e01b031990911617600160a01b6001600160401b0390921691909102179055620004a0565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60036200018482826200022d565b5050565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620001b357607f821691505b602082108103620001d457634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200022857600081815260208120601f850160051c81016020861015620002035750805b601f850160051c820191505b8181101562000224578281556001016200020f565b5050505b505050565b81516001600160401b0381111562000249576200024962000188565b62000261816200025a84546200019e565b84620001da565b602080601f831160018114620002995760008415620002805750858301515b600019600386901b1c1916600185901b17855562000224565b600085815260208120601f198616915b82811015620002ca57888601518255948401946001909101908401620002a9565b5085821015620002e95787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160a01b03811681146200030f57600080fd5b50565b80516200031f81620002f9565b919050565b80516001600160401b03811681146200031f57600080fd5b600080600080600080600080610100898b0312156200035a57600080fd5b88516200036781620002f9565b809850506020808a01516200037c81620002f9565b60408b01519098506200038f81620002f9565b60608b0151909750620003a281620002f9565b60808b01519096506001600160401b0380821115620003c057600080fd5b818c0191508c601f830112620003d557600080fd5b815181811115620003ea57620003ea62000188565b604051601f8201601f19908116603f0116810190838211818310171562000415576200041562000188565b816040528281528f868487010111156200042e57600080fd5b600093505b8284101562000452578484018601518185018701529285019262000433565b60008684830101528099505050505050506200047160a08a0162000312565b92506200048160c08a0162000312565b91506200049160e08a0162000324565b90509295985092959890939650565b60805160a05160c05160e0516101005161553e6200053960003960008181610d5e01528181610e2201528181611ca80152611cde01526000818161089001528181610a5501528181612777015281816134a10152818161355401526135f90152600081816109c801528181611d7101528181612004015261352a01526000612a7c01526000818161135d015261139f015261553e6000f3fe608060405234801561001057600080fd5b50600436106102b35760003560e01c8063644dbe0711610172578063ae4d7f9a116100d9578063e59f9e0e11610092578063e59f9e0e146106a9578063e985e9c5146106bc578063f242432a146106f8578063f2fde38b14610706578063f5c476f914610719578063f7b75ae714610721578063fb16fb721461072957600080fd5b8063ae4d7f9a1461064b578063b464f8a11461065e578063bd85b03914610666578063bf9d10f914610686578063c75445e514610699578063d2e2a975146106a157600080fd5b806388c3ffb01161012b57806388c3ffb0146105c85780638da5cb5b146105e85780638faf6d04146105f9578063911010ab1461060c57806391ddadf414610619578063a22cb4651461063857600080fd5b8063644dbe071461056c578063692ad3531461057f57806370740ac914610592578063715018a61461059a5780637a2d14e2146105a25780637c405325146105b557600080fd5b80631fe543e311610221578063427f0b00116101da578063427f0b00146104675780634bf5d7e9146104d35780634e1273f4146104db5780634e2786fb146104fb5780634f558e791461050457806351dbc830146105265780636386c1c71461053957600080fd5b80631fe543e3146103c957806320c5780c146103dc5780632e2f88441461040e5780632eb2c2d61461042157806331866934146104345780634077604b1461044757600080fd5b80630ddabda4116102735780630ddabda4146103605780630e89341c146103735780631232eb731461039357806313f352c8146103a657806318160ddd146103b95780631e820325146103c157600080fd5b80626cc35e146102b85780626da327146102e1578062fdd58e146102f657806301ffc9a71461031757806302fe53051461033a57806306b091f91461034d575b600080fd5b6009546102cb906001600160a01b031681565b6040516102d8919061464d565b60405180910390f35b6102f46102ef366004614661565b610731565b005b61030961030436600461468f565b6108f9565b6040519081526020016102d8565b61032a6103253660046146d1565b610923565b60405190151581526020016102d8565b6102f46103483660046146ee565b610973565b6102f461035b36600461468f565b6109be565b6102f461036e36600461475f565b610afc565b610386610381366004614661565b61120c565b6040516102d891906147e9565b6103096103a13660046147fc565b611217565b6103096103b43660046147fc565b611233565b600554610309565b6102f4611240565b6102f46103d73660046148f8565b611352565b6009546103f690600160a01b90046001600160401b031681565b6040516001600160401b0390911681526020016102d8565b61030961041c36600461493e565b6113d6565b6102f461042f3660046149e5565b611408565b6102f4610442366004614a92565b61145e565b610309610455366004614661565b60146020526000908152604090205481565b61047a610475366004614661565b611488565b604080519915158a5260ff90981660208a015265ffffffffffff96871697890197909752938516606088015291841660808701529290921660a085015260c084019190915260e0830152610100820152610120016102d8565b6103866114fc565b6104ee6104e9366004614ab6565b611594565b6040516102d89190614ba8565b61030960125481565b61032a610512366004614661565b600090815260046020526040902054151590565b6102f4610534366004614661565b611668565b61054c610547366004614bbb565b6116e1565b6040805194855260208501939093529183015260608201526080016102d8565b6102f461057a366004614bbb565b611823565b6102f461058d366004614bd8565b611875565b6103096118aa565b6102f4611d50565b6102f46105b0366004614c01565b611d64565b6102f46105c3366004614661565b611eb3565b6105db6105d6366004614661565b612063565b6040516102d89190614c23565b6000546001600160a01b03166102cb565b6102f4610607366004614cf7565b6121c4565b60115461032a9060ff1681565b6106216121e8565b60405165ffffffffffff90911681526020016102d8565b6102f4610646366004614d22565b6121f7565b6102f4610659366004614bbb565b612202565b610309612254565b610309610674366004614661565b60009081526004602052604090205490565b61054c610694366004614bbb565b612277565b6102f4612419565b61030961247b565b6102f46106b7366004614c01565b61276a565b61032a6106ca366004614d5b565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205460ff1690565b6102f461042f366004614d89565b6102f4610714366004614bbb565b6128b0565b6103096128ee565b610309612903565b6102f461290d565b60115460ff161561075d5760405162461bcd60e51b815260040161075490614df1565b60405180910390fd5b60006107676121e8565b336000908152600e60205260408120919250906107849083612b11565b905082816001600160d01b031610156107af5760405162461bcd60e51b815260040161075490614e21565b336000908152600e602052604090206107d390612bc76107ce86612bda565b612c12565b50506107e66010612bc76107ce86612bda565b5050600954604051633281306d60e01b81526000916001600160a01b031690633281306d9061081990339060040161464d565b6040805180830381865afa158015610835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108599190614e62565b5090508015610883576000818152600c6020526040902061088090612bc76107ce87612bda565b50505b6108b76001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163386612c4b565b604080518581526020810183905233917ff3a8b53aa070deb9cde5db0e7c4e0d505bc0fb0b5244e57ce6a9ece13dbd22fb91015b60405180910390a250505050565b60008181526001602090815260408083206001600160a01b03861684529091529020545b92915050565b60006001600160e01b03198216636cdb3d1360e11b148061095457506001600160e01b031982166303a24d0760e21b145b8061091d57506301ffc9a760e01b6001600160e01b031983161461091d565b61097b612caf565b6109ba82828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612cdc92505050565b5050565b6109c6612caf565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031603610a535760405162461bcd60e51b815260206004820152602360248201527f4c6f74746572793a2063616e6e6f742077697468647261772038383820746f6b604482015262656e7360e81b6064820152608401610754565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031603610ae85760405162461bcd60e51b815260206004820152602b60248201527f4c6f74746572793a2063616e6e6f74207769746864726177203838382f55534460448201526a43204c5020746f6b656e7360a81b6064820152608401610754565b6109ba6001600160a01b0383163383612c4b565b610b04612caf565b60115460ff1615610b575760405162461bcd60e51b815260206004820152601e60248201527f4c6f74746572793a20726f756e6420616c7265616479206f6e676f696e6700006044820152606401610754565b610b6760608201604083016147fc565b65ffffffffffff16600003610bde5760405162461bcd60e51b815260206004820152603760248201527f4c6f74746572793a206d696e74696e672077696e646f77206475726174696f6e6044820152760206d7573742062652067726561746572207468616e203604c1b6064820152608401610754565b610bee60808201606083016147fc565b65ffffffffffff16600003610c665760405162461bcd60e51b815260206004820152603860248201527f4c6f74746572793a20636c61696d696e672077696e646f77206475726174696f60448201527706e206d7573742062652067726561746572207468616e20360441b6064820152608401610754565b6702c68af0bb14000081608001351115610cd85760405162461bcd60e51b815260206004820152602d60248201527f4c6f74746572793a206275796261636b20616e64206275726e2070657263656e60448201526c0e8c2ceca40e8dede40d0d2ced609b1b6064820152608401610754565b6000610ce26121e8565b90506000610cf1600f83612b11565b90506000610d00601084612b11565b9050610d2183610d18846001600160d01b0316612bda565b600f9190612ce8565b5050610d4283610d39836001600160d01b0316612bda565b60109190612ce8565b50506040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190610d9390309060040161464d565b602060405180830381865afa158015610db0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd49190614e87565b90506000610def826080880135670de0b6b3a7640000612cf6565b90506000610e0e8367016345785d8a0000670de0b6b3a7640000612cf6565b600854909150610e4b906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116911684612c4b565b6000610e578284614eb6565b610e619085614ec9565b905060006040518061014001604052806000151581526020018a6020016020810190610e8d9190614edc565b60ff1681526020018965ffffffffffff168152602001600065ffffffffffff1681526020018a6040016020810190610ec591906147fc565b65ffffffffffff168152602001610ee260808c0160608d016147fc565b65ffffffffffff168152602001600081526020018381526020018a60a00135815260200160006001600160401b03811115610f1f57610f1f614824565b604051908082528060200260200182016040528015610f48578160200160208202803683370190505b508152509050600160126000828254610f619190614eb6565b90915550506013805460018101825560009190915281517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0906005909202918201805460208086015160408701516060880151608089015160a08a015161ffff1990961697151561ff0019169790971761010060ff9094168402176dffffffffffffffffffffffff000019166201000065ffffffffffff9384160265ffffffffffff60401b191617600160401b91831691909102176bffffffffffffffffffffffff60701b1916600160701b9682169690960265ffffffffffff60a01b191695909517600160a01b959093169490940291909117825560c08501517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a09185015560e08501517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a092850155918401517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a09384015561012084015180518594929361110a937f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a094019201906145f6565b50506011805460ff19166001179055506012546111659061112b8b80614eff565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612dba92505050565b6012547f830f1de5aa413bf4e51a8e89ccdd3b975ebbcf29e6a9c9a1de7ae9d7d0c82a128361119a60408d0160208e01614edc565b6111aa60608e0160408f016147fc565b8d60600160208101906111bd91906147fc565b6040805194855260ff93909316602085015265ffffffffffff9182168484015216606083015260808d8101359083015260a0808e013590830152519081900360c00190a2505050505050505050565b606061091d82612e0b565b6000611224601083612b11565b6001600160d01b031692915050565b6000611224600f83612b11565b611248612caf565b60115460ff1661126a5760405162461bcd60e51b815260040161075490614f4c565b6012546000601361127c600184614ec9565b8154811061128c5761128c614f7f565b60009182526020909120600590910201805490915060ff166112c05760405162461bcd60e51b815260040161075490614f95565b80546112e49065ffffffffffff600160a01b8204811691600160401b900416614fca565b65ffffffffffff166112f46121e8565b65ffffffffffff16116113195760405162461bcd60e51b815260040161075490614ff0565b6011805460ff1916905560405182907fd49620ec6474d72a2f05dd60f5ab59ad0d2d9d29090cb3b81defc30db3d510c390600090a25050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113cc5760405163073e64fd60e21b81523360048201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166024820152604401610754565b6109ba8282612eea565b601560205282600052604060002060205281600052604060002081600281106113fe57600080fd5b0154925083915050565b60405162461bcd60e51b815260206004820152602560248201527f4c6f74746572793a205469636b65747320617265206e6f6e2d7472616e7366656044820152647261626c6560d81b6064820152608401610754565b611466612caf565b6009805461ffff909216600160e01b0261ffff60e01b19909216919091179055565b6013818154811061149857600080fd5b6000918252602090912060059091020180546001820154600283015460039093015460ff80841695506101008404169365ffffffffffff620100008504811694600160401b8104821694600160701b8204831694600160a01b909204909216929089565b6060611506613151565b65ffffffffffff166115166121e8565b65ffffffffffff161461156b5760405162461bcd60e51b815260206004820152601b60248201527f4c6f74746572793a20696e636f6e73697374656e7420636c6f636b00000000006044820152606401610754565b5060408051808201909152600e81526d06d6f64653d74696d657374616d760941b602082015290565b606081518351146115c55781518351604051635b05999160e01b815260048101929092526024820152604401610754565b600083516001600160401b038111156115e0576115e0614824565b604051908082528060200260200182016040528015611609578160200160208202803683370190505b50905060005b845181101561166057602080820286010151611633906020808402870101516108f9565b82828151811061164557611645614f7f565b602090810291909101015261165981615049565b905061160f565b509392505050565b600061167433836108f9565b9050806000036116965760405162461bcd60e51b815260040161075490615062565b6116a133838361315c565b604080518381526020810183905233917fbb3d3e99bf2dd4c603c77e7d93564950ba9976830de2d943776db31b45814d8991015b60405180910390a25050565b60008060008060006116f16121e8565b6001600160a01b0387166000908152600d602052604090209091506117169082612b11565b6001600160a01b0387166000908152600e602052604090206001600160d01b039190911695506117469082612b11565b600954604051630531f2cb60e21b81526001600160d01b039290921695506000916001600160a01b03909116906314c7cb2c90611787908a9060040161464d565b602060405180830381865afa1580156117a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c89190614e87565b9050801561181a576000818152600b602052604090206117e89083612b11565b6000828152600c602052604090206001600160d01b0391909116945061180e9083612b11565b6001600160d01b031692505b50509193509193565b61182b612caf565b600880546001600160a01b0319166001600160a01b0383169081179091556040517f4e5651c05a1f32df05686898139afc9bb4bb5a17fb802e20b4f4b78094fbcc6f90600090a250565b61187d612caf565b600980546001600160401b03909216600160a01b0267ffffffffffffffff60a01b19909216919091179055565b60115460009060ff166118cf5760405162461bcd60e51b815260040161075490614f4c565b60006118d96121e8565b601254909150600060136118ee600184614ec9565b815481106118fe576118fe614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156119df57602002820191906000526020600020905b8154815260200190600101908083116119cb575b505050505081525050905060006119f633846108f9565b905060008111611a185760405162461bcd60e51b815260040161075490615062565b8151611a365760405162461bcd60e51b815260040161075490614f95565b816060015165ffffffffffff168465ffffffffffff16118015611a7c57508160a001518260600151611a689190614fca565b65ffffffffffff168465ffffffffffff1611155b611a985760405162461bcd60e51b815260040161075490614ff0565b60008381526015602090815260408083203384529091528082208151808301928390529160029082845b815481526020019060010190808311611ac25750505050509050600083610120015190506000806000611b09876020015160ff168860e001516131cb90919063ffffffff16565b905060005b8451811015611b945785518551869083908110611b2d57611b2d614f7f565b602002602001015110158015611b6357508560016020020151858281518110611b5857611b58614f7f565b602002602001015111155b15611b8257611b73600184614eb6565b9250611b7f8285614eb6565b93505b80611b8c81615049565b915050611b0e565b5081600003611be55760405162461bcd60e51b815260206004820152601b60248201527f4c6f74746572793a206e6f2077696e6e696e67207469636b65747300000000006044820152606401610754565b611bf033898861315c565b600954604051633281306d60e01b815260009182916001600160a01b0390911690633281306d90611c2590339060040161464d565b6040805180830381865afa158015611c41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c659190614e62565b90925090508115611cd1576000611c8d8666b1a2bc2ec50000670de0b6b3a764000084613216565b9050611c998187614ec9565b9550611ccf6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383612c4b565b505b611d056001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163387612c4b565b604080518b81526020810187905233917f256642a903d86ec186d0ad895b74bdbe7f9e5a72db568f4c4d58c2fa38b39e1c910160405180910390a250929a9950505050505050505050565b611d58612caf565b611d626000613267565b565b611d996001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163330856132b7565b336000908152600d60205260409020611db8906132f66107ce85612bda565b5050611dcb600f6132f66107ce85612bda565b5050611dd73382613302565b600954604051633281306d60e01b81526000916001600160a01b031690633281306d90611e0890339060040161464d565b6040805180830381865afa158015611e24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e489190614e62565b5090508015611e72576000818152600b60205260409020611e6f906132f66107ce86612bda565b50505b604080518481526020810183905233917f8df2cd4a972a1beed9236aa9769f82bb9af841456f5f3521a276b1d30d80364591015b60405180910390a2505050565b60115460ff1615611ed65760405162461bcd60e51b815260040161075490614df1565b6000611ee06121e8565b336000908152600d6020526040812091925090611efd9083612b11565b905082816001600160d01b03161015611f285760405162461bcd60e51b815260040161075490614e21565b336000908152600d60205260409020611f4790612bc76107ce86612bda565b5050611f5a600f612bc76107ce86612bda565b5050600954604051633281306d60e01b81526000916001600160a01b031690633281306d90611f8d90339060040161464d565b6040805180830381865afa158015611fa9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fcd9190614e62565b5090508015611ff7576000818152600b60205260409020611ff490612bc76107ce87612bda565b50505b61202b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163386612c4b565b604080518581526020810183905233917f78ef8056aa4d842c1cc53bf449de3dda50aca0621822909a9919c5c0c0b54d2891016108eb565b604080516101408101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082019290925261012081019190915260136120c3600184614ec9565b815481106120d3576120d3614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156121b457602002820191906000526020600020905b8154815260200190600101908083116121a0575b5050505050815250509050919050565b6121cc612caf565b600a805463ffffffff191663ffffffff92909216919091179055565b60006121f2613151565b905090565b6109ba338383613404565b61220a612caf565b600980546001600160a01b0319166001600160a01b0383169081179091556040517f828abcccea18192c21d645e575652c49e20b986dab777906fc473d056b01b6a890600090a250565b60006122696122616121e8565b601090612b11565b6001600160d01b0316905090565b60115460009081908190819060ff166122b2576122a3856122966121e8565b61229e61349a565b61369a565b92965090945092509050612412565b601254600060136122c4600184614ec9565b815481106122d4576122d4614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156123b557602002820191906000526020600020905b8154815260200190600101908083116123a1575b5050505050815250509050806080015181604001516123d49190614fca565b65ffffffffffff166123e46121e8565b65ffffffffffff161161181a5761240587826040015183610100015161369a565b9298509096509450925050505b9193509193565b612421612caf565b60115460ff166124435760405162461bcd60e51b815260040161075490614f4c565b6011805460ff191690556012546040517fd49620ec6474d72a2f05dd60f5ab59ad0d2d9d29090cb3b81defc30db3d510c390600090a2565b60115460009060ff166124a05760405162461bcd60e51b815260040161075490614f4c565b601254600060136124b2600184614ec9565b815481106124c2576124c2614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156125a357602002820191906000526020600020905b81548152602001906001019080831161258f575b5050505050815250509050806080015181604001516125c29190614fca565b65ffffffffffff166125d26121e8565b65ffffffffffff1611156126285760405162461bcd60e51b815260206004820152601e60248201527f4c6f74746572793a206e6f7420696e206d696e74696e672077696e646f7700006044820152606401610754565b600061263433846108f9565b905080156126905760405162461bcd60e51b8152602060048201526024808201527f4c6f74746572793a207573657220616c7265616479206d696e746564207469636044820152636b65747360e01b6064820152608401610754565b60006126a633846040015185610100015161369a565b505050600085815260046020526040812054919250506126d733868460405180602001604052806000815250613998565b60008581526004602090815260408083205460158352818420338552909252909120829055612707600182614ec9565b6000878152601560209081526040808320338452909152902060010155604080518781526020810185905233917f47077b9c55ea85476c20e80bb7b9315ff5e80e0354086bd502bfda0fa91ba7aa910160405180910390a2509095945050505050565b61279f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163330856132b7565b336000908152600e602052604090206127be906132f66107ce85612bda565b50506127d160106132f66107ce85612bda565b50506127dd3382613302565b600954604051633281306d60e01b81526000916001600160a01b031690633281306d9061280e90339060040161464d565b6040805180830381865afa15801561282a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284e9190614e62565b5090508015612878576000818152600c60205260409020612875906132f66107ce86612bda565b50505b604080518481526020810183905233917f5da3fec768e6a5b960b70b987d7526b05214a15a6d05ae3d7af281a3551dac2e9101611ea6565b6128b8612caf565b6001600160a01b0381166128e2576000604051631e4fbdf760e01b8152600401610754919061464d565b6128eb81613267565b50565b60006122696128fb6121e8565b600f90612b11565b60006121f261349a565b612915612caf565b600061291f6121e8565b90506000601360016012546129349190614ec9565b8154811061294457612944614f7f565b60009182526020909120600590910201805490915060ff16156129795760405162461bcd60e51b81526004016107549061508f565b805461299c9065ffffffffffff600160701b820481169162010000900416614fca565b65ffffffffffff168265ffffffffffff16116129fa5760405162461bcd60e51b815260206004820152601f60248201527f4c6f74746572793a20726166666c65206e6f74207374617274656420796574006044820152606401610754565b8054600954600a546040516305d3b1d360e41b81527fff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f926004820152600160a01b83046001600160401b03166024820152600160e01b90920461ffff16604483015263ffffffff16606482015261010090910460ff1660848201819052906000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690635d3b1d309060a4016020604051808303816000875af1158015612acd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af19190614e87565b600190930183905550506012546000918252601460205260409091205550565b815460009081816005811115612b70576000612b2c846139f5565b612b369085614ec9565b60008881526020902090915081015465ffffffffffff9081169087161015612b6057809150612b6e565b612b6b816001614eb6565b92505b505b6000612b7e87878585613add565b90508015612bb957612ba387612b95600184614ec9565b600091825260209091200190565b54600160301b90046001600160d01b0316612bbc565b60005b979650505050505050565b6000612bd382846150c4565b9392505050565b60006001600160d01b03821115612c0e576040516306dfcc6560e41b815260d0600482015260248101839052604401610754565b5090565b600080612c3e612c206121e8565b612c36612c2c88613b37565b868863ffffffff16565b879190612ce8565b915091505b935093915050565b6040516001600160a01b03838116602483015260448201839052612caa91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613b70565b505050565b6000546001600160a01b03163314611d62573360405163118cdaa760e01b8152600401610754919061464d565b60036109ba8282615164565b600080612c3e858585613bca565b6000838302816000198587098281108382030391505080600003612d2d57838281612d2357612d23615223565b0492505050612bd3565b808411612d4d5760405163227bc15360e01b815260040160405180910390fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000828152600760205260409020612dd28282615164565b50817f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b612dfe8461120c565b6040516116d591906147e9565b600081815260076020526040812080546060929190612e29906150e4565b80601f0160208091040260200160405190810160405280929190818152602001828054612e55906150e4565b8015612ea25780601f10612e7757610100808354040283529160200191612ea2565b820191906000526020600020905b815481529060010190602001808311612e8557829003601f168201915b505050505090506000815111612ec057612ebb83613d44565b612bd3565b600681604051602001612ed4929190615239565b6040516020818303038152906040529392505050565b60115460ff16612f0c5760405162461bcd60e51b815260040161075490614f4c565b600082815260146020526040812054906013612f29600184614ec9565b81548110612f3957612f39614f7f565b9060005260206000209060050201905083816001015414612f985760405162461bcd60e51b8152602060048201526019602482015278131bdd1d195c9e4e881ddc9bdb99c81c995c5d595cdd081a59603a1b6044820152606401610754565b805460ff16158015612fb857508054600160401b900465ffffffffffff16155b612fd45760405162461bcd60e51b81526004016107549061508f565b6000612fde6121e8565b82549091506130049065ffffffffffff600160701b820481169162010000900416614fca565b65ffffffffffff168165ffffffffffff16116130705760405162461bcd60e51b815260206004820152602560248201527f4c6f74746572793a20726166666c65206d696e74696e67207068617365206f6e604482015264676f696e6760d81b6064820152608401610754565b60005b8254610100900460ff168110156130e2576000848152600460205260408120548683815181106130a5576130a5614f7f565b60200260200101516130b791906152c0565b60048501805460018101825560009182526020909120015550806130da81615049565b915050613073565b50815465ffffffffffff8216600160401b026dffffffffffff00000000000000ff1990911617600117825560405183907f6ab43dfe350db3c48d094a2b8871901c673ecdd67e11b10dffe05fecb6c0f04f906131429060048601906152d4565b60405180910390a25050505050565b60006121f242613dd8565b6001600160a01b038316613185576000604051626a0d4560e21b8152600401610754919061464d565b604080516001808252602082018590528183019081526060820184905260a082019092526000608082018181529192916131c491879185908590613e0b565b5050505050565b6000816000036131e6576131df828461531b565b905061091d565b821561320d57816131f8600185614ec9565b613202919061531b565b612ebb906001614eb6565b50600092915050565b600080613224868686612cf6565b905061322f83613e5e565b801561324b57506000848061324657613246615223565b868809115b1561325e5761325b600182614eb6565b90505b95945050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0384811660248301528381166044830152606482018390526132f09186918216906323b872dd90608401612c78565b50505050565b6000612bd3828461532f565b8061330b575050565b6009546001600160a01b031661331f575050565b6009546040516337672f1b60e11b81526000916001600160a01b031690636ece5e369061335090869060040161464d565b602060405180830381865afa15801561336d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133919190614e87565b1461339a575050565b6009546040516364db1d0d60e11b81526001600160a01b038481166004830152602482018490529091169063c9b63a1a90604401600060405180830381600087803b1580156133e857600080fd5b505af11580156133fc573d6000803e3d6000fd5b505050505050565b6001600160a01b03821661342d57600060405162ced3e160e81b8152600401610754919061464d565b6001600160a01b03838116600081815260026020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156134fd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613521919061536b565b509150915060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156135b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135d491906153b2565b6001600160a01b0316146135e857816135ea565b825b6001600160701b0316905060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613655573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136799190614e87565b9050806136878360036153cf565b613691919061531b565b94505050505090565b6001600160a01b0383166000908152600d60205260408120819081908190819081906136c69089612b11565b6001600160a01b038a166000908152600e60205260408120919250906136ec908a612b11565b90506000613703896001600160d01b0384166153cf565b613716906001600160d01b038516614eb6565b600954604051633281306d60e01b81529192506000916001600160a01b0390911690633281306d9061374c908f9060040161464d565b6040805180830381865afa158015613768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061378c9190614e62565b50905080156137b5576137b28267016345785d8a0000670de0b6b3a76400006000613216565b94505b816000036137d5576000806000809850985098509850505050505061398f565b6000600960009054906101000a90046001600160a01b03166001600160a01b03166314c7cb2c8e6040518263ffffffff1660e01b8152600401613818919061464d565b602060405180830381865afa158015613835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138599190614e87565b90508015613916576000818152600b60205260408120613879908e612b11565b6000838152600c6020526040812091925090613895908f612b11565b905060006138ac8e6001600160d01b0384166153cf565b6138bf906001600160d01b038516614eb6565b905060006138d782670de0b6b3a76400008984613216565b905060006138ed82678ac7230489e80000613e8b565b90506139048882670de0b6b3a76400006000613216565b61390e908c614eb6565b9a5050505050505b6000613934670de0b6b3a764000061392e8987614eb6565b906131cb565b9050806139526001600160d01b038816670de0b6b3a76400006131cb565b61396d6001600160d01b038816670de0b6b3a76400006131cb565b61397f8a670de0b6b3a76400006131cb565b9a509a509a509a50505050505050505b93509350935093565b6001600160a01b0384166139c2576000604051632bfa23e760e11b8152600401610754919061464d565b604080516001808252602082018690528183019081526060820185905260808201909252906133fc600087848487613e0b565b600081600003613a0757506000919050565b60006001613a1484613ea1565b901c6001901b90506001818481613a2d57613a2d615223565b048201901c90506001818481613a4557613a45615223565b048201901c90506001818481613a5d57613a5d615223565b048201901c90506001818481613a7557613a75615223565b048201901c90506001818481613a8d57613a8d615223565b048201901c90506001818481613aa557613aa5615223565b048201901c90506001818481613abd57613abd615223565b048201901c9050612bd381828581613ad757613ad7615223565b04613e8b565b60005b81831015611660576000613af48484613f35565b60008781526020902090915065ffffffffffff86169082015465ffffffffffff161115613b2357809250613b31565b613b2e816001614eb6565b93505b50613ae0565b80546000908015613b6757613b5183612b95600184614ec9565b54600160301b90046001600160d01b0316612bd3565b60009392505050565b6000613b856001600160a01b03841683613f50565b90508051600014158015613baa575080806020019051810190613ba891906153e6565b155b15612caa5782604051635274afe760e01b8152600401610754919061464d565b825460009081908015613ce9576000613be887612b95600185614ec9565b60408051808201909152905465ffffffffffff808216808452600160301b9092046001600160d01b031660208401529192509087161015613c3c57604051632520601d60e01b815260040160405180910390fd5b805165ffffffffffff808816911603613c885784613c5f88612b95600186614ec9565b80546001600160d01b0392909216600160301b0265ffffffffffff909216919091179055613cd9565b6040805180820190915265ffffffffffff80881682526001600160d01b0380881660208085019182528b54600181018d5560008d81529190912094519151909216600160301b029216919091179101555b602001519250839150612c439050565b50506040805180820190915265ffffffffffff80851682526001600160d01b0380851660208085019182528854600181018a5560008a815291822095519251909316600160301b029190931617920191909155905081612c43565b606060038054613d53906150e4565b80601f0160208091040260200160405190810160405280929190818152602001828054613d7f906150e4565b8015613dcc5780601f10613da157610100808354040283529160200191613dcc565b820191906000526020600020905b815481529060010190602001808311613daf57829003601f168201915b50505050509050919050565b600065ffffffffffff821115612c0e576040516306dfcc6560e41b81526030600482015260248101839052604401610754565b613e1785858585613f5e565b6001600160a01b038416156131c45782513390600103613e505760208481015190840151613e49838989858589613f6a565b50506133fc565b6133fc818787878787614085565b60006002826003811115613e7457613e74615403565b613e7e9190615419565b60ff166001149050919050565b6000818310613e9a5781612bd3565b5090919050565b600080608083901c15613eb657608092831c92015b604083901c15613ec857604092831c92015b602083901c15613eda57602092831c92015b601083901c15613eec57601092831c92015b600883901c15613efe57600892831c92015b600483901c15613f1057600492831c92015b600283901c15613f2257600292831c92015b600183901c1561091d5760010192915050565b6000613f44600284841861531b565b612bd390848416614eb6565b6060612bd383836000614165565b6132f084848484614202565b6001600160a01b0384163b156133fc5760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e6190613fae908990899088908890889060040161543b565b6020604051808303816000875af1925050508015613fe9575060408051601f3d908101601f19168201909252613fe691810190615475565b60015b614049573d808015614017576040519150601f19603f3d011682016040523d82523d6000602084013e61401c565b606091505b5080516000036140415784604051632bfa23e760e11b8152600401610754919061464d565b805181602001fd5b6001600160e01b0319811663f23a6e6160e01b1461407c5784604051632bfa23e760e11b8152600401610754919061464d565b50505050505050565b6001600160a01b0384163b156133fc5760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906140c99089908990889088908890600401615492565b6020604051808303816000875af1925050508015614104575060408051601f3d908101601f1916820190925261410191810190615475565b60015b614132573d808015614017576040519150601f19603f3d011682016040523d82523d6000602084013e61401c565b6001600160e01b0319811663bc197c8160e01b1461407c5784604051632bfa23e760e11b8152600401610754919061464d565b60608147101561418a573060405163cd78605960e01b8152600401610754919061464d565b600080856001600160a01b031684866040516141a691906154f0565b60006040518083038185875af1925050503d80600081146141e3576040519150601f19603f3d011682016040523d82523d6000602084013e6141e8565b606091505b50915091506141f886838361435c565b9695505050505050565b61420e848484846143aa565b6001600160a01b0384166142c1576000805b83518110156142a757600083828151811061423d5761423d614f7f565b60200260200101519050806004600087858151811061425e5761425e614f7f565b6020026020010151815260200190815260200160002060008282546142839190614eb6565b9091555061429390508184614eb6565b925050806142a090615049565b9050614220565b5080600560008282546142ba9190614eb6565b9091555050505b6001600160a01b0383166132f0576000805b835181101561434b5760008382815181106142f0576142f0614f7f565b60200260200101519050806004600087858151811061431157614311614f7f565b60200260200101518152602001908152602001600020600082825403925050819055508083019250508061434490615049565b90506142d3565b506005805491909103905550505050565b60608261436c57612ebb826145cd565b815115801561438357506001600160a01b0384163b155b156143a35783604051639996b31560e01b8152600401610754919061464d565b5080612bd3565b80518251146143d95781518151604051635b05999160e01b815260048101929092526024820152604401610754565b3360005b83518110156144ee576020818102858101820151908501909101516001600160a01b038816156144945760008281526001602090815260408083206001600160a01b038c1684529091529020548181101561446b576040516303dee4c560e01b81526001600160a01b038a166004820152602481018290526044810183905260648101849052608401610754565b60008381526001602090815260408083206001600160a01b038d16845290915290209082900390555b6001600160a01b038716156144db5760008281526001602090815260408083206001600160a01b038b168452909152812080548392906144d5908490614eb6565b90915550505b5050806144e790615049565b90506143dd565b50825160010361456f5760208301516000906020840151909150856001600160a01b0316876001600160a01b0316846001600160a01b03167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628585604051614560929190918252602082015260400190565b60405180910390a450506131c4565b836001600160a01b0316856001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb86866040516145be92919061550c565b60405180910390a45050505050565b8051156145dd5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b828054828255906000526020600020908101928215614631579160200282015b82811115614631578251825591602001919060010190614616565b50612c0e9291505b80821115612c0e5760008155600101614639565b6001600160a01b0391909116815260200190565b60006020828403121561467357600080fd5b5035919050565b6001600160a01b03811681146128eb57600080fd5b600080604083850312156146a257600080fd5b82356146ad8161467a565b946020939093013593505050565b6001600160e01b0319811681146128eb57600080fd5b6000602082840312156146e357600080fd5b8135612bd3816146bb565b6000806020838503121561470157600080fd5b82356001600160401b038082111561471857600080fd5b818501915085601f83011261472c57600080fd5b81358181111561473b57600080fd5b86602082850101111561474d57600080fd5b60209290920196919550909350505050565b60006020828403121561477157600080fd5b81356001600160401b0381111561478757600080fd5b820160c08185031215612bd357600080fd5b60005b838110156147b457818101518382015260200161479c565b50506000910152565b600081518084526147d5816020860160208601614799565b601f01601f19169290920160200192915050565b602081526000612bd360208301846147bd565b60006020828403121561480e57600080fd5b813565ffffffffffff81168114612bd357600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561486257614862614824565b604052919050565b60006001600160401b0382111561488357614883614824565b5060051b60200190565b600082601f83011261489e57600080fd5b813560206148b36148ae8361486a565b61483a565b82815260059290921b840181019181810190868411156148d257600080fd5b8286015b848110156148ed57803583529183019183016148d6565b509695505050505050565b6000806040838503121561490b57600080fd5b8235915060208301356001600160401b0381111561492857600080fd5b6149348582860161488d565b9150509250929050565b60008060006060848603121561495357600080fd5b8335925060208401356149658161467a565b929592945050506040919091013590565b600082601f83011261498757600080fd5b81356001600160401b038111156149a0576149a0614824565b6149b3601f8201601f191660200161483a565b8181528460208386010111156149c857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156149fd57600080fd5b8535614a088161467a565b94506020860135614a188161467a565b935060408601356001600160401b0380821115614a3457600080fd5b614a4089838a0161488d565b94506060880135915080821115614a5657600080fd5b614a6289838a0161488d565b93506080880135915080821115614a7857600080fd5b50614a8588828901614976565b9150509295509295909350565b600060208284031215614aa457600080fd5b813561ffff81168114612bd357600080fd5b60008060408385031215614ac957600080fd5b82356001600160401b0380821115614ae057600080fd5b818501915085601f830112614af457600080fd5b81356020614b046148ae8361486a565b82815260059290921b84018101918181019089841115614b2357600080fd5b948201945b83861015614b4a578535614b3b8161467a565b82529482019490820190614b28565b96505086013592505080821115614b6057600080fd5b506149348582860161488d565b600081518084526020808501945080840160005b83811015614b9d57815187529582019590820190600101614b81565b509495945050505050565b602081526000612bd36020830184614b6d565b600060208284031215614bcd57600080fd5b8135612bd38161467a565b600060208284031215614bea57600080fd5b81356001600160401b0381168114612bd357600080fd5b60008060408385031215614c1457600080fd5b50508035926020909101359150565b60208152614c3660208201835115159052565b60006020830151614c4c604084018260ff169052565b50604083015165ffffffffffff8116606084015250606083015165ffffffffffff8116608084015250608083015165ffffffffffff811660a08401525060a083015165ffffffffffff811660c08401525060c083015160e083810191909152830151610100808401919091528301516101208084019190915283015161014080840152614cdd610160840182614b6d565b949350505050565b63ffffffff811681146128eb57600080fd5b600060208284031215614d0957600080fd5b8135612bd381614ce5565b80151581146128eb57600080fd5b60008060408385031215614d3557600080fd5b8235614d408161467a565b91506020830135614d5081614d14565b809150509250929050565b60008060408385031215614d6e57600080fd5b8235614d798161467a565b91506020830135614d508161467a565b600080600080600060a08688031215614da157600080fd5b8535614dac8161467a565b94506020860135614dbc8161467a565b9350604086013592506060860135915060808601356001600160401b03811115614de557600080fd5b614a8588828901614976565b6020808252601690820152754c6f74746572793a20726f756e64206f6e676f696e6760501b604082015260600190565b60208082526021908201527f4c6f74746572793a206e6f7420656e6f756768206c6f636b656420746f6b656e6040820152607360f81b606082015260800190565b60008060408385031215614e7557600080fd5b825191506020830151614d508161467a565b600060208284031215614e9957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561091d5761091d614ea0565b8181038181111561091d5761091d614ea0565b600060208284031215614eee57600080fd5b813560ff81168114612bd357600080fd5b6000808335601e19843603018112614f1657600080fd5b8301803591506001600160401b03821115614f3057600080fd5b602001915036819003821315614f4557600080fd5b9250929050565b6020808252601990820152784c6f74746572793a206e6f20726f756e64206f6e676f696e6760381b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6020808252818101527f4c6f74746572793a20726166666c65206e6f7420657865637574656420796574604082015260600190565b65ffffffffffff818116838216019080821115614fe957614fe9614ea0565b5092915050565b60208082526039908201527f4c6f74746572793a20636c61696d696e672077696e646f77206e6f74207374616040820152787274656420796574206f72207374696c6c206f6e676f696e6760381b606082015260800190565b60006001820161505b5761505b614ea0565b5060010190565b6020808252601390820152724c6f74746572793a206e6f207469636b65747360681b604082015260600190565b6020808252818101527f4c6f74746572793a20726166666c6520616c7265616479206578656375746564604082015260600190565b6001600160d01b03828116828216039080821115614fe957614fe9614ea0565b600181811c908216806150f857607f821691505b60208210810361511857634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115612caa57600081815260208120601f850160051c810160208610156151455750805b601f850160051c820191505b818110156133fc57828155600101615151565b81516001600160401b0381111561517d5761517d614824565b6151918161518b84546150e4565b8461511e565b602080601f8311600181146151c657600084156151ae5750858301515b600019600386901b1c1916600185901b1785556133fc565b600085815260208120601f198616915b828110156151f5578886015182559484019460019091019084016151d6565b50858210156152135787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601260045260246000fd5b6000808454615247816150e4565b6001828116801561525f5760018114615274576152a3565b60ff19841687528215158302870194506152a3565b8860005260208060002060005b8581101561529a5781548a820152908401908201615281565b50505082870194505b5050505083516152b7818360208801614799565b01949350505050565b6000826152cf576152cf615223565b500690565b6020808252825482820181905260008481528281209092916040850190845b8181101561530f578354835260019384019392850192016152f3565b50909695505050505050565b60008261532a5761532a615223565b500490565b6001600160d01b03818116838216019080821115614fe957614fe9614ea0565b80516001600160701b038116811461536657600080fd5b919050565b60008060006060848603121561538057600080fd5b6153898461534f565b92506153976020850161534f565b915060408401516153a781614ce5565b809150509250925092565b6000602082840312156153c457600080fd5b8151612bd38161467a565b808202811582820484141761091d5761091d614ea0565b6000602082840312156153f857600080fd5b8151612bd381614d14565b634e487b7160e01b600052602160045260246000fd5b600060ff83168061542c5761542c615223565b8060ff84160691505092915050565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090612bbc908301846147bd565b60006020828403121561548757600080fd5b8151612bd3816146bb565b6001600160a01b0386811682528516602082015260a0604082018190526000906154be90830186614b6d565b82810360608401526154d08186614b6d565b905082810360808401526154e481856147bd565b98975050505050505050565b60008251615502818460208701614799565b9190910192915050565b60408152600061551f6040830185614b6d565b828103602084015261325e8185614b6d56fea164736f6c6343000815000a0000000000000000000000008880111018c364912dbe5ee61d98942647680888000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000005d98ac27db9f28efde511ce32ed8e6a876f0a21400000000000000000000000000000000000000000000000000000000000001000000000000000000000000009afdbb3fead8419425e68f3a4be2baa38e03d7fb000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102b35760003560e01c8063644dbe0711610172578063ae4d7f9a116100d9578063e59f9e0e11610092578063e59f9e0e146106a9578063e985e9c5146106bc578063f242432a146106f8578063f2fde38b14610706578063f5c476f914610719578063f7b75ae714610721578063fb16fb721461072957600080fd5b8063ae4d7f9a1461064b578063b464f8a11461065e578063bd85b03914610666578063bf9d10f914610686578063c75445e514610699578063d2e2a975146106a157600080fd5b806388c3ffb01161012b57806388c3ffb0146105c85780638da5cb5b146105e85780638faf6d04146105f9578063911010ab1461060c57806391ddadf414610619578063a22cb4651461063857600080fd5b8063644dbe071461056c578063692ad3531461057f57806370740ac914610592578063715018a61461059a5780637a2d14e2146105a25780637c405325146105b557600080fd5b80631fe543e311610221578063427f0b00116101da578063427f0b00146104675780634bf5d7e9146104d35780634e1273f4146104db5780634e2786fb146104fb5780634f558e791461050457806351dbc830146105265780636386c1c71461053957600080fd5b80631fe543e3146103c957806320c5780c146103dc5780632e2f88441461040e5780632eb2c2d61461042157806331866934146104345780634077604b1461044757600080fd5b80630ddabda4116102735780630ddabda4146103605780630e89341c146103735780631232eb731461039357806313f352c8146103a657806318160ddd146103b95780631e820325146103c157600080fd5b80626cc35e146102b85780626da327146102e1578062fdd58e146102f657806301ffc9a71461031757806302fe53051461033a57806306b091f91461034d575b600080fd5b6009546102cb906001600160a01b031681565b6040516102d8919061464d565b60405180910390f35b6102f46102ef366004614661565b610731565b005b61030961030436600461468f565b6108f9565b6040519081526020016102d8565b61032a6103253660046146d1565b610923565b60405190151581526020016102d8565b6102f46103483660046146ee565b610973565b6102f461035b36600461468f565b6109be565b6102f461036e36600461475f565b610afc565b610386610381366004614661565b61120c565b6040516102d891906147e9565b6103096103a13660046147fc565b611217565b6103096103b43660046147fc565b611233565b600554610309565b6102f4611240565b6102f46103d73660046148f8565b611352565b6009546103f690600160a01b90046001600160401b031681565b6040516001600160401b0390911681526020016102d8565b61030961041c36600461493e565b6113d6565b6102f461042f3660046149e5565b611408565b6102f4610442366004614a92565b61145e565b610309610455366004614661565b60146020526000908152604090205481565b61047a610475366004614661565b611488565b604080519915158a5260ff90981660208a015265ffffffffffff96871697890197909752938516606088015291841660808701529290921660a085015260c084019190915260e0830152610100820152610120016102d8565b6103866114fc565b6104ee6104e9366004614ab6565b611594565b6040516102d89190614ba8565b61030960125481565b61032a610512366004614661565b600090815260046020526040902054151590565b6102f4610534366004614661565b611668565b61054c610547366004614bbb565b6116e1565b6040805194855260208501939093529183015260608201526080016102d8565b6102f461057a366004614bbb565b611823565b6102f461058d366004614bd8565b611875565b6103096118aa565b6102f4611d50565b6102f46105b0366004614c01565b611d64565b6102f46105c3366004614661565b611eb3565b6105db6105d6366004614661565b612063565b6040516102d89190614c23565b6000546001600160a01b03166102cb565b6102f4610607366004614cf7565b6121c4565b60115461032a9060ff1681565b6106216121e8565b60405165ffffffffffff90911681526020016102d8565b6102f4610646366004614d22565b6121f7565b6102f4610659366004614bbb565b612202565b610309612254565b610309610674366004614661565b60009081526004602052604090205490565b61054c610694366004614bbb565b612277565b6102f4612419565b61030961247b565b6102f46106b7366004614c01565b61276a565b61032a6106ca366004614d5b565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205460ff1690565b6102f461042f366004614d89565b6102f4610714366004614bbb565b6128b0565b6103096128ee565b610309612903565b6102f461290d565b60115460ff161561075d5760405162461bcd60e51b815260040161075490614df1565b60405180910390fd5b60006107676121e8565b336000908152600e60205260408120919250906107849083612b11565b905082816001600160d01b031610156107af5760405162461bcd60e51b815260040161075490614e21565b336000908152600e602052604090206107d390612bc76107ce86612bda565b612c12565b50506107e66010612bc76107ce86612bda565b5050600954604051633281306d60e01b81526000916001600160a01b031690633281306d9061081990339060040161464d565b6040805180830381865afa158015610835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108599190614e62565b5090508015610883576000818152600c6020526040902061088090612bc76107ce87612bda565b50505b6108b76001600160a01b037f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c163386612c4b565b604080518581526020810183905233917ff3a8b53aa070deb9cde5db0e7c4e0d505bc0fb0b5244e57ce6a9ece13dbd22fb91015b60405180910390a250505050565b60008181526001602090815260408083206001600160a01b03861684529091529020545b92915050565b60006001600160e01b03198216636cdb3d1360e11b148061095457506001600160e01b031982166303a24d0760e21b145b8061091d57506301ffc9a760e01b6001600160e01b031983161461091d565b61097b612caf565b6109ba82828080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612cdc92505050565b5050565b6109c6612caf565b7f0000000000000000000000008880111018c364912dbe5ee61d989426476808886001600160a01b0316826001600160a01b031603610a535760405162461bcd60e51b815260206004820152602360248201527f4c6f74746572793a2063616e6e6f742077697468647261772038383820746f6b604482015262656e7360e81b6064820152608401610754565b7f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c6001600160a01b0316826001600160a01b031603610ae85760405162461bcd60e51b815260206004820152602b60248201527f4c6f74746572793a2063616e6e6f74207769746864726177203838382f55534460448201526a43204c5020746f6b656e7360a81b6064820152608401610754565b6109ba6001600160a01b0383163383612c4b565b610b04612caf565b60115460ff1615610b575760405162461bcd60e51b815260206004820152601e60248201527f4c6f74746572793a20726f756e6420616c7265616479206f6e676f696e6700006044820152606401610754565b610b6760608201604083016147fc565b65ffffffffffff16600003610bde5760405162461bcd60e51b815260206004820152603760248201527f4c6f74746572793a206d696e74696e672077696e646f77206475726174696f6e6044820152760206d7573742062652067726561746572207468616e203604c1b6064820152608401610754565b610bee60808201606083016147fc565b65ffffffffffff16600003610c665760405162461bcd60e51b815260206004820152603860248201527f4c6f74746572793a20636c61696d696e672077696e646f77206475726174696f60448201527706e206d7573742062652067726561746572207468616e20360441b6064820152608401610754565b6702c68af0bb14000081608001351115610cd85760405162461bcd60e51b815260206004820152602d60248201527f4c6f74746572793a206275796261636b20616e64206275726e2070657263656e60448201526c0e8c2ceca40e8dede40d0d2ced609b1b6064820152608401610754565b6000610ce26121e8565b90506000610cf1600f83612b11565b90506000610d00601084612b11565b9050610d2183610d18846001600160d01b0316612bda565b600f9190612ce8565b5050610d4283610d39836001600160d01b0316612bda565b60109190612ce8565b50506040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816906370a0823190610d9390309060040161464d565b602060405180830381865afa158015610db0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd49190614e87565b90506000610def826080880135670de0b6b3a7640000612cf6565b90506000610e0e8367016345785d8a0000670de0b6b3a7640000612cf6565b600854909150610e4b906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb488116911684612c4b565b6000610e578284614eb6565b610e619085614ec9565b905060006040518061014001604052806000151581526020018a6020016020810190610e8d9190614edc565b60ff1681526020018965ffffffffffff168152602001600065ffffffffffff1681526020018a6040016020810190610ec591906147fc565b65ffffffffffff168152602001610ee260808c0160608d016147fc565b65ffffffffffff168152602001600081526020018381526020018a60a00135815260200160006001600160401b03811115610f1f57610f1f614824565b604051908082528060200260200182016040528015610f48578160200160208202803683370190505b508152509050600160126000828254610f619190614eb6565b90915550506013805460018101825560009190915281517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0906005909202918201805460208086015160408701516060880151608089015160a08a015161ffff1990961697151561ff0019169790971761010060ff9094168402176dffffffffffffffffffffffff000019166201000065ffffffffffff9384160265ffffffffffff60401b191617600160401b91831691909102176bffffffffffffffffffffffff60701b1916600160701b9682169690960265ffffffffffff60a01b191695909517600160a01b959093169490940291909117825560c08501517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a09185015560e08501517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a092850155918401517f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a09384015561012084015180518594929361110a937f66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a094019201906145f6565b50506011805460ff19166001179055506012546111659061112b8b80614eff565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612dba92505050565b6012547f830f1de5aa413bf4e51a8e89ccdd3b975ebbcf29e6a9c9a1de7ae9d7d0c82a128361119a60408d0160208e01614edc565b6111aa60608e0160408f016147fc565b8d60600160208101906111bd91906147fc565b6040805194855260ff93909316602085015265ffffffffffff9182168484015216606083015260808d8101359083015260a0808e013590830152519081900360c00190a2505050505050505050565b606061091d82612e0b565b6000611224601083612b11565b6001600160d01b031692915050565b6000611224600f83612b11565b611248612caf565b60115460ff1661126a5760405162461bcd60e51b815260040161075490614f4c565b6012546000601361127c600184614ec9565b8154811061128c5761128c614f7f565b60009182526020909120600590910201805490915060ff166112c05760405162461bcd60e51b815260040161075490614f95565b80546112e49065ffffffffffff600160a01b8204811691600160401b900416614fca565b65ffffffffffff166112f46121e8565b65ffffffffffff16116113195760405162461bcd60e51b815260040161075490614ff0565b6011805460ff1916905560405182907fd49620ec6474d72a2f05dd60f5ab59ad0d2d9d29090cb3b81defc30db3d510c390600090a25050565b336001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990916146113cc5760405163073e64fd60e21b81523360048201526001600160a01b037f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909166024820152604401610754565b6109ba8282612eea565b601560205282600052604060002060205281600052604060002081600281106113fe57600080fd5b0154925083915050565b60405162461bcd60e51b815260206004820152602560248201527f4c6f74746572793a205469636b65747320617265206e6f6e2d7472616e7366656044820152647261626c6560d81b6064820152608401610754565b611466612caf565b6009805461ffff909216600160e01b0261ffff60e01b19909216919091179055565b6013818154811061149857600080fd5b6000918252602090912060059091020180546001820154600283015460039093015460ff80841695506101008404169365ffffffffffff620100008504811694600160401b8104821694600160701b8204831694600160a01b909204909216929089565b6060611506613151565b65ffffffffffff166115166121e8565b65ffffffffffff161461156b5760405162461bcd60e51b815260206004820152601b60248201527f4c6f74746572793a20696e636f6e73697374656e7420636c6f636b00000000006044820152606401610754565b5060408051808201909152600e81526d06d6f64653d74696d657374616d760941b602082015290565b606081518351146115c55781518351604051635b05999160e01b815260048101929092526024820152604401610754565b600083516001600160401b038111156115e0576115e0614824565b604051908082528060200260200182016040528015611609578160200160208202803683370190505b50905060005b845181101561166057602080820286010151611633906020808402870101516108f9565b82828151811061164557611645614f7f565b602090810291909101015261165981615049565b905061160f565b509392505050565b600061167433836108f9565b9050806000036116965760405162461bcd60e51b815260040161075490615062565b6116a133838361315c565b604080518381526020810183905233917fbb3d3e99bf2dd4c603c77e7d93564950ba9976830de2d943776db31b45814d8991015b60405180910390a25050565b60008060008060006116f16121e8565b6001600160a01b0387166000908152600d602052604090209091506117169082612b11565b6001600160a01b0387166000908152600e602052604090206001600160d01b039190911695506117469082612b11565b600954604051630531f2cb60e21b81526001600160d01b039290921695506000916001600160a01b03909116906314c7cb2c90611787908a9060040161464d565b602060405180830381865afa1580156117a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c89190614e87565b9050801561181a576000818152600b602052604090206117e89083612b11565b6000828152600c602052604090206001600160d01b0391909116945061180e9083612b11565b6001600160d01b031692505b50509193509193565b61182b612caf565b600880546001600160a01b0319166001600160a01b0383169081179091556040517f4e5651c05a1f32df05686898139afc9bb4bb5a17fb802e20b4f4b78094fbcc6f90600090a250565b61187d612caf565b600980546001600160401b03909216600160a01b0267ffffffffffffffff60a01b19909216919091179055565b60115460009060ff166118cf5760405162461bcd60e51b815260040161075490614f4c565b60006118d96121e8565b601254909150600060136118ee600184614ec9565b815481106118fe576118fe614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156119df57602002820191906000526020600020905b8154815260200190600101908083116119cb575b505050505081525050905060006119f633846108f9565b905060008111611a185760405162461bcd60e51b815260040161075490615062565b8151611a365760405162461bcd60e51b815260040161075490614f95565b816060015165ffffffffffff168465ffffffffffff16118015611a7c57508160a001518260600151611a689190614fca565b65ffffffffffff168465ffffffffffff1611155b611a985760405162461bcd60e51b815260040161075490614ff0565b60008381526015602090815260408083203384529091528082208151808301928390529160029082845b815481526020019060010190808311611ac25750505050509050600083610120015190506000806000611b09876020015160ff168860e001516131cb90919063ffffffff16565b905060005b8451811015611b945785518551869083908110611b2d57611b2d614f7f565b602002602001015110158015611b6357508560016020020151858281518110611b5857611b58614f7f565b602002602001015111155b15611b8257611b73600184614eb6565b9250611b7f8285614eb6565b93505b80611b8c81615049565b915050611b0e565b5081600003611be55760405162461bcd60e51b815260206004820152601b60248201527f4c6f74746572793a206e6f2077696e6e696e67207469636b65747300000000006044820152606401610754565b611bf033898861315c565b600954604051633281306d60e01b815260009182916001600160a01b0390911690633281306d90611c2590339060040161464d565b6040805180830381865afa158015611c41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c659190614e62565b90925090508115611cd1576000611c8d8666b1a2bc2ec50000670de0b6b3a764000084613216565b9050611c998187614ec9565b9550611ccf6001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48168383612c4b565b505b611d056001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48163387612c4b565b604080518b81526020810187905233917f256642a903d86ec186d0ad895b74bdbe7f9e5a72db568f4c4d58c2fa38b39e1c910160405180910390a250929a9950505050505050505050565b611d58612caf565b611d626000613267565b565b611d996001600160a01b037f0000000000000000000000008880111018c364912dbe5ee61d98942647680888163330856132b7565b336000908152600d60205260409020611db8906132f66107ce85612bda565b5050611dcb600f6132f66107ce85612bda565b5050611dd73382613302565b600954604051633281306d60e01b81526000916001600160a01b031690633281306d90611e0890339060040161464d565b6040805180830381865afa158015611e24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e489190614e62565b5090508015611e72576000818152600b60205260409020611e6f906132f66107ce86612bda565b50505b604080518481526020810183905233917f8df2cd4a972a1beed9236aa9769f82bb9af841456f5f3521a276b1d30d80364591015b60405180910390a2505050565b60115460ff1615611ed65760405162461bcd60e51b815260040161075490614df1565b6000611ee06121e8565b336000908152600d6020526040812091925090611efd9083612b11565b905082816001600160d01b03161015611f285760405162461bcd60e51b815260040161075490614e21565b336000908152600d60205260409020611f4790612bc76107ce86612bda565b5050611f5a600f612bc76107ce86612bda565b5050600954604051633281306d60e01b81526000916001600160a01b031690633281306d90611f8d90339060040161464d565b6040805180830381865afa158015611fa9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fcd9190614e62565b5090508015611ff7576000818152600b60205260409020611ff490612bc76107ce87612bda565b50505b61202b6001600160a01b037f0000000000000000000000008880111018c364912dbe5ee61d98942647680888163386612c4b565b604080518581526020810183905233917f78ef8056aa4d842c1cc53bf449de3dda50aca0621822909a9919c5c0c0b54d2891016108eb565b604080516101408101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082019290925261012081019190915260136120c3600184614ec9565b815481106120d3576120d3614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156121b457602002820191906000526020600020905b8154815260200190600101908083116121a0575b5050505050815250509050919050565b6121cc612caf565b600a805463ffffffff191663ffffffff92909216919091179055565b60006121f2613151565b905090565b6109ba338383613404565b61220a612caf565b600980546001600160a01b0319166001600160a01b0383169081179091556040517f828abcccea18192c21d645e575652c49e20b986dab777906fc473d056b01b6a890600090a250565b60006122696122616121e8565b601090612b11565b6001600160d01b0316905090565b60115460009081908190819060ff166122b2576122a3856122966121e8565b61229e61349a565b61369a565b92965090945092509050612412565b601254600060136122c4600184614ec9565b815481106122d4576122d4614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156123b557602002820191906000526020600020905b8154815260200190600101908083116123a1575b5050505050815250509050806080015181604001516123d49190614fca565b65ffffffffffff166123e46121e8565b65ffffffffffff161161181a5761240587826040015183610100015161369a565b9298509096509450925050505b9193509193565b612421612caf565b60115460ff166124435760405162461bcd60e51b815260040161075490614f4c565b6011805460ff191690556012546040517fd49620ec6474d72a2f05dd60f5ab59ad0d2d9d29090cb3b81defc30db3d510c390600090a2565b60115460009060ff166124a05760405162461bcd60e51b815260040161075490614f4c565b601254600060136124b2600184614ec9565b815481106124c2576124c2614f7f565b600091825260209182902060408051610140810182526005909302909101805460ff808216151585526101008083049091168587015265ffffffffffff620100008304811686860152600160401b830481166060870152600160701b830481166080870152600160a01b90920490911660a0850152600182015460c0850152600282015460e085015260038201549084015260048101805483518187028101870190945280845293949193610120860193928301828280156125a357602002820191906000526020600020905b81548152602001906001019080831161258f575b5050505050815250509050806080015181604001516125c29190614fca565b65ffffffffffff166125d26121e8565b65ffffffffffff1611156126285760405162461bcd60e51b815260206004820152601e60248201527f4c6f74746572793a206e6f7420696e206d696e74696e672077696e646f7700006044820152606401610754565b600061263433846108f9565b905080156126905760405162461bcd60e51b8152602060048201526024808201527f4c6f74746572793a207573657220616c7265616479206d696e746564207469636044820152636b65747360e01b6064820152608401610754565b60006126a633846040015185610100015161369a565b505050600085815260046020526040812054919250506126d733868460405180602001604052806000815250613998565b60008581526004602090815260408083205460158352818420338552909252909120829055612707600182614ec9565b6000878152601560209081526040808320338452909152902060010155604080518781526020810185905233917f47077b9c55ea85476c20e80bb7b9315ff5e80e0354086bd502bfda0fa91ba7aa910160405180910390a2509095945050505050565b61279f6001600160a01b037f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c163330856132b7565b336000908152600e602052604090206127be906132f66107ce85612bda565b50506127d160106132f66107ce85612bda565b50506127dd3382613302565b600954604051633281306d60e01b81526000916001600160a01b031690633281306d9061280e90339060040161464d565b6040805180830381865afa15801561282a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061284e9190614e62565b5090508015612878576000818152600c60205260409020612875906132f66107ce86612bda565b50505b604080518481526020810183905233917f5da3fec768e6a5b960b70b987d7526b05214a15a6d05ae3d7af281a3551dac2e9101611ea6565b6128b8612caf565b6001600160a01b0381166128e2576000604051631e4fbdf760e01b8152600401610754919061464d565b6128eb81613267565b50565b60006122696128fb6121e8565b600f90612b11565b60006121f261349a565b612915612caf565b600061291f6121e8565b90506000601360016012546129349190614ec9565b8154811061294457612944614f7f565b60009182526020909120600590910201805490915060ff16156129795760405162461bcd60e51b81526004016107549061508f565b805461299c9065ffffffffffff600160701b820481169162010000900416614fca565b65ffffffffffff168265ffffffffffff16116129fa5760405162461bcd60e51b815260206004820152601f60248201527f4c6f74746572793a20726166666c65206e6f74207374617274656420796574006044820152606401610754565b8054600954600a546040516305d3b1d360e41b81527fff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f926004820152600160a01b83046001600160401b03166024820152600160e01b90920461ffff16604483015263ffffffff16606482015261010090910460ff1660848201819052906000907f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699096001600160a01b031690635d3b1d309060a4016020604051808303816000875af1158015612acd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af19190614e87565b600190930183905550506012546000918252601460205260409091205550565b815460009081816005811115612b70576000612b2c846139f5565b612b369085614ec9565b60008881526020902090915081015465ffffffffffff9081169087161015612b6057809150612b6e565b612b6b816001614eb6565b92505b505b6000612b7e87878585613add565b90508015612bb957612ba387612b95600184614ec9565b600091825260209091200190565b54600160301b90046001600160d01b0316612bbc565b60005b979650505050505050565b6000612bd382846150c4565b9392505050565b60006001600160d01b03821115612c0e576040516306dfcc6560e41b815260d0600482015260248101839052604401610754565b5090565b600080612c3e612c206121e8565b612c36612c2c88613b37565b868863ffffffff16565b879190612ce8565b915091505b935093915050565b6040516001600160a01b03838116602483015260448201839052612caa91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613b70565b505050565b6000546001600160a01b03163314611d62573360405163118cdaa760e01b8152600401610754919061464d565b60036109ba8282615164565b600080612c3e858585613bca565b6000838302816000198587098281108382030391505080600003612d2d57838281612d2357612d23615223565b0492505050612bd3565b808411612d4d5760405163227bc15360e01b815260040160405180910390fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000828152600760205260409020612dd28282615164565b50817f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b612dfe8461120c565b6040516116d591906147e9565b600081815260076020526040812080546060929190612e29906150e4565b80601f0160208091040260200160405190810160405280929190818152602001828054612e55906150e4565b8015612ea25780601f10612e7757610100808354040283529160200191612ea2565b820191906000526020600020905b815481529060010190602001808311612e8557829003601f168201915b505050505090506000815111612ec057612ebb83613d44565b612bd3565b600681604051602001612ed4929190615239565b6040516020818303038152906040529392505050565b60115460ff16612f0c5760405162461bcd60e51b815260040161075490614f4c565b600082815260146020526040812054906013612f29600184614ec9565b81548110612f3957612f39614f7f565b9060005260206000209060050201905083816001015414612f985760405162461bcd60e51b8152602060048201526019602482015278131bdd1d195c9e4e881ddc9bdb99c81c995c5d595cdd081a59603a1b6044820152606401610754565b805460ff16158015612fb857508054600160401b900465ffffffffffff16155b612fd45760405162461bcd60e51b81526004016107549061508f565b6000612fde6121e8565b82549091506130049065ffffffffffff600160701b820481169162010000900416614fca565b65ffffffffffff168165ffffffffffff16116130705760405162461bcd60e51b815260206004820152602560248201527f4c6f74746572793a20726166666c65206d696e74696e67207068617365206f6e604482015264676f696e6760d81b6064820152608401610754565b60005b8254610100900460ff168110156130e2576000848152600460205260408120548683815181106130a5576130a5614f7f565b60200260200101516130b791906152c0565b60048501805460018101825560009182526020909120015550806130da81615049565b915050613073565b50815465ffffffffffff8216600160401b026dffffffffffff00000000000000ff1990911617600117825560405183907f6ab43dfe350db3c48d094a2b8871901c673ecdd67e11b10dffe05fecb6c0f04f906131429060048601906152d4565b60405180910390a25050505050565b60006121f242613dd8565b6001600160a01b038316613185576000604051626a0d4560e21b8152600401610754919061464d565b604080516001808252602082018590528183019081526060820184905260a082019092526000608082018181529192916131c491879185908590613e0b565b5050505050565b6000816000036131e6576131df828461531b565b905061091d565b821561320d57816131f8600185614ec9565b613202919061531b565b612ebb906001614eb6565b50600092915050565b600080613224868686612cf6565b905061322f83613e5e565b801561324b57506000848061324657613246615223565b868809115b1561325e5761325b600182614eb6565b90505b95945050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b0384811660248301528381166044830152606482018390526132f09186918216906323b872dd90608401612c78565b50505050565b6000612bd3828461532f565b8061330b575050565b6009546001600160a01b031661331f575050565b6009546040516337672f1b60e11b81526000916001600160a01b031690636ece5e369061335090869060040161464d565b602060405180830381865afa15801561336d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133919190614e87565b1461339a575050565b6009546040516364db1d0d60e11b81526001600160a01b038481166004830152602482018490529091169063c9b63a1a90604401600060405180830381600087803b1580156133e857600080fd5b505af11580156133fc573d6000803e3d6000fd5b505050505050565b6001600160a01b03821661342d57600060405162ced3e160e81b8152600401610754919061464d565b6001600160a01b03838116600081815260026020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60008060007f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c6001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156134fd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613521919061536b565b509150915060007f0000000000000000000000008880111018c364912dbe5ee61d989426476808886001600160a01b03167f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c6001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156135b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135d491906153b2565b6001600160a01b0316146135e857816135ea565b825b6001600160701b0316905060007f000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c6001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613655573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136799190614e87565b9050806136878360036153cf565b613691919061531b565b94505050505090565b6001600160a01b0383166000908152600d60205260408120819081908190819081906136c69089612b11565b6001600160a01b038a166000908152600e60205260408120919250906136ec908a612b11565b90506000613703896001600160d01b0384166153cf565b613716906001600160d01b038516614eb6565b600954604051633281306d60e01b81529192506000916001600160a01b0390911690633281306d9061374c908f9060040161464d565b6040805180830381865afa158015613768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061378c9190614e62565b50905080156137b5576137b28267016345785d8a0000670de0b6b3a76400006000613216565b94505b816000036137d5576000806000809850985098509850505050505061398f565b6000600960009054906101000a90046001600160a01b03166001600160a01b03166314c7cb2c8e6040518263ffffffff1660e01b8152600401613818919061464d565b602060405180830381865afa158015613835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138599190614e87565b90508015613916576000818152600b60205260408120613879908e612b11565b6000838152600c6020526040812091925090613895908f612b11565b905060006138ac8e6001600160d01b0384166153cf565b6138bf906001600160d01b038516614eb6565b905060006138d782670de0b6b3a76400008984613216565b905060006138ed82678ac7230489e80000613e8b565b90506139048882670de0b6b3a76400006000613216565b61390e908c614eb6565b9a5050505050505b6000613934670de0b6b3a764000061392e8987614eb6565b906131cb565b9050806139526001600160d01b038816670de0b6b3a76400006131cb565b61396d6001600160d01b038816670de0b6b3a76400006131cb565b61397f8a670de0b6b3a76400006131cb565b9a509a509a509a50505050505050505b93509350935093565b6001600160a01b0384166139c2576000604051632bfa23e760e11b8152600401610754919061464d565b604080516001808252602082018690528183019081526060820185905260808201909252906133fc600087848487613e0b565b600081600003613a0757506000919050565b60006001613a1484613ea1565b901c6001901b90506001818481613a2d57613a2d615223565b048201901c90506001818481613a4557613a45615223565b048201901c90506001818481613a5d57613a5d615223565b048201901c90506001818481613a7557613a75615223565b048201901c90506001818481613a8d57613a8d615223565b048201901c90506001818481613aa557613aa5615223565b048201901c90506001818481613abd57613abd615223565b048201901c9050612bd381828581613ad757613ad7615223565b04613e8b565b60005b81831015611660576000613af48484613f35565b60008781526020902090915065ffffffffffff86169082015465ffffffffffff161115613b2357809250613b31565b613b2e816001614eb6565b93505b50613ae0565b80546000908015613b6757613b5183612b95600184614ec9565b54600160301b90046001600160d01b0316612bd3565b60009392505050565b6000613b856001600160a01b03841683613f50565b90508051600014158015613baa575080806020019051810190613ba891906153e6565b155b15612caa5782604051635274afe760e01b8152600401610754919061464d565b825460009081908015613ce9576000613be887612b95600185614ec9565b60408051808201909152905465ffffffffffff808216808452600160301b9092046001600160d01b031660208401529192509087161015613c3c57604051632520601d60e01b815260040160405180910390fd5b805165ffffffffffff808816911603613c885784613c5f88612b95600186614ec9565b80546001600160d01b0392909216600160301b0265ffffffffffff909216919091179055613cd9565b6040805180820190915265ffffffffffff80881682526001600160d01b0380881660208085019182528b54600181018d5560008d81529190912094519151909216600160301b029216919091179101555b602001519250839150612c439050565b50506040805180820190915265ffffffffffff80851682526001600160d01b0380851660208085019182528854600181018a5560008a815291822095519251909316600160301b029190931617920191909155905081612c43565b606060038054613d53906150e4565b80601f0160208091040260200160405190810160405280929190818152602001828054613d7f906150e4565b8015613dcc5780601f10613da157610100808354040283529160200191613dcc565b820191906000526020600020905b815481529060010190602001808311613daf57829003601f168201915b50505050509050919050565b600065ffffffffffff821115612c0e576040516306dfcc6560e41b81526030600482015260248101839052604401610754565b613e1785858585613f5e565b6001600160a01b038416156131c45782513390600103613e505760208481015190840151613e49838989858589613f6a565b50506133fc565b6133fc818787878787614085565b60006002826003811115613e7457613e74615403565b613e7e9190615419565b60ff166001149050919050565b6000818310613e9a5781612bd3565b5090919050565b600080608083901c15613eb657608092831c92015b604083901c15613ec857604092831c92015b602083901c15613eda57602092831c92015b601083901c15613eec57601092831c92015b600883901c15613efe57600892831c92015b600483901c15613f1057600492831c92015b600283901c15613f2257600292831c92015b600183901c1561091d5760010192915050565b6000613f44600284841861531b565b612bd390848416614eb6565b6060612bd383836000614165565b6132f084848484614202565b6001600160a01b0384163b156133fc5760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e6190613fae908990899088908890889060040161543b565b6020604051808303816000875af1925050508015613fe9575060408051601f3d908101601f19168201909252613fe691810190615475565b60015b614049573d808015614017576040519150601f19603f3d011682016040523d82523d6000602084013e61401c565b606091505b5080516000036140415784604051632bfa23e760e11b8152600401610754919061464d565b805181602001fd5b6001600160e01b0319811663f23a6e6160e01b1461407c5784604051632bfa23e760e11b8152600401610754919061464d565b50505050505050565b6001600160a01b0384163b156133fc5760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906140c99089908990889088908890600401615492565b6020604051808303816000875af1925050508015614104575060408051601f3d908101601f1916820190925261410191810190615475565b60015b614132573d808015614017576040519150601f19603f3d011682016040523d82523d6000602084013e61401c565b6001600160e01b0319811663bc197c8160e01b1461407c5784604051632bfa23e760e11b8152600401610754919061464d565b60608147101561418a573060405163cd78605960e01b8152600401610754919061464d565b600080856001600160a01b031684866040516141a691906154f0565b60006040518083038185875af1925050503d80600081146141e3576040519150601f19603f3d011682016040523d82523d6000602084013e6141e8565b606091505b50915091506141f886838361435c565b9695505050505050565b61420e848484846143aa565b6001600160a01b0384166142c1576000805b83518110156142a757600083828151811061423d5761423d614f7f565b60200260200101519050806004600087858151811061425e5761425e614f7f565b6020026020010151815260200190815260200160002060008282546142839190614eb6565b9091555061429390508184614eb6565b925050806142a090615049565b9050614220565b5080600560008282546142ba9190614eb6565b9091555050505b6001600160a01b0383166132f0576000805b835181101561434b5760008382815181106142f0576142f0614f7f565b60200260200101519050806004600087858151811061431157614311614f7f565b60200260200101518152602001908152602001600020600082825403925050819055508083019250508061434490615049565b90506142d3565b506005805491909103905550505050565b60608261436c57612ebb826145cd565b815115801561438357506001600160a01b0384163b155b156143a35783604051639996b31560e01b8152600401610754919061464d565b5080612bd3565b80518251146143d95781518151604051635b05999160e01b815260048101929092526024820152604401610754565b3360005b83518110156144ee576020818102858101820151908501909101516001600160a01b038816156144945760008281526001602090815260408083206001600160a01b038c1684529091529020548181101561446b576040516303dee4c560e01b81526001600160a01b038a166004820152602481018290526044810183905260648101849052608401610754565b60008381526001602090815260408083206001600160a01b038d16845290915290209082900390555b6001600160a01b038716156144db5760008281526001602090815260408083206001600160a01b038b168452909152812080548392906144d5908490614eb6565b90915550505b5050806144e790615049565b90506143dd565b50825160010361456f5760208301516000906020840151909150856001600160a01b0316876001600160a01b0316846001600160a01b03167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628585604051614560929190918252602082015260400190565b60405180910390a450506131c4565b836001600160a01b0316856001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb86866040516145be92919061550c565b60405180910390a45050505050565b8051156145dd5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b828054828255906000526020600020908101928215614631579160200282015b82811115614631578251825591602001919060010190614616565b50612c0e9291505b80821115612c0e5760008155600101614639565b6001600160a01b0391909116815260200190565b60006020828403121561467357600080fd5b5035919050565b6001600160a01b03811681146128eb57600080fd5b600080604083850312156146a257600080fd5b82356146ad8161467a565b946020939093013593505050565b6001600160e01b0319811681146128eb57600080fd5b6000602082840312156146e357600080fd5b8135612bd3816146bb565b6000806020838503121561470157600080fd5b82356001600160401b038082111561471857600080fd5b818501915085601f83011261472c57600080fd5b81358181111561473b57600080fd5b86602082850101111561474d57600080fd5b60209290920196919550909350505050565b60006020828403121561477157600080fd5b81356001600160401b0381111561478757600080fd5b820160c08185031215612bd357600080fd5b60005b838110156147b457818101518382015260200161479c565b50506000910152565b600081518084526147d5816020860160208601614799565b601f01601f19169290920160200192915050565b602081526000612bd360208301846147bd565b60006020828403121561480e57600080fd5b813565ffffffffffff81168114612bd357600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561486257614862614824565b604052919050565b60006001600160401b0382111561488357614883614824565b5060051b60200190565b600082601f83011261489e57600080fd5b813560206148b36148ae8361486a565b61483a565b82815260059290921b840181019181810190868411156148d257600080fd5b8286015b848110156148ed57803583529183019183016148d6565b509695505050505050565b6000806040838503121561490b57600080fd5b8235915060208301356001600160401b0381111561492857600080fd5b6149348582860161488d565b9150509250929050565b60008060006060848603121561495357600080fd5b8335925060208401356149658161467a565b929592945050506040919091013590565b600082601f83011261498757600080fd5b81356001600160401b038111156149a0576149a0614824565b6149b3601f8201601f191660200161483a565b8181528460208386010111156149c857600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156149fd57600080fd5b8535614a088161467a565b94506020860135614a188161467a565b935060408601356001600160401b0380821115614a3457600080fd5b614a4089838a0161488d565b94506060880135915080821115614a5657600080fd5b614a6289838a0161488d565b93506080880135915080821115614a7857600080fd5b50614a8588828901614976565b9150509295509295909350565b600060208284031215614aa457600080fd5b813561ffff81168114612bd357600080fd5b60008060408385031215614ac957600080fd5b82356001600160401b0380821115614ae057600080fd5b818501915085601f830112614af457600080fd5b81356020614b046148ae8361486a565b82815260059290921b84018101918181019089841115614b2357600080fd5b948201945b83861015614b4a578535614b3b8161467a565b82529482019490820190614b28565b96505086013592505080821115614b6057600080fd5b506149348582860161488d565b600081518084526020808501945080840160005b83811015614b9d57815187529582019590820190600101614b81565b509495945050505050565b602081526000612bd36020830184614b6d565b600060208284031215614bcd57600080fd5b8135612bd38161467a565b600060208284031215614bea57600080fd5b81356001600160401b0381168114612bd357600080fd5b60008060408385031215614c1457600080fd5b50508035926020909101359150565b60208152614c3660208201835115159052565b60006020830151614c4c604084018260ff169052565b50604083015165ffffffffffff8116606084015250606083015165ffffffffffff8116608084015250608083015165ffffffffffff811660a08401525060a083015165ffffffffffff811660c08401525060c083015160e083810191909152830151610100808401919091528301516101208084019190915283015161014080840152614cdd610160840182614b6d565b949350505050565b63ffffffff811681146128eb57600080fd5b600060208284031215614d0957600080fd5b8135612bd381614ce5565b80151581146128eb57600080fd5b60008060408385031215614d3557600080fd5b8235614d408161467a565b91506020830135614d5081614d14565b809150509250929050565b60008060408385031215614d6e57600080fd5b8235614d798161467a565b91506020830135614d508161467a565b600080600080600060a08688031215614da157600080fd5b8535614dac8161467a565b94506020860135614dbc8161467a565b9350604086013592506060860135915060808601356001600160401b03811115614de557600080fd5b614a8588828901614976565b6020808252601690820152754c6f74746572793a20726f756e64206f6e676f696e6760501b604082015260600190565b60208082526021908201527f4c6f74746572793a206e6f7420656e6f756768206c6f636b656420746f6b656e6040820152607360f81b606082015260800190565b60008060408385031215614e7557600080fd5b825191506020830151614d508161467a565b600060208284031215614e9957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561091d5761091d614ea0565b8181038181111561091d5761091d614ea0565b600060208284031215614eee57600080fd5b813560ff81168114612bd357600080fd5b6000808335601e19843603018112614f1657600080fd5b8301803591506001600160401b03821115614f3057600080fd5b602001915036819003821315614f4557600080fd5b9250929050565b6020808252601990820152784c6f74746572793a206e6f20726f756e64206f6e676f696e6760381b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b6020808252818101527f4c6f74746572793a20726166666c65206e6f7420657865637574656420796574604082015260600190565b65ffffffffffff818116838216019080821115614fe957614fe9614ea0565b5092915050565b60208082526039908201527f4c6f74746572793a20636c61696d696e672077696e646f77206e6f74207374616040820152787274656420796574206f72207374696c6c206f6e676f696e6760381b606082015260800190565b60006001820161505b5761505b614ea0565b5060010190565b6020808252601390820152724c6f74746572793a206e6f207469636b65747360681b604082015260600190565b6020808252818101527f4c6f74746572793a20726166666c6520616c7265616479206578656375746564604082015260600190565b6001600160d01b03828116828216039080821115614fe957614fe9614ea0565b600181811c908216806150f857607f821691505b60208210810361511857634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115612caa57600081815260208120601f850160051c810160208610156151455750805b601f850160051c820191505b818110156133fc57828155600101615151565b81516001600160401b0381111561517d5761517d614824565b6151918161518b84546150e4565b8461511e565b602080601f8311600181146151c657600084156151ae5750858301515b600019600386901b1c1916600185901b1785556133fc565b600085815260208120601f198616915b828110156151f5578886015182559484019460019091019084016151d6565b50858210156152135787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601260045260246000fd5b6000808454615247816150e4565b6001828116801561525f5760018114615274576152a3565b60ff19841687528215158302870194506152a3565b8860005260208060002060005b8581101561529a5781548a820152908401908201615281565b50505082870194505b5050505083516152b7818360208801614799565b01949350505050565b6000826152cf576152cf615223565b500690565b6020808252825482820181905260008481528281209092916040850190845b8181101561530f578354835260019384019392850192016152f3565b50909695505050505050565b60008261532a5761532a615223565b500490565b6001600160d01b03818116838216019080821115614fe957614fe9614ea0565b80516001600160701b038116811461536657600080fd5b919050565b60008060006060848603121561538057600080fd5b6153898461534f565b92506153976020850161534f565b915060408401516153a781614ce5565b809150509250925092565b6000602082840312156153c457600080fd5b8151612bd38161467a565b808202811582820484141761091d5761091d614ea0565b6000602082840312156153f857600080fd5b8151612bd381614d14565b634e487b7160e01b600052602160045260246000fd5b600060ff83168061542c5761542c615223565b8060ff84160691505092915050565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090612bbc908301846147bd565b60006020828403121561548757600080fd5b8151612bd3816146bb565b6001600160a01b0386811682528516602082015260a0604082018190526000906154be90830186614b6d565b82810360608401526154d08186614b6d565b905082810360808401526154e481856147bd565b98975050505050505050565b60008251615502818460208701614799565b9190910192915050565b60408152600061551f6040830185614b6d565b828103602084015261325e8185614b6d56fea164736f6c6343000815000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000008880111018c364912dbe5ee61d98942647680888000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000005d98ac27db9f28efde511ce32ed8e6a876f0a21400000000000000000000000000000000000000000000000000000000000001000000000000000000000000009afdbb3fead8419425e68f3a4be2baa38e03d7fb000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _lucky8Token (address): 0x8880111018C364912dBe5Ee61D98942647680888
Arg [1] : _lucky8LpToken (address): 0xe0384Fd8C9fb7b546bF80153AC9F262Df596E62C
Arg [2] : _usdcToken (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [3] : _buyBackBurnAddress (address): 0x5d98AC27DB9F28EfdE511cE32Ed8E6a876F0A214
Arg [4] : _uri (string):
Arg [5] : _referralStorage (address): 0x9afDbB3Fead8419425E68F3a4bE2bAa38e03d7fB
Arg [6] : _vrfCoordinator (address): 0x271682DEB8C4E0901D1a1550aD2e64D568E69909
Arg [7] : _chainlinkSubscriptionId (uint64): 1
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 0000000000000000000000008880111018c364912dbe5ee61d98942647680888
Arg [1] : 000000000000000000000000e0384fd8c9fb7b546bf80153ac9f262df596e62c
Arg [2] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [3] : 0000000000000000000000005d98ac27db9f28efde511ce32ed8e6a876f0a214
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000100
Arg [5] : 0000000000000000000000009afdbb3fead8419425e68f3a4be2baa38e03d7fb
Arg [6] : 000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.