Source Code
Overview
ETH Balance
ETH Value
$0.00| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 3761891 | 655 days ago | 0 ETH | ||||
| 3739621 | 655 days ago | 0 ETH | ||||
| 3736489 | 655 days ago | 0 ETH | ||||
| 3736269 | 655 days ago | 0 ETH | ||||
| 3716223 | 656 days ago | 0 ETH | ||||
| 3715909 | 656 days ago | 0 ETH | ||||
| 3715731 | 656 days ago | 0 ETH | ||||
| 3715560 | 656 days ago | 0 ETH | ||||
| 3715466 | 656 days ago | 0 ETH | ||||
| 3715306 | 656 days ago | 0 ETH | ||||
| 3715196 | 656 days ago | 0 ETH | ||||
| 3713201 | 656 days ago | 0 ETH | ||||
| 3713169 | 656 days ago | 0 ETH | ||||
| 3709616 | 656 days ago | 0 ETH | ||||
| 3709539 | 656 days ago | 0 ETH | ||||
| 3664352 | 658 days ago | 0 ETH | ||||
| 3662680 | 658 days ago | 0 ETH | ||||
| 3662632 | 658 days ago | 0 ETH | ||||
| 3662617 | 658 days ago | 0 ETH | ||||
| 3662591 | 658 days ago | 0 ETH | ||||
| 3628424 | 659 days ago | 0 ETH | ||||
| 3627831 | 659 days ago | 0 ETH | ||||
| 3625008 | 659 days ago | 0 ETH | ||||
| 3625008 | 659 days ago | 0 ETH | ||||
| 3625007 | 659 days ago | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x1c555AEa...D71b4F774 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
PCLBaseSwapInside
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "../deps/ERC1155Supply.sol";
import {IERC20Metadata} from "../deps/OpenZeppelinV5/IERC20Metadata.sol";
import {SafeERC20} from "../deps/OpenZeppelinV5/SafeERC20.sol";
import "../deps/UUPSUpgradeable.sol";
import "../interfaces/IExchange.sol";
import "../interfaces/IRegistry.sol";
import "../interfaces/pancake/IPHyperPoolSwapInside.sol";
import "../interfaces/pancake/IPancakeV3Pool.sol";
import "../lib/pancake/TickMath.sol";
import "../lib/pancake/FullMath.sol";
import "../lib/pancake/TernOpLib.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/utils/Address.sol";
// PancakeV3 Concentrated Liquidity Base contract for blue chip assets
/// @custom:oz-upgrades-unsafe-allow constructor state-variable-immutable
contract PCLBaseSwapInside is UUPSUpgradeable, ERC1155Supply {
// SHARE TOKENS
// ID 0 - Not Compounding
// ID 1 - Compounding
using SafeERC20 for IERC20Metadata;
using SafeCast for uint256;
using Address for address;
IRegistry public immutable registry;
IERC20Metadata public immutable token0;
IERC20Metadata public immutable token1;
IPancakeV3Pool public immutable lpPool;
IPHyperPoolSwapInside public immutable liquidityHypervisor;
IERC20Metadata internal immutable rewardTokenAdr;
bytes32 private constant routerAggregator = keccak256("Router V0.1");
bytes32 private constant upgrader = keccak256("PancakeStrategyUpgrader V0.1");
uint136 private constant PERCENT_DENOMINATOR = 10000;
uint112 private constant UNIFORM_PRECISION = 1e18;
uint8 private constant UNIFORM_DECIMALS = 18;
uint256 private constant LP_PRICE_PRECISION = 10 ** 36;
uint128 internal lastCompoundBlock;
uint256 public compoundShareRate;
mapping(address => uint256) public nonCompoundingDepositorRewardDebt;
uint256 public accRewardPerShare; // Accumulated rewards per share
uint256 public totalRewards; // Total rewards accumulated from non-compounding shares
uint256 public compoundRewardsToSell; // Amount of rewards to sell for compounding
// Thresholds to avoid unnecessary swaps
uint256 private swapThreshold0;
uint256 private swapThreshold1;
uint256 private rewardSwapThreshold;
uint256 internal slippagePriceThreshold; // Price threshold for slippage check after swap
modifier onlyUpgrader() {
if (msg.sender != registry.getAddressByIdentifier(upgrader)) revert CallerUpgrader();
_;
}
modifier checkPriceManipulation() {
_checkPriceManipulation(0); // provide 0 price threshold to use the default value that is set in the liquidityHypervisor contract
_;
}
constructor(
IRegistry _registry,
IPancakeV3Pool _lpPool,
IPHyperPoolSwapInside _liquidityHypervisor,
IERC20Metadata _rewardTokenAdr
) {
token0 = IERC20Metadata(address(_lpPool.token0()));
token1 = IERC20Metadata(address(_lpPool.token1()));
registry = _registry;
lpPool = _lpPool;
liquidityHypervisor = _liquidityHypervisor;
rewardTokenAdr = _rewardTokenAdr;
// lock implementation
_disableInitializers();
}
function initialize(bytes memory initializeData) external initializer {
compoundShareRate = 1e18;
(uint256 _swapThreshold0, uint256 _swapThreshold1, uint256 _rewardSwapThreshold) = abi.decode(
initializeData,
(uint256, uint256, uint256)
);
swapThreshold0 = _swapThreshold0;
swapThreshold1 = _swapThreshold1;
rewardSwapThreshold = _rewardSwapThreshold;
__UUPSUpgradeable_init();
}
function _authorizeUpgrade(address newImplementation) internal override onlyUpgrader {}
function setSwapThresholds(
uint256 _swapThreshold0,
uint256 _swapThreshold1,
uint256 _rewardSwapThreshold
) external onlyUpgrader {
swapThreshold0 = _swapThreshold0;
swapThreshold1 = _swapThreshold1;
rewardSwapThreshold = _rewardSwapThreshold;
}
/// @notice Set slippage price threshold for swap
/// @param _slippagePriceThreshold New slippage price threshold value in BPS (set 0 to use the value that is set in the liquidityHypervisor contract)
function setSlippagePriceThreshold(uint256 _slippagePriceThreshold) external onlyUpgrader {
if (_slippagePriceThreshold > PERCENT_DENOMINATOR) revert InvalidPriceThreshold();
slippagePriceThreshold = _slippagePriceThreshold;
}
/// @notice Deposit token of the strategy
function depositToken() external view returns (address) {
return address(token0);
}
function rewardToken() external view returns (address) {
return address(rewardTokenAdr);
}
// Make it check share amount
function getPendingReward() external view returns (uint256 pendingRewards) {
return _getPendingReward(msg.sender);
}
function getPendingReward(address user) external view returns (uint256 pendingRewards) {
return _getPendingReward(user);
}
function _getPendingReward(address user) internal view returns (uint256 pendingRewards) {
uint256 totalPendingRewards = liquidityHypervisor.getPendingReward() +
rewardTokenAdr.balanceOf(address(this)) -
totalRewards -
compoundRewardsToSell;
// calculate compound reward
uint256 pendingCompoundSellPortion = _calculateSellPortion(totalPendingRewards);
uint256 totalCompoundReward = pendingCompoundSellPortion + compoundRewardsToSell;
uint256 userCompoundShares = balanceOf(user, 1);
if (totalCompoundReward > 0 && userCompoundShares > 0) {
// calculate user share percentage
uint256 totalCompoundingSharesMinted = totalSupply(1); // ID 1 for Compounding
uint256 userSharePercentage = (userCompoundShares * UNIFORM_PRECISION) / totalCompoundingSharesMinted;
// calculate user reward
pendingRewards += (totalCompoundReward * userSharePercentage) / UNIFORM_PRECISION;
}
// calculate non-compound reward
uint256 totalNonCompoundPortion = totalPendingRewards - pendingCompoundSellPortion;
uint256 totalNonCompoundReward = totalRewards + totalNonCompoundPortion;
uint256 userNonCompoundShares = balanceOf(user, 0);
if (totalNonCompoundReward > 0 && userNonCompoundShares > 0) {
// calculate the reward per share for non-compounding depositors
uint256 _accRewardPerShare = accRewardPerShare;
if (totalNonCompoundPortion > 0) {
// adjust the reward per share with the new reward
uint256 totalNonCompoundingShares = totalSupply(0); // ID 0 for Non-Compounding
uint256 rewardPerShare = (totalNonCompoundPortion * UNIFORM_PRECISION) / totalNonCompoundingShares;
_accRewardPerShare += rewardPerShare;
}
// calculate the reward debt for the user
uint256 depositorRewardDebt = nonCompoundingDepositorRewardDebt[user];
uint256 accumulatedReward = (userNonCompoundShares * _accRewardPerShare) / UNIFORM_PRECISION;
if (accumulatedReward > depositorRewardDebt) {
pendingRewards += accumulatedReward - depositorRewardDebt;
}
}
}
function getAllPendingReward() external view returns (uint256) {
return liquidityHypervisor.getPendingReward();
}
function totalTokens() external view returns (uint256) {
return _totalTokens(msg.sender);
}
function totalTokens(address user) external view returns (uint256) {
return _totalTokens(user);
}
function deposit(uint256 depositTokenAmount) external checkPriceManipulation {
_deposit(depositTokenAmount, true);
}
function depositNonCompounding(uint256 depositTokenAmount) external checkPriceManipulation {
_deposit(depositTokenAmount, false);
}
function depositPair(uint256 amount0, uint256 amount1, bool compounding) public checkPriceManipulation {
_compoundRewards();
token0.safeTransferFrom(msg.sender, address(this), amount0);
token1.safeTransferFrom(msg.sender, address(this), amount1);
token0.forceApprove(address(liquidityHypervisor), amount0);
token1.forceApprove(address(liquidityHypervisor), amount1);
(uint256 depositedAmount0, uint256 depositedAmount1, uint256 mintAmount, ) = liquidityHypervisor.mint(
amount0,
amount1,
address(this)
);
if (compounding) {
uint256 newShares = (mintAmount * UNIFORM_PRECISION) / compoundShareRate;
_mint(msg.sender, 1, newShares, ""); // ID 1 for Compounding
} else {
// If not compounding, calculate the new shares based on a constant rate (1:1 for simplicity)
_mint(msg.sender, 0, mintAmount, ""); // ID 0 for Non-Compounding
// Should set then users reward dept for the tokens he has deposited.
nonCompoundingDepositorRewardDebt[msg.sender] += (mintAmount * accRewardPerShare) / UNIFORM_PRECISION;
_distributeNonCompoundingRewards(msg.sender);
}
_returnRemainingTokens(amount0, amount1, depositedAmount0, depositedAmount1);
emit DepositPair(msg.sender, depositedAmount0, depositedAmount1, compounding);
}
function _returnRemainingTokens(
uint256 amount0,
uint256 amount1,
uint256 depositedAmount0,
uint256 depositedAmount1
) internal {
uint256 remainingAmount0 = amount0 - depositedAmount0;
// use swapThreshold0 to avoid unnecessary transfers
if (remainingAmount0 > swapThreshold0) {
uint256 currentBalance0 = token0.balanceOf(address(this));
if (remainingAmount0 > currentBalance0) {
remainingAmount0 = currentBalance0;
}
token0.safeTransfer(msg.sender, remainingAmount0);
}
uint256 remainingAmount1 = amount1 - depositedAmount1;
// use swapThreshold1 to avoid unnecessary transfers
if (remainingAmount1 > swapThreshold1) {
uint256 currentBalance1 = token1.balanceOf(address(this));
if (remainingAmount1 > currentBalance1) {
remainingAmount1 = currentBalance1;
}
token1.safeTransfer(msg.sender, remainingAmount1);
}
}
function _distributeNonCompoundingRewards(address user) internal {
// Update the reward debt for the depositor
uint256 depositorShare = balanceOf(user, 0);
uint256 pendingRewards = _calculatePendingRewards(user, depositorShare);
if (pendingRewards > 0) {
// If user received rewards for his previously deposited tokens, we set his max reward dept
nonCompoundingDepositorRewardDebt[user] = (depositorShare * accRewardPerShare) / UNIFORM_PRECISION;
totalRewards -= pendingRewards;
rewardTokenAdr.safeTransfer(user, pendingRewards);
emit NonCompoundingRewardsDistributed(user, pendingRewards);
}
}
function calculatePendingRewards(address depositor) public view returns (uint256) {
uint256 depositorShare = balanceOf(depositor, 0);
return _calculatePendingRewards(depositor, depositorShare);
}
function _calculatePendingRewards(address depositor, uint256 depositorShare) internal view returns (uint256) {
if (depositorShare > 0) {
uint256 depositorRewardDebt = nonCompoundingDepositorRewardDebt[depositor];
uint256 accumulatedReward = (depositorShare * accRewardPerShare) / UNIFORM_PRECISION;
if (accumulatedReward > depositorRewardDebt) {
return accumulatedReward - depositorRewardDebt;
}
}
return 0;
}
function withdraw(uint256 amount0ToWithdraw) external checkPriceManipulation returns (uint256 amountWithdrawn) {
_beforeWithdraw();
uint256 amountLpToRemove = calculateAmountLpByToken0(amount0ToWithdraw);
if (amountLpToRemove == 0) return 0;
uint256 userShareAmountToBurn = (amountLpToRemove * UNIFORM_PRECISION) / compoundShareRate;
// calculate amount of shares to withdraw with compounding shares
_burn(msg.sender, 1, userShareAmountToBurn);
amountWithdrawn = _burnAndSingleWithdraw(amountLpToRemove);
emit Withdrawn(msg.sender, amountWithdrawn, userShareAmountToBurn);
}
function withdrawNonCompounding(
uint256 amount0ToWithdraw
) external checkPriceManipulation returns (uint256 amountWithdrawn) {
_beforeWithdraw();
_distributeNonCompoundingRewards(msg.sender);
uint256 amountLpToRemove = calculateAmountLpByToken0(amount0ToWithdraw);
_burn(msg.sender, 0, amountLpToRemove);
amountWithdrawn = _burnAndSingleWithdraw(amountLpToRemove);
emit WithdrawnNonCompounding(msg.sender, amountWithdrawn, amountLpToRemove);
}
function withdrawAll() external checkPriceManipulation returns (uint256 amountWithdrawn) {
_beforeWithdraw();
uint256 lpAmount;
uint256 userNonCompoundShares = balanceOf(msg.sender, 0);
uint256 userCompoundShares = balanceOf(msg.sender, 1);
if (userNonCompoundShares > 0) {
_distributeNonCompoundingRewards(msg.sender);
_burn(msg.sender, 0, userNonCompoundShares);
lpAmount += userNonCompoundShares;
}
if (userCompoundShares > 0) {
_burn(msg.sender, 1, userCompoundShares);
lpAmount += (userCompoundShares * compoundShareRate) / UNIFORM_PRECISION;
}
amountWithdrawn = _burnAndSingleWithdraw(lpAmount);
emit WithdrawnAll(msg.sender, amountWithdrawn, lpAmount);
}
function _burnAndSingleWithdraw(uint256 lpAmount) private returns (uint256 amountWithdrawn) {
liquidityHypervisor.burn(lpAmount, address(this));
// Swap amount1 to token0
uint256 amount1 = token1.balanceOf(address(this));
if (amount1 > swapThreshold1) {
_poolSwap(amount1, false);
}
amountWithdrawn = token0.balanceOf(address(this));
token0.safeTransfer(msg.sender, amountWithdrawn);
}
function withdrawPair(
uint256 burnAmount,
bool compounding,
uint256 minAmountOut0,
uint256 minAmountOut1
) external checkPriceManipulation returns (uint256 amount0Withdrawn, uint256 amount1Withdrawn) {
// Compound rewards and perform any necessary updates before withdrawal
_beforeWithdraw();
uint256 userShareValue;
if (compounding) {
// Calculate the share value for compounding shares
userShareValue = (burnAmount * compoundShareRate) / UNIFORM_PRECISION;
_burn(msg.sender, 1, burnAmount); // Burn compounding shares
} else {
_distributeNonCompoundingRewards(msg.sender);
// Calculate the share value for non-compounding shares (assuming 1:1 for simplicity)
userShareValue = burnAmount;
_burn(msg.sender, 0, burnAmount); // Burn non-compounding shares
}
// Withdraw user's share in token0 and token1
(amount0Withdrawn, amount1Withdrawn, ) = liquidityHypervisor.burn(userShareValue, msg.sender);
if (amount0Withdrawn < minAmountOut0 || amount1Withdrawn < minAmountOut1) revert InsufficientWithdrawnAmounts();
emit WithdrawnPair(msg.sender, burnAmount, compounding, amount0Withdrawn, amount1Withdrawn);
return (amount0Withdrawn, amount1Withdrawn);
}
function _beforeWithdraw() internal {
_compoundRewards();
}
function compound() external checkPriceManipulation {
_compoundRewards();
}
function harvest() external checkPriceManipulation {
_compoundRewards();
_distributeNonCompoundingRewards(msg.sender);
}
function _compoundRewards() internal {
// Get reward
if (lastCompoundBlock != uint128(block.number)) {
lastCompoundBlock = uint128(block.number);
try liquidityHypervisor.harvest() {} catch {
emit Log("Harvest Failed");
}
uint256 amountRewardToken = rewardTokenAdr.balanceOf(address(this)) - totalRewards - compoundRewardsToSell;
uint256 sellPortion = _calculateSellPortion(amountRewardToken);
compoundRewardsToSell += sellPortion;
if (compoundRewardsToSell > rewardSwapThreshold) {
// Sell reward to token0
IExchange exchange = IExchange(registry.getAddressByIdentifier(routerAggregator));
rewardTokenAdr.safeTransfer(address(exchange), compoundRewardsToSell);
exchange.swap(compoundRewardsToSell, address(rewardTokenAdr), address(token0), address(this));
emit RewardSold(compoundRewardsToSell);
compoundRewardsToSell = 0; // Reset the amount of rewards to sell
(uint256 amount0, uint256 amount1) = _prepareTokensToDeposit(
token0.balanceOf(address(this)),
token1.balanceOf(address(this))
);
token0.forceApprove(address(liquidityHypervisor), amount0);
token1.forceApprove(address(liquidityHypervisor), amount1);
(, , uint256 mintAmount, ) = liquidityHypervisor.mint(amount0, amount1, address(this));
adjustCompoundShareRate(mintAmount);
}
uint256 keepPortion = amountRewardToken - sellPortion;
totalRewards += keepPortion;
if (keepPortion > 0) {
// Calculate the reward per share for non-compounding depositors
uint256 totalNonCompoundingShares = totalSupply(0); // ID 0 for Non-Compounding
uint256 rewardPerShare = (keepPortion * UNIFORM_PRECISION) / totalNonCompoundingShares;
accRewardPerShare += rewardPerShare;
}
}
}
function _calculateSellPortion(uint256 rewardAmount) internal view returns (uint256) {
// Total issued shares (compounding + non-compounding)
uint256 totalShares = liquidityHypervisor.totalSharesIssued();
// Get the total supply non-compounding shares (this shares has 1:1 rate with LP tokens)
uint256 totalNonCompoundingShares = totalSupply(0); // ID 0 for Non-Compounding
// Calculate the total compounding (compounding shares are minted with a rate of compoundShareRate)
uint256 totalCompoundingShares = totalShares - totalNonCompoundingShares;
if (totalShares == 0) {
return 0; // Avoid division by zero when there are no shares
}
// Calculate the percentage of compounding shares in the total ecosystem
uint256 compoundingSharePercentage = (totalCompoundingShares * UNIFORM_PRECISION) / totalShares;
// Sell portion is proportional to the compounding shares' percentage
return (rewardAmount * compoundingSharePercentage) / UNIFORM_PRECISION;
}
function adjustCompoundShareRate(uint256 additionalValue) internal {
uint256 totalCompoundingSharesMinted = totalSupply(1); // Get the total compounding shares minted
if (totalCompoundingSharesMinted > 0 && additionalValue > 0) {
// Calculate the total value represented by the compounding shares
uint256 totalValue = (totalCompoundingSharesMinted * compoundShareRate) / UNIFORM_PRECISION;
// Add the additional value to the total value
totalValue += additionalValue;
// Update the compounding rate based on the new total value and the total shares
compoundShareRate = (totalValue * UNIFORM_PRECISION) / totalCompoundingSharesMinted;
}
}
function _deposit(uint256 _amount, bool compounding) internal {
_compoundRewards();
// Some will be compounded, some will be sent to this contract so the reward tokens are allocated fairly
if (_amount == 0) return;
token0.safeTransferFrom(msg.sender, address(this), _amount);
// Provide liquidity and get lp tokens
(uint256 amount0, uint256 amount1) = _prepareTokensToDeposit(_amount, 0);
token0.forceApprove(address(liquidityHypervisor), amount0);
token1.forceApprove(address(liquidityHypervisor), amount1);
(uint256 depositedAmount0, uint256 depositedAmount1, uint256 mintAmount, ) = liquidityHypervisor.mint(
amount0,
amount1,
address(this)
);
if (compounding) {
uint256 newShares = (mintAmount * UNIFORM_PRECISION) / compoundShareRate;
_mint(msg.sender, 1, newShares, ""); // ID 1 for Compounding
} else {
// If not compounding, calculate the new shares based on a constant rate (1:1 for simplicity)
_mint(msg.sender, 0, mintAmount, ""); // ID 0 for Non-Compounding
nonCompoundingDepositorRewardDebt[msg.sender] += (mintAmount * accRewardPerShare) / UNIFORM_PRECISION;
_distributeNonCompoundingRewards(msg.sender);
}
_returnRemainingTokens(amount0, amount1, depositedAmount0, depositedAmount1);
emit Deposit(msg.sender, depositedAmount0, depositedAmount1, compounding);
}
function _totalTokens(address user) internal view returns (uint256 amount0) {
uint256 amount1;
uint256 userShares;
uint256 userNonCompoundShares = balanceOf(user, 0);
uint256 userCompoundShares = balanceOf(user, 1);
if (userNonCompoundShares > 0) {
userShares += userNonCompoundShares;
}
if (userCompoundShares > 0) {
userShares += (userCompoundShares * compoundShareRate) / UNIFORM_PRECISION;
}
if (userShares == 0) return 0;
(uint256 currentLpPrice, uint256 priceToken1PerLpToken) = getLpPrices();
// Convert amount of LP tokens to amount of token1
amount1 = (userShares * priceToken1PerLpToken) / UNIFORM_PRECISION;
// Convert token1 to token0
amount0 = (amount1 * LP_PRICE_PRECISION) / currentLpPrice;
}
function _prepareTokensToDeposit(
uint256 desiredAmount0,
uint256 desiredAmount1
) private returns (uint256 amount0, uint256 amount1) {
(uint256 amountIn, , bool zeroForOne, ) = liquidityHypervisor.getInRatioSwap(desiredAmount0, desiredAmount1);
uint256 amountOut = _poolSwap(amountIn, zeroForOne);
unchecked {
(amount0, amount1) = zeroForOne ? (0 - amountIn, amountOut) : (amountOut, 0 - amountIn);
amount0 += desiredAmount0;
amount1 += desiredAmount1;
}
}
// Required to check price manipulation before (to be sure that price is not manipulated) and after swap (to be sure that we are not manipulated so much)
function _poolSwap(uint256 swapAmount, bool zeroForOne) private returns (uint256 amountOut) {
uint256 swapThreshold = zeroForOne ? swapThreshold0 : swapThreshold1;
if (swapAmount < swapThreshold) {
return 0;
}
// Use max price for zeroForOne = true and min price for zeroForOne = false
uint160 swapThresholdPrice = zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1;
(int256 amount0Delta, int256 amount1Delta) = lpPool.swap(
address(this),
zeroForOne,
swapAmount.toInt256(),
swapThresholdPrice,
""
);
unchecked {
amountOut = 0 - (zeroForOne ? uint256(amount1Delta) : uint256(amount0Delta));
}
// Check price manipulation after pool swap
_checkPriceManipulation(slippagePriceThreshold);
}
// Utils
function calculateAmountLpByToken0(uint256 totalAmount0) public view returns (uint256 amountLp) {
(uint256 currentLpPrice, uint256 priceToken1PerLpToken) = getLpPrices();
uint256 amount1 = (totalAmount0 * currentLpPrice) / LP_PRICE_PRECISION;
amountLp = (amount1 * UNIFORM_PRECISION) / priceToken1PerLpToken;
}
function getLpPrices() internal view returns (uint256 currentLpPrice, uint256 priceToken1PerLpToken) {
(uint160 sqrtPriceX96, , , , , , ) = lpPool.slot0();
currentLpPrice = getLpPrice(sqrtPriceX96);
// Calculate price of token1 per LP token
uint256 total = liquidityHypervisor.totalSharesIssued();
if (total > 0) {
(uint256 reserve0, uint256 reserve1, ) = liquidityHypervisor.getTotalAmounts();
uint256 reserve0PricedInToken1 = (reserve0 * currentLpPrice) / LP_PRICE_PRECISION;
priceToken1PerLpToken = ((reserve0PricedInToken1 + reserve1) * UNIFORM_PRECISION) / total;
}
}
function getLpPrice(uint160 sqrtPriceX96) internal pure returns (uint256 lpPrice) {
// calculation with a check to avoid uint256 overflow
if (sqrtPriceX96 <= type(uint128).max) {
uint256 priceX192 = uint256(sqrtPriceX96) * sqrtPriceX96;
lpPrice = FullMath.mulDiv(priceX192, LP_PRICE_PRECISION, 1 << 192);
} else {
uint256 priceX128 = FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 1 << 64);
lpPrice = FullMath.mulDiv(priceX128, LP_PRICE_PRECISION, 1 << 128);
}
}
function _checkPriceManipulation(uint256 _priceThreshold) internal {
address(liquidityHypervisor).functionCall(
abi.encodeWithSelector(liquidityHypervisor.checkPriceManipulation.selector, _priceThreshold)
);
}
// Can't transfer ID 0 due to virtual debt
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
if (from != address(0) && to != address(0)) {
// Check to prevent transfers of token ID 0
for (uint256 i = 0; i < ids.length; ++i) {
if (ids[i] == 0) revert("Transfer of token ID 0 is not allowed");
}
}
// If amounts are being transferred from an address to the zero address, the user is burning tokens
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
// If user is burning non-compounding shares, update the reward debt
if (ids[i] == 0) {
nonCompoundingDepositorRewardDebt[from] -= (amounts[i] * accRewardPerShare) / UNIFORM_PRECISION;
}
}
}
// Call the base contract's _beforeTokenTransfer
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function getIdentifiers() public pure returns (bytes32, bytes32) {
return (routerAggregator, upgrader);
}
/// @notice Pancake v3 callback fn, called back on pool.swap
function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata /*data*/) external {
require(msg.sender == address(lpPool), "callback caller");
if (amount0Delta > 0) token0.safeTransfer(msg.sender, uint256(amount0Delta));
else if (amount1Delta > 0) token1.safeTransfer(msg.sender, uint256(amount1Delta));
}
/* ERRORS */
error CallerUpgrader();
error InvalidPriceThreshold();
error InsufficientWithdrawnAmounts();
event Log(string message);
/* EVENTS */
event Deposit(address indexed depositor, uint256 amount0, uint256 amount1, bool compounding);
event DepositPair(address indexed depositor, uint256 amount0, uint256 amount1, bool compounding);
event NonCompoundingRewardsDistributed(address indexed user, uint256 rewards);
event Withdrawn(address indexed withdrawer, uint256 amountWithdrawn, uint256 sharesBurned);
event WithdrawnNonCompounding(address indexed withdrawer, uint256 amountWithdrawn, uint256 sharesBurned);
event WithdrawnPair(
address indexed withdrawer,
uint256 burnAmount,
bool compounding,
uint256 amount0Withdrawn,
uint256 amount1Withdrawn
);
event WithdrawnAll(address indexed withdrawer, uint256 amountWithdrawn, uint256 sharesBurned);
event RewardSold(uint256 amountSold);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.0;
import "../IERC1155.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
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 v4.7.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token 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 amount 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 `amount` tokens of token type `id` from `from` to `to`.
*
* 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 `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 amount,
bytes calldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` 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 amounts,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev _Available since v3.1._
*/
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 v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @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
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
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
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
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
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
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
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
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
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
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
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
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
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
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
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
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
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
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
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
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
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
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
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
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
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
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
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
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
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
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
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
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
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
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
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
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
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
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
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
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
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
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
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
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
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
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
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
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
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
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
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
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
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
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
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
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
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
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
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
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
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
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
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
enum ErrorCodes {
unknown,
functionCall,
functionCallWithValue,
functionStaticCall,
functionDelegateCall
}
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
// require(address(this).balance >= amount, "Address: insufficient balance");
if (!(address(this).balance >= amount)) revert Address__InsufficientBalance();
(bool success, ) = recipient.call{value: amount}("");
// require(success, "Address: unable to send value, recipient may have reverted");
if (!success) revert Address__UnableToSendValue();
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
// return functionCall(target, data, "Address: low-level call failed");
return functionCall(target, data, uint(ErrorCodes.functionCall));
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, uint errorCode) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorCode);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
// return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
return functionCallWithValue(target, data, value, uint(ErrorCodes.functionCallWithValue));
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
uint errorCode
) internal returns (bytes memory) {
// require(address(this).balance >= value, "Address: insufficient balance for call");
// require(isContract(target), "Address: call to non-contract");
if (!(address(this).balance >= value)) revert Address__InsufficientBalanceForCall();
if (!(isContract(target))) revert Address__CallToNonContract();
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorCode);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
// return functionStaticCall(target, data, "Address: low-level static call failed");
return functionStaticCall(target, data, uint(ErrorCodes.functionStaticCall));
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
uint errorCode
) internal view returns (bytes memory) {
// require(isContract(target), "Address: static call to non-contract");
if (!(isContract(target))) revert Address__StaticCallToNonContract();
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorCode);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
uint errorCode
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
// revert(errorMessage);
if (errorCode == uint(ErrorCodes.functionCall)) revert Address__LowLevelCallFailed();
else if (errorCode == uint(ErrorCodes.functionCallWithValue))
revert Address__LowLevelCallWithValueFailed();
else if (errorCode == uint(ErrorCodes.functionStaticCall)) revert Address__LowLevelStaticCallFailed();
else revert Address__LowLevelCallFailedWithCustomErrorCode(uint(errorCode));
}
}
}
/* ERRORS */
error Address__InsufficientBalance();
error Address__UnableToSendValue();
error Address__InsufficientBalanceForCall();
error Address__CallToNonContract();
error Address__StaticCallToNonContract();
error Address__LowLevelCallFailedWithCustomErrorCode(uint errorCode);
error Address__LowLevelCallFailed();
error Address__LowLevelCallWithValueFailed();
error Address__LowLevelStaticCallFailed();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165.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
*
* _Available since v3.1._
*/
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
using Address for address;
// Mapping from token ID to account balances
mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping(address => mapping(address => 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 {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) public view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: address zero is not a valid owner");
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 override returns (uint256[] memory) {
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev Transfers `amount` 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 `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 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, 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.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, 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 amounts 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 `amount` tokens of token 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 amount, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - 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 amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `amount` tokens of token type `id`.
*/
function _burn(address from, uint256 id, uint256 amount) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `ids` and `amounts` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155Receiver.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol)
pragma solidity ^0.8.0;
import "./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.
*/
abstract contract ERC1155Supply is ERC1155 {
mapping(uint256 => uint256) private _totalSupply;
/**
* @dev Total amount of tokens in with a given id.
*/
function totalSupply(uint256 id) public view virtual returns (uint256) {
return _totalSupply[id];
}
/**
* @dev Indicates whether any token exist with a given id, or not.
*/
function exists(uint256 id) public view virtual returns (bool) {
return ERC1155Supply.totalSupply(id) > 0;
}
/**
* @dev See {ERC1155-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
_totalSupply[ids[i]] += amounts[i];
}
}
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 supply = _totalSupply[id];
require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
unchecked {
_totalSupply[id] = supply - amount;
}
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol";
import "./AddressUpgradeable.sol";
import "./StorageSlotUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967UpgradeUpgradeable is Initializable {
function __ERC1967Upgrade_init() internal onlyInitializing {}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {}
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
// require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
if (!(AddressUpgradeable.isContract(newImplementation))) revert ERC1967_NewImplementationIsNotAContract();
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
_functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
// require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
if (!(slot == _IMPLEMENTATION_SLOT)) revert ERC1967Upgrade_UnsupportedProxiableUUID();
} catch {
// revert("ERC1967Upgrade: new implementation is not UUPS");
revert ERC1967Upgrade_NewImplementationIsNotUUPS();
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
// require(newAdmin != address(0), "ERC1967: new admin is the zero address");
if (!(newAdmin != address(0))) revert ERC1967_NewAdminIsZeroAddress();
StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
// require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
// require(
// AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
// "ERC1967: beacon implementation is not a contract"
// );
if (!(AddressUpgradeable.isContract(newBeacon))) revert ERC1967_NewBeaconIsNotAContract();
if (!(AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()))) {
revert ERC1967_BeaconImplementationIsNotAContract();
}
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
_functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
}
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function _functionDelegateCall(address target, bytes memory data) private returns (bytes memory) {
// require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");
if (!(AddressUpgradeable.isContract(target))) revert Address_DelegateCallToNonContract();
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return
AddressUpgradeable.verifyCallResult(
success,
returndata,
uint256(AddressUpgradeable.ErrorCodes.functionDelegateCall)
);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
/* ERRORS */
error ERC1967_NewImplementationIsNotAContract();
error ERC1967Upgrade_UnsupportedProxiableUUID();
error ERC1967Upgrade_NewImplementationIsNotUUPS();
error ERC1967_NewAdminIsZeroAddress();
error ERC1967_NewBeaconIsNotAContract();
error ERC1967_BeaconImplementationIsNotAContract();
error Address_DelegateCallToNonContract();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "./AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() rereinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
// require(
// (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
// "Initializable: contract is already initialized"
// );
if (
!((isTopLevelCall && _initialized < 1) ||
(!AddressUpgradeable.isContract(address(this)) && _initialized == 1))
) {
revert Initializable__ContractIsAlreadyInitialized();
}
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
* initialization step. This is essential to configure modules that are added through upgrades and that require
* initialization.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*/
modifier reinitializer(uint8 version) {
// require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
if (!(!_initializing && _initialized < version)) revert Initializable__ContractIsAlreadyInitialized();
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
// require(_initializing, "Initializable: contract is not initializing");
if (!(_initializing)) revert Initializable__ContractIsNotInitializing();
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*/
function _disableInitializers() internal virtual {
// require(!_initializing, "Initializable: contract is initializing");
if (!(!_initializing)) revert Initializable_ContractIsInitializing();
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/* ERRORS */
error Initializable__ContractIsAlreadyInitialized();
error Initializable__ContractIsNotInitializing();
error Initializable_ContractIsInitializing();
}// 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) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 ERC-20 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) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 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) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Permit} from "./IERC20Permit.sol";
import {Address} from "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 ERC-20 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
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @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:
* ```
* 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(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlotUpgradeable {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 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
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol";
import "./ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
function __UUPSUpgradeable_init() internal onlyInitializing {}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {}
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
// require(address(this) != __self, "Function must be called through delegatecall");
// require(_getImplementation() == __self, "Function must be called through active proxy");
if (!(address(this) != __self)) revert FunctionMustBeCalledThroughDelegatecall();
if (!(_getImplementation() == __self)) revert FunctionMustBeCalledThroughActiveProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
// require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
if (!(address(this) == __self)) revert UUPSUpgradeable__MustNotBeCalledThroughDelegatecall();
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate that the this implementation remains valid after an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeTo(address newImplementation) external virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
/* ERRORS */
error FunctionMustBeCalledThroughDelegatecall();
error FunctionMustBeCalledThroughActiveProxy();
error UUPSUpgradeable__MustNotBeCalledThroughDelegatecall();
}//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import {TokenPrice} from "../lib/Structs.sol";
interface IExchange {
function stablecoinSwap(
uint256 amountA,
address tokenA,
address tokenB,
address to,
TokenPrice calldata usdPriceTokenA,
TokenPrice calldata usdPriceTokenB
) external returns (uint256 amountReceived);
function swap(
uint256 amountA,
address tokenA,
address tokenB,
address to
) external returns (uint256 amountReceived);
function getExchangeProtocolFee(
uint256 amountA,
address tokenA,
address tokenB
) external view returns (uint256 feePercent);
function protectedSwap(
uint256 amountA,
address tokenA,
address tokenB,
address to,
TokenPrice calldata usdPriceTokenA,
TokenPrice calldata usdPriceTokenB
) external returns (uint256 amountReceived);
function getRoutePrice(address tokenA, address tokenB) external view returns (uint256 price);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IRegistry {
function getBytes32Identifier(string calldata identifierString) external pure returns (bytes32);
function registerAddress(bytes32 bytes32Identifier, address contractAddress) external;
function getAddressByIdentifier(bytes32 bytes32Identifier) external view returns (address identifierAddress);
function getAllRegisteredIdentifiers() external view returns (bytes32[] memory);
function getRegisteredIdentifierById(uint256 id) external view returns (bytes32 registeredIdentifier);
function getRegisteredIdentifierCount() external view returns (uint256);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "./pool/IPancakeV3PoolImmutables.sol";
import "./pool/IPancakeV3PoolState.sol";
import "./pool/IPancakeV3PoolDerivedState.sol";
import "./pool/IPancakeV3PoolActions.sol";
/// @title The interface for a PancakeSwap V3 Pool
/// @notice A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IPancakeV3Pool is
IPancakeV3PoolImmutables,
IPancakeV3PoolState,
IPancakeV3PoolDerivedState,
IPancakeV3PoolActions
{
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IPHyperPoolSwapInside {
// Events
event Minted(address receiver, uint256 mintAmount, uint256 amount0In, uint256 amount1In, uint128 liquidityMinted);
event Burned(address receiver, uint256 burnAmount, uint256 amount0Out, uint256 amount1Out, uint128 liquidityBurned);
event Rebalance(int24 lowerTick_, int24 upperTick_, uint128 liquidityBefore, uint128 liquidityAfter);
event FeesEarned(uint256 feesEarned0, uint256 feesEarned1);
// Functions
function mint(
uint256 amount0Max,
uint256 amount1Max,
address receiver
) external returns (uint256 amount0, uint256 amount1, uint256 mintAmount, uint128 liquidityMinted);
function depositNftToFarm() external returns (bool _allocatedToFarming);
function harvest() external;
function getLiquidity() external view returns (uint128 liquidity);
function burn(
uint256 burnAmount,
address receiver
) external returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned);
function getMintAmounts(
uint256 amount0Max,
uint256 amount1Max
) external view returns (uint256 amount0, uint256 amount1, uint256 mintAmount, uint160 sqrtRatioX96);
function getTotalAmounts()
external
view
returns (uint256 totalAmount0, uint256 totalAmount1, uint128 totalLiquidity);
function LP_PRICE_PRECISION() external view returns (uint256);
function getLpPrice(uint160 sqrtRatioX96) external view returns (uint256);
function totalSharesIssued() external view returns (uint256);
function getPositionNftData()
external
view
returns (uint256 nftId, int24 lowerTick_, int24 upperTick_, bool allocatedToFarming, bytes memory harvestData);
function farmingContract() external view returns (address);
function getPendingReward() external view returns (uint256 pendingReward);
function getInRatioSwap(
uint256 amount0Desired,
uint256 amount1Desired
) external view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96);
function checkPriceManipulation(uint256 customPriceThreshold) external view;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IPancakeV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IPancakeV3MintCallback#pancakeV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(int24 tickLower, int24 tickUpper, uint128 amount) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IPancakeV3SwapCallback#pancakeV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IPancakeV3FlashCallback#pancakeV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(address recipient, uint256 amount0, uint256 amount1, bytes calldata data) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IPancakeV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(
uint32[] calldata secondsAgos
) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(
int24 tickLower,
int24 tickUpper
) external view returns (int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IPancakeV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IPancakeV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint32 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(
int24 tick
)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return _liquidity The amount of liquidity in the position,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(
bytes32 key
)
external
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns initialized whether the observation has been initialized and the values are safe to use
function observations(
uint256 index
)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
// https://ethereum.stackexchange.com/a/96646
uint256 twos = denominator & (~denominator + 1);
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
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
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use 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.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // 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 precoditions 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 * inv;
return result;
}
}
/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
/// @notice Calculates x * y / 2^96 with full precision.
function mulDiv96(uint256 x, uint256 y) internal pure returns (uint256 result) {
assembly ("memory-safe") {
// 512-bit multiply `[prod1 prod0] = x * y`.
// Compute the product mod `2**256` and mod `2**256 - 1`
// then 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`.
// Least significant 256 bits of the product.
let prod0 := mul(x, y)
let mm := mulmod(x, y, not(0))
// Most significant 256 bits of the product.
let prod1 := sub(mm, add(prod0, lt(mm, prod0)))
// Make sure the result is less than `2**256`.
if iszero(gt(0x1000000000000000000000000, prod1)) {
// Store the function selector of `FullMulDivFailed()`.
mstore(0x00, 0xae47f702)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
// Divide [prod1 prod0] by 2^96.
result := or(shr(96, prod0), shl(160, prod1))
}
}
/// @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
/// @title Library for efficient ternary operators
/// @author Clip Finance
library TernOpLib {
/// @notice Equivalent to the ternary operator: `condition ? a : b`
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256 res) {
assembly {
res := xor(b, mul(xor(a, b), condition))
}
}
/// @notice Equivalent to the ternary operator: `condition ? a : b`
function ternary(bool condition, address a, address b) internal pure returns (address res) {
assembly {
res := xor(b, mul(xor(a, b), condition))
}
}
/// @notice Equivalent to: `uint256(x < 0 ? -x : x)`
function abs(int256 x) internal pure returns (uint256 y) {
assembly {
// mask = 0 if x >= 0 else -1
let mask := sub(0, slt(x, 0))
// If x >= 0, |x| = x = 0 ^ x
// If x < 0, |x| = ~~|x| = ~(-|x| - 1) = ~(x - 1) = -1 ^ (x - 1)
// Either case, |x| = mask ^ (x + mask)
y := xor(mask, add(mask, x))
}
}
/// @notice Equivalent to: `a < b ? a : b`
function min(uint256 a, uint256 b) internal pure returns (uint256 res) {
assembly {
res := xor(b, mul(xor(a, b), lt(a, b)))
}
}
/// @notice Equivalent to: `a > b ? a : b`
function max(uint256 a, uint256 b) internal pure returns (uint256 res) {
assembly {
res := xor(b, mul(xor(a, b), gt(a, b)))
}
}
/// @notice Equivalent to: `condition ? (b, a) : (a, b)`
function switchIf(bool condition, uint256 a, uint256 b) internal pure returns (uint256, uint256) {
assembly {
let diff := mul(xor(a, b), condition)
a := xor(a, diff)
b := xor(b, diff)
}
return (a, b);
}
/// @notice Equivalent to: `condition ? (b, a) : (a, b)`
function switchIf(bool condition, address a, address b) internal pure returns (address, address) {
assembly {
let diff := mul(xor(a, b), condition)
a := xor(a, diff)
b := xor(b, diff)
}
return (a, b);
}
/// @notice Sorts two addresses and returns them in ascending order
function sort2(address a, address b) internal pure returns (address, address) {
assembly {
let diff := mul(xor(a, b), lt(b, a))
a := xor(a, diff)
b := xor(b, diff)
}
return (a, b);
}
/// @notice Sorts two uint160s and returns them in ascending order
function sort2(uint160 a, uint160 b) internal pure returns (uint160, uint160) {
assembly {
let diff := mul(xor(a, b), lt(b, a))
a := xor(a, diff)
b := xor(b, diff)
}
return (a, b);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
int24 internal constant MIN_TICK = -887272;
/// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
int24 internal constant MAX_TICK = -MIN_TICK;
/// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
uint160 internal constant MIN_SQRT_RATIO = 4295128739;
/// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
/// @notice Calculates sqrt(1.0001^tick) * 2^96
/// @dev Throws if |tick| > max tick
/// @param tick The input tick for the above formula
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
require(absTick <= uint256(uint24(MAX_TICK)), "T");
uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
// second inequality must be < because the price can never reach the price at the max tick
require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, "R");
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := gt(r, 0x1)
msb := or(msb, f)
}
if (msb >= 128) r = ratio >> (msb - 127);
else r = ratio << (127 - msb);
int256 log_2 = (int256(msb) - 128) << 64;
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(50, f))
}
int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number
int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
}
}//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
struct TokenPrice {
uint256 price;
uint8 priceDecimals;
address token;
}
struct StrategyInfo {
address strategyAddress;
address depositToken;
uint256 depositTokenInSupportedTokensIndex;
uint256 weight;
}
struct IdleStrategyInfo {
address strategyAddress;
address depositToken;
}
struct ReceiptData {
uint256 cycleId;
uint256 tokenAmountUniform; // in token
address token;
}
struct Cycle {
// block.timestamp at which cycle started
uint256 startAt;
// batch USD value before deposited into strategies
uint256 totalDepositedInUsd;
// USD value received by strategies after all swaps necessary to ape into strategies
uint256 receivedByStrategiesInUsd;
// Protocol TVL after compound idle strategy and actual deposit to strategies
uint256 strategiesBalanceWithCompoundAndBatchDepositsInUsd;
// price per share in USD
uint256 pricePerShare;
// tokens price at time of the deposit to strategies
mapping(address => uint256) prices;
}{
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 1,
"details": {
"peephole": true,
"yulDetails": {
"stackAllocation": true,
"optimizerSteps": "dhfoD[xarrscLMcCTU]uljmul"
}
}
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IRegistry","name":"_registry","type":"address"},{"internalType":"contract IPancakeV3Pool","name":"_lpPool","type":"address"},{"internalType":"contract IPHyperPoolSwapInside","name":"_liquidityHypervisor","type":"address"},{"internalType":"contract IERC20Metadata","name":"_rewardTokenAdr","type":"address"}],"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":"Address_DelegateCallToNonContract","type":"error"},{"inputs":[],"name":"Address__LowLevelCallFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"errorCode","type":"uint256"}],"name":"Address__LowLevelCallFailedWithCustomErrorCode","type":"error"},{"inputs":[],"name":"Address__LowLevelCallWithValueFailed","type":"error"},{"inputs":[],"name":"Address__LowLevelStaticCallFailed","type":"error"},{"inputs":[],"name":"CallerUpgrader","type":"error"},{"inputs":[],"name":"ERC1967Upgrade_NewImplementationIsNotUUPS","type":"error"},{"inputs":[],"name":"ERC1967Upgrade_UnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"ERC1967_BeaconImplementationIsNotAContract","type":"error"},{"inputs":[],"name":"ERC1967_NewAdminIsZeroAddress","type":"error"},{"inputs":[],"name":"ERC1967_NewBeaconIsNotAContract","type":"error"},{"inputs":[],"name":"ERC1967_NewImplementationIsNotAContract","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"FunctionMustBeCalledThroughActiveProxy","type":"error"},{"inputs":[],"name":"FunctionMustBeCalledThroughDelegatecall","type":"error"},{"inputs":[],"name":"Initializable_ContractIsInitializing","type":"error"},{"inputs":[],"name":"Initializable__ContractIsAlreadyInitialized","type":"error"},{"inputs":[],"name":"Initializable__ContractIsNotInitializing","type":"error"},{"inputs":[],"name":"InsufficientWithdrawnAmounts","type":"error"},{"inputs":[],"name":"InvalidPriceThreshold","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UUPSUpgradeable__MustNotBeCalledThroughDelegatecall","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"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":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"bool","name":"compounding","type":"bool"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":false,"internalType":"bool","name":"compounding","type":"bool"}],"name":"DepositPair","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"message","type":"string"}],"name":"Log","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewards","type":"uint256"}],"name":"NonCompoundingRewardsDistributed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amountSold","type":"uint256"}],"name":"RewardSold","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountWithdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"Withdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountWithdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"WithdrawnAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountWithdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"WithdrawnNonCompounding","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnAmount","type":"uint256"},{"indexed":false,"internalType":"bool","name":"compounding","type":"bool"},{"indexed":false,"internalType":"uint256","name":"amount0Withdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Withdrawn","type":"uint256"}],"name":"WithdrawnPair","type":"event"},{"inputs":[],"name":"accRewardPerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"totalAmount0","type":"uint256"}],"name":"calculateAmountLpByToken0","outputs":[{"internalType":"uint256","name":"amountLp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"}],"name":"calculatePendingRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"compound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"compoundRewardsToSell","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"compoundShareRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositTokenAmount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"depositTokenAmount","type":"uint256"}],"name":"depositNonCompounding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bool","name":"compounding","type":"bool"}],"name":"depositPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllPendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getIdentifiers","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getPendingReward","outputs":[{"internalType":"uint256","name":"pendingRewards","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPendingReward","outputs":[{"internalType":"uint256","name":"pendingRewards","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"initializeData","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","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":"liquidityHypervisor","outputs":[{"internalType":"contract IPHyperPoolSwapInside","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpPool","outputs":[{"internalType":"contract IPancakeV3Pool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonCompoundingDepositorRewardDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"pancakeV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract IRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_slippagePriceThreshold","type":"uint256"}],"name":"setSlippagePriceThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapThreshold0","type":"uint256"},{"internalType":"uint256","name":"_swapThreshold1","type":"uint256"},{"internalType":"uint256","name":"_rewardSwapThreshold","type":"uint256"}],"name":"setSwapThresholds","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":"token0","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalRewards","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":[],"name":"totalTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0ToWithdraw","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amountWithdrawn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[{"internalType":"uint256","name":"amountWithdrawn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0ToWithdraw","type":"uint256"}],"name":"withdrawNonCompounding","outputs":[{"internalType":"uint256","name":"amountWithdrawn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"bool","name":"compounding","type":"bool"},{"internalType":"uint256","name":"minAmountOut0","type":"uint256"},{"internalType":"uint256","name":"minAmountOut1","type":"uint256"}],"name":"withdrawPair","outputs":[{"internalType":"uint256","name":"amount0Withdrawn","type":"uint256"},{"internalType":"uint256","name":"amount1Withdrawn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x610160604052346200016a57620000236200001962000247565b92919091620002db565b6040516154ae9081620004db8239608051818181611d3d0152611ddb015260a051818181610b8b01528181612514015281816125ee015281816126670152613f97015260c0518181816104c10152818161273401528181612c9f015281816133af01528181613a39015281816140140152818161443101526153eb015260e051818181610e7d01528181612ce2015281816132fc015281816139bb015281816140e9015281816144ba0152615434015261010051818181610876015281816148af01528181614b310152615398015261012051818181610b520152818161281e01528181612ae601528181612d1a0152818161394b01528181613ba701528181613e17015281816142ee01528181614485015281816146b401528181614b930152614e7801526101405181818161275d0152818161287b015281816134f20152613e6c0152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b03821117620001a757604052565b6200016f565b90620001c4620001bc60405190565b928362000185565b565b6001600160a01b031690565b90565b620001d290620001c6565b620001eb81620001d5565b036200016a57565b90505190620001c482620001e0565b6080818303126200016a57620002198282620001f3565b92620001d26200022d8460208501620001f3565b9360606200023f8260408701620001f3565b9401620001f3565b6200026a62005989803803806200025e81620001ad565b92833981019062000202565b929391929091565b620001d290620001c6906001600160a01b031682565b620001d29062000272565b620001d29062000288565b620001eb81620001c6565b90505190620001c4826200029e565b906020828203126200016a57620001d291620002a9565b6040513d6000823e3d90fd5b620002e5620003b7565b620002f08262000293565b604051630dfe168160e01b8152602081600481855afa8015620003b15762000322916000916200037c575b5062000293565b60c05260206200033160405190565b63d21220a760e01b815291829060049082905afa8015620003b15762000360916000916200037c575062000293565b60e05260a052610100526101205261014052620001c46200044f565b620003a2915060203d8111620003a9575b62000399818362000185565b810190620002b8565b386200031b565b503d6200038d565b620002cf565b620001c4620001c4620001c4620001c4620001c4620001c4620001c4620003de3062000293565b608052565b620001d29060081c5b60ff1690565b620001d29054620003e3565b620001d290620003ec565b620001d29054620003fe565b620003ec620001d2620001d29260ff1690565b906200043c620001d26200044b9262000415565b825460ff191660ff9091161790565b9055565b6200046762000463620004636000620003f2565b1590565b620004c85762000478600062000409565b60ff908116106200048557565b6200049360ff600062000428565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498620004be60405190565b60ff8152602090a1565b604051630e02e8e160e21b8152600490fdfe6080604052600436101561001257600080fd5b60003560e01c8062fdd58e146102f157806301ffc9a7146102ec578063097aad10146102e75780630c326c69146102e25780630dfe1681146102dd5780630e15561a146102d85780630e89341c146102d357806323a69e75146102ce5780632e1a7d4d146102c95780632eb2c2d6146102c45780633659cfe6146102bf5780633737bcb4146102ba5780633cf28dd2146102b55780634147f40c146102b0578063439fab91146102ab5780634641257d146102a65780634df9d6ba146102a15780634e1273f41461029c5780634f1ef286146102975780634f558e791461029257806352d1902d1461028d5780635a23248d146102885780635d7acf9714610283578063614efea31461027e5780637b103999146102795780637e1c0c0914610274578063853828b61461026f5780638eee6b5c1461026a578063939d62371461026557806396cac4f414610260578063973c406f1461025b578063a22cb46514610256578063a4770a8814610251578063a4c515ab1461024c578063b6b55f2514610247578063bd85b03914610242578063be27bd931461023d578063c89039c514610238578063cb9199a214610233578063d21220a71461022e578063d3dc025b14610229578063d433403314610224578063e985e9c51461021f578063f242432a1461021a578063f69e2046146102155763f7c618c10361031e57610f97565b610f7f565b610f63565b610f06565b610ec8565b610ead565b610e68565b610e4d565b610e26565b610df4565b610db0565b610d98565b610d7f565b610d3e565b610d25565b610cd0565b610c54565b610c39565b610c12565b610bca565b610baf565b610b76565b610b3d565b610b22565b610b07565b610aec565b610ad1565b610abd565b610a60565b61092e565b610916565b6108fe565b6108c1565b6108a6565b610861565b610849565b61082d565b61064c565b610630565b610596565b61050f565b6104ac565b610445565b610416565b6103d4565b61036c565b6001600160a01b031690565b61030b906102f6565b90565b61031781610302565b0361031e57565b600080fd5b905035906103308261030e565b565b80610317565b9050359061033082610332565b919060408382031261031e5780602061036161030b9386610323565b9401610338565b9052565b3461031e57610399610388610382366004610345565b906111c7565b6040515b9182918290815260200190565b0390f35b6001600160e01b03191690565b6103178161039d565b90503590610330826103aa565b9060208282031261031e5761030b916103b3565b3461031e576103996103ef6103ea3660046103c0565b610fb2565b6040515b91829182901515815260200190565b9060208282031261031e5761030b91610323565b3461031e5761039961038861042c366004610402565b613525565b9060208282031261031e5761030b91610338565b3461031e5761045d610458366004610431565b612bab565b604051005b600091031261031e57565b61047c61030b61030b926102f6565b6102f6565b61030b9061046d565b61030b90610481565b6103689061048a565b6020810192916103309190610493565b3461031e576104bc366004610462565b6103997f00000000000000000000000000000000000000000000000000000000000000005b6040519182918261049c565b61030b9160031b1c81565b9061030b91546104ed565b61030b6000606d6104f8565b3461031e5761051f366004610462565b610399610388610503565b60005b83811061053d5750506000910152565b818101518382015260200161052d565b61056e61057760209361058193610562815190565b80835293849260200190565b9586910161052a565b601f01601f191690565b0190565b90602061030b92818152019061054d565b3461031e576103996105b16105ac366004610431565b61111b565b60405191829182610585565b9181601f8401121561031e57823591826001600160401b03811161031e576020908186019501011161031e57565b9160608383031261031e576106008284610338565b9261060e8360208301610338565b9260408201356001600160401b03811161031e5761062c92016105bd565b9091565b3461031e5761045d6106433660046105eb565b92919091615389565b3461031e57610399610388610662366004610431565b61362e565b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b0382111761069e57604052565b610667565b906103306106b060405190565b928361067d565b6001600160401b03811161069e5760051b60200190565b909291926106e36106de826106b7565b6106a3565b93602085838152019160051b83019281841161031e57915b8383106107085750505050565b602080916107168486610338565b8152019201916106fb565b9080601f8301121561031e5781602061030b933591016106ce565b6001600160401b03811161069e57602090601f01601f19160190565b90826000939282370152565b909291926107746106de8261073c565b9182948284528282011161031e576020610330930190610758565b9080601f8301121561031e5781602061030b93359101610764565b91909160a08184031261031e576107c18382610323565b926107cf8160208401610323565b9260408301356001600160401b03811161031e57826107ef918501610721565b9260608101356001600160401b03811161031e578361080f918301610721565b9260808201356001600160401b03811161031e5761030b920161078f565b3461031e5761045d6108403660046107aa565b9392909261147e565b3461031e5761045d61085c366004610402565b611e9b565b3461031e57610871366004610462565b6103997f00000000000000000000000000000000000000000000000000000000000000006104e1565b61030b6000606a6104f8565b3461031e576108b6366004610462565b61039961038861089a565b3461031e5761045d6108d4366004610431565b612726565b9060208282031261031e5781356001600160401b03811161031e5761030b920161078f565b3461031e5761045d6109113660046108d9565b61248e565b3461031e57610926366004610462565b61045d613d1c565b3461031e57610399610388610944366004610402565b61278a565b909291926109596106de826106b7565b93602085838152019160051b83019281841161031e57915b83831061097e5750505050565b6020809161098c8486610323565b815201920191610971565b9080601f8301121561031e5781602061030b93359101610949565b91909160408184031261031e5780356001600160401b03811161031e57836109db918301610997565b9260208201356001600160401b03811161031e5761030b9201610721565b90610a19610a12610a08845190565b8084529260200190565b9260200190565b9060005b818110610a2a5750505090565b909192610a47610a406001928651815260200190565b9460200190565b929101610a1d565b90602061030b9281815201906109f9565b3461031e57610399610a7c610a763660046109b2565b90611305565b60405191829182610a4f565b91909160408184031261031e57610a9f8382610323565b9260208201356001600160401b03811161031e5761030b920161078f565b61045d610acb366004610a88565b90612260565b3461031e576103996103ef610ae7366004610431565b611d13565b3461031e57610afc366004610462565b610399610388611dbd565b3461031e57610b17366004610462565b610399610388612781565b3461031e57610b32366004610462565b610399610388612ae1565b3461031e57610b4d366004610462565b6103997f00000000000000000000000000000000000000000000000000000000000000006104e1565b3461031e57610b86366004610462565b6103997f00000000000000000000000000000000000000000000000000000000000000006104e1565b3461031e57610bbf366004610462565b610399610388612b53565b3461031e57610bda366004610462565b6103996103886138f8565b90610bef9061048a565b600052602052604060002090565b6000610c0d61030b92606b610be5565b6104f8565b3461031e57610399610388610c28366004610402565b610bfd565b61030b6000606c6104f8565b3461031e57610c49366004610462565b610399610388610c2d565b3461031e57610399610388610c6a366004610431565b614a4f565b801515610317565b9050359061033082610c6f565b60808183031261031e57610c988282610338565b9261030b610ca98460208501610c77565b9360606103618260408701610338565b9081526040810192916103309160200152565b0152565b3461031e57610cec610ce3366004610c84565b92919091613cc7565b90610399610cf960405190565b92839283610cb9565b919060408382031261031e57806020610d1e61030b9386610323565b9401610c77565b3461031e5761045d610d38366004610d02565b906113a0565b3461031e57610d4e366004610462565b610cec61533a565b909160608284031261031e5761030b610d6f8484610338565b936040610d1e8260208701610338565b3461031e5761045d610d92366004610d56565b91612e8f565b3461031e5761045d610dab366004610431565b612b86565b3461031e57610399610388610dc6366004610431565b611d05565b909160608284031261031e5761030b610de48484610338565b9360406103618260208701610338565b3461031e5761045d610e07366004610dcb565b91612652565b61036890610302565b6020810192916103309190610e0d565b3461031e57610e36366004610462565b610399610e4161272f565b60405191829182610e16565b3461031e57610399610388610e63366004610402565b612b5c565b3461031e57610e78366004610462565b6103997f00000000000000000000000000000000000000000000000000000000000000006104e1565b61030b6000606e6104f8565b3461031e57610ebd366004610462565b610399610388610ea1565b3461031e57610399610388610ede366004610431565b61380b565b919060408382031261031e57806020610eff61030b9386610323565b9401610323565b3461031e576103996103ef610f1c366004610ee3565b906113c0565b91909160a08184031261031e57610f398382610323565b92610f478160208401610323565b92610f558260408501610338565b9261080f8360608301610338565b3461031e5761045d610f76366004610f22565b9392909261143a565b3461031e57610f8f366004610462565b61045d613cf3565b3461031e57610fa7366004610462565b610399610e41612758565b610fc2636cdb3d1360e11b61039d565b90610fcc8161039d565b918214918215610fec575b508115610fe2575090565b61030b9150611007565b909150610fff6303a24d0760e21b61039d565b149038610fd7565b61102061101a6301ffc9a760e01b61039d565b9161039d565b1490565b634e487b7160e01b600052602260045260246000fd5b600181811c92911682811561105b575b50602083101461105657565b611024565b607f1692503861104a565b805460009392916110836110798361103a565b8085529360200190565b91600181169081156110d5575060011461109c57505050565b6110af9192939450600052602060002090565b916000925b8184106110c15750500190565b8054848401526020909301926001016110b4565b60ff19168352505090151560051b019150565b9061030b91611066565b906103306110ff60405190565b8061110b8180966110e8565b039061067d565b61030b906110f2565b5061030b6067611112565b61047c61030b61030b9290565b61030b90611126565b1561114357565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b6064820152608490fd5b0390fd5b61030b61030b61030b9290565b90610bef9061119f565b61030b9081565b61030b90546111b6565b611203906111fe61030b936111f76111e76111e26000611133565b610302565b6111f085610302565b141561113c565b60656111ac565b610be5565b6111bd565b1561120f57565b60405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608490fd5b906112736106de836106b7565b918252565b369037565b9061033061128a83611266565b6020819461129a601f19916106b7565b019101611278565b634e487b7160e01b600052601160045260246000fd5b60001981146112c75760010190565b6112a2565b634e487b7160e01b600052603260045260246000fd5b80518210156112f65760209160051b010190565b6112cc565b61030b9051610302565b90611329611311835190565b61132361131f61030b855190565b9190565b14611208565b611339611334835190565b61127d565b91611344600061119f565b61134f61030b835190565b81101561139a578061139061138361137261136d61139595876112e2565b6112fb565b61038261137f85896112e2565b5190565b61138d83886112e2565b52565b6112b8565b611344565b50505090565b6103309190336118a4565b61030b905b60ff1690565b61030b90546113ab565b61030b916111fe6113d2926066610be5565b6113b6565b156113de57565b60405162461bcd60e51b815260206004820152602e60248201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60448201526d195c881bdc88185c1c1c9bdd995960921b6064820152608490fd5b6103309493929190611468335b61145081610302565b61145984610302565b1490811561146d575b506113d7565b61157b565b6114789150836113c0565b38611462565b610330949392919061148f33611447565b6116f4565b1561149b57565b60405162461bcd60e51b815260206004820152602560248201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b156114f557565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60448201526939103a3930b739b332b960b11b6064820152608490fd5b5090565b9061030b61030b6115619261119f565b9055565b9190611570565b9290565b82018092116112c757565b90610330949392916115a36115936111e26000611133565b61159c84610302565b1415611494565b336115c3866115b186611ce1565b6115ba88611ce1565b90868686615061565b6116006115ec866115dc611203866111fe8a60656111ac565b6115e8828210156114ee565b0390565b6115fb846111fe8860656111ac565b611551565b61162a611612846111fe8760656111ac565b6116248761161f836111bd565b611565565b90611551565b6116338161048a565b61163c8361048a565b6116458561048a565b9160008051602061545983398151915261165e60405190565b8061166a8b8b83610cb9565b0390a4611a1f565b1561167957565b60405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608490fd5b90916116e661030b936040845260408401906109f9565b9160208184039101526109f9565b939492919092611719611705835190565b61171361131f61030b875190565b14611672565b6117326117296111e26000611133565b61159c86610302565b3395611742818585888a8c615061565b61174c600061119f565b61175761030b855190565b8110156117c45780611390886116246117b58a6111fe8b6111f761178f61137f8a8f61137f6117bf9e611789926112e2565b946112e2565b966115fb6117a9896115dc611203856111fe8960656111ac565b916111fe8560656111ac565b9161161f836111bd565b61174c565b5093909594610330956117d68161048a565b6117df8361048a565b6117e88561048a565b917f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb61181360405190565b8061181f8b8b836116cf565b0390a4611c41565b1561182e57565b60405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608490fd5b9061189561030b61156192151590565b825460ff191660ff9091161790565b61191861190e6119087f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31936118eb6118db87610302565b6118e483610302565b1415611827565b611903876118fe886111fe856066610be5565b611885565b61048a565b9361048a565b936103f360405190565b0390a3565b90505190610330826103aa565b9060208282031261031e5761030b9161191d565b919361196c60a09461196561030b989761195b8761197397610e0d565b6020870190610e0d565b6040850152565b6060830152565b816080820152019061054d565b6040513d6000823e3d90fd5b60009060033d1161199957565b905060046000803e60005160e01c90565b600060443d1061030b576040513d600319016004823e8051916001600160401b0383113d602485011117611a19578183018051909390916001600160401b038311611a11573d84016003190185840160200111611a11575061030b9291016020019061067d565b949350505050565b92915050565b939491611a2b81611bdd565b611a38575b505050505050565b602094611a70611a4c61190360009461048a565b94611a5660405190565b9889978896879563f23a6e6160e01b87526004870161193e565b03925af160009181611bad575b50611b3f57506001611a8d61198c565b6308c379a014611b0a575b611aa8575b388080808080611a30565b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608490fd5b611b126119aa565b80611b1d5750611a98565b61119b90611b2a60405190565b62461bcd60e51b815291829160048301610585565b611b5261101a63f23a6e6160e01b61039d565b14611a9d5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a204552433131353552656365697665722072656a656374656044820152676420746f6b656e7360c01b6064820152608490fd5b611bcf91925060203d8111611bd6575b611bc7818361067d565b81019061192a565b9038611a7d565b503d611bbd565b3b611beb61131f600061119f565b1190565b939061030b9593611c14611c3394611c0a88611c2595610e0d565b6020880190610e0d565b60a0604087015260a08601906109f9565b9084820360608601526109f9565b91608081840391015261054d565b939491611c4d81611bdd565b611c5957505050505050565b602094611c91611c6d61190360009461048a565b94611c7760405190565b9889978896879563bc197c8160e01b875260048701611bef565b03925af160009181611cc1575b50611cae57506001611a8d61198c565b611b5261101a63bc197c8160e01b61039d565b611cda91925060203d8111611bd657611bc7818361067d565b9038611c9e565b61030b611cf1611334600161119f565b9161138d611cff600061119f565b846112e2565b61120361030b9160686111ac565b611d1c90611d05565b611beb61131f600061119f565b611d6c611d353061048a565b611d67611d617f0000000000000000000000000000000000000000000000000000000000000000610302565b91610302565b141590565b611d795761030b90611db4565b604051632e4771e760e21b8152600490fd5b61030b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc61119f565b5061030b611d8b565b61030b6000611d29565b611020611e07611dd63061048a565b611dff7f0000000000000000000000000000000000000000000000000000000000000000610302565b928391610302565b611e3957611e1a90611d676111e2611eae565b611e275761033090611e75565b604051631b50ae3760e11b8152600490fd5b604051637170f3db60e01b8152600490fd5b906112736106de8361073c565b90610330611e6583611e4b565b6020819461129a601f199161073c565b600061033091611e84816125d9565b611e95611e908361119f565b611e58565b90611f0b565b61033090611dc7565b61030b9054610302565b61030b611ebc61030b611d8b565b611ea4565b61030b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd914361119f565b9050519061033082610332565b9060208282031261031e5761030b91611eea565b9190611f1b6113d261030b611ec1565b15611f2b57505061033090612004565b611f376119038461048a565b6020611f4260405190565b6352d1902d60e01b815291829060049082905afa60009181611fa8575b50611f775750604051636f5837f160e01b8152600490fd5b611f8990611d6761131f61030b611d8b565b611f96576103309261203e565b6040516304e7393f60e41b8152600490fd5b611fca91925060203d8111611fd1575b611fc2818361067d565b810190611ef7565b9038611f5f565b503d611fb8565b90611fe861030b6115619261048a565b82546001600160a01b0319166001600160a01b03919091161790565b61201461201082611bdd565b1590565b61202c576103309061202761030b611d8b565b611fd8565b60405163075de2d760e51b8152600490fd5b916120488361207d565b815161205761131f600061119f565b11908115612075575b50612069575050565b61207291612113565b50565b905038612060565b61208a9061190381612004565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b6120b460405190565b80805b0390a2565b3d156120d6576120cb3d611e4b565b903d6000602084013e565b606090565b634e487b7160e01b600052602160045260246000fd5b600511156120fb57565b6120db565b90610330826120f1565b61030b90612100565b9061212061201083611bdd565b61214d5760008161030b9360208394519201905af461213d6120bc565b612147600461210a565b9161215f565b60405163ae931db960e01b8152600490fd5b9091901561216b575090565b815161217a61131f600061119f565b11156121895750805190602001fd5b61219661030b600161210a565b819081036121b05760405163014bd73d60e21b8152600490fd5b6121bd61030b600261210a565b81036121d557604051630a4d4fd160e01b8152600490fd5b6121e261030b600361210a565b036121f95760405163166c491f60e11b8152600490fd5b61119b9061220660405190565b632638bfdb60e11b81529182916004830190815260200190565b90611020612230611dd63061048a565b611e395761224390611d676111e2611eae565b611e2757610330916103309160019161225b816125d9565b611f0b565b9061033091612220565b61030b9060081c6113b0565b61030b905461226a565b6113b061030b61030b9290565b6113b061030b61030b9260ff1690565b9061189561030b6115619261228d565b906122bd61030b61156192151590565b825461ff00191660089190911b61ff00161790565b61036890612280565b60208101929161033091906122d2565b6122f86120106000612276565b9081806123e3575b801561239e575b155b61238c5761232f908261232661231f6001612280565b600061229d565b61237b57612431565b61233557565b6123406000806122ad565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249861236a60405190565b806123766001826122db565b0390a1565b612387600160006122ad565b612431565b604051632785437f60e21b8152600490fd5b506123b36120106123ae3061048a565b611bdd565b801561230757506123096123c760006113b6565b6123db6123d46001612280565b9160ff1690565b149050612307565b506123ee60006113b6565b6123fb6123d46001612280565b10612300565b909160608284031261031e5761030b61241a8484611eea565b93604061242a8260208701611eea565b9401611eea565b61247861247f61246e61248693612459612452670de0b6b3a764000061119f565b606a611551565b602080612464835190565b8301019101612401565b939091606f611551565b6070611551565b6071611551565b6103306124bc565b610330906122eb565b6124a46120106000612276565b6124aa57565b60405163dec57a6f60e01b8152600490fd5b610330612497565b7fac1ce290f7f8beba2a3b749ceabee6385de96b5d2625626d6c5d226614ae7fab90565b905051906103308261030e565b9060208282031261031e5761030b916124e8565b5061256860206125387f000000000000000000000000000000000000000000000000000000000000000061048a565b6125406124c4565b9061254a60405190565b93849283918291636f7a8bad60e01b83526004830190815260200190565b03915afa80156125d457612584916000916125a6575b50610302565b61258d33610302565b0361259457565b604051633b082d6b60e11b8152600490fd5b6125c7915060203d81116125cd575b6125bf818361067d565b8101906124f5565b3861257e565b503d6125b5565b611980565b61033090612509565b919061261260206125387f000000000000000000000000000000000000000000000000000000000000000061048a565b03915afa80156125d45761262d916000916125a65750610302565b61263633610302565b036125945761033092610330929161247861247f92606f611551565b9061033092916125e2565b61268b60206125387f000000000000000000000000000000000000000000000000000000000000000061048a565b03915afa80156125d4576126a6916000916125a65750610302565b6126af33610302565b0361259457610330906126f3565b6126ca61030b61030b9290565b6001600160881b031690565b61030b6127106126bd565b61030b9081906001600160881b031681565b6127036126fe6126d6565b6126e1565b811161271457610330906072611551565b6040516309524aff60e41b8152600490fd5b6103309061265d565b61030b7f000000000000000000000000000000000000000000000000000000000000000061048a565b61030b7f000000000000000000000000000000000000000000000000000000000000000061048a565b61030b33612814565b61030b90612814565b919082039182116112c757565b6127ad61030b61030b9290565b6001600160701b031690565b61030b670de0b6b3a76400006127a0565b61030b9081906001600160701b031681565b818102929181159184041417156112c757565b634e487b7160e01b600052601260045260246000fd5b811561280f570490565b6127ef565b90600080926128427f000000000000000000000000000000000000000000000000000000000000000061048a565b602061284d60405190565b635a23248d60e01b815291829060049082905afa80156125d4576128cd91600091612ac3575b50602061289f7f000000000000000000000000000000000000000000000000000000000000000061048a565b6128a83061048a565b906128b260405190565b948592839182916370a0823160e01b5b835260048301610e16565b03915afa9182156125d45761290c92612902926128f292600092612aa3575b50611565565b6128fc606d6111bd565b90612793565b6128fc606e6111bd565b612915816142e9565b90612929612923606e6111bd565b83611565565b93612934600161119f565b9461293f86866111c7565b9061294a600061119f565b9687821180612a9a575b612a5b575b505050509061296791612793565b6129758161161f606d6111bd565b928061298861298482866111c7565b9590565b1180612a52575b61299a575b50505050565b6129ea926129d4926129ac606c6111bd565b908193806129b78390565b11612a16575b5050506112036129ce91606b610be5565b936127dc565b6129e46129df6127b9565b6127ca565b90612805565b8181116129f9575b8080612994565b612a0e929391612a0891612793565b90611565565b9038806129f2565b6129ce93945091612a08612a4a92612a45612a3361120396611d05565b91612a3f6129df6127b9565b906127dc565b612805565b9291386129bd565b5080841161298f565b6129679594995091612a45612a0892612a3f612a7a612a8f9796611d05565b612a45612a886129df6127b9565b80966127dc565b959091388080612959565b50878311612954565b612abc91925060203d8111611fd157611fc2818361067d565b90386128ec565b612adb915060203d8111611fd157611fc2818361067d565b38612873565b612b0a7f000000000000000000000000000000000000000000000000000000000000000061048a565b6020612b1560405190565b635a23248d60e01b815291829060049082905afa9081156125d457600091612b3b575090565b61030b915060203d8111611fd157611fc2818361067d565b61030b336145c1565b61030b906145c1565b61033090612b7b612b76600061119f565b614e6f565b600161033091614410565b61033090612b65565b61033090612ba0612b76600061119f565b600061033091614410565b61033090612b8f565b906103309291612bc7612b76600061119f565b612c88565b6001600160801b031690565b61031781612bcc565b9050519061033082612bd8565b60808183031261031e57612c028282611eea565b9261030b612c138460208501611eea565b936060612c238260408701611eea565b9401612be1565b604090612c4c6103309496959396612c458360608101999052565b6020830152565b0190610e0d565b61030b6000611e4b565b61030b612c53565b604090612c806103309496959396612c458360608101999052565b019015159052565b90600090612c94613dd9565b6080612d6c84612cc37f000000000000000000000000000000000000000000000000000000000000000061048a565b612d4c85612cd03061048a565b92612cdd85853384612f6f565b612d067f000000000000000000000000000000000000000000000000000000000000000061048a565b612d1283863384612f6f565b612d47612d3e7f000000000000000000000000000000000000000000000000000000000000000061048a565b96878094612ff5565b612ff5565b604051958693849283919063e7d3fe6b60e01b8352888b60048501612c2a565b03925af19081156125d4577fbb85dcf60b5fb7cd8cced6769caa040c05781172b4e8da0f39283e6926dbba2d9360009283948491612e52575b50612df292859285928915612e1157612dd3612dc9612ded92612a3f6129df6127b9565b6129e4606a6111bd565b612ddd600161119f565b90612de6612c5d565b9133612ef0565b6132a5565b6120b7612dfe3361048a565b94612e0860405190565b93849384612c65565b612e3b6129d4612e4992612e31612e28600061119f565b82612de6612c5d565b612a3f606c6111bd565b6116246117b533606b610be5565b612ded33613458565b9050612df2929450612e7c91935060803d8111612e88575b612e74818361067d565b810190612bee565b50909491939192612da5565b503d612e6a565b906103309291612bb4565b15612ea157565b60405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b90610330939291612f016000611133565b612f1d612f0d82610302565b612f1684610302565b1415612e9a565b33611600866115b186611ce1565b612f44612f3e61030b9263ffffffff1690565b60e01b90565b61039d565b604090610ccc6103309496959396612f65836060810199610e0d565b6020830190610e0d565b9091612fb290612fa461033095612f896323b872dd612f2b565b92612f9360405190565b968794602086015260248501612f49565b03601f19810184528361067d565b6130b4565b916020610330929493610ccc816040810197610e0d565b6103689061119f565b916020610330929493612fee816040810197610e0d565b0190612fce565b613027919261303561300a63095ea7b3612f2b565b9161301460405190565b9485918460208401528760248401612fb7565b03601f19810185528461067d565b6130426120108484613226565b61304c5750505050565b61308a93613084612fb292613076600061306560405190565b948593602085015260248401612fd7565b03601f19810183528261067d565b826130b4565b38808080612994565b9050519061033082610c6f565b9060208282031261031e5761030b91613093565b6130c06130c79161048a565b918261312e565b80516130d661131f600061119f565b1415908161310a575b506130e75750565b61119b906130f460405190565b635274afe760e01b815291829160048301610e16565b61312891508060208061311e612010945190565b83010191016130a0565b386130df565b61030b9161313c600061119f565b6131453061048a565b8181311061316f57506000828192602061030b969551920190855af16131696120bc565b91613192565b61119b9061317c60405190565b63cd78605960e01b815291829160048301610e16565b9061319d57506131f7565b6131b86131a8835190565b6131b2600061119f565b91829190565b1490816131ec575b506131c9575090565b61119b906131d660405190565b639996b31560e01b815291829160048301610e16565b9050813b14386131c0565b805161320661131f600061119f565b111561321457805190602001fd5b604051630a12f52160e11b8152600490fd5b6000613232819261048a565b9260208151910182855af1906132466120bc565b82613266575b5081613256575090565b90503b611beb61131f600061119f565b909150613271815190565b61327e61131f600061119f565b1490811561328f575b50903861324c565b61329f915060208061311e835190565b38613287565b916132b1919392612793565b91826132c76132c361030b606f6111bd565b9490565b9384116133a9575b506132da9250612793565b806132eb61156c61030b60706111bd565b9182116132f6575050565b61334e917f00000000000000000000000000000000000000000000000000000000000000009060206133278361048a565b6133303061048a565b9061333a60405190565b968792839182916370a0823160e01b6128c2565b03915afa9081156125d45761033094600092613389575b50815b1061337f575b506133789061048a565b3390613426565b915061337861336e565b6133a291925060203d8111611fd157611fc2818361067d565b9038613365565b613400907f000000000000000000000000000000000000000000000000000000000000000060206133d98261048a565b6133e23061048a565b906133ec60405190565b958692839182916370a0823160e01b6128c2565b03915afa80156125d4576132da9661342094600092613389575081613368565b386132cf565b612fb261033093612fa461343d63a9059cbb612f2b565b9161344760405190565b958693602085015260248401612fb7565b613462600061119f565b9061346d82826111c7565b90613478828261353e565b92831161348457505050565b61351b6120b7916134cb6134c06129d47f7303a08499b208e2de9337c07f90295d0cdfb47be7a5e16e17edfe957eb65dc096612a3f606c6111bd565b6115fb83606b610be5565b6134e86134e1866134dc606d6111bd565b612793565b606d611551565b61190385826135167f000000000000000000000000000000000000000000000000000000000000000061048a565b613426565b9261038c60405190565b61030b9061353c613536600061119f565b826111c7565b905b90613549600061119f565b9182821161355657505090565b6129d461356a61120361357593606b610be5565b92612a3f606c6111bd565b81811161358157505090565b61030b9250612793565b9061030b9161359d612b76600061119f565b506135aa90610c6a613cd6565b906135b5600061119f565b80831461362a57506135f16135d7612dc96135d16129df6127b9565b856127dc565b926135ec846135e6600161119f565b336136e9565b613940565b7f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6819361361d3361048a565b926120b7610cf960405190565b9150565b61030b90600061358b565b1561364057565b60405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b1561369857565b60405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608490fd5b6000805160206154598339815191526111fe929361378761378161378187611903613772866137666112038b61371f6000611133565b9d8e9761373e61372e8a610302565b61373785610302565b1415613639565b6111f733809a61374d84611ce1565b6137568a611ce1565b9187613760612c5d565b94615061565b6115e882821015613691565b6115fb896111fe8d60656111ac565b9461048a565b94613794610cf960405190565b0390a4612072612c5d565b9061030b916137b1612b76600061119f565b506137c7906137be613cd6565b610c6a33613458565b906137d6826135e6600061119f565b6137df82613940565b7fc8f4420b387a6a10a91391480c679640ed2e1fc60c9ef3704acbd2d5f033b1ce819361361d3361048a565b61030b90600061379f565b61030b90613827612b76600061119f565b50613830613cd6565b6000908161383e600061119f565b61384881336111c7565b90613853600161119f565b9161385e83336111c7565b938282116138d6575b50506138708390565b116138ad575b505061388182613940565b7f8f420e722d4b21a3e3ef6314f97a0827afa394a45c56d2f53f2b638d1efa845e819361361d3361048a565b6129d4826138c46138ce959694612a0894336136e9565b612a3f606a6111bd565b903880613876565b6138f09296506138e533613458565b61161f8288336136e9565b933880613867565b61030b6000613816565b909160608284031261031e5761030b61391b8484611eea565b936040612c238260208701611eea565b90815260408101929161033091602090612c4c565b906139a6606061396f7f000000000000000000000000000000000000000000000000000000000000000061048a565b936139793061048a565b948591600061398760405190565b80968195829461399b63fcd3533c60e01b90565b84526004840161392b565b03925af180156125d457613aeb575b506139df7f000000000000000000000000000000000000000000000000000000000000000061048a565b916139e960405190565b6020816370a0823160e01b958682528180613a078760048301610e16565b03915afa9182156125d457613a7d92602092600091613ace575b50613a2f61030b60706111bd565b8111613abc575b507f000000000000000000000000000000000000000000000000000000000000000094613a628661048a565b90613a6c60405190565b809581948293835260048301610e16565b03915afa80156125d45761033091600091613a9e575b50613378819461048a565b613ab6915060203d8111611fd157611fc2818361067d565b38613a93565b6000613ac79161486c565b5038613a36565b613ae59150833d8111611fd157611fc2818361067d565b38613a21565b613b0b9060603d8111613b13575b613b03818361067d565b810190613902565b9150506139b5565b503d613af9565b9061062c9594939291613b30612b76600061119f565b613b62565b610ccc61033094613b5b606094989795613b5285608081019b9052565b15156020850152565b6040830152565b5050906000929493613b72613cd6565b818414613ca6576060613bf2613b946129d4613b8e606a6111bd565b876127dc565b613ba2866135e6600161119f565b613bcb7f000000000000000000000000000000000000000000000000000000000000000061048a565b90613bd560405190565b9788938492839190633f34d4cf60e21b835233906004840161392b565b03925af19586156125d4576000948597613c7e575b505b8410908115613c74575b50613c62577f714e31952f7187229250e8ee2874acc655f2f2af3b4609b659d6bd7392a6c19f90613c433361048a565b92613c5b8786613c5260405190565b94859485613b35565b0390a29190565b6040516373bdb3a760e11b8152600490fd5b9050851038613c13565b613c099750613c9c91955060603d8111613b1357613b03818361067d565b5096909490613c07565b613caf33613458565b6060613bf284613cc2866135e68961119f565b613ba2565b61062c93929190600080613b1a565b610330613dd9565b613ceb612b76600061119f565b610330613cd6565b610330613cde565b613d08612b76600061119f565b610330613d13613dd9565b61033033613458565b610330613cfb565b61030b90612bcc565b61030b9054613d24565b613d4461030b61030b9290565b612bcc565b613d4461030b61030b92612bcc565b90613d6861030b61156192613d49565b82546001600160801b0319166001600160801b03919091161790565b7f85bd1d72e7c5b7eca5a1d5e5f606f0ec29133572bd2f25cd91349d23a86d1c2f90565b612c4c61033094613dcf606094989795613dc585608081019b9052565b6020850190610e0d565b6040830190610e0d565b613de36069613d2d565b613dec43613d37565b90613dff613df983612bcc565b91612bcc565b03613e075750565b613e12906069613d58565b613e3b7f000000000000000000000000000000000000000000000000000000000000000061048a565b803b1561031e57604051634641257d60e01b815260008160048183865af190816142cb575b506142c657614271565b7f000000000000000000000000000000000000000000000000000000000000000090613e958261048a565b90613e9f3061048a565b91613ea960405190565b926370a0823160e01b9384815260208180613ec78560048301610e16565b0381865afa9081156125d457613eee9161290291600091614253575b506128fc606d6111bd565b92613ef8846142e9565b94613f11613f0a8761161f606e6111bd565b606e611551565b613f1b606e6111bd565b613f2b61131f61030b60716111bd565b11613f8d575b50505050613f3f9250612793565b613f506134e18261161f606d6111bd565b613f5a600061119f565b90818111613f66575050565b613f7c613f8691612a45612a3361033095611d05565b61161f606c6111bd565b606c611551565b613fc36020613fbb7f000000000000000000000000000000000000000000000000000000000000000061048a565b612540613d84565b03915afa9081156125d457600098614007613ff5613fef61190889966020968f91614236575b5061048a565b9261048a565b9182614001606e6111bd565b91613426565b614011606e6111bd565b907f00000000000000000000000000000000000000000000000000000000000000009761403d8961048a565b9b8c9361406661404c60405190565b978896879586946388156e6560e01b865260048601613da8565b03925af180156125d45761421a575b507f762c2dd3d0af24badf328547c5f6d995c8d549bc0a11cf304b6e79816ba867a26140a4610388606e6111bd565b0390a16140b4613f0a600061119f565b60206140bf60405190565b809883825281806140d38860048301610e16565b03915afa9687156125d4576000976141fa575b507f000000000000000000000000000000000000000000000000000000000000000060206141138261048a565b9261411d60405190565b938491825281806141318960048301610e16565b03915afa9081156125d45761417160809685612d47612d479461190361416761418e9f98600099869b8b926141da575b506146ad565b9981988b9761048a565b6040519889958694859363e7d3fe6b60e01b855260048501612c2a565b03925af19283156125d457613f3f936141af916000916141b8575b506143a5565b38808080613f31565b6141d0915060803d8111612e8857612e74818361067d565b90925090506141a9565b6141f391925060203d8111611fd157611fc2818361067d565b9038614161565b61421391975060203d8111611fd157611fc2818361067d565b95386140e6565b6142319060203d8111611fd157611fc2818361067d565b614075565b61424d9150873d81116125cd576125bf818361067d565b38613fe9565b61426b915060203d8111611fd157611fc2818361067d565b38613ee3565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab61429b60405190565b6020808252600e908201526d12185c9d995cdd0811985a5b195960921b6040820152606090a1613e6a565b613e6a565b6142e39060006142db818361067d565b810190610462565b38613e60565b6143127f000000000000000000000000000000000000000000000000000000000000000061048a565b602061431d60405190565b637d59659b60e11b815291829060049082905afa9081156125d457600091614387575b5061434b600061119f565b9061435e61435883611d05565b82612793565b91808214614380575061030b92612a3f612a4592612a45612a886129df6127b9565b9250505090565b61439f915060203d8111611fd157611fc2818361067d565b38614340565b6143b2610dc6600161119f565b906143bd600061119f565b8083119081614406575b506143d0575050565b61033091612a45612452926144016143eb6135d1606a6111bd565b9161161f6143fa6129df6127b9565b8094612805565b6127dc565b90508111386143c7565b614418613dd9565b614422600061119f565b8082146145a5576000906144557f000000000000000000000000000000000000000000000000000000000000000061048a565b60806144fe614479846144673061048a565b97614474818a3389612f6f565b6146ad565b9390966144b0886144a97f000000000000000000000000000000000000000000000000000000000000000061048a565b8094612ff5565b6144de8583612d477f000000000000000000000000000000000000000000000000000000000000000061048a565b604051968793849283919063e7d3fe6b60e01b8352888c60048501612c2a565b03925af19384156125d4577f6dbb6056a2fff319358e6dd7d0d72cb3baa992cdcc7e120fb0a32cd1601840e59460009384958592614576575b509285928592612df2958a60001461455f5750612dd3612dc9612ded92612a3f6129df6127b9565b6129d482612e31612e3b93612e4995612de6612c5d565b909550612df2939450614597915060803d8111612e8857612e74818361067d565b509095919493509085614537565b505050565b61030b6a0c097ce7bc90715b34b9f160241b61119f565b6000806145ce600061119f565b926145e76145dc85836111c7565b91610382600161119f565b91848211614648575b5050826145fa8290565b1161462d575b5081811461154d5761030b9150612a456146256129d461461e614b2a565b90946127dc565b612a3f6145aa565b90612a086129d461464293612a3f606a6111bd565b38614600565b614653929350611565565b9038806145f0565b610317816102f6565b905051906103308261465b565b60808183031261031e576146858282611eea565b9261030b6146968460208501611eea565b9360606146a68260408701613093565b9401614664565b91906146d87f000000000000000000000000000000000000000000000000000000000000000061048a565b9260806146e460405190565b948590635a80abe560e11b82528180614701878760048401610cb9565b03915afa80156125d4576000948591614757575b5061030b929181614729614741938861486c565b96600091156147465761058191506115e8600061119f565b930190565b6115e86147529261119f565b950190565b61030b9392955061474191506147839060803d8111614792575b61477b818361067d565b810190614671565b50919693949192506147159050565b503d614771565b61030b73fffd8963efd1fc6a506488495d951d5263988d26611126565b6147c26147c8916102f6565b916102f6565b9003906001600160a01b0382116112c757565b61030b6401000276a3611126565b6147c26147f5916102f6565b01906001600160a01b0382116112c757565b919060408382031261031e5780602061242a61030b9386611eea565b610368906102f6565b919361485160a09461196561030b976148488761485b97610e0d565b15156020870152565b6060830190614823565b816080820152016000815260200190565b81156149c05761487f61030b606f6111bd565b81106149b45781156149915760406148a86148986147db565b6148a26001611126565b906147e9565b915b6148d37f000000000000000000000000000000000000000000000000000000000000000061048a565b8460006148e86148e23061048a565b94614a2a565b9361490f6148f560405190565b97889687958694630251596160e31b86526004860161482c565b03925af19081156125d45761494292600091829361495f575b501561495057506149389061119f565b6115e8600061119f565b90610330612b7660726111bd565b61495a915061119f565b614938565b909250614983915060403d811161498a575b61497b818361067d565b810190614807565b9138614928565b503d614971565b60406149ae61499e614799565b6149a86001611126565b906147b6565b916148aa565b505061030b600061119f565b61487f61030b60706111bd565b156149d457565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b61030b90614a4a614a42836001600160ff1b0361119f565b8211156149cd565b61119f565b61030b90612a45614a72614a6a614a64614b2a565b946127dc565b6129e46145aa565b612a3f6129df6127b9565b6103178160020b90565b9050519061033082614a7d565b61ffff8116610317565b9050519061033082614a94565b63ffffffff8116610317565b9050519061033082614aab565b60e08183031261031e57614ad88282614664565b92614ae68360208401614a87565b92614af48160408501614a9e565b92614b028260608301614a9e565b9261030b614b138460808501614a9e565b9360c0614b238260a08701614ab7565b9401613093565b6000614b557f000000000000000000000000000000000000000000000000000000000000000061048a565b60e0614b6060405190565b633850c7bd60e01b815291829060049082905afa80156125d457614b8c91600091614c96575b50614ce8565b9182614bb77f000000000000000000000000000000000000000000000000000000000000000061048a565b90614bc160405190565b637d59659b60e11b815290602082600481865afa9182156125d457600092614c76575b50614bef600061119f565b8211614bfa57505050565b90919293506060614c0a60405190565b636253bb0f60e11b815293849060049082905afa9283156125d45761030b93612a4592614a72926000908193614c49575b5061161f91614a6a916127dc565b61161f929350614a6a9150614c6b9060603d8111613b1357613b03818361067d565b509392909150614c3b565b614c8f91925060203d8111611fd157611fc2818361067d565b9038614be4565b614cb7915060e03d8111614cc3575b614caf818361067d565b810190614ac4565b9450614b869350505050565b503d614ca5565b61047c61030b61030b92612bcc565b61030b61030b61030b926102f6565b614cf86001600160801b03614cca565b614d01826102f6565b11614d3657614d1b614d1561030b92614cd9565b806127dc565b614d236145aa565b614d30600160c01b61119f565b91614d75565b614d59614d4561030b92614cd9565b614d52600160401b61119f565b9080614d75565b614d616145aa565b614d30600160801b61119f565b1561031e57565b90919060001983820991838202928380821091030391614d95600061119f565b8390808214614e5a5750948291614db661030b97614db08590565b11614d6e565b09614e52614de5614dcc8419610581600161119f565b8416809404946001858060000304019087851190030290565b93614df7614dfb82614df7600361119f565b0290565b614e4d614e47614e3e614e35614e2c614e23614e17600261119f565b96871889810288030290565b80890287030290565b80880286030290565b80870285030290565b80860284030290565b80940290565b900390565b930304170290565b9295505050614e6b9150614db08490565b0490565b61207290614e9c7f000000000000000000000000000000000000000000000000000000000000000061048a565b614ecd614eac6353c9d830612f2b565b612fa4614eb860405190565b94859260208401526024830190815260200190565b614f0d565b614edc601e611e4b565b7f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000602082015290565b61030b614ed2565b61030b91614f1b600061119f565b90614f24614f05565b92614f85565b15614f3157565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608490fd5b906000809161030b9594614fa5614f9b3061048a565b8290311015614f2a565b60208251920190855af1614fb76120bc565b91615009565b15614fc457565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b9192901561503b5750815161502161131f600061119f565b1461502a575090565b61503661030b91611bdd565b614fbd565b8290615045825190565b61505261131f600061119f565b1115611b1d5750805190602001fd5b959493929190956150756111e26000611133565b8061507f89610302565b1415806151d3575b615127575b61509583610302565b146150a6575b956103309596615242565b949092936150b4600061119f565b93845b6150c261030b865190565b81101561511b5780866150de61030b61137f6150e8958a6112e2565b146150ed576112b8565b6150b7565b6113906151036129d4612e3161137f858d6112e2565b6116246151118d606b610be5565b916134dc836111bd565b5091959094935061509b565b96939095929491615138600061119f565b96875b61514661030b895190565b8110156151c4578861515e61030b61137f848c6112e2565b146151715761516c906112b8565b61513b565b60405162461bcd60e51b815260206004820152602560248201527f5472616e73666572206f6620746f6b656e2049442030206973206e6f7420616c6044820152641b1bddd95960da1b6064820152608490fd5b5091949790929593965061508c565b50806151de84610302565b1415615087565b156151ec57565b60405162461bcd60e51b815260206004820152602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608490fd5b506152589293959450611dff6111e26000611133565b146152e1575b61526790610302565b1461527157509050565b61527b600061119f565b61528661030b835190565b8110156152db57806113906152a161137f6152d694866112e2565b6115fb6152ce6152b461137f868b6112e2565b6152c26112038560686111ac565b6115e8828210156151e5565b9160686111ac565b61527b565b50509050565b92906152ed600061119f565b6152f861030b855190565b811015615332578061139061531361137f61532d948a6112e2565b6116246117b561532661137f868b6112e2565b60686111ac565b6152ed565b50909261525e565b615342613d84565b9061030b6124c4565b1561535257565b60405162461bcd60e51b815260206004820152600f60248201526e31b0b6363130b1b59031b0b63632b960891b6044820152606490fd5b915091506153cb6153bc6111e27f000000000000000000000000000000000000000000000000000000000000000061048a565b6153c533610302565b1461534b565b6153d5600061119f565b8082131561541d5750610330915061541561540f7f000000000000000000000000000000000000000000000000000000000000000061048a565b9161119f565b903390613426565b905081136154285750565b6103309061541561540f7f000000000000000000000000000000000000000000000000000000000000000061048a56fec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a264697066735822122030d9556f1cbfbebb8ad6127297b596a3c0ff9f5e98febee9da785f2467e0b12464736f6c6343000814003300000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf202750000000000000000000000006a72f4f191720c411cd1ff6a5ea8dedec3a647710000000000000000000000005757a514aef25ff8909614489766053400f5de860000000000000000000000000d1e753a25ebda689453309112904807625befbe
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c8062fdd58e146102f157806301ffc9a7146102ec578063097aad10146102e75780630c326c69146102e25780630dfe1681146102dd5780630e15561a146102d85780630e89341c146102d357806323a69e75146102ce5780632e1a7d4d146102c95780632eb2c2d6146102c45780633659cfe6146102bf5780633737bcb4146102ba5780633cf28dd2146102b55780634147f40c146102b0578063439fab91146102ab5780634641257d146102a65780634df9d6ba146102a15780634e1273f41461029c5780634f1ef286146102975780634f558e791461029257806352d1902d1461028d5780635a23248d146102885780635d7acf9714610283578063614efea31461027e5780637b103999146102795780637e1c0c0914610274578063853828b61461026f5780638eee6b5c1461026a578063939d62371461026557806396cac4f414610260578063973c406f1461025b578063a22cb46514610256578063a4770a8814610251578063a4c515ab1461024c578063b6b55f2514610247578063bd85b03914610242578063be27bd931461023d578063c89039c514610238578063cb9199a214610233578063d21220a71461022e578063d3dc025b14610229578063d433403314610224578063e985e9c51461021f578063f242432a1461021a578063f69e2046146102155763f7c618c10361031e57610f97565b610f7f565b610f63565b610f06565b610ec8565b610ead565b610e68565b610e4d565b610e26565b610df4565b610db0565b610d98565b610d7f565b610d3e565b610d25565b610cd0565b610c54565b610c39565b610c12565b610bca565b610baf565b610b76565b610b3d565b610b22565b610b07565b610aec565b610ad1565b610abd565b610a60565b61092e565b610916565b6108fe565b6108c1565b6108a6565b610861565b610849565b61082d565b61064c565b610630565b610596565b61050f565b6104ac565b610445565b610416565b6103d4565b61036c565b6001600160a01b031690565b61030b906102f6565b90565b61031781610302565b0361031e57565b600080fd5b905035906103308261030e565b565b80610317565b9050359061033082610332565b919060408382031261031e5780602061036161030b9386610323565b9401610338565b9052565b3461031e57610399610388610382366004610345565b906111c7565b6040515b9182918290815260200190565b0390f35b6001600160e01b03191690565b6103178161039d565b90503590610330826103aa565b9060208282031261031e5761030b916103b3565b3461031e576103996103ef6103ea3660046103c0565b610fb2565b6040515b91829182901515815260200190565b9060208282031261031e5761030b91610323565b3461031e5761039961038861042c366004610402565b613525565b9060208282031261031e5761030b91610338565b3461031e5761045d610458366004610431565b612bab565b604051005b600091031261031e57565b61047c61030b61030b926102f6565b6102f6565b61030b9061046d565b61030b90610481565b6103689061048a565b6020810192916103309190610493565b3461031e576104bc366004610462565b6103997f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff5b6040519182918261049c565b61030b9160031b1c81565b9061030b91546104ed565b61030b6000606d6104f8565b3461031e5761051f366004610462565b610399610388610503565b60005b83811061053d5750506000910152565b818101518382015260200161052d565b61056e61057760209361058193610562815190565b80835293849260200190565b9586910161052a565b601f01601f191690565b0190565b90602061030b92818152019061054d565b3461031e576103996105b16105ac366004610431565b61111b565b60405191829182610585565b9181601f8401121561031e57823591826001600160401b03811161031e576020908186019501011161031e57565b9160608383031261031e576106008284610338565b9261060e8360208301610338565b9260408201356001600160401b03811161031e5761062c92016105bd565b9091565b3461031e5761045d6106433660046105eb565b92919091615389565b3461031e57610399610388610662366004610431565b61362e565b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b0382111761069e57604052565b610667565b906103306106b060405190565b928361067d565b6001600160401b03811161069e5760051b60200190565b909291926106e36106de826106b7565b6106a3565b93602085838152019160051b83019281841161031e57915b8383106107085750505050565b602080916107168486610338565b8152019201916106fb565b9080601f8301121561031e5781602061030b933591016106ce565b6001600160401b03811161069e57602090601f01601f19160190565b90826000939282370152565b909291926107746106de8261073c565b9182948284528282011161031e576020610330930190610758565b9080601f8301121561031e5781602061030b93359101610764565b91909160a08184031261031e576107c18382610323565b926107cf8160208401610323565b9260408301356001600160401b03811161031e57826107ef918501610721565b9260608101356001600160401b03811161031e578361080f918301610721565b9260808201356001600160401b03811161031e5761030b920161078f565b3461031e5761045d6108403660046107aa565b9392909261147e565b3461031e5761045d61085c366004610402565b611e9b565b3461031e57610871366004610462565b6103997f0000000000000000000000006a72f4f191720c411cd1ff6a5ea8dedec3a647716104e1565b61030b6000606a6104f8565b3461031e576108b6366004610462565b61039961038861089a565b3461031e5761045d6108d4366004610431565b612726565b9060208282031261031e5781356001600160401b03811161031e5761030b920161078f565b3461031e5761045d6109113660046108d9565b61248e565b3461031e57610926366004610462565b61045d613d1c565b3461031e57610399610388610944366004610402565b61278a565b909291926109596106de826106b7565b93602085838152019160051b83019281841161031e57915b83831061097e5750505050565b6020809161098c8486610323565b815201920191610971565b9080601f8301121561031e5781602061030b93359101610949565b91909160408184031261031e5780356001600160401b03811161031e57836109db918301610997565b9260208201356001600160401b03811161031e5761030b9201610721565b90610a19610a12610a08845190565b8084529260200190565b9260200190565b9060005b818110610a2a5750505090565b909192610a47610a406001928651815260200190565b9460200190565b929101610a1d565b90602061030b9281815201906109f9565b3461031e57610399610a7c610a763660046109b2565b90611305565b60405191829182610a4f565b91909160408184031261031e57610a9f8382610323565b9260208201356001600160401b03811161031e5761030b920161078f565b61045d610acb366004610a88565b90612260565b3461031e576103996103ef610ae7366004610431565b611d13565b3461031e57610afc366004610462565b610399610388611dbd565b3461031e57610b17366004610462565b610399610388612781565b3461031e57610b32366004610462565b610399610388612ae1565b3461031e57610b4d366004610462565b6103997f0000000000000000000000005757a514aef25ff8909614489766053400f5de866104e1565b3461031e57610b86366004610462565b6103997f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf202756104e1565b3461031e57610bbf366004610462565b610399610388612b53565b3461031e57610bda366004610462565b6103996103886138f8565b90610bef9061048a565b600052602052604060002090565b6000610c0d61030b92606b610be5565b6104f8565b3461031e57610399610388610c28366004610402565b610bfd565b61030b6000606c6104f8565b3461031e57610c49366004610462565b610399610388610c2d565b3461031e57610399610388610c6a366004610431565b614a4f565b801515610317565b9050359061033082610c6f565b60808183031261031e57610c988282610338565b9261030b610ca98460208501610c77565b9360606103618260408701610338565b9081526040810192916103309160200152565b0152565b3461031e57610cec610ce3366004610c84565b92919091613cc7565b90610399610cf960405190565b92839283610cb9565b919060408382031261031e57806020610d1e61030b9386610323565b9401610c77565b3461031e5761045d610d38366004610d02565b906113a0565b3461031e57610d4e366004610462565b610cec61533a565b909160608284031261031e5761030b610d6f8484610338565b936040610d1e8260208701610338565b3461031e5761045d610d92366004610d56565b91612e8f565b3461031e5761045d610dab366004610431565b612b86565b3461031e57610399610388610dc6366004610431565b611d05565b909160608284031261031e5761030b610de48484610338565b9360406103618260208701610338565b3461031e5761045d610e07366004610dcb565b91612652565b61036890610302565b6020810192916103309190610e0d565b3461031e57610e36366004610462565b610399610e4161272f565b60405191829182610e16565b3461031e57610399610388610e63366004610402565b612b5c565b3461031e57610e78366004610462565b6103997f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b936104e1565b61030b6000606e6104f8565b3461031e57610ebd366004610462565b610399610388610ea1565b3461031e57610399610388610ede366004610431565b61380b565b919060408382031261031e57806020610eff61030b9386610323565b9401610323565b3461031e576103996103ef610f1c366004610ee3565b906113c0565b91909160a08184031261031e57610f398382610323565b92610f478160208401610323565b92610f558260408501610338565b9261080f8360608301610338565b3461031e5761045d610f76366004610f22565b9392909261143a565b3461031e57610f8f366004610462565b61045d613cf3565b3461031e57610fa7366004610462565b610399610e41612758565b610fc2636cdb3d1360e11b61039d565b90610fcc8161039d565b918214918215610fec575b508115610fe2575090565b61030b9150611007565b909150610fff6303a24d0760e21b61039d565b149038610fd7565b61102061101a6301ffc9a760e01b61039d565b9161039d565b1490565b634e487b7160e01b600052602260045260246000fd5b600181811c92911682811561105b575b50602083101461105657565b611024565b607f1692503861104a565b805460009392916110836110798361103a565b8085529360200190565b91600181169081156110d5575060011461109c57505050565b6110af9192939450600052602060002090565b916000925b8184106110c15750500190565b8054848401526020909301926001016110b4565b60ff19168352505090151560051b019150565b9061030b91611066565b906103306110ff60405190565b8061110b8180966110e8565b039061067d565b61030b906110f2565b5061030b6067611112565b61047c61030b61030b9290565b61030b90611126565b1561114357565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b6064820152608490fd5b0390fd5b61030b61030b61030b9290565b90610bef9061119f565b61030b9081565b61030b90546111b6565b611203906111fe61030b936111f76111e76111e26000611133565b610302565b6111f085610302565b141561113c565b60656111ac565b610be5565b6111bd565b1561120f57565b60405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608490fd5b906112736106de836106b7565b918252565b369037565b9061033061128a83611266565b6020819461129a601f19916106b7565b019101611278565b634e487b7160e01b600052601160045260246000fd5b60001981146112c75760010190565b6112a2565b634e487b7160e01b600052603260045260246000fd5b80518210156112f65760209160051b010190565b6112cc565b61030b9051610302565b90611329611311835190565b61132361131f61030b855190565b9190565b14611208565b611339611334835190565b61127d565b91611344600061119f565b61134f61030b835190565b81101561139a578061139061138361137261136d61139595876112e2565b6112fb565b61038261137f85896112e2565b5190565b61138d83886112e2565b52565b6112b8565b611344565b50505090565b6103309190336118a4565b61030b905b60ff1690565b61030b90546113ab565b61030b916111fe6113d2926066610be5565b6113b6565b156113de57565b60405162461bcd60e51b815260206004820152602e60248201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60448201526d195c881bdc88185c1c1c9bdd995960921b6064820152608490fd5b6103309493929190611468335b61145081610302565b61145984610302565b1490811561146d575b506113d7565b61157b565b6114789150836113c0565b38611462565b610330949392919061148f33611447565b6116f4565b1561149b57565b60405162461bcd60e51b815260206004820152602560248201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b156114f557565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60448201526939103a3930b739b332b960b11b6064820152608490fd5b5090565b9061030b61030b6115619261119f565b9055565b9190611570565b9290565b82018092116112c757565b90610330949392916115a36115936111e26000611133565b61159c84610302565b1415611494565b336115c3866115b186611ce1565b6115ba88611ce1565b90868686615061565b6116006115ec866115dc611203866111fe8a60656111ac565b6115e8828210156114ee565b0390565b6115fb846111fe8860656111ac565b611551565b61162a611612846111fe8760656111ac565b6116248761161f836111bd565b611565565b90611551565b6116338161048a565b61163c8361048a565b6116458561048a565b9160008051602061545983398151915261165e60405190565b8061166a8b8b83610cb9565b0390a4611a1f565b1561167957565b60405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608490fd5b90916116e661030b936040845260408401906109f9565b9160208184039101526109f9565b939492919092611719611705835190565b61171361131f61030b875190565b14611672565b6117326117296111e26000611133565b61159c86610302565b3395611742818585888a8c615061565b61174c600061119f565b61175761030b855190565b8110156117c45780611390886116246117b58a6111fe8b6111f761178f61137f8a8f61137f6117bf9e611789926112e2565b946112e2565b966115fb6117a9896115dc611203856111fe8960656111ac565b916111fe8560656111ac565b9161161f836111bd565b61174c565b5093909594610330956117d68161048a565b6117df8361048a565b6117e88561048a565b917f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb61181360405190565b8061181f8b8b836116cf565b0390a4611c41565b1561182e57565b60405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608490fd5b9061189561030b61156192151590565b825460ff191660ff9091161790565b61191861190e6119087f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31936118eb6118db87610302565b6118e483610302565b1415611827565b611903876118fe886111fe856066610be5565b611885565b61048a565b9361048a565b936103f360405190565b0390a3565b90505190610330826103aa565b9060208282031261031e5761030b9161191d565b919361196c60a09461196561030b989761195b8761197397610e0d565b6020870190610e0d565b6040850152565b6060830152565b816080820152019061054d565b6040513d6000823e3d90fd5b60009060033d1161199957565b905060046000803e60005160e01c90565b600060443d1061030b576040513d600319016004823e8051916001600160401b0383113d602485011117611a19578183018051909390916001600160401b038311611a11573d84016003190185840160200111611a11575061030b9291016020019061067d565b949350505050565b92915050565b939491611a2b81611bdd565b611a38575b505050505050565b602094611a70611a4c61190360009461048a565b94611a5660405190565b9889978896879563f23a6e6160e01b87526004870161193e565b03925af160009181611bad575b50611b3f57506001611a8d61198c565b6308c379a014611b0a575b611aa8575b388080808080611a30565b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608490fd5b611b126119aa565b80611b1d5750611a98565b61119b90611b2a60405190565b62461bcd60e51b815291829160048301610585565b611b5261101a63f23a6e6160e01b61039d565b14611a9d5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a204552433131353552656365697665722072656a656374656044820152676420746f6b656e7360c01b6064820152608490fd5b611bcf91925060203d8111611bd6575b611bc7818361067d565b81019061192a565b9038611a7d565b503d611bbd565b3b611beb61131f600061119f565b1190565b939061030b9593611c14611c3394611c0a88611c2595610e0d565b6020880190610e0d565b60a0604087015260a08601906109f9565b9084820360608601526109f9565b91608081840391015261054d565b939491611c4d81611bdd565b611c5957505050505050565b602094611c91611c6d61190360009461048a565b94611c7760405190565b9889978896879563bc197c8160e01b875260048701611bef565b03925af160009181611cc1575b50611cae57506001611a8d61198c565b611b5261101a63bc197c8160e01b61039d565b611cda91925060203d8111611bd657611bc7818361067d565b9038611c9e565b61030b611cf1611334600161119f565b9161138d611cff600061119f565b846112e2565b61120361030b9160686111ac565b611d1c90611d05565b611beb61131f600061119f565b611d6c611d353061048a565b611d67611d617f000000000000000000000000bd51a873900ea1226ab5c95892b2c2388e16e220610302565b91610302565b141590565b611d795761030b90611db4565b604051632e4771e760e21b8152600490fd5b61030b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc61119f565b5061030b611d8b565b61030b6000611d29565b611020611e07611dd63061048a565b611dff7f000000000000000000000000bd51a873900ea1226ab5c95892b2c2388e16e220610302565b928391610302565b611e3957611e1a90611d676111e2611eae565b611e275761033090611e75565b604051631b50ae3760e11b8152600490fd5b604051637170f3db60e01b8152600490fd5b906112736106de8361073c565b90610330611e6583611e4b565b6020819461129a601f199161073c565b600061033091611e84816125d9565b611e95611e908361119f565b611e58565b90611f0b565b61033090611dc7565b61030b9054610302565b61030b611ebc61030b611d8b565b611ea4565b61030b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd914361119f565b9050519061033082610332565b9060208282031261031e5761030b91611eea565b9190611f1b6113d261030b611ec1565b15611f2b57505061033090612004565b611f376119038461048a565b6020611f4260405190565b6352d1902d60e01b815291829060049082905afa60009181611fa8575b50611f775750604051636f5837f160e01b8152600490fd5b611f8990611d6761131f61030b611d8b565b611f96576103309261203e565b6040516304e7393f60e41b8152600490fd5b611fca91925060203d8111611fd1575b611fc2818361067d565b810190611ef7565b9038611f5f565b503d611fb8565b90611fe861030b6115619261048a565b82546001600160a01b0319166001600160a01b03919091161790565b61201461201082611bdd565b1590565b61202c576103309061202761030b611d8b565b611fd8565b60405163075de2d760e51b8152600490fd5b916120488361207d565b815161205761131f600061119f565b11908115612075575b50612069575050565b61207291612113565b50565b905038612060565b61208a9061190381612004565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b6120b460405190565b80805b0390a2565b3d156120d6576120cb3d611e4b565b903d6000602084013e565b606090565b634e487b7160e01b600052602160045260246000fd5b600511156120fb57565b6120db565b90610330826120f1565b61030b90612100565b9061212061201083611bdd565b61214d5760008161030b9360208394519201905af461213d6120bc565b612147600461210a565b9161215f565b60405163ae931db960e01b8152600490fd5b9091901561216b575090565b815161217a61131f600061119f565b11156121895750805190602001fd5b61219661030b600161210a565b819081036121b05760405163014bd73d60e21b8152600490fd5b6121bd61030b600261210a565b81036121d557604051630a4d4fd160e01b8152600490fd5b6121e261030b600361210a565b036121f95760405163166c491f60e11b8152600490fd5b61119b9061220660405190565b632638bfdb60e11b81529182916004830190815260200190565b90611020612230611dd63061048a565b611e395761224390611d676111e2611eae565b611e2757610330916103309160019161225b816125d9565b611f0b565b9061033091612220565b61030b9060081c6113b0565b61030b905461226a565b6113b061030b61030b9290565b6113b061030b61030b9260ff1690565b9061189561030b6115619261228d565b906122bd61030b61156192151590565b825461ff00191660089190911b61ff00161790565b61036890612280565b60208101929161033091906122d2565b6122f86120106000612276565b9081806123e3575b801561239e575b155b61238c5761232f908261232661231f6001612280565b600061229d565b61237b57612431565b61233557565b6123406000806122ad565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249861236a60405190565b806123766001826122db565b0390a1565b612387600160006122ad565b612431565b604051632785437f60e21b8152600490fd5b506123b36120106123ae3061048a565b611bdd565b801561230757506123096123c760006113b6565b6123db6123d46001612280565b9160ff1690565b149050612307565b506123ee60006113b6565b6123fb6123d46001612280565b10612300565b909160608284031261031e5761030b61241a8484611eea565b93604061242a8260208701611eea565b9401611eea565b61247861247f61246e61248693612459612452670de0b6b3a764000061119f565b606a611551565b602080612464835190565b8301019101612401565b939091606f611551565b6070611551565b6071611551565b6103306124bc565b610330906122eb565b6124a46120106000612276565b6124aa57565b60405163dec57a6f60e01b8152600490fd5b610330612497565b7fac1ce290f7f8beba2a3b749ceabee6385de96b5d2625626d6c5d226614ae7fab90565b905051906103308261030e565b9060208282031261031e5761030b916124e8565b5061256860206125387f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf2027561048a565b6125406124c4565b9061254a60405190565b93849283918291636f7a8bad60e01b83526004830190815260200190565b03915afa80156125d457612584916000916125a6575b50610302565b61258d33610302565b0361259457565b604051633b082d6b60e11b8152600490fd5b6125c7915060203d81116125cd575b6125bf818361067d565b8101906124f5565b3861257e565b503d6125b5565b611980565b61033090612509565b919061261260206125387f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf2027561048a565b03915afa80156125d45761262d916000916125a65750610302565b61263633610302565b036125945761033092610330929161247861247f92606f611551565b9061033092916125e2565b61268b60206125387f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf2027561048a565b03915afa80156125d4576126a6916000916125a65750610302565b6126af33610302565b0361259457610330906126f3565b6126ca61030b61030b9290565b6001600160881b031690565b61030b6127106126bd565b61030b9081906001600160881b031681565b6127036126fe6126d6565b6126e1565b811161271457610330906072611551565b6040516309524aff60e41b8152600490fd5b6103309061265d565b61030b7f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff61048a565b61030b7f0000000000000000000000000d1e753a25ebda689453309112904807625befbe61048a565b61030b33612814565b61030b90612814565b919082039182116112c757565b6127ad61030b61030b9290565b6001600160701b031690565b61030b670de0b6b3a76400006127a0565b61030b9081906001600160701b031681565b818102929181159184041417156112c757565b634e487b7160e01b600052601260045260246000fd5b811561280f570490565b6127ef565b90600080926128427f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b602061284d60405190565b635a23248d60e01b815291829060049082905afa80156125d4576128cd91600091612ac3575b50602061289f7f0000000000000000000000000d1e753a25ebda689453309112904807625befbe61048a565b6128a83061048a565b906128b260405190565b948592839182916370a0823160e01b5b835260048301610e16565b03915afa9182156125d45761290c92612902926128f292600092612aa3575b50611565565b6128fc606d6111bd565b90612793565b6128fc606e6111bd565b612915816142e9565b90612929612923606e6111bd565b83611565565b93612934600161119f565b9461293f86866111c7565b9061294a600061119f565b9687821180612a9a575b612a5b575b505050509061296791612793565b6129758161161f606d6111bd565b928061298861298482866111c7565b9590565b1180612a52575b61299a575b50505050565b6129ea926129d4926129ac606c6111bd565b908193806129b78390565b11612a16575b5050506112036129ce91606b610be5565b936127dc565b6129e46129df6127b9565b6127ca565b90612805565b8181116129f9575b8080612994565b612a0e929391612a0891612793565b90611565565b9038806129f2565b6129ce93945091612a08612a4a92612a45612a3361120396611d05565b91612a3f6129df6127b9565b906127dc565b612805565b9291386129bd565b5080841161298f565b6129679594995091612a45612a0892612a3f612a7a612a8f9796611d05565b612a45612a886129df6127b9565b80966127dc565b959091388080612959565b50878311612954565b612abc91925060203d8111611fd157611fc2818361067d565b90386128ec565b612adb915060203d8111611fd157611fc2818361067d565b38612873565b612b0a7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b6020612b1560405190565b635a23248d60e01b815291829060049082905afa9081156125d457600091612b3b575090565b61030b915060203d8111611fd157611fc2818361067d565b61030b336145c1565b61030b906145c1565b61033090612b7b612b76600061119f565b614e6f565b600161033091614410565b61033090612b65565b61033090612ba0612b76600061119f565b600061033091614410565b61033090612b8f565b906103309291612bc7612b76600061119f565b612c88565b6001600160801b031690565b61031781612bcc565b9050519061033082612bd8565b60808183031261031e57612c028282611eea565b9261030b612c138460208501611eea565b936060612c238260408701611eea565b9401612be1565b604090612c4c6103309496959396612c458360608101999052565b6020830152565b0190610e0d565b61030b6000611e4b565b61030b612c53565b604090612c806103309496959396612c458360608101999052565b019015159052565b90600090612c94613dd9565b6080612d6c84612cc37f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff61048a565b612d4c85612cd03061048a565b92612cdd85853384612f6f565b612d067f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b9361048a565b612d1283863384612f6f565b612d47612d3e7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b96878094612ff5565b612ff5565b604051958693849283919063e7d3fe6b60e01b8352888b60048501612c2a565b03925af19081156125d4577fbb85dcf60b5fb7cd8cced6769caa040c05781172b4e8da0f39283e6926dbba2d9360009283948491612e52575b50612df292859285928915612e1157612dd3612dc9612ded92612a3f6129df6127b9565b6129e4606a6111bd565b612ddd600161119f565b90612de6612c5d565b9133612ef0565b6132a5565b6120b7612dfe3361048a565b94612e0860405190565b93849384612c65565b612e3b6129d4612e4992612e31612e28600061119f565b82612de6612c5d565b612a3f606c6111bd565b6116246117b533606b610be5565b612ded33613458565b9050612df2929450612e7c91935060803d8111612e88575b612e74818361067d565b810190612bee565b50909491939192612da5565b503d612e6a565b906103309291612bb4565b15612ea157565b60405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b90610330939291612f016000611133565b612f1d612f0d82610302565b612f1684610302565b1415612e9a565b33611600866115b186611ce1565b612f44612f3e61030b9263ffffffff1690565b60e01b90565b61039d565b604090610ccc6103309496959396612f65836060810199610e0d565b6020830190610e0d565b9091612fb290612fa461033095612f896323b872dd612f2b565b92612f9360405190565b968794602086015260248501612f49565b03601f19810184528361067d565b6130b4565b916020610330929493610ccc816040810197610e0d565b6103689061119f565b916020610330929493612fee816040810197610e0d565b0190612fce565b613027919261303561300a63095ea7b3612f2b565b9161301460405190565b9485918460208401528760248401612fb7565b03601f19810185528461067d565b6130426120108484613226565b61304c5750505050565b61308a93613084612fb292613076600061306560405190565b948593602085015260248401612fd7565b03601f19810183528261067d565b826130b4565b38808080612994565b9050519061033082610c6f565b9060208282031261031e5761030b91613093565b6130c06130c79161048a565b918261312e565b80516130d661131f600061119f565b1415908161310a575b506130e75750565b61119b906130f460405190565b635274afe760e01b815291829160048301610e16565b61312891508060208061311e612010945190565b83010191016130a0565b386130df565b61030b9161313c600061119f565b6131453061048a565b8181311061316f57506000828192602061030b969551920190855af16131696120bc565b91613192565b61119b9061317c60405190565b63cd78605960e01b815291829160048301610e16565b9061319d57506131f7565b6131b86131a8835190565b6131b2600061119f565b91829190565b1490816131ec575b506131c9575090565b61119b906131d660405190565b639996b31560e01b815291829160048301610e16565b9050813b14386131c0565b805161320661131f600061119f565b111561321457805190602001fd5b604051630a12f52160e11b8152600490fd5b6000613232819261048a565b9260208151910182855af1906132466120bc565b82613266575b5081613256575090565b90503b611beb61131f600061119f565b909150613271815190565b61327e61131f600061119f565b1490811561328f575b50903861324c565b61329f915060208061311e835190565b38613287565b916132b1919392612793565b91826132c76132c361030b606f6111bd565b9490565b9384116133a9575b506132da9250612793565b806132eb61156c61030b60706111bd565b9182116132f6575050565b61334e917f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b939060206133278361048a565b6133303061048a565b9061333a60405190565b968792839182916370a0823160e01b6128c2565b03915afa9081156125d45761033094600092613389575b50815b1061337f575b506133789061048a565b3390613426565b915061337861336e565b6133a291925060203d8111611fd157611fc2818361067d565b9038613365565b613400907f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff60206133d98261048a565b6133e23061048a565b906133ec60405190565b958692839182916370a0823160e01b6128c2565b03915afa80156125d4576132da9661342094600092613389575081613368565b386132cf565b612fb261033093612fa461343d63a9059cbb612f2b565b9161344760405190565b958693602085015260248401612fb7565b613462600061119f565b9061346d82826111c7565b90613478828261353e565b92831161348457505050565b61351b6120b7916134cb6134c06129d47f7303a08499b208e2de9337c07f90295d0cdfb47be7a5e16e17edfe957eb65dc096612a3f606c6111bd565b6115fb83606b610be5565b6134e86134e1866134dc606d6111bd565b612793565b606d611551565b61190385826135167f0000000000000000000000000d1e753a25ebda689453309112904807625befbe61048a565b613426565b9261038c60405190565b61030b9061353c613536600061119f565b826111c7565b905b90613549600061119f565b9182821161355657505090565b6129d461356a61120361357593606b610be5565b92612a3f606c6111bd565b81811161358157505090565b61030b9250612793565b9061030b9161359d612b76600061119f565b506135aa90610c6a613cd6565b906135b5600061119f565b80831461362a57506135f16135d7612dc96135d16129df6127b9565b856127dc565b926135ec846135e6600161119f565b336136e9565b613940565b7f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6819361361d3361048a565b926120b7610cf960405190565b9150565b61030b90600061358b565b1561364057565b60405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b1561369857565b60405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608490fd5b6000805160206154598339815191526111fe929361378761378161378187611903613772866137666112038b61371f6000611133565b9d8e9761373e61372e8a610302565b61373785610302565b1415613639565b6111f733809a61374d84611ce1565b6137568a611ce1565b9187613760612c5d565b94615061565b6115e882821015613691565b6115fb896111fe8d60656111ac565b9461048a565b94613794610cf960405190565b0390a4612072612c5d565b9061030b916137b1612b76600061119f565b506137c7906137be613cd6565b610c6a33613458565b906137d6826135e6600061119f565b6137df82613940565b7fc8f4420b387a6a10a91391480c679640ed2e1fc60c9ef3704acbd2d5f033b1ce819361361d3361048a565b61030b90600061379f565b61030b90613827612b76600061119f565b50613830613cd6565b6000908161383e600061119f565b61384881336111c7565b90613853600161119f565b9161385e83336111c7565b938282116138d6575b50506138708390565b116138ad575b505061388182613940565b7f8f420e722d4b21a3e3ef6314f97a0827afa394a45c56d2f53f2b638d1efa845e819361361d3361048a565b6129d4826138c46138ce959694612a0894336136e9565b612a3f606a6111bd565b903880613876565b6138f09296506138e533613458565b61161f8288336136e9565b933880613867565b61030b6000613816565b909160608284031261031e5761030b61391b8484611eea565b936040612c238260208701611eea565b90815260408101929161033091602090612c4c565b906139a6606061396f7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b936139793061048a565b948591600061398760405190565b80968195829461399b63fcd3533c60e01b90565b84526004840161392b565b03925af180156125d457613aeb575b506139df7f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b9361048a565b916139e960405190565b6020816370a0823160e01b958682528180613a078760048301610e16565b03915afa9182156125d457613a7d92602092600091613ace575b50613a2f61030b60706111bd565b8111613abc575b507f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff94613a628661048a565b90613a6c60405190565b809581948293835260048301610e16565b03915afa80156125d45761033091600091613a9e575b50613378819461048a565b613ab6915060203d8111611fd157611fc2818361067d565b38613a93565b6000613ac79161486c565b5038613a36565b613ae59150833d8111611fd157611fc2818361067d565b38613a21565b613b0b9060603d8111613b13575b613b03818361067d565b810190613902565b9150506139b5565b503d613af9565b9061062c9594939291613b30612b76600061119f565b613b62565b610ccc61033094613b5b606094989795613b5285608081019b9052565b15156020850152565b6040830152565b5050906000929493613b72613cd6565b818414613ca6576060613bf2613b946129d4613b8e606a6111bd565b876127dc565b613ba2866135e6600161119f565b613bcb7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b90613bd560405190565b9788938492839190633f34d4cf60e21b835233906004840161392b565b03925af19586156125d4576000948597613c7e575b505b8410908115613c74575b50613c62577f714e31952f7187229250e8ee2874acc655f2f2af3b4609b659d6bd7392a6c19f90613c433361048a565b92613c5b8786613c5260405190565b94859485613b35565b0390a29190565b6040516373bdb3a760e11b8152600490fd5b9050851038613c13565b613c099750613c9c91955060603d8111613b1357613b03818361067d565b5096909490613c07565b613caf33613458565b6060613bf284613cc2866135e68961119f565b613ba2565b61062c93929190600080613b1a565b610330613dd9565b613ceb612b76600061119f565b610330613cd6565b610330613cde565b613d08612b76600061119f565b610330613d13613dd9565b61033033613458565b610330613cfb565b61030b90612bcc565b61030b9054613d24565b613d4461030b61030b9290565b612bcc565b613d4461030b61030b92612bcc565b90613d6861030b61156192613d49565b82546001600160801b0319166001600160801b03919091161790565b7f85bd1d72e7c5b7eca5a1d5e5f606f0ec29133572bd2f25cd91349d23a86d1c2f90565b612c4c61033094613dcf606094989795613dc585608081019b9052565b6020850190610e0d565b6040830190610e0d565b613de36069613d2d565b613dec43613d37565b90613dff613df983612bcc565b91612bcc565b03613e075750565b613e12906069613d58565b613e3b7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b803b1561031e57604051634641257d60e01b815260008160048183865af190816142cb575b506142c657614271565b7f0000000000000000000000000d1e753a25ebda689453309112904807625befbe90613e958261048a565b90613e9f3061048a565b91613ea960405190565b926370a0823160e01b9384815260208180613ec78560048301610e16565b0381865afa9081156125d457613eee9161290291600091614253575b506128fc606d6111bd565b92613ef8846142e9565b94613f11613f0a8761161f606e6111bd565b606e611551565b613f1b606e6111bd565b613f2b61131f61030b60716111bd565b11613f8d575b50505050613f3f9250612793565b613f506134e18261161f606d6111bd565b613f5a600061119f565b90818111613f66575050565b613f7c613f8691612a45612a3361033095611d05565b61161f606c6111bd565b606c611551565b613fc36020613fbb7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf2027561048a565b612540613d84565b03915afa9081156125d457600098614007613ff5613fef61190889966020968f91614236575b5061048a565b9261048a565b9182614001606e6111bd565b91613426565b614011606e6111bd565b907f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff9761403d8961048a565b9b8c9361406661404c60405190565b978896879586946388156e6560e01b865260048601613da8565b03925af180156125d45761421a575b507f762c2dd3d0af24badf328547c5f6d995c8d549bc0a11cf304b6e79816ba867a26140a4610388606e6111bd565b0390a16140b4613f0a600061119f565b60206140bf60405190565b809883825281806140d38860048301610e16565b03915afa9687156125d4576000976141fa575b507f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b9360206141138261048a565b9261411d60405190565b938491825281806141318960048301610e16565b03915afa9081156125d45761417160809685612d47612d479461190361416761418e9f98600099869b8b926141da575b506146ad565b9981988b9761048a565b6040519889958694859363e7d3fe6b60e01b855260048501612c2a565b03925af19283156125d457613f3f936141af916000916141b8575b506143a5565b38808080613f31565b6141d0915060803d8111612e8857612e74818361067d565b90925090506141a9565b6141f391925060203d8111611fd157611fc2818361067d565b9038614161565b61421391975060203d8111611fd157611fc2818361067d565b95386140e6565b6142319060203d8111611fd157611fc2818361067d565b614075565b61424d9150873d81116125cd576125bf818361067d565b38613fe9565b61426b915060203d8111611fd157611fc2818361067d565b38613ee3565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab61429b60405190565b6020808252600e908201526d12185c9d995cdd0811985a5b195960921b6040820152606090a1613e6a565b613e6a565b6142e39060006142db818361067d565b810190610462565b38613e60565b6143127f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b602061431d60405190565b637d59659b60e11b815291829060049082905afa9081156125d457600091614387575b5061434b600061119f565b9061435e61435883611d05565b82612793565b91808214614380575061030b92612a3f612a4592612a45612a886129df6127b9565b9250505090565b61439f915060203d8111611fd157611fc2818361067d565b38614340565b6143b2610dc6600161119f565b906143bd600061119f565b8083119081614406575b506143d0575050565b61033091612a45612452926144016143eb6135d1606a6111bd565b9161161f6143fa6129df6127b9565b8094612805565b6127dc565b90508111386143c7565b614418613dd9565b614422600061119f565b8082146145a5576000906144557f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff61048a565b60806144fe614479846144673061048a565b97614474818a3389612f6f565b6146ad565b9390966144b0886144a97f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b8094612ff5565b6144de8583612d477f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b9361048a565b604051968793849283919063e7d3fe6b60e01b8352888c60048501612c2a565b03925af19384156125d4577f6dbb6056a2fff319358e6dd7d0d72cb3baa992cdcc7e120fb0a32cd1601840e59460009384958592614576575b509285928592612df2958a60001461455f5750612dd3612dc9612ded92612a3f6129df6127b9565b6129d482612e31612e3b93612e4995612de6612c5d565b909550612df2939450614597915060803d8111612e8857612e74818361067d565b509095919493509085614537565b505050565b61030b6a0c097ce7bc90715b34b9f160241b61119f565b6000806145ce600061119f565b926145e76145dc85836111c7565b91610382600161119f565b91848211614648575b5050826145fa8290565b1161462d575b5081811461154d5761030b9150612a456146256129d461461e614b2a565b90946127dc565b612a3f6145aa565b90612a086129d461464293612a3f606a6111bd565b38614600565b614653929350611565565b9038806145f0565b610317816102f6565b905051906103308261465b565b60808183031261031e576146858282611eea565b9261030b6146968460208501611eea565b9360606146a68260408701613093565b9401614664565b91906146d87f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b9260806146e460405190565b948590635a80abe560e11b82528180614701878760048401610cb9565b03915afa80156125d4576000948591614757575b5061030b929181614729614741938861486c565b96600091156147465761058191506115e8600061119f565b930190565b6115e86147529261119f565b950190565b61030b9392955061474191506147839060803d8111614792575b61477b818361067d565b810190614671565b50919693949192506147159050565b503d614771565b61030b73fffd8963efd1fc6a506488495d951d5263988d26611126565b6147c26147c8916102f6565b916102f6565b9003906001600160a01b0382116112c757565b61030b6401000276a3611126565b6147c26147f5916102f6565b01906001600160a01b0382116112c757565b919060408382031261031e5780602061242a61030b9386611eea565b610368906102f6565b919361485160a09461196561030b976148488761485b97610e0d565b15156020870152565b6060830190614823565b816080820152016000815260200190565b81156149c05761487f61030b606f6111bd565b81106149b45781156149915760406148a86148986147db565b6148a26001611126565b906147e9565b915b6148d37f0000000000000000000000006a72f4f191720c411cd1ff6a5ea8dedec3a6477161048a565b8460006148e86148e23061048a565b94614a2a565b9361490f6148f560405190565b97889687958694630251596160e31b86526004860161482c565b03925af19081156125d45761494292600091829361495f575b501561495057506149389061119f565b6115e8600061119f565b90610330612b7660726111bd565b61495a915061119f565b614938565b909250614983915060403d811161498a575b61497b818361067d565b810190614807565b9138614928565b503d614971565b60406149ae61499e614799565b6149a86001611126565b906147b6565b916148aa565b505061030b600061119f565b61487f61030b60706111bd565b156149d457565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b61030b90614a4a614a42836001600160ff1b0361119f565b8211156149cd565b61119f565b61030b90612a45614a72614a6a614a64614b2a565b946127dc565b6129e46145aa565b612a3f6129df6127b9565b6103178160020b90565b9050519061033082614a7d565b61ffff8116610317565b9050519061033082614a94565b63ffffffff8116610317565b9050519061033082614aab565b60e08183031261031e57614ad88282614664565b92614ae68360208401614a87565b92614af48160408501614a9e565b92614b028260608301614a9e565b9261030b614b138460808501614a9e565b9360c0614b238260a08701614ab7565b9401613093565b6000614b557f0000000000000000000000006a72f4f191720c411cd1ff6a5ea8dedec3a6477161048a565b60e0614b6060405190565b633850c7bd60e01b815291829060049082905afa80156125d457614b8c91600091614c96575b50614ce8565b9182614bb77f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b90614bc160405190565b637d59659b60e11b815290602082600481865afa9182156125d457600092614c76575b50614bef600061119f565b8211614bfa57505050565b90919293506060614c0a60405190565b636253bb0f60e11b815293849060049082905afa9283156125d45761030b93612a4592614a72926000908193614c49575b5061161f91614a6a916127dc565b61161f929350614a6a9150614c6b9060603d8111613b1357613b03818361067d565b509392909150614c3b565b614c8f91925060203d8111611fd157611fc2818361067d565b9038614be4565b614cb7915060e03d8111614cc3575b614caf818361067d565b810190614ac4565b9450614b869350505050565b503d614ca5565b61047c61030b61030b92612bcc565b61030b61030b61030b926102f6565b614cf86001600160801b03614cca565b614d01826102f6565b11614d3657614d1b614d1561030b92614cd9565b806127dc565b614d236145aa565b614d30600160c01b61119f565b91614d75565b614d59614d4561030b92614cd9565b614d52600160401b61119f565b9080614d75565b614d616145aa565b614d30600160801b61119f565b1561031e57565b90919060001983820991838202928380821091030391614d95600061119f565b8390808214614e5a5750948291614db661030b97614db08590565b11614d6e565b09614e52614de5614dcc8419610581600161119f565b8416809404946001858060000304019087851190030290565b93614df7614dfb82614df7600361119f565b0290565b614e4d614e47614e3e614e35614e2c614e23614e17600261119f565b96871889810288030290565b80890287030290565b80880286030290565b80870285030290565b80860284030290565b80940290565b900390565b930304170290565b9295505050614e6b9150614db08490565b0490565b61207290614e9c7f0000000000000000000000005757a514aef25ff8909614489766053400f5de8661048a565b614ecd614eac6353c9d830612f2b565b612fa4614eb860405190565b94859260208401526024830190815260200190565b614f0d565b614edc601e611e4b565b7f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000602082015290565b61030b614ed2565b61030b91614f1b600061119f565b90614f24614f05565b92614f85565b15614f3157565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608490fd5b906000809161030b9594614fa5614f9b3061048a565b8290311015614f2a565b60208251920190855af1614fb76120bc565b91615009565b15614fc457565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b9192901561503b5750815161502161131f600061119f565b1461502a575090565b61503661030b91611bdd565b614fbd565b8290615045825190565b61505261131f600061119f565b1115611b1d5750805190602001fd5b959493929190956150756111e26000611133565b8061507f89610302565b1415806151d3575b615127575b61509583610302565b146150a6575b956103309596615242565b949092936150b4600061119f565b93845b6150c261030b865190565b81101561511b5780866150de61030b61137f6150e8958a6112e2565b146150ed576112b8565b6150b7565b6113906151036129d4612e3161137f858d6112e2565b6116246151118d606b610be5565b916134dc836111bd565b5091959094935061509b565b96939095929491615138600061119f565b96875b61514661030b895190565b8110156151c4578861515e61030b61137f848c6112e2565b146151715761516c906112b8565b61513b565b60405162461bcd60e51b815260206004820152602560248201527f5472616e73666572206f6620746f6b656e2049442030206973206e6f7420616c6044820152641b1bddd95960da1b6064820152608490fd5b5091949790929593965061508c565b50806151de84610302565b1415615087565b156151ec57565b60405162461bcd60e51b815260206004820152602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608490fd5b506152589293959450611dff6111e26000611133565b146152e1575b61526790610302565b1461527157509050565b61527b600061119f565b61528661030b835190565b8110156152db57806113906152a161137f6152d694866112e2565b6115fb6152ce6152b461137f868b6112e2565b6152c26112038560686111ac565b6115e8828210156151e5565b9160686111ac565b61527b565b50509050565b92906152ed600061119f565b6152f861030b855190565b811015615332578061139061531361137f61532d948a6112e2565b6116246117b561532661137f868b6112e2565b60686111ac565b6152ed565b50909261525e565b615342613d84565b9061030b6124c4565b1561535257565b60405162461bcd60e51b815260206004820152600f60248201526e31b0b6363130b1b59031b0b63632b960891b6044820152606490fd5b915091506153cb6153bc6111e27f0000000000000000000000006a72f4f191720c411cd1ff6a5ea8dedec3a6477161048a565b6153c533610302565b1461534b565b6153d5600061119f565b8082131561541d5750610330915061541561540f7f000000000000000000000000176211869ca2b568f2a7d4ee941e073a821ee1ff61048a565b9161119f565b903390613426565b905081136154285750565b6103309061541561540f7f000000000000000000000000a219439258ca9da29e9cc4ce5596924745e12b9361048a56fec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a264697066735822122030d9556f1cbfbebb8ad6127297b596a3c0ff9f5e98febee9da785f2467e0b12464736f6c63430008140033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.